Search in sources :

Example 1 with NIOLooper

use of org.apache.heron.common.basics.NIOLooper in project heron by twitter.

the class HeronServerTest method before.

@Before
public void before() throws IOException {
    // Get an available port
    int serverPort = SysUtils.getFreePort();
    serverOnConnectSignal = new CountDownLatch(1);
    serverOnMessageSignal = new CountDownLatch(TOTAL_MESSAGES);
    serverOnRequestSignal = new CountDownLatch(1);
    clientOnConnectSignal = new CountDownLatch(1);
    clientOnResponseSignal = new CountDownLatch(1);
    heronServer = new SimpleHeronServer(new NIOLooper(), HeronServerTester.SERVER_HOST, serverPort, serverOnConnectSignal, serverOnMessageSignal, serverOnRequestSignal);
    heronClient = new SimpleHeronClient(new NIOLooper(), HeronServerTester.SERVER_HOST, serverPort, clientOnConnectSignal, clientOnResponseSignal);
    heronServerTester = new HeronServerTester(heronServer, heronClient);
}
Also used : NIOLooper(org.apache.heron.common.basics.NIOLooper) CountDownLatch(java.util.concurrent.CountDownLatch) HeronServerTester(org.apache.heron.common.testhelpers.HeronServerTester) Before(org.junit.Before)

Example 2 with NIOLooper

use of org.apache.heron.common.basics.NIOLooper in project heron by twitter.

the class MetricsCacheTest method testMetricCache.

@Test
public void testMetricCache() throws IOException {
    // prepare config files
    SystemConfig systemConfig = SystemConfig.newBuilder(true).putAll(CONFIG_SYSTEM_PATH, true).build();
    MetricsSinksConfig sinksConfig = new MetricsSinksConfig(CONFIG_SINK_PATH, null);
    // initialize metric cache, except looper
    MetricsCache mc = new MetricsCache(systemConfig, sinksConfig, new NIOLooper());
    mc.addMetrics(TopologyManager.PublishMetrics.newBuilder().addMetrics(TopologyManager.MetricDatum.newBuilder().setComponentName("c1").setInstanceId("i1").setName("__jvm-uptime-secs").setTimestamp(System.currentTimeMillis()).setValue("0.1")).addExceptions(TopologyManager.TmanagerExceptionLog.newBuilder().setComponentName("c1").setHostname("h1").setInstanceId("i1").setStacktrace("s1").setLogging("l1").setCount(1).setFirsttime(String.valueOf(System.currentTimeMillis())).setLasttime(String.valueOf(System.currentTimeMillis()))).build());
    // query last 10 seconds
    TopologyManager.MetricResponse response = mc.getMetrics(TopologyManager.MetricRequest.newBuilder().setComponentName("c1").addInstanceId("i1").setInterval(10).addMetric("__jvm-uptime-secs").build());
    assertEquals(response.getMetricCount(), 1);
    assertEquals(response.getMetric(0).getInstanceId(), "i1");
    assertEquals(response.getMetric(0).getMetricCount(), 1);
    assertEquals(response.getMetric(0).getMetric(0).getName(), "__jvm-uptime-secs");
    assertEquals(response.getMetric(0).getMetric(0).getValue(), "0.1");
}
Also used : MetricsSinksConfig(org.apache.heron.metricsmgr.MetricsSinksConfig) TopologyManager(org.apache.heron.proto.tmanager.TopologyManager) SystemConfig(org.apache.heron.common.config.SystemConfig) NIOLooper(org.apache.heron.common.basics.NIOLooper) Test(org.junit.Test)

Example 3 with NIOLooper

use of org.apache.heron.common.basics.NIOLooper in project heron by twitter.

the class AbstractNetworkTest method runStreamManagerClient.

