Search in sources :

Example 11 with CoordinatorStreamMessage

use of org.apache.samza.coordinator.stream.messages.CoordinatorStreamMessage 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 12 with CoordinatorStreamMessage

use of org.apache.samza.coordinator.stream.messages.CoordinatorStreamMessage in project samza by apache.

the class CoordinatorStreamSystemConsumer method getUnreadMessages.

/**
   * returns all unread messages of a specific type, after an iterator on the stream
   *
   * @param iterator the iterator pointing to an offset in the coordinator stream. All unread messages after this iterator are returned
   * @param type     the type of the messages to be returned
   * @return a set of unread messages of a given type, after a given iterator
   */
public Set<CoordinatorStreamMessage> getUnreadMessages(SystemStreamPartitionIterator iterator, String type) {
    LinkedHashSet<CoordinatorStreamMessage> messages = new LinkedHashSet<CoordinatorStreamMessage>();
    while (iterator.hasNext()) {
        IncomingMessageEnvelope envelope = iterator.next();
        Object[] keyArray = keySerde.fromBytes((byte[]) envelope.getKey()).toArray();
        Map<String, Object> valueMap = null;
        if (envelope.getMessage() != null) {
            valueMap = messageSerde.fromBytes((byte[]) envelope.getMessage());
        }
        CoordinatorStreamMessage coordinatorStreamMessage = new CoordinatorStreamMessage(keyArray, valueMap);
        if (type == null || type.equals(coordinatorStreamMessage.getType())) {
            messages.add(coordinatorStreamMessage);
        }
    }
    return messages;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CoordinatorStreamMessage(org.apache.samza.coordinator.stream.messages.CoordinatorStreamMessage) IncomingMessageEnvelope(org.apache.samza.system.IncomingMessageEnvelope)

Aggregations

CoordinatorStreamMessage (org.apache.samza.coordinator.stream.messages.CoordinatorStreamMessage)12 Test (org.junit.Test)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 SetConfig (org.apache.samza.coordinator.stream.messages.SetConfig)4 LinkedHashSet (java.util.LinkedHashSet)3 IncomingMessageEnvelope (org.apache.samza.system.IncomingMessageEnvelope)3 SetContainerHostMapping (org.apache.samza.coordinator.stream.messages.SetContainerHostMapping)2 SystemStream (org.apache.samza.system.SystemStream)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)1 Partition (org.apache.samza.Partition)1 SamzaException (org.apache.samza.SamzaException)1 TaskName (org.apache.samza.container.TaskName)1 MockCoordinatorStreamSystemProducer (org.apache.samza.coordinator.stream.MockCoordinatorStreamSystemFactory.MockCoordinatorStreamSystemProducer)1 Delete (org.apache.samza.coordinator.stream.messages.Delete)1 SetChangelogMapping (org.apache.samza.coordinator.stream.messages.SetChangelogMapping)1