Skip to content

Commit

Permalink
Test all plugins in isolation (#161)
Browse files Browse the repository at this point in the history
* E2E test all plugins

* use `compileOnly` in schema's dependencies

* fix DynamoDBPositionsStorageTest

* Fix rerun task

* Introduce `ApplicationRunner`

* Add ClassLoader isolation to `ApplicationRunner`

* fix Lombok's scope (from `testCompile` to `testCompileOnly`)

* add logging
  • Loading branch information
bsideup authored Jul 28, 2019
1 parent bb90ebe commit b6f388b
Show file tree
Hide file tree
Showing 18 changed files with 231 additions and 161 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public boolean isApplicable(Path pluginPath) {

@Override
public ClassLoader loadPlugin(Path pluginPath, PluginDescriptor pluginDescriptor) {
var pluginClassLoader = new PluginClassLoader(pluginManager, pluginDescriptor, getClass().getClassLoader());
var pluginClassLoader = new PluginClassLoader(pluginManager, pluginDescriptor, Thread.currentThread().getContextClassLoader());
pluginClassLoader.addFile(pluginPath.toFile());

// TODO consider fat jars
Expand Down
2 changes: 2 additions & 0 deletions gradle/rerunTests.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ project.afterEvaluate {
beforeTest { desc -> logger.warn("Re-running ${desc.className}.${desc.name}") }

useTestFramework(originalTask.getTestFramework())
classpath = originalTask.classpath
testClassesDirs = originalTask.testClassesDirs

testLogging {
displayGranularity 1
Expand Down
17 changes: 8 additions & 9 deletions plugins/dynamodb-positions-storage/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,24 @@ jar {
}

into('lib') {
from configurations.compile
from(configurations.compile - configurations.compileOnly)
}
}

tasks.test.dependsOn(
jar,
rootProject.project(":inmemory-records-storage").getTasksByName("jar", false)
)

dependencies {
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
compileOnly 'com.google.auto.service:auto-service'
annotationProcessor 'com.google.auto.service:auto-service'

compileOnly 'org.springframework.boot:spring-boot-starter'
compileOnly 'org.springframework.boot:spring-boot-starter-validation'
compileOnly project(":api")
compileOnly 'io.projectreactor:reactor-core'
compileOnly project(":app")

compile('software.amazon.awssdk:dynamodb:2.3.0') {
exclude group: 'org.slf4j'
exclude group: 'org.reactivestreams'
}
compile 'software.amazon.awssdk:dynamodb:2.3.0'

testCompileOnly 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,63 +1,37 @@
package com.github.bsideup.liiklus.dynamodb;

import com.github.bsideup.liiklus.ApplicationRunner;
import com.github.bsideup.liiklus.positions.PositionsStorage;
import com.github.bsideup.liiklus.positions.PositionsStorageTests;
import lombok.Getter;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.context.ApplicationContext;
import org.testcontainers.containers.localstack.LocalStackContainer;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient;
import software.amazon.awssdk.services.dynamodb.model.AttributeDefinition;
import software.amazon.awssdk.services.dynamodb.model.CreateTableRequest;
import software.amazon.awssdk.services.dynamodb.model.KeySchemaElement;
import software.amazon.awssdk.services.dynamodb.model.KeyType;
import software.amazon.awssdk.services.dynamodb.model.ProvisionedThroughput;
import software.amazon.awssdk.services.dynamodb.model.ScalarAttributeType;

import java.net.URI;
import org.testcontainers.containers.localstack.LocalStackContainer.Service;

import java.util.UUID;

class DynamoDBPositionsStorageTest implements PositionsStorageTests {

private static final LocalStackContainer localstack = new LocalStackContainer("0.8.6")
.withServices(LocalStackContainer.Service.DYNAMODB);
.withServices(Service.DYNAMODB);

static final ApplicationContext applicationContext;

static {
localstack.start();
}

private final DynamoDbAsyncClient dynamoDB = DynamoDbAsyncClient.builder()
.region(Region.of(localstack.getEndpointConfiguration(LocalStackContainer.Service.DYNAMODB).getSigningRegion()))
.endpointOverride(URI.create(localstack.getEndpointConfiguration(LocalStackContainer.Service.DYNAMODB).getServiceEndpoint()))
.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("key", "secret")))
.build();
System.setProperty("dynamodb.autoCreateTable", "true");
System.setProperty("dynamodb.positionsTable", "positions-" + UUID.randomUUID());
var endpointConfiguration = localstack.getEndpointConfiguration(Service.DYNAMODB);
System.setProperty("dynamodb.endpoint", endpointConfiguration.getServiceEndpoint());
System.setProperty("aws.region", endpointConfiguration.getSigningRegion());
var credentials = localstack.getDefaultCredentialsProvider().getCredentials();
System.setProperty("aws.accessKeyId", credentials.getAWSAccessKeyId());
System.setProperty("aws.secretAccessKey", credentials.getAWSSecretKey());

private final String tableName = UUID.randomUUID().toString();
applicationContext = new ApplicationRunner("MEMORY", "DYNAMODB").run();
}

@Getter
PositionsStorage storage = new DynamoDBPositionsStorage(dynamoDB, tableName);

@BeforeEach
void setUp() {
var request = CreateTableRequest.builder()
.keySchema(
KeySchemaElement.builder().attributeName(DynamoDBPositionsStorage.HASH_KEY_FIELD).keyType(KeyType.HASH).build(),
KeySchemaElement.builder().attributeName(DynamoDBPositionsStorage.RANGE_KEY_FIELD).keyType(KeyType.RANGE).build()
)
.attributeDefinitions(
AttributeDefinition.builder().attributeName(DynamoDBPositionsStorage.HASH_KEY_FIELD).attributeType(ScalarAttributeType.S).build(),
AttributeDefinition.builder().attributeName(DynamoDBPositionsStorage.RANGE_KEY_FIELD).attributeType(ScalarAttributeType.S).build()
)
.tableName(tableName)
.provisionedThroughput(ProvisionedThroughput.builder().readCapacityUnits(10L).writeCapacityUnits(10L).build())
.build();

try {
dynamoDB.createTable(request).get();
} catch (Exception e) {
throw new IllegalStateException("Can't create positions dynamodb table", e);
}
}
PositionsStorage storage = applicationContext.getBean(PositionsStorage.class);
}
11 changes: 7 additions & 4 deletions plugins/inmemory-positions-storage/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@ jar {
}

into('lib') {
from configurations.compile
from(configurations.compile - configurations.compileOnly)
}
}

tasks.test.dependsOn(
jar,
rootProject.project(":inmemory-records-storage").getTasksByName("jar", false)
)

dependencies {
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
compileOnly 'com.google.auto.service:auto-service'
annotationProcessor 'com.google.auto.service:auto-service'

compileOnly 'org.springframework.boot:spring-boot-starter'
compileOnly project(":api")
compileOnly 'io.projectreactor:reactor-core'
compileOnly project(":app")

testCompileOnly 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package com.github.bsideup.liiklus.positions.inmemory;

import com.github.bsideup.liiklus.ApplicationRunner;
import com.github.bsideup.liiklus.positions.PositionsStorage;
import com.github.bsideup.liiklus.positions.PositionsStorageTests;
import lombok.Getter;
import org.springframework.context.ApplicationContext;

class InMemoryPositionsStorageTest implements PositionsStorageTests {

static final ApplicationContext applicationContext = new ApplicationRunner("MEMORY", "MEMORY").run();

@Getter
PositionsStorage storage = new InMemoryPositionsStorage();
PositionsStorage storage = applicationContext.getBean(PositionsStorage.class);

}
13 changes: 7 additions & 6 deletions plugins/inmemory-records-storage/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,25 @@ jar {
}

into('lib') {
from configurations.compile
from(configurations.compile - configurations.compileOnly)
}
}

tasks.test.dependsOn(
jar,
rootProject.project(":inmemory-positions-storage").getTasksByName("jar", false)
)

dependencies {
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
compileOnly 'com.google.auto.service:auto-service'
annotationProcessor 'com.google.auto.service:auto-service'

compileOnly 'org.springframework.boot:spring-boot-starter'
compileOnly 'org.springframework.boot:spring-boot-starter-validation'
compileOnly project(":api")
compileOnly 'io.projectreactor:reactor-core'
compileOnly project(":app")

testCompileOnly 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'

testCompile project(":tck")
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.github.bsideup.liiklus.records.inmemory;

import com.github.bsideup.liiklus.ApplicationRunner;
import com.github.bsideup.liiklus.records.RecordStorageTests;
import com.github.bsideup.liiklus.records.RecordsStorage;
import lombok.Getter;
import lombok.SneakyThrows;
import org.springframework.context.ApplicationContext;
import reactor.core.publisher.Mono;

import java.time.Duration;
Expand All @@ -13,7 +14,7 @@

class InMemoryRecordsStorageTest implements RecordStorageTests {

private static final int NUM_OF_PARTITIONS = 4;
private static final int NUM_OF_PARTITIONS = 32;

// Generate a set of keys where each key goes to unique partition
public static Map<Integer, String> PARTITION_KEYS = Mono.fromCallable(() -> UUID.randomUUID().toString())
Expand All @@ -28,17 +29,14 @@ class InMemoryRecordsStorageTest implements RecordStorageTests {
.filter(it -> it.size() == NUM_OF_PARTITIONS)
.blockFirst(Duration.ofSeconds(10));

static final ApplicationContext applicationContext = new ApplicationRunner("MEMORY", "MEMORY").run();

@Getter
RecordsStorage target;
RecordsStorage target = applicationContext.getBean(RecordsStorage.class);

@Getter
String topic = UUID.randomUUID().toString();

@SneakyThrows
public InMemoryRecordsStorageTest() {
this.target = new InMemoryRecordsStorage(NUM_OF_PARTITIONS);
}

@Override
public String keyByPartition(int partition) {
return PARTITION_KEYS.get(partition);
Expand Down
19 changes: 9 additions & 10 deletions plugins/kafka-records-storage/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,28 @@ jar {
}

into('lib') {
from configurations.compile
from(configurations.compile - configurations.compileOnly)
}
}

tasks.test.dependsOn(
jar,
rootProject.project(":inmemory-positions-storage").getTasksByName("jar", false)
)

dependencies {
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
compileOnly 'com.google.auto.service:auto-service'
annotationProcessor 'com.google.auto.service:auto-service'

compileOnly 'org.springframework.boot:spring-boot-starter'
compileOnly 'org.springframework.boot:spring-boot-starter-validation'
compileOnly project(":api")
compileOnly 'io.projectreactor:reactor-core'
compileOnly project(":app")

compile 'org.apache.kafka:kafka-clients', {
exclude group: "org.slf4j"
}
compile 'org.apache.kafka:kafka-clients'

testCompileOnly 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'

testCompile project(":tck")
testCompile 'org.testcontainers:kafka'
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.github.bsideup.liiklus.kafka;

import com.github.bsideup.liiklus.ApplicationRunner;
import com.github.bsideup.liiklus.records.RecordStorageTests;
import com.github.bsideup.liiklus.records.RecordsStorage;
import lombok.Getter;
import org.apache.kafka.common.utils.Utils;
import org.springframework.context.ApplicationContext;
import org.testcontainers.containers.KafkaContainer;
import reactor.core.publisher.Mono;

Expand Down Expand Up @@ -32,14 +34,18 @@ public class KafkaRecordsStorageTest implements RecordStorageTests {
private static final KafkaContainer kafka = new KafkaContainer()
.withEnv("KAFKA_NUM_PARTITIONS", NUM_OF_PARTITIONS + "");

static final ApplicationContext applicationContext;

static {
kafka.start();

System.setProperty("kafka.bootstrapServers", kafka.getBootstrapServers());

applicationContext = new ApplicationRunner("KAFKA", "MEMORY").run();
}

@Getter
RecordsStorage target = new KafkaRecordsStorage(
kafka.getBootstrapServers()
);
RecordsStorage target = applicationContext.getBean(RecordsStorage.class);

@Getter
String topic = UUID.randomUUID().toString();
Expand Down
17 changes: 8 additions & 9 deletions plugins/pulsar-records-storage/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,28 @@ jar {
}

into('lib') {
from configurations.compile
from(configurations.compile - configurations.compileOnly)
}
}

tasks.test.dependsOn(
jar,
rootProject.project(":inmemory-positions-storage").getTasksByName("jar", false)
)

dependencies {
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
compileOnly 'com.google.auto.service:auto-service'
annotationProcessor 'com.google.auto.service:auto-service'

compileOnly 'org.springframework.boot:spring-boot-starter'
compileOnly 'org.springframework.boot:spring-boot-starter-validation'
compileOnly project(":api")
compileOnly 'io.projectreactor:reactor-core'
compileOnly project(":app")

compile ('org.apache.pulsar:pulsar-client:2.3.2') {
exclude group: "org.slf4j"
}
compile 'org.apache.pulsar:pulsar-client:2.3.2'

testCompileOnly 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'

testCompile project(":tck")
testCompile 'org.testcontainers:pulsar'
testCompile 'org.apache.pulsar:pulsar-client-admin:2.3.2'
Expand Down
Loading

0 comments on commit b6f388b

Please sign in to comment.