Search in sources :

Example 6 with SinkContextImpl

use of com.twitter.heron.metricsmgr.sink.SinkContextImpl in project heron by twitter.

the class MetricsCacheSinkTest method testHandleMetricsCacheLocation.

/**
   * Test whether MetricsCacheSink would handle MetricsCacheLocation in SingletonRegistry automatically
   */
@Test
public void testHandleMetricsCacheLocation() throws Exception {
    // create a new MetricsCacheClientService
    MetricsCacheSink metricsCacheSink = new MetricsCacheSink();
    Map<String, Object> sinkConfig = new HashMap<String, Object>();
    // Fill with necessary config
    sinkConfig.put("metricscache-location-check-interval-sec", METRICSCACHE_LOCATION_CHECK_INTERVAL_SECONDS);
    // These are config for MetricsCacheClient
    Map<String, Object> serviceConfig = buildServiceConfig();
    sinkConfig.put("metricscache-client", serviceConfig);
    // It is null since we have not set it
    Assert.assertNull(metricsCacheSink.getCurrentMetricsCacheLocation());
    SinkContext sinkContext = new SinkContextImpl("topology-name", "metricsmgr-id", "sink-id", new MultiCountMetric());
    // Start the MetricsCacheSink
    metricsCacheSink.init(sinkConfig, sinkContext);
    // Put the MetricsCacheLocation into SingletonRegistry
    TopologyMaster.MetricsCacheLocation oldLoc = TopologyMaster.MetricsCacheLocation.newBuilder().setTopologyName("topology-name").setTopologyId("topology-id").setHost("host").setControllerPort(0).setMasterPort(0).build();
    SingletonRegistry.INSTANCE.registerSingleton(METRICSCACHE_LOCATION_BEAN_NAME, oldLoc);
    Thread.sleep(WAIT_SECONDS * 1000);
    // The MetricsCacheService should start
    Assert.assertTrue(metricsCacheSink.getMetricsCacheStartedAttempts() > 0);
    Assert.assertEquals(oldLoc, metricsCacheSink.getCurrentMetricsCacheLocation());
    Assert.assertEquals(oldLoc, metricsCacheSink.getCurrentMetricsCacheLocationInService());
    // Update it, the MetricsCacheSink should pick up the new one.
    TopologyMaster.MetricsCacheLocation newLoc = TopologyMaster.MetricsCacheLocation.newBuilder().setTopologyName("topology-name").setTopologyId("topology-id").setHost("host").setControllerPort(0).setMasterPort(1).build();
    SingletonRegistry.INSTANCE.updateSingleton(METRICSCACHE_LOCATION_BEAN_NAME, newLoc);
    int lastMetricsCacheStartedAttempts = metricsCacheSink.getMetricsCacheStartedAttempts();
    Thread.sleep(WAIT_SECONDS * 1000);
    // The MetricsCacheService should use the new MetricsCacheLocation
    Assert.assertTrue(metricsCacheSink.getMetricsCacheStartedAttempts() > lastMetricsCacheStartedAttempts);
    Assert.assertNotSame(oldLoc, metricsCacheSink.getCurrentMetricsCacheLocation());
    Assert.assertNotSame(oldLoc, metricsCacheSink.getCurrentMetricsCacheLocationInService());
    Assert.assertEquals(newLoc, metricsCacheSink.getCurrentMetricsCacheLocation());
    Assert.assertEquals(newLoc, metricsCacheSink.getCurrentMetricsCacheLocationInService());
    metricsCacheSink.close();
}
Also used : HashMap(java.util.HashMap) SinkContext(com.twitter.heron.spi.metricsmgr.sink.SinkContext) SinkContextImpl(com.twitter.heron.metricsmgr.sink.SinkContextImpl) MultiCountMetric(com.twitter.heron.api.metric.MultiCountMetric) TopologyMaster(com.twitter.heron.proto.tmaster.TopologyMaster) Test(org.junit.Test)

