use of com.twitter.heron.spi.metricsmgr.sink.SinkContext 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();
}
use of com.twitter.heron.spi.metricsmgr.sink.SinkContext in project incubator-heron by apache.
the class FileSinkTest method before.
@Before
public void before() throws IOException {
fileSink = new FileSink();
Map<String, Object> conf = new HashMap<>();
tmpDir = Files.createTempDirectory("filesink").toFile();
conf.put("filename-output", tmpDir.getAbsolutePath() + "/filesink");
conf.put("file-maximum", 100);
SinkContext context = Mockito.mock(SinkContext.class);
Mockito.when(context.getMetricsMgrId()).thenReturn("test");
fileSink.init(conf, context);
}
Aggregations