Search in sources :

Example 1 with ServerMetaData

use of com.navercorp.pinpoint.bootstrap.context.ServerMetaData in project pinpoint by naver.

the class DefaultServerMetaDataHolderTest method testRaceConditionWhenAddingAndInteratingServiceInfo.

@Test
public void testRaceConditionWhenAddingAndInteratingServiceInfo() throws InterruptedException {
    // Given
    final CountDownLatch initLatch = new CountDownLatch(THREAD_COUNT);
    final CountDownLatch startLatch = new CountDownLatch(1);
    final CountDownLatch endLatch = new CountDownLatch(THREAD_COUNT);
    final Queue<Throwable> exceptions = new ConcurrentLinkedQueue<Throwable>();
    final TestableServerMetaDataListener listener = new TestableServerMetaDataListener();
    final ServerMetaDataHolder metaDataContext = new DefaultServerMetaDataHolder(VM_ARGS);
    metaDataContext.addListener(listener);
    metaDataContext.setServerName(SERVER_INFO);
    // When
    final List<ServerMetaData> serverMetaDatas = new Vector<ServerMetaData>(THREAD_COUNT / 2);
    for (int i = 0; i < THREAD_COUNT; ++i) {
        if (i % 2 == 0) {
            final String serviceName = "/name" + i;
            final List<String> serviceLibs = new ArrayList<String>();
            executorService.submit(new Callable<Void>() {

                @Override
                public Void call() throws Exception {
                    initLatch.countDown();
                    try {
                        startLatch.await();
                        metaDataContext.addServiceInfo(serviceName, serviceLibs);
                        metaDataContext.notifyListeners();
                    } catch (Throwable t) {
                        exceptions.add(t);
                    } finally {
                        endLatch.countDown();
                    }
                    return null;
                }
            });
        } else {
            executorService.submit(new Callable<Void>() {

                @Override
                public Void call() throws Exception {
                    initLatch.countDown();
                    try {
                        startLatch.await();
                        ServerMetaData serverMetaData = listener.getServerMetaData();
                        serverMetaDatas.add(serverMetaData);
                    } catch (Throwable t) {
                        exceptions.add(t);
                    } finally {
                        endLatch.countDown();
                    }
                    return null;
                }
            });
        }
    }
    initLatch.await();
    startLatch.countDown();
    endLatch.await();
    // Then
    assertTrue("Failed with exceptions : " + exceptions, exceptions.isEmpty());
    ServerMetaData metaData = listener.getServerMetaData();
    assertEquals(metaData.getServerInfo(), SERVER_INFO);
    assertEquals(metaData.getVmArgs(), VM_ARGS);
    assertEquals(metaData.getServiceInfos().size(), THREAD_COUNT / 2);
    assertEquals(serverMetaDatas.size(), THREAD_COUNT / 2);
}
Also used : ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) ServerMetaDataHolder(com.navercorp.pinpoint.bootstrap.context.ServerMetaDataHolder) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Vector(java.util.Vector) ServerMetaData(com.navercorp.pinpoint.bootstrap.context.ServerMetaData) Test(org.junit.Test)

Example 2 with ServerMetaData

use of com.navercorp.pinpoint.bootstrap.context.ServerMetaData in project pinpoint by naver.

the class StandardServiceModifierTest method startShouldCollectServerInfo.

@Test
public void startShouldCollectServerInfo() throws Exception {
    // Given
    String expectedServerInfo = ServerInfo.getServerInfo();
    // When
    service.start();
    service.stop();
    // Then
    ServerMetaData serverMetaData = getServerMetaData();
    assertEquals(serverMetaData.getServerInfo(), expectedServerInfo);
}
Also used : ServerMetaData(com.navercorp.pinpoint.bootstrap.context.ServerMetaData) BasePinpointTest(com.navercorp.pinpoint.test.junit4.BasePinpointTest) Test(org.junit.Test)

Example 3 with ServerMetaData

use of com.navercorp.pinpoint.bootstrap.context.ServerMetaData in project pinpoint by naver.

the class DefaultServerMetaDataHolderTest method testRaceConditionWhenAddingServiceInfo.

@Test
public void testRaceConditionWhenAddingServiceInfo() throws InterruptedException {
    // Given
    final CountDownLatch initLatch = new CountDownLatch(THREAD_COUNT);
    final CountDownLatch startLatch = new CountDownLatch(1);
    final CountDownLatch endLatch = new CountDownLatch(THREAD_COUNT);
    final Queue<Throwable> exceptions = new ConcurrentLinkedQueue<Throwable>();
    final String serviceName = "/test";
    final TestableServerMetaDataListener listener = new TestableServerMetaDataListener();
    final ServerMetaDataHolder metaDataContext = new DefaultServerMetaDataHolder(VM_ARGS);
    metaDataContext.addListener(listener);
    metaDataContext.setServerName(SERVER_INFO);
    // When
    for (int i = 0; i < THREAD_COUNT; ++i) {
        final List<String> serviceLibs = new ArrayList<String>();
        executorService.submit(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                initLatch.countDown();
                try {
                    startLatch.await();
                    metaDataContext.addServiceInfo(serviceName, serviceLibs);
                    metaDataContext.notifyListeners();
                } catch (final Throwable t) {
                    exceptions.add(t);
                } finally {
                    endLatch.countDown();
                }
                return null;
            }
        });
    }
    initLatch.await();
    startLatch.countDown();
    endLatch.await();
    // Then
    assertTrue("Failed with exceptions : " + exceptions, exceptions.isEmpty());
    ServerMetaData metaData = listener.getServerMetaData();
    assertEquals(metaData.getServerInfo(), SERVER_INFO);
    assertEquals(metaData.getVmArgs(), VM_ARGS);
    assertEquals(metaData.getServiceInfos().size(), THREAD_COUNT);
}
Also used : ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) ServerMetaDataHolder(com.navercorp.pinpoint.bootstrap.context.ServerMetaDataHolder) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) ServerMetaData(com.navercorp.pinpoint.bootstrap.context.ServerMetaData) Test(org.junit.Test)

