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