Search in sources :

Example 46 with Bytes

use of org.apache.kafka.common.utils.Bytes in project apache-kafka-on-k8s by banzaicloud.

the class SessionKeySchemaTest method testUpperBoundWithLargeTimestamps.

@Test
public void testUpperBoundWithLargeTimestamps() {
    Bytes upper = sessionKeySchema.upperRange(Bytes.wrap(new byte[] { 0xA, 0xB, 0xC }), Long.MAX_VALUE);
    assertThat("shorter key with max timestamp should be in range", upper.compareTo(Bytes.wrap(SessionKeySchema.toBinary(new Windowed<>(Bytes.wrap(new byte[] { 0xA }), new SessionWindow(Long.MAX_VALUE, Long.MAX_VALUE))))) >= 0);
    assertThat("shorter key with max timestamp should be in range", upper.compareTo(Bytes.wrap(SessionKeySchema.toBinary(new Windowed<>(Bytes.wrap(new byte[] { 0xA, 0xB }), new SessionWindow(Long.MAX_VALUE, Long.MAX_VALUE))))) >= 0);
    assertThat(upper, equalTo(Bytes.wrap(SessionKeySchema.toBinary(new Windowed<>(Bytes.wrap(new byte[] { 0xA }), new SessionWindow(Long.MAX_VALUE, Long.MAX_VALUE))))));
}
Also used : Windowed(org.apache.kafka.streams.kstream.Windowed) Bytes(org.apache.kafka.common.utils.Bytes) SessionWindow(org.apache.kafka.streams.kstream.internals.SessionWindow) Test(org.junit.Test)

Example 47 with Bytes

use of org.apache.kafka.common.utils.Bytes in project apache-kafka-on-k8s by banzaicloud.

the class SessionKeySchemaTest method testUpperBoundWithKeyBytesLargerThanFirstTimestampByte.

@Test
public void testUpperBoundWithKeyBytesLargerThanFirstTimestampByte() {
    Bytes upper = sessionKeySchema.upperRange(Bytes.wrap(new byte[] { 0xA, (byte) 0x8F, (byte) 0x9F }), Long.MAX_VALUE);
    assertThat("shorter key with max timestamp should be in range", upper.compareTo(Bytes.wrap(SessionKeySchema.toBinary(new Windowed<>(Bytes.wrap(new byte[] { 0xA, (byte) 0x8F }), new SessionWindow(Long.MAX_VALUE, Long.MAX_VALUE))))) >= 0);
    assertThat(upper, equalTo(Bytes.wrap(SessionKeySchema.toBinary(new Windowed<>(Bytes.wrap(new byte[] { 0xA, (byte) 0x8F, (byte) 0x9F }), new SessionWindow(Long.MAX_VALUE, Long.MAX_VALUE))))));
}
Also used : Windowed(org.apache.kafka.streams.kstream.Windowed) Bytes(org.apache.kafka.common.utils.Bytes) SessionWindow(org.apache.kafka.streams.kstream.internals.SessionWindow) Test(org.junit.Test)

Example 48 with Bytes

use of org.apache.kafka.common.utils.Bytes in project apache-kafka-on-k8s by banzaicloud.

the class SessionKeySchemaTest method testLowerBoundWithZeroTimestamp.

@Test
public void testLowerBoundWithZeroTimestamp() {
    Bytes lower = sessionKeySchema.lowerRange(Bytes.wrap(new byte[] { 0xA, 0xB, 0xC }), 0);
    assertThat(lower, equalTo(Bytes.wrap(SessionKeySchema.toBinary(new Windowed<>(Bytes.wrap(new byte[] { 0xA, 0xB, 0xC }), new SessionWindow(0, 0))))));
}
Also used : Windowed(org.apache.kafka.streams.kstream.Windowed) Bytes(org.apache.kafka.common.utils.Bytes) SessionWindow(org.apache.kafka.streams.kstream.internals.SessionWindow) Test(org.junit.Test)

Example 49 with Bytes

use of org.apache.kafka.common.utils.Bytes in project apache-kafka-on-k8s by banzaicloud.

the class SessionKeySchemaTest method shouldFetchExactKeysSkippingLongerKeys.

@Test
public void shouldFetchExactKeysSkippingLongerKeys() {
    final Bytes key = Bytes.wrap(new byte[] { 0 });
    final List<Integer> result = getValues(sessionKeySchema.hasNextCondition(key, key, 0, Long.MAX_VALUE));
    assertThat(result, equalTo(Arrays.asList(2, 4)));
}
Also used : Bytes(org.apache.kafka.common.utils.Bytes) Test(org.junit.Test)

Example 50 with Bytes

use of org.apache.kafka.common.utils.Bytes in project apache-kafka-on-k8s by banzaicloud.

the class SessionKeySchemaTest method testUpperBoundWithZeroTimestamp.

@Test
public void testUpperBoundWithZeroTimestamp() {
    Bytes upper = sessionKeySchema.upperRange(Bytes.wrap(new byte[] { 0xA, 0xB, 0xC }), 0);
    assertThat(upper, equalTo(Bytes.wrap(SessionKeySchema.toBinary(new Windowed<>(Bytes.wrap(new byte[] { 0xA, 0xB, 0xC }), new SessionWindow(0, 0))))));
}
Also used : Windowed(org.apache.kafka.streams.kstream.Windowed) Bytes(org.apache.kafka.common.utils.Bytes) SessionWindow(org.apache.kafka.streams.kstream.internals.SessionWindow) Test(org.junit.Test)

Aggregations

Bytes (org.apache.kafka.common.utils.Bytes)398 Test (org.junit.Test)309 Windowed (org.apache.kafka.streams.kstream.Windowed)84 KeyValue (org.apache.kafka.streams.KeyValue)68 StreamsBuilder (org.apache.kafka.streams.StreamsBuilder)53 SessionWindow (org.apache.kafka.streams.kstream.internals.SessionWindow)50 Properties (java.util.Properties)49 ArrayList (java.util.ArrayList)42 StringSerializer (org.apache.kafka.common.serialization.StringSerializer)38 StreamsConfig (org.apache.kafka.streams.StreamsConfig)35 KeyValueStore (org.apache.kafka.streams.state.KeyValueStore)35 Materialized (org.apache.kafka.streams.kstream.Materialized)33 Serdes (org.apache.kafka.common.serialization.Serdes)32 Metrics (org.apache.kafka.common.metrics.Metrics)29 KafkaStreams (org.apache.kafka.streams.KafkaStreams)28 MockStreamsMetrics (org.apache.kafka.streams.processor.internals.MockStreamsMetrics)27 Consumed (org.apache.kafka.streams.kstream.Consumed)25 KTable (org.apache.kafka.streams.kstream.KTable)23 TopologyTestDriver (org.apache.kafka.streams.TopologyTestDriver)22 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)21