Example 7 with SinkContextImpl

use of com.twitter.heron.metricsmgr.sink.SinkContextImpl in project incubator-heron by apache.

the class MetricsCacheSinkTest method testHandleMetricsCacheLocation.

/**
 * Test whether MetricsCacheSink would handle MetricsCacheLocation in SingletonRegistry automatically
 */
@Test
public void testHandleMetricsCacheLocation() throws Exception {
    // create a new MetricsCacheClientService
    MetricsCacheSink metricsCacheSink = new MetricsCacheSink();
    Map<String, Object> sinkConfig = new HashMap<String, Object>();
    // Fill with necessary config
    sinkConfig.put("metricscache-location-check-interval-sec", METRICSCACHE_LOCATION_CHECK_INTERVAL.getSeconds());
    sinkConfig.put("metricscache-client", buildServiceConfig());
    // It is null since we have not set it
    Assert.assertNull(metricsCacheSink.getCurrentMetricsCacheLocation());
    MultiCountMetric multiCountMetric = new MultiCountMetric();
    SinkContext sinkContext = new SinkContextImpl("topology-name", "cluster", "role", "environment", "metricsmgr-id", "sink-id", multiCountMetric);
    // Start the MetricsCacheSink
    metricsCacheSink.init(sinkConfig, sinkContext);
    // Put the MetricsCacheLocation into SingletonRegistry
    TopologyMaster.MetricsCacheLocation oldLoc = getMetricsCacheLocation(0);
    SingletonRegistry.INSTANCE.registerSingleton(METRICSCACHE_LOCATION_BEAN_NAME, oldLoc);
    SysUtils.sleep(RESTART_WAIT_INTERVAL);
    // The MetricsCacheService should start
    assertTrue(metricsCacheSink.getMetricsCacheStartedAttempts() > 0);
    assertEquals(oldLoc, metricsCacheSink.getCurrentMetricsCacheLocation());
    assertEquals(oldLoc, metricsCacheSink.getCurrentMetricsCacheLocationInService());
    // Update it, the MetricsCacheSink should pick up the new one.
    TopologyMaster.MetricsCacheLocation newLoc = getMetricsCacheLocation(1);
    SingletonRegistry.INSTANCE.updateSingleton(METRICSCACHE_LOCATION_BEAN_NAME, newLoc);
    int lastMetricsCacheStartedAttempts = metricsCacheSink.getMetricsCacheStartedAttempts();
    SysUtils.sleep(RESTART_WAIT_INTERVAL);
    // The MetricsCacheService should use the new MetricsCacheLocation
    assertTrue(metricsCacheSink.getMetricsCacheStartedAttempts() > lastMetricsCacheStartedAttempts);
    assertNotSame(oldLoc, metricsCacheSink.getCurrentMetricsCacheLocation());
    assertNotSame(oldLoc, metricsCacheSink.getCurrentMetricsCacheLocationInService());
    assertEquals(newLoc, metricsCacheSink.getCurrentMetricsCacheLocation());
    assertEquals(newLoc, metricsCacheSink.getCurrentMetricsCacheLocationInService());
    metricsCacheSink.close();
}
Also used : HashMap(java.util.HashMap) SinkContext(com.twitter.heron.spi.metricsmgr.sink.SinkContext) SinkContextImpl(com.twitter.heron.metricsmgr.sink.SinkContextImpl) MultiCountMetric(com.twitter.heron.api.metric.MultiCountMetric) TopologyMaster(com.twitter.heron.proto.tmaster.TopologyMaster) Test(org.junit.Test)

Example 8 with SinkContextImpl

use of com.twitter.heron.metricsmgr.sink.SinkContextImpl in project incubator-heron by apache.

the class TMasterSinkTest method testHandleTMasterLocation.

/**
 * Test whether TMasterSink would handle TMasterLocation in SingletonRegistry automatically
 */
