use of com.navercorp.pinpoint.rpc.RecordedStreamChannelMessageListener in project pinpoint by naver.
the class StreamChannelTest method testName.
@Test(expected = StreamException.class)
public void testName() throws Exception {
Channel mockChannel = Mockito.mock(Channel.class);
Mockito.when(mockChannel.write(Mockito.any())).thenReturn(null);
RecordedStreamChannelMessageListener recordEventHandler = new RecordedStreamChannelMessageListener(0);
NettyClientStreamChannel sc = new NettyClientStreamChannel(mockChannel, 1, new StreamChannelRepository(), recordEventHandler);
sc.init();
Assert.assertEquals(StreamChannelStateCode.OPEN, recordEventHandler.getCurrentState());
sc.connectAndAwait(new byte[0], 3000);
}
use of com.navercorp.pinpoint.rpc.RecordedStreamChannelMessageListener in project pinpoint by naver.
the class StreamChannelManagerTest method streamClosedTest3.
// ServerSocket to Client Stream
// ServerStreamChannel first close.
@Test(expected = PinpointSocketException.class)
public void streamClosedTest3() throws IOException, InterruptedException, StreamException {
TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(testServerMessageListenerFactory);
int bindPort = testPinpointServerAcceptor.bind();
SimpleStreamBO bo = new SimpleStreamBO();
ServerListener serverStreamChannelMessageHandler = new ServerListener(bo);
TestPinpointClient testPinpointClient = new TestPinpointClient(SimpleMessageListener.INSTANCE, serverStreamChannelMessageHandler);
testPinpointClient.connect(bindPort);
try {
testPinpointServerAcceptor.assertAwaitClientConnected(1000);
List<PinpointSocket> writableServerList = testPinpointServerAcceptor.getConnectedPinpointSocketList();
Assert.assertEquals(1, writableServerList.size());
PinpointSocket writableServer = writableServerList.get(0);
if (writableServer instanceof PinpointServer) {
RecordedStreamChannelMessageListener clientListener = new RecordedStreamChannelMessageListener(4);
ClientStreamChannel clientStreamChannel = ((PinpointServer) writableServer).openStreamAndAwait(new byte[0], clientListener, 3000);
StreamChannel streamChannel = serverStreamChannelMessageHandler.bo.serverStreamChannelList.get(0);
streamChannel.close();
sendRandomBytes(bo);
Thread.sleep(100);
clientStreamChannel.close();
} else {
Assert.fail();
}
} finally {
testPinpointClient.closeAll();
testPinpointServerAcceptor.close();
}
}
use of com.navercorp.pinpoint.rpc.RecordedStreamChannelMessageListener in project pinpoint by naver.
the class StreamChannelManagerTest method streamSuccessTest3.
@Test
public void streamSuccessTest3() throws IOException, InterruptedException, StreamException {
TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(testServerMessageListenerFactory);
int bindPort = testPinpointServerAcceptor.bind();
SimpleStreamBO bo = new SimpleStreamBO();
TestPinpointClient testPinpointClient = new TestPinpointClient(SimpleMessageListener.INSTANCE, new ServerListener(bo));
try {
testPinpointClient.connect(bindPort);
testPinpointServerAcceptor.assertAwaitClientConnected(1000);
List<PinpointSocket> writableServerList = testPinpointServerAcceptor.getConnectedPinpointSocketList();
Assert.assertEquals(1, writableServerList.size());
PinpointSocket writableServer = writableServerList.get(0);
RecordedStreamChannelMessageListener clientListener = new RecordedStreamChannelMessageListener(4);
if (writableServer instanceof PinpointServer) {
ClientStreamChannel clientStreamChannel = ((PinpointServer) writableServer).openStreamAndAwait(new byte[0], clientListener, 3000);
int sendCount = 4;
for (int i = 0; i < sendCount; i++) {
sendRandomBytes(bo);
}
clientListener.getLatch().await();
Assert.assertEquals(sendCount, clientListener.getReceivedMessage().size());
clientStreamChannel.close();
} else {
Assert.fail();
}
} finally {
testPinpointClient.closeAll();
testPinpointServerAcceptor.close();
}
}
use of com.navercorp.pinpoint.rpc.RecordedStreamChannelMessageListener in project pinpoint by naver.
the class StreamChannelManagerTest method streamSuccessTest1.
// Client to Server Stream
@Test
public void streamSuccessTest1() throws IOException, InterruptedException, StreamException {
SimpleStreamBO bo = new SimpleStreamBO();
TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(testServerMessageListenerFactory, new ServerListener(bo));
int bindPort = testPinpointServerAcceptor.bind();
TestPinpointClient testPinpointClient = new TestPinpointClient();
try {
testPinpointClient.connect(bindPort);
RecordedStreamChannelMessageListener clientListener = new RecordedStreamChannelMessageListener(4);
ClientStreamChannel clientStreamChannel = testPinpointClient.openStream(new byte[0], clientListener);
int sendCount = 4;
for (int i = 0; i < sendCount; i++) {
sendRandomBytes(bo);
}
clientListener.getLatch().await();
Assert.assertEquals(sendCount, clientListener.getReceivedMessage().size());
clientStreamChannel.close();
} finally {
testPinpointClient.closeAll();
testPinpointServerAcceptor.close();
}
}
use of com.navercorp.pinpoint.rpc.RecordedStreamChannelMessageListener in project pinpoint by naver.
the class StreamChannelManagerTest method streamClosedTest2.
@Test
public void streamClosedTest2() throws IOException, InterruptedException, StreamException {
final SimpleStreamBO bo = new SimpleStreamBO();
TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(testServerMessageListenerFactory, new ServerListener(bo));
int bindPort = testPinpointServerAcceptor.bind();
TestPinpointClient testPinpointClient = new TestPinpointClient();
try {
testPinpointClient.connect(bindPort);
RecordedStreamChannelMessageListener clientListener = new RecordedStreamChannelMessageListener(4);
ClientStreamChannel clientStreamChannel = testPinpointClient.openStream(new byte[0], clientListener);
Assert.assertEquals(1, bo.getStreamChannelContextSize());
clientStreamChannel.close();
Awaitility.await().until(new Callable<Integer>() {
@Override
public Integer call() throws Exception {
return bo.getStreamChannelContextSize();
}
}, is(0));
Assert.assertEquals(0, bo.getStreamChannelContextSize());
} finally {
testPinpointClient.closeAll();
testPinpointServerAcceptor.close();
}
}
Aggregations