use of org.apache.kafka.common.utils.Bytes in project kafka by apache.
the class SessionKeySerdeTest method shouldExtractWindowFromBindary.
@Test
public void shouldExtractWindowFromBindary() throws Exception {
final Bytes serialized = SessionKeySerde.toBinary(windowedKey, serde.serializer());
assertEquals(window, SessionKeySerde.extractWindow(serialized.get()));
}
use of org.apache.kafka.common.utils.Bytes in project kafka by apache.
the class SessionKeySerdeTest method shouldExtractEndTimeFromBinary.
@Test
public void shouldExtractEndTimeFromBinary() throws Exception {
final Bytes serialized = SessionKeySerde.toBinary(windowedKey, serde.serializer());
assertEquals(endTime, SessionKeySerde.extractEnd(serialized.get()));
}
use of org.apache.kafka.common.utils.Bytes in project kafka by apache.
the class SessionKeySerdeTest method shouldExtractStartTimeFromBinary.
@Test
public void shouldExtractStartTimeFromBinary() throws Exception {
final Bytes serialized = SessionKeySerde.toBinary(windowedKey, serde.serializer());
assertEquals(startTime, SessionKeySerde.extractStart(serialized.get()));
}
use of org.apache.kafka.common.utils.Bytes in project kafka by apache.
the class SinkNodeTest method shouldThrowStreamsExceptionOnInputRecordWithInvalidTimestamp.
@Test
@SuppressWarnings("unchecked")
public void shouldThrowStreamsExceptionOnInputRecordWithInvalidTimestamp() {
// Given
final Serializer anySerializer = Serdes.Bytes().serializer();
final StateSerdes anyStateSerde = StateSerdes.withBuiltinTypes("anyName", Bytes.class, Bytes.class);
final MockProcessorContext context = new MockProcessorContext(anyStateSerde, new RecordCollectorImpl(new MockProducer<byte[], byte[]>(true, anySerializer, anySerializer), null));
final SinkNode sink = new SinkNode<>("anyNodeName", "any-output-topic", anySerializer, anySerializer, null);
sink.init(context);
final Bytes anyKey = new Bytes("any key".getBytes());
final Bytes anyValue = new Bytes("any value".getBytes());
// When/Then
// ensures a negative timestamp is set for the record we send next
context.setTime(-1);
try {
sink.process(anyKey, anyValue);
fail("Should have thrown StreamsException");
} catch (final StreamsException ignored) {
}
}
use of org.apache.kafka.common.utils.Bytes in project kafka by apache.
the class ThreadCacheTest method shouldDelete.
@Test
public void shouldDelete() throws Exception {
final ThreadCache cache = new ThreadCache("testCache", 10000L, new MockStreamsMetrics(new Metrics()));
final Bytes key = Bytes.wrap(new byte[] { 0 });
cache.put("name", key, dirtyEntry(key.get()));
assertEquals(key.get(), cache.delete("name", key).value);
assertNull(cache.get("name", key));
}
Aggregations