|
|
@ -27,25 +27,25 @@ import static org.hamcrest.Matchers.notNullValue; |
|
|
|
import static org.hamcrest.Matchers.nullValue; |
|
|
|
import static org.hamcrest.Matchers.nullValue; |
|
|
|
|
|
|
|
|
|
|
|
public class ValueAndTimestampSerializerTest { |
|
|
|
public class ValueAndTimestampSerializerTest { |
|
|
|
private static final String topic = "some-topic"; |
|
|
|
private static final String TOPIC = "some-topic"; |
|
|
|
private static final long timestamp = 23; |
|
|
|
private static final long TIMESTAMP = 23; |
|
|
|
|
|
|
|
|
|
|
|
private static final ValueAndTimestampSerde<String> stringSerde = |
|
|
|
private static final ValueAndTimestampSerde<String> STRING_SERDE = |
|
|
|
new ValueAndTimestampSerde<>(Serdes.String()); |
|
|
|
new ValueAndTimestampSerde<>(Serdes.String()); |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void shouldSerializeNonNullDataUsingTheInternalSerializer() { |
|
|
|
public void shouldSerializeNonNullDataUsingTheInternalSerializer() { |
|
|
|
final String value = "some-string"; |
|
|
|
final String value = "some-string"; |
|
|
|
|
|
|
|
|
|
|
|
final ValueAndTimestamp<String> valueAndTimestamp = ValueAndTimestamp.make(value, timestamp); |
|
|
|
final ValueAndTimestamp<String> valueAndTimestamp = ValueAndTimestamp.make(value, TIMESTAMP); |
|
|
|
|
|
|
|
|
|
|
|
final byte[] serialized = |
|
|
|
final byte[] serialized = |
|
|
|
stringSerde.serializer().serialize(topic, valueAndTimestamp); |
|
|
|
STRING_SERDE.serializer().serialize(TOPIC, valueAndTimestamp); |
|
|
|
|
|
|
|
|
|
|
|
assertThat(serialized, is(notNullValue())); |
|
|
|
assertThat(serialized, is(notNullValue())); |
|
|
|
|
|
|
|
|
|
|
|
final ValueAndTimestamp<String> deserialized = |
|
|
|
final ValueAndTimestamp<String> deserialized = |
|
|
|
stringSerde.deserializer().deserialize(topic, serialized); |
|
|
|
STRING_SERDE.deserializer().deserialize(TOPIC, serialized); |
|
|
|
|
|
|
|
|
|
|
|
assertThat(deserialized, is(valueAndTimestamp)); |
|
|
|
assertThat(deserialized, is(valueAndTimestamp)); |
|
|
|
} |
|
|
|
} |
|
|
@ -53,7 +53,7 @@ public class ValueAndTimestampSerializerTest { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void shouldSerializeNullDataAsNull() { |
|
|
|
public void shouldSerializeNullDataAsNull() { |
|
|
|
final byte[] serialized = |
|
|
|
final byte[] serialized = |
|
|
|
stringSerde.serializer().serialize(topic, ValueAndTimestamp.make(null, timestamp)); |
|
|
|
STRING_SERDE.serializer().serialize(TOPIC, ValueAndTimestamp.make(null, TIMESTAMP)); |
|
|
|
|
|
|
|
|
|
|
|
assertThat(serialized, is(nullValue())); |
|
|
|
assertThat(serialized, is(nullValue())); |
|
|
|
} |
|
|
|
} |
|
|
@ -67,7 +67,7 @@ public class ValueAndTimestampSerializerTest { |
|
|
|
final ValueAndTimestampSerializer<String> serializer = |
|
|
|
final ValueAndTimestampSerializer<String> serializer = |
|
|
|
new ValueAndTimestampSerializer<>(alwaysNullSerializer); |
|
|
|
new ValueAndTimestampSerializer<>(alwaysNullSerializer); |
|
|
|
|
|
|
|
|
|
|
|
final byte[] serialized = serializer.serialize(topic, "non-null-data", timestamp); |
|
|
|
final byte[] serialized = serializer.serialize(TOPIC, "non-null-data", TIMESTAMP); |
|
|
|
|
|
|
|
|
|
|
|
assertThat(serialized, is(nullValue())); |
|
|
|
assertThat(serialized, is(nullValue())); |
|
|
|
} |
|
|
|
} |
|
|
|