From 507f652122c78ec6231b4b24c86362124467f55f Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Tue, 22 Oct 2019 15:04:19 -0400 Subject: [PATCH] Disable CBOR for AWS; enable Kinesis tests * Since Local Stack Kinesis support is based on Kinesalite, it turns out that `System.setProperty(SDKGlobalConfiguration.AWS_CBOR_DISABLE_SYSTEM_PROPERTY, "true");` does the trick to make Kinesis integration tests to pass with Local Stack in Docker * Suppress `serial` warning in the `AwsIntegrationEvent` classes * Make `junit-jupiter-api` as `testCompile` dependency * Fix README in regards Local Stack support for testing --- README.md | 6 +++--- build.gradle | 2 +- .../integration/aws/event/AwsIntegrationEvent.java | 1 + .../aws/event/KinesisIntegrationEvent.java | 1 + .../integration/aws/event/KinesisShardEndedEvent.java | 1 + .../integration/aws/EnvironmentHostNameResolver.java | 5 +++++ .../aws/kinesis/KinesisIntegrationTests.java | 11 +++++------ .../DynamoDbLockRegistryLeaderInitiatorTests.java | 3 +-- 8 files changed, 18 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 210ae56..a5aa316 100644 --- a/README.md +++ b/README.md @@ -522,8 +522,7 @@ this.amazonDynamoDB = AmazonDynamoDBAsyncClientBuilder.standard() ```` Where you should specify the port on which you have ran the Dynalite service. -Also you can use for your testing purpose a copy of `org.springframework.integration.aws.DynamoDbLocalRunning` in the `/test` directory of this project. -The default port is expected as `4568`, because the `4567` is reserved for the `KinesisLocalRunning` against local Kinesalite npm service. +Also you can use for you testing purpose a [Local Stack][] library. Starting with _version 2.0_, the `DynamoDbMetadataStore` can be configured with the `timeToLive` option to enable the [DynamoDB TTL][] feature. The `TTL` attribute is added to each item with the value based on the sum of current time and provided `timeToLive` in seconds. @@ -647,7 +646,7 @@ this.amazonKinesis = AmazonKinesisAsyncClientBuilder.standard() ```` Where you should specify the port on which you have ran the Kinesalite service. -Also you can use for you testing purpose a copy of `org.springframework.integration.aws.KinesisLocalRunning` in the `/test` directory of this project. +Also you can use for you testing purpose a [Local Stack][] library. Also the `KplMessageHandler` is provided for performing streams consumption by [Kinesis Producer Library][]. @@ -679,3 +678,4 @@ The `com.amazonaws:dynamodb-lock-client` dependency must be present to make a `D [Leader Election]: https://docs.spring.io/spring-integration/docs/current/reference/html/messaging-endpoints-chapter.html#leadership-event-handling [Kinesis Producer Library]: https://docs.aws.amazon.com/streams/latest/dev/developing-producers-with-kpl.html [LockRegistryLeaderInitiator]: https://docs.spring.io/spring-integration/docs/current/reference/html/messaging-endpoints-chapter.html#leadership-event-handling +[Local Stack]: https://localstack.cloud diff --git a/build.gradle b/build.gradle index 775eb95..d737aae 100644 --- a/build.gradle +++ b/build.gradle @@ -119,7 +119,7 @@ dependencies { testCompile ("org.awaitility:awaitility:$awaitilityVersion") { exclude group: 'org.hamcrest' } - compile 'org.junit.jupiter:junit-jupiter-api' + testCompile 'org.junit.jupiter:junit-jupiter-api' testRuntime "org.apache.logging.log4j:log4j-slf4j-impl:$log4jVersion" testRuntime "org.apache.logging.log4j:log4j-jcl:$log4jVersion" diff --git a/src/main/java/org/springframework/integration/aws/event/AwsIntegrationEvent.java b/src/main/java/org/springframework/integration/aws/event/AwsIntegrationEvent.java index db76687..8a541af 100644 --- a/src/main/java/org/springframework/integration/aws/event/AwsIntegrationEvent.java +++ b/src/main/java/org/springframework/integration/aws/event/AwsIntegrationEvent.java @@ -25,6 +25,7 @@ import org.springframework.integration.events.IntegrationEvent; * * @since 2.3 */ +@SuppressWarnings("serial") public abstract class AwsIntegrationEvent extends IntegrationEvent { public AwsIntegrationEvent(Object source) { diff --git a/src/main/java/org/springframework/integration/aws/event/KinesisIntegrationEvent.java b/src/main/java/org/springframework/integration/aws/event/KinesisIntegrationEvent.java index 8884a64..8b93b45 100644 --- a/src/main/java/org/springframework/integration/aws/event/KinesisIntegrationEvent.java +++ b/src/main/java/org/springframework/integration/aws/event/KinesisIntegrationEvent.java @@ -23,6 +23,7 @@ package org.springframework.integration.aws.event; * * @since 2.3 */ +@SuppressWarnings("serial") public abstract class KinesisIntegrationEvent extends AwsIntegrationEvent { public KinesisIntegrationEvent(Object source) { diff --git a/src/main/java/org/springframework/integration/aws/event/KinesisShardEndedEvent.java b/src/main/java/org/springframework/integration/aws/event/KinesisShardEndedEvent.java index 1e1574b..d458c4d 100644 --- a/src/main/java/org/springframework/integration/aws/event/KinesisShardEndedEvent.java +++ b/src/main/java/org/springframework/integration/aws/event/KinesisShardEndedEvent.java @@ -23,6 +23,7 @@ package org.springframework.integration.aws.event; * * @since 2.3 */ +@SuppressWarnings("serial") public class KinesisShardEndedEvent extends KinesisIntegrationEvent { private final String shardKey; diff --git a/src/test/java/org/springframework/integration/aws/EnvironmentHostNameResolver.java b/src/test/java/org/springframework/integration/aws/EnvironmentHostNameResolver.java index b26b1d2..e614022 100644 --- a/src/test/java/org/springframework/integration/aws/EnvironmentHostNameResolver.java +++ b/src/test/java/org/springframework/integration/aws/EnvironmentHostNameResolver.java @@ -17,6 +17,7 @@ package org.springframework.integration.aws; import cloud.localstack.docker.annotation.IHostNameResolver; +import com.amazonaws.SDKGlobalConfiguration; /** * @author Artem Bilan @@ -27,6 +28,10 @@ public class EnvironmentHostNameResolver implements IHostNameResolver { public static final String DOCKER_HOST_NAME = "DOCKER_HOST_NAME"; + static { + System.setProperty(SDKGlobalConfiguration.AWS_CBOR_DISABLE_SYSTEM_PROPERTY, "true"); + } + @Override public String getHostName() { return System.getenv(DOCKER_HOST_NAME); diff --git a/src/test/java/org/springframework/integration/aws/kinesis/KinesisIntegrationTests.java b/src/test/java/org/springframework/integration/aws/kinesis/KinesisIntegrationTests.java index e56684a..6cacdcc 100644 --- a/src/test/java/org/springframework/integration/aws/kinesis/KinesisIntegrationTests.java +++ b/src/test/java/org/springframework/integration/aws/kinesis/KinesisIntegrationTests.java @@ -25,7 +25,6 @@ import java.util.Set; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; import org.junit.jupiter.api.extension.ExtendWith; @@ -68,7 +67,7 @@ import com.amazonaws.services.kinesis.AmazonKinesisAsync; * * @since 1.1 */ -@Disabled("Looks like Kinesis is not supported well in Local Stack") +//@Disabled("Looks like Kinesis is not supported well in Local Stack") @SpringJUnitConfig @EnabledIfEnvironmentVariable(named = EnvironmentHostNameResolver.DOCKER_HOST_NAME, matches = ".+") @ExtendWith(LocalstackDockerExtension.class) @@ -124,21 +123,21 @@ public class KinesisIntegrationTests { .contains("Channel 'kinesisReceiveChannel' expected one of the following data types " + "[class java.util.Date], but received [class java.lang.String]"); - for (int i = 0; i < 1000; i++) { + for (int i = 0; i < 10; i++) { this.kinesisSendChannel .send(MessageBuilder.withPayload(new Date()).setHeader(AwsHeaders.STREAM, TEST_STREAM).build()); } Set receivedSequences = new HashSet<>(); - for (int i = 0; i < 1000; i++) { - receive = this.kinesisReceiveChannel.receive(10_000); + for (int i = 0; i < 10; i++) { + receive = this.kinesisReceiveChannel.receive(20_000); assertThat(receive).isNotNull(); String sequenceNumber = receive.getHeaders().get(AwsHeaders.RECEIVED_SEQUENCE_NUMBER, String.class); assertThat(receivedSequences.add(sequenceNumber)).isTrue(); } - assertThat(receivedSequences.size()).isEqualTo(1000); + assertThat(receivedSequences.size()).isEqualTo(10); receive = this.kinesisReceiveChannel.receive(10); assertThat(receive).isNull(); diff --git a/src/test/java/org/springframework/integration/aws/leader/DynamoDbLockRegistryLeaderInitiatorTests.java b/src/test/java/org/springframework/integration/aws/leader/DynamoDbLockRegistryLeaderInitiatorTests.java index 3970e90..55b8af3 100644 --- a/src/test/java/org/springframework/integration/aws/leader/DynamoDbLockRegistryLeaderInitiatorTests.java +++ b/src/test/java/org/springframework/integration/aws/leader/DynamoDbLockRegistryLeaderInitiatorTests.java @@ -26,7 +26,6 @@ import java.util.concurrent.TimeUnit; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; import org.junit.jupiter.api.extension.ExtendWith; @@ -87,7 +86,7 @@ class DynamoDbLockRegistryLeaderInitiatorTests { DYNAMO_DB.deleteTable(DynamoDbLockRegistry.DEFAULT_TABLE_NAME); } - @Disabled("Doesn't work properly against Local Stack when two instances try to lock in table") + // @Disabled("Doesn't work properly against Local Stack when two instances try to lock in table") @Test void testDistributedLeaderElection() throws Exception { CountDownLatch granted = new CountDownLatch(1);