StreamManagerClient runStreamManagerClient() {
    SystemConfig systemConfig = (SystemConfig) SingletonRegistry.INSTANCE.getSingleton(SystemConfig.HERON_SYSTEM_CONFIG);
    HeronSocketOptions socketOptions = new HeronSocketOptions(systemConfig.getInstanceNetworkWriteBatchSize(), systemConfig.getInstanceNetworkWriteBatchTime(), systemConfig.getInstanceNetworkReadBatchSize(), systemConfig.getInstanceNetworkReadBatchTime(), systemConfig.getInstanceNetworkOptionsSocketSendBufferSize(), systemConfig.getInstanceNetworkOptionsSocketReceivedBufferSize(), systemConfig.getInstanceNetworkOptionsMaximumPacketSize());
    final NIOLooper nioLooper = (NIOLooper) communicatorTester.getTestLooper();
    streamManagerClient = new StreamManagerClient(nioLooper, HOST, serverPort, "topology-name", "topologyId", UnitTestHelper.getInstance("bolt-id"), communicatorTester.getInStreamQueue(), communicatorTester.getOutStreamQueue(), communicatorTester.getInControlQueue(), socketOptions, gatewayMetrics);
    Runnable r = new Runnable() {

        @Override
        public void run() {
            try {
                streamManagerClient.start();
                nioLooper.loop();
            } finally {
                streamManagerClient.stop();
                nioLooper.exitLoop();
            }
        }
    };
    threadPool.execute(r);
    return streamManagerClient;
}
Also used : SystemConfig(org.apache.heron.common.config.SystemConfig) NIOLooper(org.apache.heron.common.basics.NIOLooper) HeronSocketOptions(org.apache.heron.common.network.HeronSocketOptions)

Example 4 with NIOLooper

use of org.apache.heron.common.basics.NIOLooper in project heron by twitter.

the class EchoTest method before.

@Before
public void before() throws IOException {
    int serverPort = SysUtils.getFreePort();
    serverRequestsReceivedLatch = new CountDownLatch(MAX_REQUESTS);
    server = new EchoServer(new NIOLooper(), serverPort, MAX_REQUESTS, serverRequestsReceivedLatch);
    client = new EchoClient(new NIOLooper(), serverPort, MAX_REQUESTS);
    heronServerTester = new HeronServerTester(server, client);
    heronServerTester.start();
}
Also used : NIOLooper(org.apache.heron.common.basics.NIOLooper) CountDownLatch(java.util.concurrent.CountDownLatch) HeronServerTester(org.apache.heron.common.testhelpers.HeronServerTester) Before(org.junit.Before)

Example 5 with NIOLooper

use of org.apache.heron.common.basics.NIOLooper in project heron by twitter.

the class HandleTManagerLocationTest method before.

@Before
public void before() throws IOException {
    // MetricsManagerServer increments this counter every time a location refresh message is
    // received, so we can await this counter getting to 4 before proceeding with the test
    serverMetrics = new LatchedMultiCountMetric("tmanager-location-received", 4L);
    // Spy it for unit test
    metricsManagerServer = spy(new MetricsManagerServer(new NIOLooper(), HeronServerTester.SERVER_HOST, SysUtils.getFreePort(), HeronServerTester.TEST_SOCKET_OPTIONS, serverMetrics));
    heronServerTester = new HeronServerTester(metricsManagerServer, new TestRequestHandler(), new HeronServerTester.SuccessResponseHandler(Metrics.MetricPublisherRegisterResponse.class, new TestResponseHandler()), RESPONSE_RECEIVED_TIMEOUT);
    heronServerTester.start();
}
Also used : Metrics(org.apache.heron.proto.system.Metrics) NIOLooper(org.apache.heron.common.basics.NIOLooper) HeronServerTester(org.apache.heron.common.testhelpers.HeronServerTester) Before(org.junit.Before)

Aggregations

NIOLooper (org.apache.heron.common.basics.NIOLooper)7 HeronServerTester (org.apache.heron.common.testhelpers.HeronServerTester)4 Before (org.junit.Before)4 CountDownLatch (java.util.concurrent.CountDownLatch)2 SystemConfig (org.apache.heron.common.config.SystemConfig)2 HeronSocketOptions (org.apache.heron.common.network.HeronSocketOptions)2 Metrics (org.apache.heron.proto.system.Metrics)2 MultiCountMetric (org.apache.heron.api.metric.MultiCountMetric)1 MetricsSinksConfig (org.apache.heron.metricsmgr.MetricsSinksConfig)1 TopologyManager (org.apache.heron.proto.tmanager.TopologyManager)1 IStatefulStorage (org.apache.heron.spi.statefulstorage.IStatefulStorage)1 Test (org.junit.Test)1