Search in sources :

Example 6 with CoordinatorStreamValueSerde

use of org.apache.samza.coordinator.stream.CoordinatorStreamValueSerde in project samza by apache.

the class TestContainerHeartbeatMonitor method testConnectToNewAMSerdeException.

@Test
public void testConnectToNewAMSerdeException() throws InterruptedException {
    String newCoordinatorUrl = "http://some-host-2.prod.linkedin.com";
    this.containerHeartbeatMonitor = spy(buildContainerHeartbeatMonitor(true));
    CoordinatorStreamValueSerde serde = new CoordinatorStreamValueSerde(SetConfig.TYPE);
    ContainerHeartbeatMonitor.ContainerHeartbeatMetrics metrics = this.containerHeartbeatMonitor.getMetrics();
    when(this.containerHeartbeatClient.requestHeartbeat()).thenReturn(FAILURE_RESPONSE);
    when(this.containerHeartbeatMonitor.createContainerHeartbeatClient(newCoordinatorUrl, CONTAINER_EXECUTION_ID)).thenReturn(this.containerHeartbeatClient);
    when(this.coordinatorStreamStore.get(CoordinationConstants.YARN_COORDINATOR_URL)).thenThrow(new NullPointerException("serde failed"));
    this.containerHeartbeatMonitor.start();
    // wait for the executor to finish the heartbeat check task
    boolean fixedRateTaskCompleted = this.schedulerFixedRateExecutionLatch.await(10, TimeUnit.SECONDS);
    assertTrue("Did not complete heartbeat check", fixedRateTaskCompleted);
    assertEquals("Heartbeat expired count should be 1", 1, metrics.getHeartbeatExpiredCount().getCount());
    assertEquals("Heartbeat established failure count should be 1", 1, metrics.getHeartbeatEstablishedFailureCount().getCount());
    // shutdown task should have been submitted
    verify(this.scheduler).schedule(any(Runnable.class), eq((long) ContainerHeartbeatMonitor.SHUTDOWN_TIMOUT_MS), eq(TimeUnit.MILLISECONDS));
    verify(this.onExpired).run();
    this.containerHeartbeatMonitor.stop();
    verify(this.scheduler).shutdown();
}
Also used : CoordinatorStreamValueSerde(org.apache.samza.coordinator.stream.CoordinatorStreamValueSerde) Test(org.junit.Test)

Example 7 with CoordinatorStreamValueSerde

use of org.apache.samza.coordinator.stream.CoordinatorStreamValueSerde in project samza by apache.

the class TestContainerHeartbeatMonitor method testConnectToNewAMFailed.

@Test
public void testConnectToNewAMFailed() throws InterruptedException {
    String newCoordinatorUrl = "http://some-host-2.prod.linkedin.com";
    this.containerHeartbeatMonitor = spy(buildContainerHeartbeatMonitor(true));
    CoordinatorStreamValueSerde serde = new CoordinatorStreamValueSerde(SetConfig.TYPE);
    ContainerHeartbeatMonitor.ContainerHeartbeatMetrics metrics = this.containerHeartbeatMonitor.getMetrics();
    when(this.containerHeartbeatClient.requestHeartbeat()).thenReturn(FAILURE_RESPONSE);
    when(this.containerHeartbeatMonitor.createContainerHeartbeatClient(newCoordinatorUrl, CONTAINER_EXECUTION_ID)).thenReturn(this.containerHeartbeatClient);
    when(this.coordinatorStreamStore.get(CoordinationConstants.YARN_COORDINATOR_URL)).thenReturn(serde.toBytes(newCoordinatorUrl));
    this.containerHeartbeatMonitor.start();
    // wait for the executor to finish the heartbeat check task
    boolean fixedRateTaskCompleted = this.schedulerFixedRateExecutionLatch.await(2, TimeUnit.SECONDS);
    assertTrue("Did not complete heartbeat check", fixedRateTaskCompleted);
    assertEquals("Heartbeat expired count should be 1", 1, metrics.getHeartbeatExpiredCount().getCount());
    assertEquals("Heartbeat established failure count should be 1", 1, metrics.getHeartbeatEstablishedFailureCount().getCount());
    // shutdown task should have been submitted
    verify(this.scheduler).schedule(any(Runnable.class), eq((long) ContainerHeartbeatMonitor.SHUTDOWN_TIMOUT_MS), eq(TimeUnit.MILLISECONDS));
    verify(this.onExpired).run();
    this.containerHeartbeatMonitor.stop();
    verify(this.scheduler).shutdown();
}
Also used : CoordinatorStreamValueSerde(org.apache.samza.coordinator.stream.CoordinatorStreamValueSerde) Test(org.junit.Test)

