Search in sources :

Example 46 with SessionWindow

use of org.apache.kafka.streams.kstream.internals.SessionWindow 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)

Example 47 with SessionWindow

use of org.apache.kafka.streams.kstream.internals.SessionWindow in project apache-kafka-on-k8s by banzaicloud.

the class MeteredSessionStoreTest method shouldWriteBytesToInnerStoreAndRecordPutMetric.

@Test
public void shouldWriteBytesToInnerStoreAndRecordPutMetric() {
    inner.put(EasyMock.eq(windowedKeyBytes), EasyMock.aryEq(keyBytes));
    EasyMock.expectLastCall();
    init();
    metered.put(new Windowed<>(key, new SessionWindow(0, 0)), key);
    final KafkaMetric metric = metric("put-rate");
    assertTrue(metric.value() > 0);
    EasyMock.verify(inner);
}
Also used : SessionWindow(org.apache.kafka.streams.kstream.internals.SessionWindow) KafkaMetric(org.apache.kafka.common.metrics.KafkaMetric) Test(org.junit.Test)

Example 48 with SessionWindow

use of org.apache.kafka.streams.kstream.internals.SessionWindow in project apache-kafka-on-k8s by banzaicloud.

the class MeteredSessionStoreTest method shouldRemoveFromStoreAndRecordRemoveMetric.

@Test
public void shouldRemoveFromStoreAndRecordRemoveMetric() {
    inner.remove(windowedKeyBytes);
    EasyMock.expectLastCall();
    init();
    metered.remove(new Windowed<>(key, new SessionWindow(0, 0)));
    final KafkaMetric metric = metric("remove-rate");
    assertTrue(metric.value() > 0);
    EasyMock.verify(inner);
}
Also used : SessionWindow(org.apache.kafka.streams.kstream.internals.SessionWindow) KafkaMetric(org.apache.kafka.common.metrics.KafkaMetric) Test(org.junit.Test)

Example 49 with SessionWindow

use of org.apache.kafka.streams.kstream.internals.SessionWindow in project apache-kafka-on-k8s by banzaicloud.

the class RocksDBSegmentedBytesStoreTest method shouldGetAllSegments.

@Test
public void shouldGetAllSegments() {
    // just to validate directories
    final Segments segments = new Segments(storeName, retention, numSegments);
    final String key = "a";
    bytesStore.put(serializeKey(new Windowed<>(key, new SessionWindow(0L, 0L))), serializeValue(50L));
    assertEquals(Collections.singleton(segments.segmentName(0)), segmentDirs());
    bytesStore.put(serializeKey(new Windowed<>(key, new SessionWindow(30000L, 60000L))), serializeValue(100L));
    assertEquals(Utils.mkSet(segments.segmentName(0), segments.segmentName(1)), segmentDirs());
    bytesStore.put(serializeKey(new Windowed<>(key, new SessionWindow(61000L, 120000L))), serializeValue(200L));
    assertEquals(Utils.mkSet(segments.segmentName(0), segments.segmentName(1), segments.segmentName(2)), segmentDirs());
    final List<KeyValue<Windowed<String>, Long>> results = toList(bytesStore.all());
    assertEquals(Arrays.asList(KeyValue.pair(new Windowed<>(key, new SessionWindow(0L, 0L)), 50L), KeyValue.pair(new Windowed<>(key, new SessionWindow(30000L, 60000L)), 100L), KeyValue.pair(new Windowed<>(key, new SessionWindow(61000L, 120000L)), 200L)), results);
}
Also used : Windowed(org.apache.kafka.streams.kstream.Windowed) KeyValue(org.apache.kafka.streams.KeyValue) SessionWindow(org.apache.kafka.streams.kstream.internals.SessionWindow) Test(org.junit.Test)

Example 50 with SessionWindow

use of org.apache.kafka.streams.kstream.internals.SessionWindow in project apache-kafka-on-k8s by banzaicloud.

the class RocksDBSegmentedBytesStoreTest method shouldFetchAllSegments.

@Test
public void shouldFetchAllSegments() {
    // just to validate directories
    final Segments segments = new Segments(storeName, retention, numSegments);
    final String key = "a";
    bytesStore.put(serializeKey(new Windowed<>(key, new SessionWindow(0L, 0L))), serializeValue(50L));
    assertEquals(Collections.singleton(segments.segmentName(0)), segmentDirs());
    bytesStore.put(serializeKey(new Windowed<>(key, new SessionWindow(30000L, 60000L))), serializeValue(100L));
    assertEquals(Utils.mkSet(segments.segmentName(0), segments.segmentName(1)), segmentDirs());
    bytesStore.put(serializeKey(new Windowed<>(key, new SessionWindow(61000L, 120000L))), serializeValue(200L));
    assertEquals(Utils.mkSet(segments.segmentName(0), segments.segmentName(1), segments.segmentName(2)), segmentDirs());
    final List<KeyValue<Windowed<String>, Long>> results = toList(bytesStore.fetchAll(0L, 60000L));
    assertEquals(Arrays.asList(KeyValue.pair(new Windowed<>(key, new SessionWindow(0L, 0L)), 50L), KeyValue.pair(new Windowed<>(key, new SessionWindow(30000L, 60000L)), 100L)), results);
}
Also used : Windowed(org.apache.kafka.streams.kstream.Windowed) KeyValue(org.apache.kafka.streams.KeyValue) SessionWindow(org.apache.kafka.streams.kstream.internals.SessionWindow) Test(org.junit.Test)

Aggregations

SessionWindow (org.apache.kafka.streams.kstream.internals.SessionWindow)126 Test (org.junit.Test)112 Windowed (org.apache.kafka.streams.kstream.Windowed)110 Bytes (org.apache.kafka.common.utils.Bytes)50 KeyValue (org.apache.kafka.streams.KeyValue)50 ArrayList (java.util.ArrayList)10 Properties (java.util.Properties)9 HashMap (java.util.HashMap)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 StringSerializer (org.apache.kafka.common.serialization.StringSerializer)8 StreamsTestUtils.verifyWindowedKeyValue (org.apache.kafka.test.StreamsTestUtils.verifyWindowedKeyValue)8 LinkedList (java.util.LinkedList)6 ReadOnlySessionStoreStub (org.apache.kafka.test.ReadOnlySessionStoreStub)6 GenericRow (io.confluent.ksql.GenericRow)4 StringDeserializer (org.apache.kafka.common.serialization.StringDeserializer)4 KeyValueTimestamp (org.apache.kafka.streams.KeyValueTimestamp)4 ProcessorContext (org.apache.kafka.streams.processor.ProcessorContext)4 IntegrationTest (org.apache.kafka.test.IntegrationTest)4 GenericKey (io.confluent.ksql.GenericKey)3 KafkaMetric (org.apache.kafka.common.metrics.KafkaMetric)3