Search in sources :

Example 11 with SinkContext

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();
}
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 12 with SinkContext

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);
}
Also used : HashMap(java.util.HashMap) SinkContext(com.twitter.heron.spi.metricsmgr.sink.SinkContext) Before(org.junit.Before)

Aggregations

SinkContext (com.twitter.heron.spi.metricsmgr.sink.SinkContext)12 MultiCountMetric (com.twitter.heron.api.metric.MultiCountMetric)8 SinkContextImpl (com.twitter.heron.metricsmgr.sink.SinkContextImpl)8 HashMap (java.util.HashMap)8 Test (org.junit.Test)6 SlaveLooper (com.twitter.heron.common.basics.SlaveLooper)4 TopologyMaster (com.twitter.heron.proto.tmaster.TopologyMaster)4 Before (org.junit.Before)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