Search in sources :

Example 16 with Bytes

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()));
}
Also used : Bytes(org.apache.kafka.common.utils.Bytes) Test(org.junit.Test)

Example 17 with Bytes

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()));
}
Also used : Bytes(org.apache.kafka.common.utils.Bytes) Test(org.junit.Test)

Example 18 with Bytes

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()));
}
Also used : Bytes(org.apache.kafka.common.utils.Bytes) Test(org.junit.Test)

Example 19 with Bytes

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) {
    }
}
Also used : Bytes(org.apache.kafka.common.utils.Bytes) MockProducer(org.apache.kafka.clients.producer.MockProducer) StreamsException(org.apache.kafka.streams.errors.StreamsException) StateSerdes(org.apache.kafka.streams.state.StateSerdes) MockProcessorContext(org.apache.kafka.test.MockProcessorContext) Serializer(org.apache.kafka.common.serialization.Serializer) Test(org.junit.Test)

Example 20 with Bytes

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));
}
Also used : Bytes(org.apache.kafka.common.utils.Bytes) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Test(org.junit.Test)

Aggregations

Bytes (org.apache.kafka.common.utils.Bytes)54 Test (org.junit.Test)34 Metrics (org.apache.kafka.common.metrics.Metrics)14 MockStreamsMetrics (org.apache.kafka.streams.processor.internals.MockStreamsMetrics)14 Windowed (org.apache.kafka.streams.kstream.Windowed)5 ArrayList (java.util.ArrayList)4 KeyValue (org.apache.kafka.streams.KeyValue)4 SessionWindow (org.apache.kafka.streams.kstream.internals.SessionWindow)3 MockProcessorContext (org.apache.kafka.test.MockProcessorContext)3 ByteBuffer (java.nio.ByteBuffer)2 NoSuchElementException (java.util.NoSuchElementException)2 ProcessorRecordContext (org.apache.kafka.streams.processor.internals.ProcessorRecordContext)2 KeyValueIterator (org.apache.kafka.streams.state.KeyValueIterator)2 Before (org.junit.Before)2 MockProducer (org.apache.kafka.clients.producer.MockProducer)1 Serializer (org.apache.kafka.common.serialization.Serializer)1 StreamsException (org.apache.kafka.streams.errors.StreamsException)1 RecordContext (org.apache.kafka.streams.processor.internals.RecordContext)1 StateSerdes (org.apache.kafka.streams.state.StateSerdes)1