Example 8 with CoordinatorStreamValueSerde

use of org.apache.samza.coordinator.stream.CoordinatorStreamValueSerde in project samza by apache.

the class TestExecutionContainerIdManager method testExecutionContainerIdManager.

@Test
public void testExecutionContainerIdManager() {
    String physicalId = "container_123_123_123";
    String processorId = "0";
    executionContainerIdManager.writeExecutionEnvironmentContainerIdMapping(processorId, physicalId);
    Map<String, String> localMap = executionContainerIdManager.readExecutionEnvironmentContainerIdMapping();
    Map<String, String> expectedMap = ImmutableMap.of(processorId, physicalId);
    assertEquals(expectedMap, localMap);
    executionContainerIdManager.close();
    MockCoordinatorStreamSystemFactory.MockCoordinatorStreamSystemProducer producer = coordinatorStreamStoreTestUtil.getMockCoordinatorStreamSystemProducer();
    MockCoordinatorStreamSystemFactory.MockCoordinatorStreamSystemConsumer consumer = coordinatorStreamStoreTestUtil.getMockCoordinatorStreamSystemConsumer();
    assertTrue(producer.isStopped());
    assertTrue(consumer.isStopped());
    ArgumentCaptor<byte[]> argument1 = ArgumentCaptor.forClass(byte[].class);
    Mockito.verify(store).put(Mockito.eq(processorId), argument1.capture());
    CoordinatorStreamValueSerde valueSerde = new CoordinatorStreamValueSerde(SetExecutionEnvContainerIdMapping.TYPE);
    assertEquals(physicalId, valueSerde.fromBytes(argument1.getValue()));
}
Also used : MockCoordinatorStreamSystemFactory(org.apache.samza.coordinator.stream.MockCoordinatorStreamSystemFactory) CoordinatorStreamValueSerde(org.apache.samza.coordinator.stream.CoordinatorStreamValueSerde) Test(org.junit.Test)

Aggregations

CoordinatorStreamValueSerde (org.apache.samza.coordinator.stream.CoordinatorStreamValueSerde)8 Test (org.junit.Test)6 HashMap (java.util.HashMap)2 JobConfig (org.apache.samza.config.JobConfig)2 MetricsRegistryMap (org.apache.samza.metrics.MetricsRegistryMap)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 IOException (java.io.IOException)1 Map (java.util.Map)1 SamzaException (org.apache.samza.SamzaException)1 MapConfig (org.apache.samza.config.MapConfig)1 MetadataResourceUtil (org.apache.samza.coordinator.MetadataResourceUtil)1 CoordinatorStreamStore (org.apache.samza.coordinator.metadatastore.CoordinatorStreamStore)1 NamespaceAwareCoordinatorStreamStore (org.apache.samza.coordinator.metadatastore.NamespaceAwareCoordinatorStreamStore)1 MockCoordinatorStreamSystemFactory (org.apache.samza.coordinator.stream.MockCoordinatorStreamSystemFactory)1 JobCoordinatorMetadata (org.apache.samza.job.JobCoordinatorMetadata)1 MetadataStore (org.apache.samza.metadatastore.MetadataStore)1 MetadataStoreFactory (org.apache.samza.metadatastore.MetadataStoreFactory)1 StartpointManager (org.apache.samza.startpoint.StartpointManager)1 ZkMetadataStore (org.apache.samza.zk.ZkMetadataStore)1 Matchers.anyString (org.mockito.Matchers.anyString)1