use of org.apache.samza.serializers.StringSerde in project samza by apache.
the class TestTimeSeriesKeySerde method testNullTimeSeriesKey.
@Test
public void testNullTimeSeriesKey() {
TimeSeriesKey<String> storeKey = new TimeSeriesKey<>(null, 1, 23);
TimeSeriesKeySerde<String> serde = new TimeSeriesKeySerde<>(new StringSerde("UTF-8"));
byte[] serializedBytes = serde.toBytes(storeKey);
TimeSeriesKey<String> deserializedTimeSeriesKey = serde.fromBytes(serializedBytes);
assertEquals(storeKey.getKey(), deserializedTimeSeriesKey.getKey());
assertEquals(storeKey.getSeqNum(), deserializedTimeSeriesKey.getSeqNum());
assertEquals(storeKey.getTimestamp(), deserializedTimeSeriesKey.getTimestamp());
assertEquals(storeKey, deserializedTimeSeriesKey);
}
use of org.apache.samza.serializers.StringSerde in project samza by apache.
the class TestOperatorSpec method testJoinOperatorSpec.
@Test
public void testJoinOperatorSpec() {
InputOperatorSpec leftOpSpec = new InputOperatorSpec("test-input-1", new NoOpSerde<>(), new NoOpSerde<>(), null, false, "op0");
InputOperatorSpec rightOpSpec = new InputOperatorSpec("test-input-2", new NoOpSerde<>(), new NoOpSerde<>(), null, false, "op1");
Serde<Object> objSerde = new Serde<Object>() {
@Override
public Object fromBytes(byte[] bytes) {
return null;
}
@Override
public byte[] toBytes(Object object) {
return new byte[0];
}
};
JoinFunction<String, Object, Object, TestOutputMessageEnvelope> joinFn = new TestJoinFunction();
JoinOperatorSpec<String, Object, Object, TestOutputMessageEnvelope> joinOperatorSpec = new JoinOperatorSpec<>(leftOpSpec, rightOpSpec, joinFn, new StringSerde("UTF-8"), objSerde, objSerde, 50000, "op2");
JoinOperatorSpec<String, Object, Object, TestOutputMessageEnvelope> joinOpCopy = (JoinOperatorSpec<String, Object, Object, TestOutputMessageEnvelope>) OperatorSpecTestUtils.copyOpSpec(joinOperatorSpec);
assertNotEquals("Expected deserialized copy of operator spec should not be the same as the original operator spec", joinOperatorSpec, joinOpCopy);
assertTrue(joinOperatorSpec.isClone(joinOpCopy));
assertTrue(joinOpCopy.getLeftInputOpSpec().isClone(leftOpSpec));
assertTrue(joinOpCopy.getRightInputOpSpec().isClone(rightOpSpec));
}
use of org.apache.samza.serializers.StringSerde in project samza by apache.
the class TestOperatorSpec method testInputOperatorSpec.
@Test
public void testInputOperatorSpec() {
Serde<Object> objSerde = new Serde<Object>() {
@Override
public Object fromBytes(byte[] bytes) {
return null;
}
@Override
public byte[] toBytes(Object object) {
return new byte[0];
}
};
InputOperatorSpec inputOperatorSpec = new InputOperatorSpec("mockStreamId", new StringSerde("UTF-8"), objSerde, null, true, "op0");
InputOperatorSpec inputOpCopy = (InputOperatorSpec) OperatorSpecTestUtils.copyOpSpec(inputOperatorSpec);
assertNotEquals("Expected deserialized copy of operator spec should not be the same as the original operator spec", inputOperatorSpec, inputOpCopy);
assertTrue(inputOperatorSpec.isClone(inputOpCopy));
}
use of org.apache.samza.serializers.StringSerde in project samza by apache.
the class TestTimeSeriesStoreImpl method testPutWithMultipleEntries.
@Test
public void testPutWithMultipleEntries() {
TimeSeriesStore<String, byte[]> timeSeriesStore = newTimeSeriesStore(new StringSerde("UTF-8"), true);
// insert 100 entries at timestamps "1" and "2"
for (int i = 0; i < 100; i++) {
timeSeriesStore.put("hello", "world-1".getBytes(), 1L);
timeSeriesStore.put("hello", "world-2".getBytes(), 2L);
}
// read from time-range [0,2) should return 100 entries
List<TimestampedValue<byte[]>> values = readStore(timeSeriesStore, "hello", 0L, 2L);
Assert.assertEquals(100, values.size());
values.forEach(timeSeriesValue -> {
Assert.assertEquals("world-1", new String(timeSeriesValue.getValue()));
});
// read from time-range [2,4) should return 100 entries
values = readStore(timeSeriesStore, "hello", 2L, 4L);
Assert.assertEquals(100, values.size());
values.forEach(timeSeriesValue -> {
Assert.assertEquals("world-2", new String(timeSeriesValue.getValue()));
});
// read all entries in the store
values = readStore(timeSeriesStore, "hello", 0L, Integer.MAX_VALUE);
Assert.assertEquals(200, values.size());
}
use of org.apache.samza.serializers.StringSerde in project samza by apache.
the class TestTimeSeriesStoreImpl method testDeletesInOverwriteMode.
@Test
public void testDeletesInOverwriteMode() {
// instantiate a store in overwrite mode
TimeSeriesStore<String, byte[]> timeSeriesStore = newTimeSeriesStore(new StringSerde("UTF-8"), false);
// insert an entry with key "hello" at timestamps "1" and "2"
timeSeriesStore.put("hello", "world-1".getBytes(), 1L);
timeSeriesStore.put("hello", "world-1".getBytes(), 2L);
timeSeriesStore.put("hello", "world-2".getBytes(), 2L);
List<TimestampedValue<byte[]>> values = readStore(timeSeriesStore, "hello", 1L, 3L);
Assert.assertEquals(2, values.size());
timeSeriesStore.remove("hello", 0L, 3L);
values = readStore(timeSeriesStore, "hello", 1L, 3L);
Assert.assertEquals(0, values.size());
}
Aggregations