Search in sources :

Example 1 with TopicInfo

use of io.confluent.ksql.test.tools.TopicInfoCache.TopicInfo in project ksql by confluentinc.

the class TestExecutor method serialize.

private ProducerRecord<byte[], byte[]> serialize(final ProducerRecord<?, ?> rec) {
    final TopicInfo topicInfo = topicInfoCache.get(rec.topic()).orElseThrow(() -> new KsqlException("No information found for topic: " + rec.topic()));
    final byte[] key;
    final byte[] value;
    try {
        key = topicInfo.getKeySerializer().serialize(rec.topic(), rec.key());
    } catch (final Exception e) {
        throw new AssertionError("Failed to serialize key: " + e.getMessage() + System.lineSeparator() + "rec: " + rec, e);
    }
    try {
        value = topicInfo.getValueSerializer().serialize(rec.topic(), rec.value());
    } catch (final Exception e) {
        throw new AssertionError("Failed to serialize value: " + e.getMessage() + System.lineSeparator() + "rec: " + rec, e);
    }
    return new ProducerRecord<>(rec.topic(), rec.partition(), rec.timestamp(), key, value, rec.headers());
}
Also used : ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) KsqlException(io.confluent.ksql.util.KsqlException) TopicInfo(io.confluent.ksql.test.tools.TopicInfoCache.TopicInfo) KsqlException(io.confluent.ksql.util.KsqlException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) KsqlServerException(io.confluent.ksql.util.KsqlServerException)

Example 2 with TopicInfo

use of io.confluent.ksql.test.tools.TopicInfoCache.TopicInfo in project ksql by confluentinc.

the class TestExecutor method verifyOutput.

private void verifyOutput(final TestCase testCase) {
    final boolean ranWithInsertStatements = testCase.getInputRecords().size() == 0;
    final Map<String, List<Record>> expectedByTopic = testCase.getOutputRecords().stream().collect(Collectors.groupingBy(Record::getTopicName));
    final Map<String, List<ProducerRecord<byte[], byte[]>>> actualByTopic = expectedByTopic.keySet().stream().collect(Collectors.toMap(Function.identity(), kafka::readRecords));
    expectedByTopic.forEach((kafkaTopic, expectedRecords) -> {
        final TopicInfo topicInfo = topicInfoCache.get(kafkaTopic).orElseThrow(() -> new KsqlException("No information found for topic: " + kafkaTopic));
        final List<ProducerRecord<?, ?>> actualRecords = actualByTopic.getOrDefault(kafkaTopic, ImmutableList.of()).stream().map(rec -> deserialize(rec, topicInfo)).collect(Collectors.toList());
        if (validateResults) {
            validateTopicData(kafkaTopic, expectedRecords, actualRecords, ranWithInsertStatements);
        }
    });
}
Also used : InternalFunctionRegistry(io.confluent.ksql.function.InternalFunctionRegistry) SchemaNode(io.confluent.ksql.test.model.SchemaNode) SequentialQueryIdGenerator(io.confluent.ksql.query.id.SequentialQueryIdGenerator) SourceNode(io.confluent.ksql.test.model.SourceNode) StringDescription(org.hamcrest.StringDescription) SchemaRegistryClient(io.confluent.kafka.schemaregistry.client.SchemaRegistryClient) ServiceContext(io.confluent.ksql.services.ServiceContext) ProcessingLogContext(io.confluent.ksql.logging.processing.ProcessingLogContext) MutableMetaStore(io.confluent.ksql.metastore.MutableMetaStore) ByteBuffer(java.nio.ByteBuffer) DefaultConnectClient(io.confluent.ksql.services.DefaultConnectClient) NullNode(com.fasterxml.jackson.databind.node.NullNode) TestUtils(io.confluent.ksql.test.utils.TestUtils) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) TestRecord(org.apache.kafka.streams.test.TestRecord) CONNECT_REQUEST_TIMEOUT_DEFAULT(io.confluent.ksql.util.KsqlConfig.CONNECT_REQUEST_TIMEOUT_DEFAULT) MockSchemaRegistryClient(io.confluent.kafka.schemaregistry.client.MockSchemaRegistryClient) TestHeader(io.confluent.ksql.test.model.TestHeader) DefaultServiceContext(io.confluent.ksql.services.DefaultServiceContext) ImmutableSet(com.google.common.collect.ImmutableSet) RuntimeBuildContext(io.confluent.ksql.execution.runtime.RuntimeBuildContext) ImmutableMap(com.google.common.collect.ImmutableMap) FunctionRegistry(io.confluent.ksql.function.FunctionRegistry) Collection(java.util.Collection) TopicInfo(io.confluent.ksql.test.tools.TopicInfoCache.TopicInfo) Set(java.util.Set) ConsumerConfig(org.apache.kafka.clients.consumer.ConsumerConfig) KsqlConfig(io.confluent.ksql.util.KsqlConfig) Streams(com.google.common.collect.Streams) Collectors(java.util.stream.Collectors) MetaStoreImpl(io.confluent.ksql.metastore.MetaStoreImpl) DisabledKsqlClient(io.confluent.ksql.services.DisabledKsqlClient) List(java.util.List) Header(org.apache.kafka.common.header.Header) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) Entry(java.util.Map.Entry) KsqlEngineMetrics(io.confluent.ksql.internal.KsqlEngineMetrics) KsqlException(io.confluent.ksql.util.KsqlException) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) StreamsConfig(org.apache.kafka.streams.StreamsConfig) StubKafkaTopicClient(io.confluent.ksql.test.tools.stubs.StubKafkaTopicClient) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) WindowData(io.confluent.ksql.test.model.WindowData) PostTopicNode(io.confluent.ksql.test.model.PostConditionsNode.PostTopicNode) Headers(org.apache.kafka.common.header.Headers) MetricCollectors(io.confluent.ksql.metrics.MetricCollectors) OptionalInt(java.util.OptionalInt) Function(java.util.function.Function) StubKafkaClientSupplier(io.confluent.ksql.test.tools.stubs.StubKafkaClientSupplier) SchemaRegistryUtil(io.confluent.ksql.schema.registry.SchemaRegistryUtil) ImmutableList(com.google.common.collect.ImmutableList) Windowed(org.apache.kafka.streams.kstream.Windowed) Objects.requireNonNull(java.util.Objects.requireNonNull) StubKafkaService(io.confluent.ksql.test.tools.stubs.StubKafkaService) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) ProtobufFormat(io.confluent.ksql.serde.protobuf.ProtobufFormat) TestOutputTopic(org.apache.kafka.streams.TestOutputTopic) Iterator(java.util.Iterator) KsqlEngine(io.confluent.ksql.engine.KsqlEngine) MutableFunctionRegistry(io.confluent.ksql.function.MutableFunctionRegistry) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) StubKafkaConsumerGroupClient(io.confluent.ksql.test.tools.stubs.StubKafkaConsumerGroupClient) BytesUtils(io.confluent.ksql.util.BytesUtils) JUnitMatchers.isThrowable(org.junit.matchers.JUnitMatchers.isThrowable) KsqlServerException(io.confluent.ksql.util.KsqlServerException) Closeable(java.io.Closeable) Matcher(org.hamcrest.Matcher) VisibleForTesting(com.google.common.annotations.VisibleForTesting) SchemaMetadata(io.confluent.kafka.schemaregistry.client.SchemaMetadata) Collections(java.util.Collections) UdfLoaderUtil(io.confluent.ksql.function.UdfLoaderUtil) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) KsqlException(io.confluent.ksql.util.KsqlException) TopicInfo(io.confluent.ksql.test.tools.TopicInfoCache.TopicInfo)

