use of com.navercorp.pinpoint.rpc.stream.StreamChannelRepository in project pinpoint by naver.
the class GrpcClientStreamChannelTest method connectTimeoutTest.
@Test
public void connectTimeoutTest() throws StreamException {
GrpcClientStreamChannel grpcClientStreamChannel = new GrpcClientStreamChannel(mockRemoteAddress, 20, new StreamChannelRepository(), ClientStreamChannelEventHandler.DISABLED_INSTANCE);
grpcClientStreamChannel.init();
StreamException streamException = null;
try {
grpcClientStreamChannel.connect(new Runnable() {
@Override
public void run() {
}
}, 500);
} catch (StreamException e) {
streamException = e;
}
Assert.assertEquals(StreamCode.CONNECTION_TIMEOUT, streamException.getStreamCode());
Assert.assertEquals(StreamChannelStateCode.CLOSED, grpcClientStreamChannel.getCurrentState());
}
use of com.navercorp.pinpoint.rpc.stream.StreamChannelRepository in project pinpoint by naver.
the class GrpcClientStreamChannelTest method connectFailTest.
@Test
public void connectFailTest() throws StreamException {
GrpcClientStreamChannel grpcClientStreamChannel = new GrpcClientStreamChannel(mockRemoteAddress, 20, new StreamChannelRepository(), ClientStreamChannelEventHandler.DISABLED_INSTANCE);
grpcClientStreamChannel.init();
StreamException streamException = null;
try {
grpcClientStreamChannel.connect(new Runnable() {
@Override
public void run() {
throw new IllegalStateException("fail");
}
}, 500);
} catch (StreamException e) {
streamException = e;
}
Assert.assertEquals(StreamCode.CONNECTION_ERRROR, streamException.getStreamCode());
Assert.assertEquals(StreamChannelStateCode.CLOSED, grpcClientStreamChannel.getCurrentState());
}
use of com.navercorp.pinpoint.rpc.stream.StreamChannelRepository in project pinpoint by naver.
the class GrpcClientStreamChannelTest method simpleTest.
@Test
public void simpleTest() throws StreamException, InterruptedException {
StreamChannelRepository streamChannelRepository = new StreamChannelRepository();
RecordClientStreamChannelEventHandler recordStreamChannelHandler = new RecordClientStreamChannelEventHandler();
GrpcClientStreamChannel grpcClientStreamChannel = new GrpcClientStreamChannel(mockRemoteAddress, 20, streamChannelRepository, recordStreamChannelHandler);
Assert.assertEquals(StreamChannelStateCode.NEW, grpcClientStreamChannel.getCurrentState());
grpcClientStreamChannel.init();
Assert.assertEquals(StreamChannelStateCode.OPEN, grpcClientStreamChannel.getCurrentState());
Assert.assertEquals(1, streamChannelRepository.size());
CountDownLatch connectCompleteLatch = new CountDownLatch(1);
CountDownLatch threadCompleteLatch = connect(grpcClientStreamChannel, connectCompleteLatch);
final AtomicInteger callCompletedCount = new AtomicInteger(0);
grpcClientStreamChannel.setConnectionObserver(new StreamObserver<Empty>() {
@Override
public void onNext(Empty value) {
}
@Override
public void onError(Throwable t) {
}
@Override
public void onCompleted() {
callCompletedCount.incrementAndGet();
}
});
Assert.assertTrue(connectCompleteLatch.await(1000, TimeUnit.MILLISECONDS));
Assert.assertEquals(StreamChannelStateCode.CONNECT_AWAIT, grpcClientStreamChannel.getCurrentState());
grpcClientStreamChannel.changeStateConnected();
Assert.assertEquals(StreamChannelStateCode.CONNECTED, grpcClientStreamChannel.getCurrentState());
Assert.assertTrue(threadCompleteLatch.await(1000, TimeUnit.MILLISECONDS));
String message = "hello";
grpcClientStreamChannel.handleStreamResponsePacket(new StreamResponsePacket(1, message.getBytes()));
Assert.assertEquals(message, new String(recordStreamChannelHandler.getLastStreamResponsePacket().getPayload()));
Assert.assertEquals(0, callCompletedCount.get());
grpcClientStreamChannel.handleStreamClosePacket(new StreamClosePacket(1, StreamCode.STATE_CLOSED));
Assert.assertEquals(0, streamChannelRepository.size());
Assert.assertEquals(StreamChannelStateCode.CLOSED, grpcClientStreamChannel.getCurrentState());
Assert.assertEquals(1, callCompletedCount.get());
// do nothing
grpcClientStreamChannel.disconnect();
Assert.assertEquals(1, callCompletedCount.get());
grpcClientStreamChannel.close();
Assert.assertEquals(1, callCompletedCount.get());
}
use of com.navercorp.pinpoint.rpc.stream.StreamChannelRepository in project pinpoint by pinpoint-apm.
the class GrpcClientStreamChannelTest method connectFailTest.
@Test
public void connectFailTest() throws StreamException {
GrpcClientStreamChannel grpcClientStreamChannel = new GrpcClientStreamChannel(mockRemoteAddress, 20, new StreamChannelRepository(), ClientStreamChannelEventHandler.DISABLED_INSTANCE);
grpcClientStreamChannel.init();
StreamException streamException = null;
try {
grpcClientStreamChannel.connect(new Runnable() {
@Override
public void run() {
throw new IllegalStateException("fail");
}
}, 500);
} catch (StreamException e) {
streamException = e;
}
Assert.assertEquals(StreamCode.CONNECTION_ERRROR, streamException.getStreamCode());
Assert.assertEquals(StreamChannelStateCode.CLOSED, grpcClientStreamChannel.getCurrentState());
}
use of com.navercorp.pinpoint.rpc.stream.StreamChannelRepository in project pinpoint by pinpoint-apm.
the class GrpcClientStreamChannelTest method simpleTest.
@Test
public void simpleTest() throws StreamException, InterruptedException {
StreamChannelRepository streamChannelRepository = new StreamChannelRepository();
RecordClientStreamChannelEventHandler recordStreamChannelHandler = new RecordClientStreamChannelEventHandler();
GrpcClientStreamChannel grpcClientStreamChannel = new GrpcClientStreamChannel(mockRemoteAddress, 20, streamChannelRepository, recordStreamChannelHandler);
Assert.assertEquals(StreamChannelStateCode.NEW, grpcClientStreamChannel.getCurrentState());
grpcClientStreamChannel.init();
Assert.assertEquals(StreamChannelStateCode.OPEN, grpcClientStreamChannel.getCurrentState());
Assert.assertEquals(1, streamChannelRepository.size());
CountDownLatch connectCompleteLatch = new CountDownLatch(1);
CountDownLatch threadCompleteLatch = connect(grpcClientStreamChannel, connectCompleteLatch);
final AtomicInteger callCompletedCount = new AtomicInteger(0);
grpcClientStreamChannel.setConnectionObserver(new StreamObserver<Empty>() {
@Override
public void onNext(Empty value) {
}
@Override
public void onError(Throwable t) {
}
@Override
public void onCompleted() {
callCompletedCount.incrementAndGet();
}
});
Assert.assertTrue(connectCompleteLatch.await(1000, TimeUnit.MILLISECONDS));
Assert.assertEquals(StreamChannelStateCode.CONNECT_AWAIT, grpcClientStreamChannel.getCurrentState());
grpcClientStreamChannel.changeStateConnected();
Assert.assertEquals(StreamChannelStateCode.CONNECTED, grpcClientStreamChannel.getCurrentState());
Assert.assertTrue(threadCompleteLatch.await(1000, TimeUnit.MILLISECONDS));
String message = "hello";
grpcClientStreamChannel.handleStreamResponsePacket(new StreamResponsePacket(1, message.getBytes()));
Assert.assertEquals(message, new String(recordStreamChannelHandler.getLastStreamResponsePacket().getPayload()));
Assert.assertEquals(0, callCompletedCount.get());
grpcClientStreamChannel.handleStreamClosePacket(new StreamClosePacket(1, StreamCode.STATE_CLOSED));
Assert.assertEquals(0, streamChannelRepository.size());
Assert.assertEquals(StreamChannelStateCode.CLOSED, grpcClientStreamChannel.getCurrentState());
Assert.assertEquals(1, callCompletedCount.get());
// do nothing
grpcClientStreamChannel.disconnect();
Assert.assertEquals(1, callCompletedCount.get());
grpcClientStreamChannel.close();
Assert.assertEquals(1, callCompletedCount.get());
}
Aggregations