use of com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor in project pinpoint by naver.
the class AgentInfoSenderTest method agentInfoShouldInitiallyRetryIndefinitely.
@Test
public void agentInfoShouldInitiallyRetryIndefinitely() throws InterruptedException {
final AtomicInteger requestCount = new AtomicInteger();
final AtomicInteger successCount = new AtomicInteger();
final long agentInfoSendRetryIntervalMs = 100L;
final int expectedTriesUntilSuccess = AgentInfoSender.DEFAULT_MAX_TRY_COUNT_PER_ATTEMPT * 5;
ResponseServerMessageListener serverListener = new ResponseServerMessageListener(requestCount, successCount, expectedTriesUntilSuccess);
PinpointServerAcceptor serverAcceptor = createServerAcceptor(serverListener);
PinpointClientFactory socketFactory = createPinpointClientFactory();
PinpointClient pinpointClient = ClientFactoryUtils.createPinpointClient(HOST, PORT, socketFactory);
TcpDataSender dataSender = new TcpDataSender(pinpointClient);
AgentInfoSender agentInfoSender = new AgentInfoSender.Builder(dataSender, getAgentInfo()).sendInterval(agentInfoSendRetryIntervalMs).build();
try {
agentInfoSender.start();
waitExpectedRequestCount(requestCount, expectedTriesUntilSuccess);
} finally {
closeAll(serverAcceptor, agentInfoSender, pinpointClient, socketFactory);
}
assertEquals(expectedTriesUntilSuccess, requestCount.get());
assertEquals(1, successCount.get());
}
use of com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor in project pinpoint by naver.
the class ClassPreLoader method preload.
public static void preload(int port) {
PinpointServerAcceptor serverAcceptor = null;
PinpointClient client = null;
PinpointClientFactory clientFactory = null;
try {
serverAcceptor = new PinpointServerAcceptor();
serverAcceptor.bind("127.0.0.1", port);
clientFactory = new DefaultPinpointClientFactory();
client = clientFactory.connect("127.0.0.1", port);
client.sendSync(new byte[0]);
} catch (Exception ex) {
System.err.print("preLoad error Caused:" + ex.getMessage());
ex.printStackTrace();
final Logger logger = LoggerFactory.getLogger(ClassPreLoader.class);
logger.warn("preLoad error Caused:{}", ex.getMessage(), ex);
if (ex instanceof PinpointSocketException) {
throw (PinpointSocketException) ex;
} else {
throw new PinpointSocketException(ex.getMessage(), ex);
}
} finally {
if (client != null) {
try {
client.close();
} catch (Exception e) {
e.printStackTrace();
}
}
if (clientFactory != null) {
try {
clientFactory.release();
} catch (Exception e) {
e.printStackTrace();
}
}
if (serverAcceptor != null) {
try {
serverAcceptor.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
use of com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor in project pinpoint by naver.
the class PinpointClientStateTest method closeStateTest.
@Test
public void closeStateTest() throws InterruptedException {
PinpointServerAcceptor serverAcceptor = null;
PinpointClientFactory clientSocketFactory = null;
DefaultPinpointClientHandler handler = null;
try {
serverAcceptor = PinpointRPCTestUtils.createPinpointServerFactory(bindPort, PinpointRPCTestUtils.createEchoServerListener());
clientSocketFactory = PinpointRPCTestUtils.createClientFactory(PinpointRPCTestUtils.getParams(), PinpointRPCTestUtils.createEchoClientListener());
handler = connect(clientSocketFactory);
assertHandlerState(SocketStateCode.RUN_DUPLEX, handler);
handler.close();
assertHandlerState(SocketStateCode.CLOSED_BY_CLIENT, handler);
} finally {
closeHandler(handler);
closeSocketFactory(clientSocketFactory);
PinpointRPCTestUtils.close(serverAcceptor);
}
}
use of com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor in project pinpoint by naver.
the class PinpointClientStateTest method unexpectedCloseByPeerStateTest.
@Test
public void unexpectedCloseByPeerStateTest() throws InterruptedException {
PinpointServerAcceptor serverAcceptor = null;
PinpointClientFactory clientFactory = null;
DefaultPinpointClientHandler handler = null;
try {
serverAcceptor = PinpointRPCTestUtils.createPinpointServerFactory(bindPort, PinpointRPCTestUtils.createEchoServerListener());
clientFactory = PinpointRPCTestUtils.createClientFactory(PinpointRPCTestUtils.getParams(), PinpointRPCTestUtils.createEchoClientListener());
handler = connect(clientFactory);
assertHandlerState(SocketStateCode.RUN_DUPLEX, handler);
List<PinpointSocket> pinpointServerList = serverAcceptor.getWritableSocketList();
PinpointSocket pinpointServer = pinpointServerList.get(0);
((DefaultPinpointServer) pinpointServer).stop(true);
assertHandlerState(SocketStateCode.UNEXPECTED_CLOSE_BY_SERVER, handler);
} finally {
closeHandler(handler);
closeSocketFactory(clientFactory);
PinpointRPCTestUtils.close(serverAcceptor);
}
}
use of com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor in project pinpoint by naver.
the class ReconnectTest method serverCloseAndWrite.
@Test
public void serverCloseAndWrite() throws IOException, InterruptedException {
// when abnormal case in which server has been closed first, confirm that a client socket should be closed properly.
PinpointServerAcceptor serverAcceptor = PinpointRPCTestUtils.createPinpointServerFactory(bindPort);
PinpointClient client = clientFactory.connect("127.0.0.1", bindPort);
// just close server and request
PinpointRPCTestUtils.close(serverAcceptor);
byte[] randomByte = TestByteUtils.createRandomByte(10);
Future<ResponseMessage> response = client.request(randomByte);
response.await();
try {
response.getResult();
Assert.fail("expected exception");
} catch (Exception e) {
}
assertClientDisconnected(client);
PinpointRPCTestUtils.close(client);
}
Aggregations