Search in sources :

Example 1 with MockCoordinatorStreamSystemFactory

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

the class TestTaskAssignmentManager method testDeleteMappings.

@Test
public void testDeleteMappings() throws Exception {
    MockCoordinatorStreamSystemFactory mockCoordinatorStreamSystemFactory = new MockCoordinatorStreamSystemFactory();
    MockCoordinatorStreamSystemProducer producer = mockCoordinatorStreamSystemFactory.getCoordinatorStreamSystemProducer(config, null);
    MockCoordinatorStreamSystemConsumer consumer = mockCoordinatorStreamSystemFactory.getCoordinatorStreamSystemConsumer(config, null);
    consumer.register();
    TaskAssignmentManager taskAssignmentManager = new TaskAssignmentManager(producer, consumer);
    assertTrue(producer.isRegistered());
    assertEquals(producer.getRegisteredSource(), "SamzaTaskAssignmentManager");
    taskAssignmentManager.start();
    assertTrue(producer.isStarted());
    assertTrue(consumer.isStarted());
    Map<String, String> expectedMap = new HashMap<String, String>() {

        {
            this.put("Task0", "0");
            this.put("Task1", "1");
        }
    };
    for (Map.Entry<String, String> entry : expectedMap.entrySet()) {
        taskAssignmentManager.writeTaskContainerMapping(entry.getKey(), entry.getValue());
    }
    Map<String, String> localMap = taskAssignmentManager.readTaskAssignment();
    assertEquals(expectedMap, localMap);
    taskAssignmentManager.deleteTaskContainerMappings(localMap.keySet());
    Map<String, String> deletedMap = taskAssignmentManager.readTaskAssignment();
    assertTrue(deletedMap.isEmpty());
    taskAssignmentManager.stop();
    assertTrue(producer.isStopped());
    assertTrue(consumer.isStopped());
}
Also used : MockCoordinatorStreamSystemConsumer(org.apache.samza.coordinator.stream.MockCoordinatorStreamSystemFactory.MockCoordinatorStreamSystemConsumer) HashMap(java.util.HashMap) MockCoordinatorStreamSystemProducer(org.apache.samza.coordinator.stream.MockCoordinatorStreamSystemFactory.MockCoordinatorStreamSystemProducer) MockCoordinatorStreamSystemFactory(org.apache.samza.coordinator.stream.MockCoordinatorStreamSystemFactory) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 2 with MockCoordinatorStreamSystemFactory

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

the class TestTaskAssignmentManager method testTaskAssignmentManagerEmptyCoordinatorStream.

@Test
public void testTaskAssignmentManagerEmptyCoordinatorStream() throws Exception {
    MockCoordinatorStreamSystemFactory mockCoordinatorStreamSystemFactory = new MockCoordinatorStreamSystemFactory();
    MockCoordinatorStreamSystemProducer producer = mockCoordinatorStreamSystemFactory.getCoordinatorStreamSystemProducer(config, null);
    MockCoordinatorStreamSystemConsumer consumer = mockCoordinatorStreamSystemFactory.getCoordinatorStreamSystemConsumer(config, null);
    consumer.register();
    TaskAssignmentManager taskAssignmentManager = new TaskAssignmentManager(producer, consumer);
    assertTrue(producer.isRegistered());
    assertEquals(producer.getRegisteredSource(), "SamzaTaskAssignmentManager");
    taskAssignmentManager.start();
    assertTrue(producer.isStarted());
    assertTrue(consumer.isStarted());
    Map<String, String> expectedMap = new HashMap<>();
    Map<String, String> localMap = taskAssignmentManager.readTaskAssignment();
    assertEquals(expectedMap, localMap);
    taskAssignmentManager.stop();
    assertTrue(producer.isStopped());
    assertTrue(consumer.isStopped());
}
Also used : MockCoordinatorStreamSystemConsumer(org.apache.samza.coordinator.stream.MockCoordinatorStreamSystemFactory.MockCoordinatorStreamSystemConsumer) HashMap(java.util.HashMap) MockCoordinatorStreamSystemProducer(org.apache.samza.coordinator.stream.MockCoordinatorStreamSystemFactory.MockCoordinatorStreamSystemProducer) MockCoordinatorStreamSystemFactory(org.apache.samza.coordinator.stream.MockCoordinatorStreamSystemFactory) Test(org.junit.Test)

Example 3 with MockCoordinatorStreamSystemFactory

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

the class TestTaskAssignmentManager method testTaskAssignmentManager.

@Test
public void testTaskAssignmentManager() throws Exception {
    MockCoordinatorStreamSystemFactory mockCoordinatorStreamSystemFactory = new MockCoordinatorStreamSystemFactory();
    MockCoordinatorStreamSystemProducer producer = mockCoordinatorStreamSystemFactory.getCoordinatorStreamSystemProducer(config, null);
    MockCoordinatorStreamSystemConsumer consumer = mockCoordinatorStreamSystemFactory.getCoordinatorStreamSystemConsumer(config, null);
    consumer.register();
    TaskAssignmentManager taskAssignmentManager = new TaskAssignmentManager(producer, consumer);
    assertTrue(producer.isRegistered());
    assertEquals(producer.getRegisteredSource(), "SamzaTaskAssignmentManager");
    taskAssignmentManager.start();
    assertTrue(producer.isStarted());
    assertTrue(consumer.isStarted());
    Map<String, String> expectedMap = new HashMap<String, String>() {

        {
            this.put("Task0", "0");
            this.put("Task1", "1");
            this.put("Task2", "2");
            this.put("Task3", "0");
            this.put("Task4", "1");
        }
    };
    for (Map.Entry<String, String> entry : expectedMap.entrySet()) {
        taskAssignmentManager.writeTaskContainerMapping(entry.getKey(), entry.getValue());
    }
    Map<String, String> localMap = taskAssignmentManager.readTaskAssignment();
    assertEquals(expectedMap, localMap);
    taskAssignmentManager.stop();
    assertTrue(producer.isStopped());
    assertTrue(consumer.isStopped());
}
Also used : MockCoordinatorStreamSystemConsumer(org.apache.samza.coordinator.stream.MockCoordinatorStreamSystemFactory.MockCoordinatorStreamSystemConsumer) HashMap(java.util.HashMap) MockCoordinatorStreamSystemProducer(org.apache.samza.coordinator.stream.MockCoordinatorStreamSystemFactory.MockCoordinatorStreamSystemProducer) MockCoordinatorStreamSystemFactory(org.apache.samza.coordinator.stream.MockCoordinatorStreamSystemFactory) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)3 MockCoordinatorStreamSystemFactory (org.apache.samza.coordinator.stream.MockCoordinatorStreamSystemFactory)3 MockCoordinatorStreamSystemConsumer (org.apache.samza.coordinator.stream.MockCoordinatorStreamSystemFactory.MockCoordinatorStreamSystemConsumer)3 MockCoordinatorStreamSystemProducer (org.apache.samza.coordinator.stream.MockCoordinatorStreamSystemFactory.MockCoordinatorStreamSystemProducer)3 Test (org.junit.Test)3 Map (java.util.Map)2