Example 3 with TopicInfo

use of io.confluent.ksql.test.tools.TopicInfoCache.TopicInfo in project ksql by confluentinc.

the class RestTestExecutor method verifyOutput.

private void verifyOutput(final RestTestCase testCase) {
    testCase.getOutputsByTopic().forEach((topicName, records) -> {
        final TopicInfo topicInfo = topicInfoCache.get(topicName).orElseThrow(() -> new KsqlException("No information found for topic: " + topicName));
        final List<? extends ConsumerRecord<?, ?>> received = kafkaCluster.verifyAvailableRecords(topicName, records.size(), topicInfo.getKeyDeserializer(), topicInfo.getValueDeserializer());
        for (int idx = 0; idx < records.size(); idx++) {
            final Record expected = records.get(idx);
            final ConsumerRecord<?, ?> actual = received.get(idx);
            compareKeyValueTimestamp(actual, expected);
        }
    });
}
Also used : Record(io.confluent.ksql.test.tools.Record) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) KsqlException(io.confluent.ksql.util.KsqlException) TopicInfo(io.confluent.ksql.test.tools.TopicInfoCache.TopicInfo)

Aggregations

TopicInfo (io.confluent.ksql.test.tools.TopicInfoCache.TopicInfo)3 KsqlException (io.confluent.ksql.util.KsqlException)3 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)1 NullNode (com.fasterxml.jackson.databind.node.NullNode)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Streams (com.google.common.collect.Streams)1 MockSchemaRegistryClient (io.confluent.kafka.schemaregistry.client.MockSchemaRegistryClient)1 SchemaMetadata (io.confluent.kafka.schemaregistry.client.SchemaMetadata)1 SchemaRegistryClient (io.confluent.kafka.schemaregistry.client.SchemaRegistryClient)1 KsqlEngine (io.confluent.ksql.engine.KsqlEngine)1 RuntimeBuildContext (io.confluent.ksql.execution.runtime.RuntimeBuildContext)1 FunctionRegistry (io.confluent.ksql.function.FunctionRegistry)1 InternalFunctionRegistry (io.confluent.ksql.function.InternalFunctionRegistry)1 MutableFunctionRegistry (io.confluent.ksql.function.MutableFunctionRegistry)1