Search in sources :

Example 1 with MockCoordinatorStreamSystemProducer

use of org.apache.samza.coordinator.stream.MockCoordinatorStreamSystemFactory.MockCoordinatorStreamSystemProducer 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 MockCoordinatorStreamSystemProducer

use of org.apache.samza.coordinator.stream.MockCoordinatorStreamSystemFactory.MockCoordinatorStreamSystemProducer 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 MockCoordinatorStreamSystemProducer

use of org.apache.samza.coordinator.stream.MockCoordinatorStreamSystemFactory.MockCoordinatorStreamSystemProducer 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 MockCoordinatorStreamSystemProducer

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

the class TestLocalityManager method testWriteOnlyLocalityManager.

@Test
public void testWriteOnlyLocalityManager() {
    MockCoordinatorStreamSystemProducer producer = mockCoordinatorStreamSystemFactory.getCoordinatorStreamSystemProducer(config, null);
    LocalityManager localityManager = new LocalityManager(producer);
    localityManager.register("containerId-1");
    assertTrue(producer.isRegistered());
    assertEquals(producer.getRegisteredSource(), "SamzaContainer-containerId-1");
    localityManager.start();
    assertTrue(producer.isStarted());
    localityManager.writeContainerToHostMapping("1", "localhost", "jmx:localhost:8181", "jmx:tunnel:localhost:9191");
    try {
        localityManager.readContainerLocality();
        fail("Should have thrown UnsupportedOperationException");
    } catch (UnsupportedOperationException uoe) {
    // expected
    }
    assertEquals(producer.getEnvelopes().size(), 1);
    CoordinatorStreamMessage coordinatorStreamMessage = MockCoordinatorStreamSystemFactory.deserializeCoordinatorStreamMessage(producer.getEnvelopes().get(0));
    SetContainerHostMapping expectedContainerMap = new SetContainerHostMapping("SamzaContainer-1", "1", "localhost", "jmx:localhost:8181", "jmx:tunnel:localhost:9191");
    assertEquals(expectedContainerMap, coordinatorStreamMessage);
    localityManager.stop();
    assertTrue(producer.isStopped());
}
Also used : CoordinatorStreamMessage(org.apache.samza.coordinator.stream.messages.CoordinatorStreamMessage) MockCoordinatorStreamSystemProducer(org.apache.samza.coordinator.stream.MockCoordinatorStreamSystemFactory.MockCoordinatorStreamSystemProducer) SetContainerHostMapping(org.apache.samza.coordinator.stream.messages.SetContainerHostMapping) Test(org.junit.Test)

Example 5 with MockCoordinatorStreamSystemProducer

use of org.apache.samza.coordinator.stream.MockCoordinatorStreamSystemFactory.MockCoordinatorStreamSystemProducer 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

MockCoordinatorStreamSystemProducer (org.apache.samza.coordinator.stream.MockCoordinatorStreamSystemFactory.MockCoordinatorStreamSystemProducer)5 Test (org.junit.Test)5 HashMap (java.util.HashMap)4 MockCoordinatorStreamSystemConsumer (org.apache.samza.coordinator.stream.MockCoordinatorStreamSystemFactory.MockCoordinatorStreamSystemConsumer)4 Map (java.util.Map)3 MockCoordinatorStreamSystemFactory (org.apache.samza.coordinator.stream.MockCoordinatorStreamSystemFactory)3 CoordinatorStreamMessage (org.apache.samza.coordinator.stream.messages.CoordinatorStreamMessage)1 SetContainerHostMapping (org.apache.samza.coordinator.stream.messages.SetContainerHostMapping)1