Example 4 with ServerMetaData

use of com.navercorp.pinpoint.bootstrap.context.ServerMetaData in project pinpoint by naver.

the class AgentInfoSenderTest method serverMetaDataShouldBeSentOnPublish.

@Test
public void serverMetaDataShouldBeSentOnPublish() throws InterruptedException {
    // Given
    final AtomicInteger requestCount = new AtomicInteger();
    final AtomicInteger successCount = new AtomicInteger();
    final long agentInfoSendRetryIntervalMs = 1000L;
    ResponseServerMessageListener serverListener = new ResponseServerMessageListener(requestCount, successCount);
    PinpointServerAcceptor serverAcceptor = createServerAcceptor(serverListener);
    PinpointClientFactory clientFactory = createPinpointClientFactory();
    PinpointClient pinpointClient = ClientFactoryUtils.createPinpointClient(HOST, PORT, clientFactory);
    TcpDataSender dataSender = new TcpDataSender(pinpointClient);
    AgentInfoSender agentInfoSender = new AgentInfoSender.Builder(dataSender, getAgentInfo()).sendInterval(agentInfoSendRetryIntervalMs).build();
    final List<ServerMetaData> serverMetaDataObjects = new ArrayList<ServerMetaData>();
    serverMetaDataObjects.add(new DefaultServerMetaData("server1", Collections.<String>emptyList(), Collections.<Integer, String>emptyMap(), Collections.<ServiceInfo>emptyList()));
    serverMetaDataObjects.add(new DefaultServerMetaData("server2", Collections.<String>emptyList(), Collections.<Integer, String>emptyMap(), Collections.<ServiceInfo>emptyList()));
    serverMetaDataObjects.add(new DefaultServerMetaData("server3", Collections.<String>emptyList(), Collections.<Integer, String>emptyMap(), Collections.<ServiceInfo>emptyList()));
    serverMetaDataObjects.add(new DefaultServerMetaData("server4", Collections.<String>emptyList(), Collections.<Integer, String>emptyMap(), Collections.<ServiceInfo>emptyList()));
    serverMetaDataObjects.add(new DefaultServerMetaData("server5", Collections.<String>emptyList(), Collections.<Integer, String>emptyMap(), Collections.<ServiceInfo>emptyList()));
    // When
    try {
        for (ServerMetaData serverMetaData : serverMetaDataObjects) {
            agentInfoSender.publishServerMetaData(serverMetaData);
        }
        waitExpectedRequestCount(requestCount, 5);
    } finally {
        closeAll(serverAcceptor, agentInfoSender, pinpointClient, clientFactory);
    }
    // Then
    assertEquals(5, requestCount.get());
    assertEquals(5, successCount.get());
}
Also used : PinpointClient(com.navercorp.pinpoint.rpc.client.PinpointClient) ArrayList(java.util.ArrayList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ServiceInfo(com.navercorp.pinpoint.bootstrap.context.ServiceInfo) PinpointClientFactory(com.navercorp.pinpoint.rpc.client.PinpointClientFactory) DefaultPinpointClientFactory(com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PinpointServerAcceptor(com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor) TcpDataSender(com.navercorp.pinpoint.profiler.sender.TcpDataSender) DefaultServerMetaData(com.navercorp.pinpoint.profiler.context.DefaultServerMetaData) ServerMetaData(com.navercorp.pinpoint.bootstrap.context.ServerMetaData) DefaultServerMetaData(com.navercorp.pinpoint.profiler.context.DefaultServerMetaData) Test(org.junit.Test)

Aggregations

ServerMetaData (com.navercorp.pinpoint.bootstrap.context.ServerMetaData)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 ServerMetaDataHolder (com.navercorp.pinpoint.bootstrap.context.ServerMetaDataHolder)2 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ServiceInfo (com.navercorp.pinpoint.bootstrap.context.ServiceInfo)1 DefaultServerMetaData (com.navercorp.pinpoint.profiler.context.DefaultServerMetaData)1 TcpDataSender (com.navercorp.pinpoint.profiler.sender.TcpDataSender)1 DefaultPinpointClientFactory (com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory)1 PinpointClient (com.navercorp.pinpoint.rpc.client.PinpointClient)1 PinpointClientFactory (com.navercorp.pinpoint.rpc.client.PinpointClientFactory)1 PinpointServerAcceptor (com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor)1 BasePinpointTest (com.navercorp.pinpoint.test.junit4.BasePinpointTest)1 Vector (java.util.Vector)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1