@Test
public void testHandleTMasterLocation() throws InterruptedException {
    // create a new TMasterClientService
    TMasterSink tMasterSink = new TMasterSink();
    Map<String, Object> sinkConfig = new HashMap<>();
    // Fill with necessary config
    sinkConfig.put("tmaster-location-check-interval-sec", TMASTER_LOCATION_CHECK_INTERVAL.getSeconds());
    sinkConfig.put("tmaster-client", buildServiceConfig());
    // It is null since we have not set it
    Assert.assertNull(tMasterSink.getCurrentTMasterLocation());
    MultiCountMetric multiCountMetric = new MultiCountMetric();
    SinkContext sinkContext = new SinkContextImpl("topology-name", "cluster", "role", "environment", "metricsmgr-id", "sink-id", multiCountMetric);
    // Start the TMasterSink
    tMasterSink.init(sinkConfig, sinkContext);
    // Put the TMasterLocation into SingletonRegistry
    TopologyMaster.TMasterLocation oldLoc = getTMasterLocation(0);
    SingletonRegistry.INSTANCE.registerSingleton(TMASTER_LOCATION_BEAN_NAME, oldLoc);
    SysUtils.sleep(RESTART_WAIT_INTERVAL);
    // The TMasterService should start
    assertTrue(tMasterSink.getTMasterStartedAttempts() > 0);
    assertEquals(oldLoc, tMasterSink.getCurrentTMasterLocation());
    assertEquals(oldLoc, tMasterSink.getCurrentTMasterLocationInService());
    // Update it, the TMasterSink should pick up the new one.
    TopologyMaster.TMasterLocation newLoc = getTMasterLocation(1);
    SingletonRegistry.INSTANCE.updateSingleton(TMASTER_LOCATION_BEAN_NAME, newLoc);
    int lastTMasterStartedAttempts = tMasterSink.getTMasterStartedAttempts();
    SysUtils.sleep(RESTART_WAIT_INTERVAL);
    // The TMasterService should use the new TMasterLocation
    assertTrue(tMasterSink.getTMasterStartedAttempts() > lastTMasterStartedAttempts);
    assertNotSame(oldLoc, tMasterSink.getCurrentTMasterLocation());
    assertNotSame(oldLoc, tMasterSink.getCurrentTMasterLocationInService());
    assertEquals(newLoc, tMasterSink.getCurrentTMasterLocation());
    assertEquals(newLoc, tMasterSink.getCurrentTMasterLocationInService());
    tMasterSink.close();
}
Also used : HashMap(java.util.HashMap) SinkContext(com.twitter.heron.spi.metricsmgr.sink.SinkContext) SinkContextImpl(com.twitter.heron.metricsmgr.sink.SinkContextImpl) MultiCountMetric(com.twitter.heron.api.metric.MultiCountMetric) TopologyMaster(com.twitter.heron.proto.tmaster.TopologyMaster) Test(org.junit.Test)

Aggregations

MultiCountMetric (com.twitter.heron.api.metric.MultiCountMetric)8 SinkContextImpl (com.twitter.heron.metricsmgr.sink.SinkContextImpl)8 SinkContext (com.twitter.heron.spi.metricsmgr.sink.SinkContext)8 SlaveLooper (com.twitter.heron.common.basics.SlaveLooper)4 TopologyMaster (com.twitter.heron.proto.tmaster.TopologyMaster)4 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 Communicator (com.twitter.heron.common.basics.Communicator)2 MetricsCollector (com.twitter.heron.common.utils.metrics.MetricsCollector)2 SinkExecutor (com.twitter.heron.metricsmgr.executor.SinkExecutor)2 MetricsRecord (com.twitter.heron.spi.metricsmgr.metrics.MetricsRecord)2 IMetricsSink (com.twitter.heron.spi.metricsmgr.sink.IMetricsSink)2 Before (org.junit.Before)2