Search in sources :

Example 1 with MockCoordinatorStreamSystemConsumer

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

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

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());
}
Also used : MockCoordinatorStreamSystemConsumer(org.apache.samza.coordinator.stream.MockCoordinatorStreamSystemFactory.MockCoordinatorStreamSystemConsumer) HashMap(java.util.HashMap) MockCoordinatorStreamSystemProducer(org.apache.samza.coordinator.stream.MockCoordinatorStreamSystemFactory.MockCoordinatorStreamSystemProducer) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 4 with MockCoordinatorStreamSystemConsumer

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());
}
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)4 MockCoordinatorStreamSystemConsumer (org.apache.samza.coordinator.stream.MockCoordinatorStreamSystemFactory.MockCoordinatorStreamSystemConsumer)4 MockCoordinatorStreamSystemProducer (org.apache.samza.coordinator.stream.MockCoordinatorStreamSystemFactory.MockCoordinatorStreamSystemProducer)4 Test (org.junit.Test)4 Map (java.util.Map)3 MockCoordinatorStreamSystemFactory (org.apache.samza.coordinator.stream.MockCoordinatorStreamSystemFactory)3