use of io.confluent.ksql.execution.streams.materialization.WindowedRow in project ksql by confluentinc.
the class KsMaterializedWindowTableTest method shouldReturnValuesForOpenEndBounds_fetchAll.
@Test
public void shouldReturnValuesForOpenEndBounds_fetchAll() {
// Given:
final Range<Instant> end = Range.open(NOW, NOW.plusSeconds(10));
final Range<Instant> startEquiv = Range.open(end.lowerEndpoint().minus(WINDOW_SIZE), end.upperEndpoint().minus(WINDOW_SIZE));
when(keyValueIterator.hasNext()).thenReturn(true, true, true, false);
when(keyValueIterator.next()).thenReturn(new KeyValue<>(new Windowed<>(A_KEY, new TimeWindow(startEquiv.lowerEndpoint().toEpochMilli(), startEquiv.lowerEndpoint().toEpochMilli() + WINDOW_SIZE.toMillis())), VALUE_1)).thenReturn(new KeyValue<>(new Windowed<>(A_KEY2, new TimeWindow(startEquiv.lowerEndpoint().plusMillis(1).toEpochMilli(), startEquiv.lowerEndpoint().toEpochMilli() + WINDOW_SIZE.toMillis() + 1)), VALUE_2)).thenReturn(new KeyValue<>(new Windowed<>(A_KEY3, new TimeWindow(startEquiv.upperEndpoint().toEpochMilli(), startEquiv.upperEndpoint().toEpochMilli() + WINDOW_SIZE.toMillis())), VALUE_3)).thenThrow(new AssertionError());
// When:
final Iterator<WindowedRow> rowIterator = table.get(PARTITION, Range.all(), end).rowIterator;
// Then:
assertThat(rowIterator.hasNext(), is(true));
assertThat(rowIterator.next(), is(WindowedRow.of(SCHEMA, windowedKey(A_KEY2, startEquiv.lowerEndpoint().plusMillis(1)), VALUE_2.value(), VALUE_2.timestamp())));
assertThat(rowIterator.hasNext(), is(false));
}
use of io.confluent.ksql.execution.streams.materialization.WindowedRow in project ksql by confluentinc.
the class KsMaterializedWindowTableTest method shouldReturnValuesForOpenStartBounds_fetchAll.
@Test
public void shouldReturnValuesForOpenStartBounds_fetchAll() {
// Given:
final Range<Instant> start = Range.open(NOW, NOW.plusSeconds(10));
when(keyValueIterator.hasNext()).thenReturn(true, true, true, false);
when(keyValueIterator.next()).thenReturn(new KeyValue<>(new Windowed<>(A_KEY, new TimeWindow(start.lowerEndpoint().toEpochMilli(), start.lowerEndpoint().toEpochMilli() + WINDOW_SIZE.toMillis())), VALUE_1)).thenReturn(new KeyValue<>(new Windowed<>(A_KEY2, new TimeWindow(start.lowerEndpoint().plusMillis(1).toEpochMilli(), start.lowerEndpoint().toEpochMilli() + WINDOW_SIZE.toMillis() + 1)), VALUE_2)).thenReturn(new KeyValue<>(new Windowed<>(A_KEY3, new TimeWindow(start.upperEndpoint().toEpochMilli(), start.upperEndpoint().toEpochMilli() + WINDOW_SIZE.toMillis())), VALUE_3)).thenThrow(new AssertionError());
// When:
final Iterator<WindowedRow> rowIterator = table.get(PARTITION, start, Range.all()).rowIterator;
// Then:
assertThat(rowIterator.hasNext(), is(true));
assertThat(rowIterator.next(), is(WindowedRow.of(SCHEMA, windowedKey(A_KEY2, start.lowerEndpoint().plusMillis(1)), VALUE_2.value(), VALUE_2.timestamp())));
assertThat(rowIterator.hasNext(), is(false));
}
use of io.confluent.ksql.execution.streams.materialization.WindowedRow in project ksql by confluentinc.
the class KsMaterializedWindowTableIQv2Test method shouldReturnEmptyIfKeyNotPresent_fetchAll.
@Test
public void shouldReturnEmptyIfKeyNotPresent_fetchAll() {
// When:
final StateQueryResult partitionResult = new StateQueryResult();
final QueryResult queryResult = QueryResult.forResult(keyValueIterator);
queryResult.setPosition(POSITION);
partitionResult.addResult(PARTITION, queryResult);
when(kafkaStreams.query(any())).thenReturn(partitionResult);
when(keyValueIterator.hasNext()).thenReturn(false);
final Iterator<WindowedRow> rowIterator = table.get(PARTITION, WINDOW_START_BOUNDS, WINDOW_END_BOUNDS).rowIterator;
// Then:
assertThat(rowIterator.hasNext(), is(false));
}
use of io.confluent.ksql.execution.streams.materialization.WindowedRow in project ksql by confluentinc.
the class KsMaterializedWindowTableIQv2Test method shouldReturnEmptyIfKeyNotPresent.
@Test
public void shouldReturnEmptyIfKeyNotPresent() {
// When:
final StateQueryResult partitionResult = new StateQueryResult();
final QueryResult result = QueryResult.forResult(fetchIterator);
result.setPosition(POSITION);
partitionResult.addResult(PARTITION, result);
when(kafkaStreams.query(any())).thenReturn(partitionResult);
when(fetchIterator.hasNext()).thenReturn(false);
final Iterator<WindowedRow> rowIterator = table.get(A_KEY, PARTITION, WINDOW_START_BOUNDS, WINDOW_END_BOUNDS).rowIterator;
// Then:
assertThat(rowIterator.hasNext(), is(false));
}
use of io.confluent.ksql.execution.streams.materialization.WindowedRow in project ksql by confluentinc.
the class KsMaterializedWindowTableIQv2Test method shouldReturnValuesForOpenStartBounds_fetchAll.
@Test
public void shouldReturnValuesForOpenStartBounds_fetchAll() {
// Given:
final Range<Instant> start = Range.open(NOW, NOW.plusSeconds(10));
final StateQueryResult partitionResult = new StateQueryResult();
final QueryResult queryResult = QueryResult.forResult(keyValueIterator);
queryResult.setPosition(POSITION);
partitionResult.addResult(PARTITION, queryResult);
when(kafkaStreams.query(any())).thenReturn(partitionResult);
when(keyValueIterator.hasNext()).thenReturn(true, true, true, false);
when(keyValueIterator.next()).thenReturn(new KeyValue<>(new Windowed<>(A_KEY, new TimeWindow(start.lowerEndpoint().toEpochMilli(), start.lowerEndpoint().toEpochMilli() + WINDOW_SIZE.toMillis())), VALUE_1)).thenReturn(new KeyValue<>(new Windowed<>(A_KEY2, new TimeWindow(start.lowerEndpoint().plusMillis(1).toEpochMilli(), start.lowerEndpoint().toEpochMilli() + WINDOW_SIZE.toMillis() + 1)), VALUE_2)).thenReturn(new KeyValue<>(new Windowed<>(A_KEY3, new TimeWindow(start.upperEndpoint().toEpochMilli(), start.upperEndpoint().toEpochMilli() + WINDOW_SIZE.toMillis())), VALUE_3)).thenThrow(new AssertionError());
// When:
final KsMaterializedQueryResult<WindowedRow> result = table.get(PARTITION, start, Range.all());
// Then:
final Iterator<WindowedRow> rowIterator = result.getRowIterator();
assertThat(rowIterator.hasNext(), is(true));
assertThat(rowIterator.next(), is(WindowedRow.of(SCHEMA, windowedKey(A_KEY2, start.lowerEndpoint().plusMillis(1)), VALUE_2.value(), VALUE_2.timestamp())));
assertThat(rowIterator.hasNext(), is(false));
assertThat(result.getPosition(), not(Optional.empty()));
assertThat(result.getPosition().get(), is(POSITION));
}
Aggregations