use of org.apache.samza.coordinator.stream.MockCoordinatorStreamSystemFactory.MockCoordinatorStreamSystemConsumer 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.MockCoordinatorStreamSystemConsumer 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.MockCoordinatorStreamSystemConsumer in project samza by apache.
the class TestLocalityManager method testLocalityManager.
@Test
public void testLocalityManager() throws Exception {
MockCoordinatorStreamSystemProducer producer = mockCoordinatorStreamSystemFactory.getCoordinatorStreamSystemProducer(config, null);
MockCoordinatorStreamSystemConsumer consumer = mockCoordinatorStreamSystemFactory.getCoordinatorStreamSystemConsumer(config, null);
LocalityManager localityManager = new LocalityManager(producer, consumer);
try {
localityManager.register(new TaskName("task-0"));
fail("Should have thrown UnsupportedOperationException");
} catch (UnsupportedOperationException uoe) {
// expected
}
localityManager.register("containerId-0");
assertTrue(producer.isRegistered());
assertEquals(producer.getRegisteredSource(), "SamzaContainer-containerId-0");
assertTrue(consumer.isRegistered());
localityManager.start();
assertTrue(producer.isStarted());
assertTrue(consumer.isStarted());
localityManager.writeContainerToHostMapping("0", "localhost", "jmx:localhost:8080", "jmx:tunnel:localhost:9090");
Map<String, Map<String, String>> localMap = localityManager.readContainerLocality();
Map<String, Map<String, String>> expectedMap = new HashMap<String, Map<String, String>>() {
{
this.put("0", new HashMap<String, String>() {
{
this.put(SetContainerHostMapping.HOST_KEY, "localhost");
this.put(SetContainerHostMapping.JMX_URL_KEY, "jmx:localhost:8080");
this.put(SetContainerHostMapping.JMX_TUNNELING_URL_KEY, "jmx:tunnel:localhost:9090");
}
});
}
};
assertEquals(expectedMap, localMap);
localityManager.stop();
assertTrue(producer.isStopped());
assertTrue(consumer.isStopped());
}
use of org.apache.samza.coordinator.stream.MockCoordinatorStreamSystemFactory.MockCoordinatorStreamSystemConsumer 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