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