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();
}
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();
}
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();
}
Aggregations