use of org.apache.samza.system.OutgoingMessageEnvelope in project samza by apache.
the class TestOperatorSpecs method testCreateSinkOperator.
@Test
public void testCreateSinkOperator() {
SystemStream testStream = new SystemStream("test-sys", "test-stream");
SinkFunction<TestMessageEnvelope> sinkFn = (TestMessageEnvelope message, MessageCollector messageCollector, TaskCoordinator taskCoordinator) -> {
messageCollector.send(new OutgoingMessageEnvelope(testStream, message.getKey(), message.getMessage()));
};
SinkOperatorSpec<TestMessageEnvelope> sinkOp = OperatorSpecs.createSinkOperatorSpec(sinkFn, 1);
assertEquals(sinkOp.getSinkFn(), sinkFn);
TestMessageEnvelope mockInput = mock(TestMessageEnvelope.class);
when(mockInput.getKey()).thenReturn("my-test-msg-key");
MessageType mockMsgBody = mock(MessageType.class);
when(mockInput.getMessage()).thenReturn(mockMsgBody);
final List<OutgoingMessageEnvelope> outputMsgs = new ArrayList<>();
MessageCollector mockCollector = mock(MessageCollector.class);
doAnswer(invocation -> {
outputMsgs.add((OutgoingMessageEnvelope) invocation.getArguments()[0]);
return null;
}).when(mockCollector).send(any());
sinkOp.getSinkFn().apply(mockInput, mockCollector, null);
assertEquals(1, outputMsgs.size());
assertEquals(outputMsgs.get(0).getKey(), "my-test-msg-key");
assertEquals(outputMsgs.get(0).getMessage(), mockMsgBody);
assertEquals(sinkOp.getOpCode(), OperatorSpec.OpCode.SINK);
assertEquals(sinkOp.getNextStream(), null);
}
use of org.apache.samza.system.OutgoingMessageEnvelope in project samza by apache.
the class TestCoordinatorStreamSystemProducer method testCoordinatorStreamSystemProducer.
@Test
public void testCoordinatorStreamSystemProducer() {
String source = "source";
SystemStream systemStream = new SystemStream("system", "stream");
MockCoordinatorSystemProducer systemProducer = new MockCoordinatorSystemProducer(source);
MockSystemAdmin systemAdmin = new MockSystemAdmin();
CoordinatorStreamSystemProducer producer = new CoordinatorStreamSystemProducer(systemStream, systemProducer, systemAdmin);
SetConfig setConfig1 = new SetConfig(source, "job.name", "my-job-name");
SetConfig setConfig2 = new SetConfig(source, "job.id", "1234");
Delete delete = new Delete(source, "job.name", SetConfig.TYPE);
assertFalse(systemProducer.isRegistered());
producer.register(source);
assertTrue(systemProducer.isRegistered());
assertFalse(systemProducer.isStarted());
producer.start();
assertTrue(systemProducer.isStarted());
producer.send(setConfig1);
producer.send(setConfig2);
producer.send(delete);
assertFalse(systemProducer.isStopped());
producer.stop();
assertTrue(systemProducer.isStopped());
List<OutgoingMessageEnvelope> envelopes = systemProducer.getEnvelopes();
OutgoingMessageEnvelope envelope0 = envelopes.get(0);
OutgoingMessageEnvelope envelope1 = envelopes.get(1);
OutgoingMessageEnvelope envelope2 = envelopes.get(2);
TypeReference<Object[]> keyRef = new TypeReference<Object[]>() {
};
TypeReference<Map<String, Object>> msgRef = new TypeReference<Map<String, Object>>() {
};
assertEquals(3, envelopes.size());
assertEquals(new CoordinatorStreamMessage(setConfig1), new CoordinatorStreamMessage(deserialize((byte[]) envelope0.getKey(), keyRef), deserialize((byte[]) envelope0.getMessage(), msgRef)));
assertEquals(new CoordinatorStreamMessage(setConfig2), new CoordinatorStreamMessage(deserialize((byte[]) envelope1.getKey(), keyRef), deserialize((byte[]) envelope1.getMessage(), msgRef)));
assertEquals(new CoordinatorStreamMessage(delete), new CoordinatorStreamMessage(deserialize((byte[]) envelope2.getKey(), keyRef), deserialize((byte[]) envelope2.getMessage(), msgRef)));
}
use of org.apache.samza.system.OutgoingMessageEnvelope in project samza by apache.
the class DefaultIndexRequestFactoryTest method testGetIndexRequestNoPartitionKey.
@Test
public void testGetIndexRequestNoPartitionKey() throws Exception {
IndexRequest indexRequest = indexRequestFactory.getIndexRequest(new OutgoingMessageEnvelope(SYSTEM, EMPTY_MSG));
assertNull(indexRequest.routing());
}
use of org.apache.samza.system.OutgoingMessageEnvelope in project samza by apache.
the class DefaultIndexRequestFactoryTest method testGetIndexRequestStreamName.
@Test
public void testGetIndexRequestStreamName() {
IndexRequest indexRequest = indexRequestFactory.getIndexRequest(new OutgoingMessageEnvelope(SYSTEM, EMPTY_MSG));
assertEquals(INDEX, indexRequest.index());
assertEquals(TYPE, indexRequest.type());
}
use of org.apache.samza.system.OutgoingMessageEnvelope in project samza by apache.
the class DefaultIndexRequestFactoryTest method testGetIndexRequestMessageBytes.
@Test
public void testGetIndexRequestMessageBytes() throws Exception {
IndexRequest indexRequest = indexRequestFactory.getIndexRequest(new OutgoingMessageEnvelope(SYSTEM, "{\"foo\":\"bar\"}".getBytes(Charsets.UTF_8)));
assertEquals(Collections.singletonMap("foo", "bar"), indexRequest.sourceAsMap());
}
Aggregations