use of com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor in project pinpoint by naver.
the class StreamChannelManagerTest method streamSuccessTest2.
// Client to Server Stream
@Test
public void streamSuccessTest2() 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);
RecordedStreamChannelMessageListener clientListener2 = new RecordedStreamChannelMessageListener(8);
ClientStreamChannel clientStreamChannel2 = testPinpointClient.openStream(new byte[0], clientListener2);
int sendCount = 4;
for (int i = 0; i < sendCount; i++) {
sendRandomBytes(bo);
}
clientListener.getLatch().await();
Assert.assertEquals(sendCount, clientListener.getReceivedMessage().size());
clientStreamChannel.close();
sendCount = 4;
for (int i = 0; i < sendCount; i++) {
sendRandomBytes(bo);
}
clientListener2.getLatch().await();
Assert.assertEquals(sendCount, clientListener.getReceivedMessage().size());
Assert.assertEquals(8, clientListener2.getReceivedMessage().size());
clientStreamChannel2.close();
} finally {
testPinpointClient.closeAll();
testPinpointServerAcceptor.close();
}
}
use of com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor in project pinpoint by naver.
the class PinpointClientFactoryTest method requestAndResponse.
@Test
public void requestAndResponse() throws IOException, InterruptedException {
TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(new TestServerMessageListenerFactory(TestServerMessageListenerFactory.HandshakeType.DUPLEX));
int bindPort = testPinpointServerAcceptor.bind();
try {
PinpointClient client = clientFactory.connect("127.0.0.1", bindPort);
byte[] randomByte = TestByteUtils.createRandomByte(20);
byte[] response = PinpointRPCTestUtils.request(client, randomByte);
Assert.assertArrayEquals(randomByte, response);
PinpointRPCTestUtils.close(client);
} finally {
testPinpointServerAcceptor.close();
}
}
use of com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor in project pinpoint by naver.
the class PinpointClientFactoryTest method sendSync.
@Test
public void sendSync() throws IOException, InterruptedException {
TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor();
int bindPort = testPinpointServerAcceptor.bind();
try {
PinpointClient client = clientFactory.connect("127.0.0.1", bindPort);
logger.debug("send1");
client.send(new byte[20]);
logger.debug("send2");
client.sendSync(new byte[20]);
PinpointRPCTestUtils.close(client);
} finally {
testPinpointServerAcceptor.close();
}
}
use of com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor in project pinpoint by naver.
the class ReconnectTest method scheduledConnect.
@Test
public void scheduledConnect() throws IOException, InterruptedException {
final PinpointClientFactory clientFactory = new DefaultPinpointClientFactory();
clientFactory.setReconnectDelay(200);
PinpointClient client = null;
TestPinpointServerAcceptor testPinpointServerAcceptor = null;
try {
int availableTcpPort = SocketUtils.findAvailableTcpPort(47000);
client = clientFactory.scheduledConnect("localhost", availableTcpPort);
testPinpointServerAcceptor = new TestPinpointServerAcceptor(testServerMessageListenerFactory);
testPinpointServerAcceptor.bind(availableTcpPort);
assertClientConnected(client);
logger.debug("request server");
byte[] randomByte = TestByteUtils.createRandomByte(10);
byte[] response = PinpointRPCTestUtils.request(client, randomByte);
Assert.assertArrayEquals(randomByte, response);
} finally {
PinpointRPCTestUtils.close(client);
clientFactory.release();
TestPinpointServerAcceptor.staticClose(testPinpointServerAcceptor);
}
}
use of com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor in project pinpoint by naver.
the class ReconnectTest method reconnectStressTest.
// it takes very long time.
// @Test
@Ignore
public void reconnectStressTest() throws IOException, InterruptedException {
int count = 3;
ThreadMXBean tbean = ManagementFactory.getThreadMXBean();
int threadCount = tbean.getThreadCount();
for (int i = 0; i < count; i++) {
logger.debug((i + 1) + "th's start.");
TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor();
int bindPort = testPinpointServerAcceptor.bind();
PinpointClient client = clientFactory.connect("localhost", bindPort);
testPinpointServerAcceptor.close();
logger.debug("server.close");
assertClientDisconnected(client);
testPinpointServerAcceptor = new TestPinpointServerAcceptor(testServerMessageListenerFactory);
logger.debug("bind server");
assertClientConnected(client);
logger.debug("request server");
byte[] randomByte = TestByteUtils.createRandomByte(10);
byte[] response = PinpointRPCTestUtils.request(client, randomByte);
Assert.assertArrayEquals(randomByte, response);
PinpointRPCTestUtils.close(client);
testPinpointServerAcceptor.close();
}
Thread.sleep(10000);
Assert.assertEquals(threadCount, tbean.getThreadCount());
}
Aggregations