use of io.confluent.ksql.test.model.WindowData in project ksql by confluentinc.
the class TestExecutor method validateCreatedMessage.
private static void validateCreatedMessage(final String topicName, final Record expectedRecord, final ProducerRecord<?, ?> actualProducerRecord, final boolean ranWithInsertStatements, final int messageIndex) {
final Object actualKey = coerceRecordFields(actualProducerRecord.key());
final Object actualValue = coerceRecordFields(actualProducerRecord.value());
final long actualTimestamp = actualProducerRecord.timestamp();
final Headers actualHeaders = actualProducerRecord.headers();
final JsonNode expectedKey = expectedRecord.getJsonKey().orElse(NullNode.getInstance());
final JsonNode expectedValue = expectedRecord.getJsonValue().orElseThrow(() -> new KsqlServerException("could not get expected value from test record: " + expectedRecord));
final long expectedTimestamp = expectedRecord.timestamp().orElse(actualTimestamp);
final List<TestHeader> expectedHeaders = expectedRecord.headers().orElse(ImmutableList.of());
final AssertionError error = new AssertionError("Topic '" + topicName + "', message " + messageIndex + ": Expected <" + expectedKey + ", " + expectedValue + "> " + "with timestamp=" + expectedTimestamp + " and headers=[" + printHeaders(expectedHeaders) + "] but was " + getProducerRecordInString(actualProducerRecord));
if (expectedRecord.getWindow() != null) {
final Windowed<?> windowed = (Windowed<?>) actualKey;
if (!new WindowData(windowed).equals(expectedRecord.getWindow()) || !ExpectedRecordComparator.matches(((Windowed<?>) actualKey).key(), expectedKey)) {
throw error;
}
} else {
if (!ExpectedRecordComparator.matches(actualKey, expectedKey)) {
throw error;
}
}
if (!ExpectedRecordComparator.matches(actualValue, expectedValue)) {
throw error;
}
if (!ExpectedRecordComparator.matches(actualHeaders.toArray(), expectedHeaders)) {
throw error;
}
if ((actualTimestamp != expectedTimestamp) && (!ranWithInsertStatements || expectedTimestamp != 0L)) {
throw error;
}
}
use of io.confluent.ksql.test.model.WindowData in project ksql by confluentinc.
the class RecordTest method shouldGetSessionWindowKey.
@Test
public void shouldGetSessionWindowKey() {
// Given:
final Record record = new Record(TOPIC_NAME, "foo", null, "bar", null, Optional.of(1000L), new WindowData(100L, 1000L, "SESSION"), Optional.empty());
// When:
final Object key = record.key();
// Then:
assertThat(key, instanceOf(Windowed.class));
final Windowed<?> windowed = (Windowed<?>) key;
assertThat(windowed.window(), instanceOf(SessionWindow.class));
assertThat(windowed.window().start(), equalTo(100L));
assertThat(windowed.window().end(), equalTo(1000L));
}
use of io.confluent.ksql.test.model.WindowData in project ksql by confluentinc.
the class RecordTest method shouldGetTimeWindowKey.
@Test
public void shouldGetTimeWindowKey() {
// Given:
final Record record = new Record(TOPIC_NAME, "foo", null, "bar", null, Optional.of(1000L), new WindowData(100L, 1000L, "TIME"), Optional.empty());
// When:
final Object key = record.key();
// Then:
assertThat(key, instanceOf(Windowed.class));
final Windowed<?> windowed = (Windowed<?>) key;
assertThat(windowed.window(), instanceOf(TimeWindow.class));
assertThat(windowed.window().start(), equalTo(100L));
assertThat(windowed.window().end(), equalTo(1000L));
}
use of io.confluent.ksql.test.model.WindowData in project ksql by confluentinc.
the class RecordTest method shouldGetHeaders.
@Test
public void shouldGetHeaders() {
// Given:
final Record record = new Record(TOPIC_NAME, "foo", null, "bar", null, Optional.of(1000L), new WindowData(100L, 1000L, "SESSION"), Optional.of(ImmutableList.of(new TestHeader("a", new byte[] { 12 }))));
// When:
final List<TestHeader> headers = record.headers().get();
// Then:
assertThat(headers.size(), equalTo(1));
assertThat(headers.get(0).key(), equalTo("a"));
assertThat(headers.get(0).value(), equalTo(new byte[] { 12 }));
}
Aggregations