Skip to content

Commit

Permalink
fix: Remove dependencies on test-jars from ksql-functional-tests jar (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
purplefox committed Sep 27, 2019
1 parent 2f27b68 commit e09d6ad
Show file tree
Hide file tree
Showing 31 changed files with 828 additions and 198 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public KsqlEngine(
queryIdGenerator);
}

KsqlEngine(
public KsqlEngine(
final ServiceContext serviceContext,
final ProcessingLogContext processingLogContext,
final String serviceId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
import org.apache.kafka.connect.data.Struct;

// CHECKSTYLE_RULES.OFF: ClassDataAbstractionCoupling
public class InsertValuesExecutor {
public class StubValuesExecutor {
// CHECKSTYLE_RULES.ON: ClassDataAbstractionCoupling

private static final Duration MAX_SEND_TIMEOUT = Duration.ofSeconds(5);
Expand All @@ -82,8 +82,8 @@ public class InsertValuesExecutor {
private final ValueSerdeFactory valueSerdeFactory;
private final KeySerdeFactory keySerdeFactory;

public InsertValuesExecutor() {
this(true, InsertValuesExecutor::sendRecord);
public StubValuesExecutor() {
this(true, StubValuesExecutor::sendRecord);
}

public interface RecordProducer {
Expand All @@ -96,7 +96,7 @@ void sendRecord(
}

@VisibleForTesting
InsertValuesExecutor(
StubValuesExecutor(
final boolean canBeDisabledByConfig,
final RecordProducer producer
) {
Expand All @@ -110,15 +110,15 @@ void sendRecord(
}

@VisibleForTesting
InsertValuesExecutor(
StubValuesExecutor(
final LongSupplier clock,
final KeySerdeFactory keySerdeFactory,
final ValueSerdeFactory valueSerdeFactory
) {
this(InsertValuesExecutor::sendRecord, true, clock, keySerdeFactory, valueSerdeFactory);
this(StubValuesExecutor::sendRecord, true, clock, keySerdeFactory, valueSerdeFactory);
}

private InsertValuesExecutor(
private StubValuesExecutor(
final RecordProducer producer,
final boolean canBeDisabledByConfig,
final LongSupplier clock,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class DefaultServiceContext implements ServiceContext, AutoCloseable {
private final SchemaRegistryClient srClient;
private final ConnectClient connectClient;

DefaultServiceContext(
public DefaultServiceContext(
final KafkaClientSupplier kafkaClientSupplier,
final Admin adminClient,
final KafkaTopicClient topicClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private TopicValidationUtil() {

}

static void validateTopicProperties(
public static void validateTopicProperties(
final int requiredNumPartition,
final int requiredNumReplicas,
final TopicDescription existingTopic
Expand All @@ -42,7 +42,7 @@ static void validateTopicProperties(
actualNumReplicas);
}

static void validateTopicProperties(
public static void validateTopicProperties(
final String topicName,
final int requiredNumPartition,
final int requiredNumReplicas,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public class InsertValuesExecutorTest {
private KeySerdeFactory keySerdeFactory;
@Mock
private Supplier<SchemaRegistryClient> srClientFactory;
private InsertValuesExecutor executor;
private StubValuesExecutor executor;

@Before
public void setup() {
Expand Down Expand Up @@ -173,7 +173,7 @@ public void setup() {

when(clock.getAsLong()).thenReturn(1L);

executor = new InsertValuesExecutor(clock, keySerdeFactory, valueSerdeFactory);
executor = new StubValuesExecutor(clock, keySerdeFactory, valueSerdeFactory);
}

@Test
Expand Down
44 changes: 24 additions & 20 deletions ksql-functional-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,7 @@
<dependency>
<groupId>io.confluent.ksql</groupId>
<artifactId>ksql-engine</artifactId>
</dependency>

<dependency>
<groupId>io.confluent.ksql</groupId>
<artifactId>ksql-engine</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
</dependency>

<dependency>
<groupId>io.confluent.ksql</groupId>
<artifactId>ksql-common</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
</dependency>

<dependency>
<groupId>io.confluent.ksql</groupId>
<artifactId>ksql-metastore</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
</dependency>

<dependency>
Expand Down Expand Up @@ -90,6 +70,30 @@
<artifactId>kafka-streams-test-utils</artifactId>
</dependency>

<dependency>
<groupId>io.confluent.ksql</groupId>
<artifactId>ksql-engine</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.confluent.ksql</groupId>
<artifactId>ksql-common</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.confluent.ksql</groupId>
<artifactId>ksql-metastore</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.confluent.ksql</groupId>
<artifactId>ksql-rest-app</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,46 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.annotations.VisibleForTesting;
import io.confluent.ksql.test.serde.string.StringSerdeSupplier;
import io.confluent.ksql.test.tools.FakeKafkaRecord;
import io.confluent.ksql.test.tools.FakeKafkaService;
import io.confluent.ksql.test.tools.Record;
import io.confluent.ksql.test.tools.Topic;
import io.confluent.ksql.test.tools.exceptions.InvalidFieldException;
import io.confluent.ksql.test.tools.stubs.StubKafkaRecord;
import io.confluent.ksql.test.tools.stubs.StubKafkaService;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Objects;
import java.util.Optional;
import org.apache.kafka.clients.producer.ProducerRecord;

public final class FakeInsertValuesExecutor {
public final class StubInsertValuesExecutor {

private FakeInsertValuesExecutor() {
private StubInsertValuesExecutor() {
}

public static InsertValuesExecutor of(final FakeKafkaService fakeKafkaService) {
final FakeProduer fakeProduer = new FakeProduer(fakeKafkaService);
public static StubValuesExecutor of(final StubKafkaService stubKafkaService) {
final StubProducer stubProducer = new StubProducer(stubKafkaService);

return new InsertValuesExecutor(
return new StubValuesExecutor(
false,
(record, ignored1, ingnored2) -> fakeProduer.sendRecord(record));
(record, ignored1, ingnored2) -> stubProducer.sendRecord(record));
}

@VisibleForTesting
static class FakeProduer {
static class StubProducer {

private final FakeKafkaService fakeKafkaService;
private final StubKafkaService stubKafkaService;

FakeProduer(final FakeKafkaService fakeKafkaService) {
this.fakeKafkaService = Objects.requireNonNull(fakeKafkaService, "fakeKafkaService");
StubProducer(final StubKafkaService stubKafkaService) {
this.stubKafkaService = Objects.requireNonNull(stubKafkaService, "stubKafkaService");
}

void sendRecord(final ProducerRecord<byte[], byte[]> record) {
final Object value = getValue(record);

this.fakeKafkaService.writeRecord(record.topic(),
FakeKafkaRecord.of(
this.stubKafkaService.writeRecord(record.topic(),
StubKafkaRecord.of(
new Record(
fakeKafkaService.getTopic(record.topic()),
stubKafkaService.getTopic(record.topic()),
new String(record.key(), StandardCharsets.UTF_8),
value,
Optional.of(record.timestamp()),
Expand All @@ -68,7 +68,7 @@ void sendRecord(final ProducerRecord<byte[], byte[]> record) {
}

private Object getValue(final ProducerRecord<byte[], byte[]> record) {
final Topic topic = fakeKafkaService.getTopic(record.topic());
final Topic topic = stubKafkaService.getTopic(record.topic());

final Object value;
if (topic.getValueSerdeSupplier() instanceof StringSerdeSupplier) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
import static org.hamcrest.Matchers.containsString;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.confluent.ksql.test.model.matchers.KsqlExceptionMatcher;
import io.confluent.ksql.test.tools.exceptions.InvalidFieldException;
import io.confluent.ksql.test.tools.exceptions.KsqlExpectedException;
import io.confluent.ksql.test.tools.exceptions.MissingFieldException;
import io.confluent.ksql.util.KsqlExceptionMatcher;
import io.confluent.ksql.util.KsqlStatementException;
import java.util.Optional;
import org.hamcrest.Matcher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import io.confluent.ksql.metastore.model.KeyField;
import io.confluent.ksql.metastore.model.MetaStoreMatchers.KeyFieldMatchers;
import io.confluent.ksql.schema.ksql.types.SqlType;
import io.confluent.ksql.schema.ksql.types.SqlTypes;
import io.confluent.ksql.test.model.matchers.MetaStoreMatchers.KeyFieldMatchers;
import io.confluent.ksql.test.serde.KeyFieldDeserializer;
import java.util.Objects;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import io.confluent.ksql.model.WindowType;
import io.confluent.ksql.serde.Format;
import io.confluent.ksql.serde.FormatMatchers.KeyFormatMatchers;
import io.confluent.ksql.serde.KeyFormat;
import io.confluent.ksql.test.model.matchers.FormatMatchers.KeyFormatMatchers;
import java.time.Duration;
import java.util.Objects;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import io.confluent.ksql.metastore.model.DataSource;
import io.confluent.ksql.metastore.model.KsqlStream;
import io.confluent.ksql.metastore.model.KsqlTable;
import io.confluent.ksql.metastore.model.MetaStoreMatchers;
import io.confluent.ksql.schema.ksql.SchemaConverters;
import io.confluent.ksql.schema.ksql.SqlTypeParser;
import io.confluent.ksql.test.model.matchers.MetaStoreMatchers;
import io.confluent.ksql.test.tools.exceptions.InvalidFieldException;
import java.util.Objects;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright 2019 Confluent Inc.
*
* Licensed under the Confluent Community License (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.confluent.io/confluent-community-license
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package io.confluent.ksql.test.model.matchers;

import io.confluent.ksql.model.WindowType;
import io.confluent.ksql.serde.Format;
import io.confluent.ksql.serde.KeyFormat;
import java.time.Duration;
import java.util.Optional;
import org.hamcrest.FeatureMatcher;
import org.hamcrest.Matcher;

public final class FormatMatchers {

private FormatMatchers() {
}

public static final class KeyFormatMatchers {

private KeyFormatMatchers() {
}

public static Matcher<KeyFormat> hasFormat(
final Matcher<Format> matcher
) {
return new FeatureMatcher<KeyFormat, Format>(
matcher,
"key format of",
"key format"
) {
@Override
protected Format featureValueOf(final KeyFormat actual) {
return actual.getFormat();
}
};
}

public static Matcher<KeyFormat> hasWindowType(
final Matcher<Optional<WindowType>> matcher
) {
return new FeatureMatcher<KeyFormat, Optional<WindowType>>(
matcher,
"key window type",
"window type"
) {
@Override
protected Optional<WindowType> featureValueOf(final KeyFormat actual) {
return actual.getWindowType();
}
};
}

public static Matcher<KeyFormat> hasWindowSize(
final Matcher<Optional<Duration>> matcher
) {
return new FeatureMatcher<KeyFormat, Optional<Duration>>(
matcher,
"key window size",
"window size"
) {
@Override
protected Optional<Duration> featureValueOf(final KeyFormat actual) {
return actual.getWindowSize();
}
};
}
}

}
Loading

0 comments on commit e09d6ad

Please sign in to comment.