use of org.apache.samza.serializers.IntermediateMessageSerde in project samza by apache.
the class TestIntermediateMessageSerde method testWatermarkMessageSerde.
@Test
public void testWatermarkMessageSerde() {
IntermediateMessageSerde imserde = new IntermediateMessageSerde(new ObjectSerde());
String taskName = "task-1";
WatermarkMessage watermark = new WatermarkMessage(System.currentTimeMillis(), taskName);
byte[] bytes = imserde.toBytes(watermark);
WatermarkMessage de = (WatermarkMessage) imserde.fromBytes(bytes);
assertEquals(MessageType.of(de), MessageType.WATERMARK);
assertEquals(de.getTaskName(), taskName);
assertTrue(de.getTimestamp() > 0);
}
use of org.apache.samza.serializers.IntermediateMessageSerde in project samza by apache.
the class TestIntermediateMessageSerde method testUserMessageSerde.
@Test
public void testUserMessageSerde() {
IntermediateMessageSerde imserde = new IntermediateMessageSerde(new ObjectSerde());
String msg = "this is a test message";
TestUserMessage userMessage = new TestUserMessage(msg, 0, System.currentTimeMillis());
byte[] bytes = imserde.toBytes(userMessage);
TestUserMessage de = (TestUserMessage) imserde.fromBytes(bytes);
assertEquals(MessageType.of(de), MessageType.USER_MESSAGE);
assertEquals(de.getMessage(), msg);
assertEquals(de.getOffset(), 0);
assertTrue(de.getTimestamp() > 0);
}
use of org.apache.samza.serializers.IntermediateMessageSerde in project samza by apache.
the class TestIntermediateMessageSerde method testUserMessageSerdeException.
@Test(expected = IllegalArgumentException.class)
public void testUserMessageSerdeException() {
Serde<?> mockUserMessageSerde = mock(Serde.class);
when(mockUserMessageSerde.fromBytes(anyObject())).then(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
byte[] bytes = invocation.getArgumentAt(0, byte[].class);
if (Arrays.equals(bytes, new byte[] { 1, 2 })) {
throw new IllegalArgumentException("User message serde failed to deserialize this message.");
} else {
// Intermediate message serde shouldn't try to deserialize user message with wrong bytes
Assert.fail();
return null;
}
}
});
IntermediateMessageSerde imserde = new IntermediateMessageSerde(mockUserMessageSerde);
byte[] bytes = new byte[] { 0, 1, 2 };
imserde.fromBytes(bytes);
}
use of org.apache.samza.serializers.IntermediateMessageSerde in project samza by apache.
the class TestIntermediateMessageSerde method testEndOfStreamMessageSerde.
@Test
public void testEndOfStreamMessageSerde() {
IntermediateMessageSerde imserde = new IntermediateMessageSerde(new ObjectSerde());
String streamId = "test-stream";
String taskName = "task-1";
EndOfStreamMessage eos = new EndOfStreamMessage(taskName);
byte[] bytes = imserde.toBytes(eos);
EndOfStreamMessage de = (EndOfStreamMessage) imserde.fromBytes(bytes);
assertEquals(MessageType.of(de), MessageType.END_OF_STREAM);
assertEquals(de.getTaskName(), taskName);
assertEquals(de.getVersion(), 1);
}
Aggregations