GH-99: Add Rule to ignore Kinesis test
Fixes spring-cloud/spring-cloud-stream-samples#99 Add `LocalKinesisResource` which is going to be used as a `@ClassRule` to ensure in the unit test that local service is available for performing the test. For that reason add `spring-cloud-stream-test-support-internal` dependency since `LocalKinesisResource` is based on the `AbstractExternalResourceTestSupport`
This commit is contained in:
@@ -43,6 +43,12 @@
|
||||
<artifactId>reactor-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-stream-test-support-internal</artifactId>
|
||||
<version>2.1.0.BUILD-SNAPSHOT</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package kinesis.webflux;
|
||||
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -62,9 +63,11 @@ import reactor.test.StepVerifier;
|
||||
}
|
||||
)
|
||||
@AutoConfigureWebTestClient
|
||||
@Ignore
|
||||
public class CloudStreamKinesisToWebfluxApplicationTests {
|
||||
|
||||
@ClassRule
|
||||
public static LocalKinesisResource localKinesisResource = new LocalKinesisResource();
|
||||
|
||||
@Autowired
|
||||
private WebTestClient webTestClient;
|
||||
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package kinesis.webflux;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.cloud.stream.test.junit.AbstractExternalResourceTestSupport;
|
||||
|
||||
import com.amazonaws.ClientConfiguration;
|
||||
import com.amazonaws.SDKGlobalConfiguration;
|
||||
import com.amazonaws.auth.AWSStaticCredentialsProvider;
|
||||
import com.amazonaws.auth.BasicAWSCredentials;
|
||||
import com.amazonaws.client.builder.AwsClientBuilder;
|
||||
import com.amazonaws.regions.Regions;
|
||||
import com.amazonaws.services.kinesis.AmazonKinesisAsync;
|
||||
import com.amazonaws.services.kinesis.AmazonKinesisAsyncClientBuilder;
|
||||
import com.amazonaws.services.kinesis.model.ListStreamsRequest;
|
||||
import com.amazonaws.services.kinesis.model.ListStreamsResult;
|
||||
import com.amazonaws.services.kinesis.model.ResourceNotFoundException;
|
||||
|
||||
/**
|
||||
* An {@link AbstractExternalResourceTestSupport} implementation for Kinesis local service.
|
||||
*
|
||||
* @author Artem Bilan
|
||||
* @author Jacob Severson
|
||||
*
|
||||
*/
|
||||
public class LocalKinesisResource
|
||||
extends AbstractExternalResourceTestSupport<AmazonKinesisAsync> {
|
||||
|
||||
/**
|
||||
* The default port for the local Kinesis service.
|
||||
*/
|
||||
public static final int DEFAULT_PORT = 4568;
|
||||
|
||||
private final int port;
|
||||
|
||||
public LocalKinesisResource() {
|
||||
this(DEFAULT_PORT);
|
||||
}
|
||||
|
||||
public LocalKinesisResource(int port) {
|
||||
super("KINESIS");
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void obtainResource() {
|
||||
// See https://github.com/mhart/kinesalite#cbor-protocol-issues-with-the-java-sdk
|
||||
System.setProperty(SDKGlobalConfiguration.AWS_CBOR_DISABLE_SYSTEM_PROPERTY,
|
||||
"true");
|
||||
|
||||
this.resource = AmazonKinesisAsyncClientBuilder.standard()
|
||||
.withClientConfiguration(new ClientConfiguration().withMaxErrorRetry(0)
|
||||
.withConnectionTimeout(1000))
|
||||
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(
|
||||
"http://localhost:" + this.port,
|
||||
Regions.DEFAULT_REGION.getName()))
|
||||
.withCredentials(
|
||||
new AWSStaticCredentialsProvider(new BasicAWSCredentials("", "")))
|
||||
.build();
|
||||
|
||||
// Check connection
|
||||
this.resource.listStreams();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void cleanupResource() {
|
||||
ListStreamsRequest listStreamsRequest = new ListStreamsRequest();
|
||||
ListStreamsResult listStreamsResult = this.resource
|
||||
.listStreams(listStreamsRequest);
|
||||
|
||||
List<String> streamNames = listStreamsResult.getStreamNames();
|
||||
|
||||
while (listStreamsResult.getHasMoreStreams()) {
|
||||
if (streamNames.size() > 0) {
|
||||
listStreamsRequest.setExclusiveStartStreamName(
|
||||
streamNames.get(streamNames.size() - 1));
|
||||
}
|
||||
listStreamsResult = this.resource.listStreams(listStreamsRequest);
|
||||
streamNames.addAll(listStreamsResult.getStreamNames());
|
||||
}
|
||||
|
||||
for (String stream : streamNames) {
|
||||
this.resource.deleteStream(stream);
|
||||
while (true) {
|
||||
try {
|
||||
this.resource.describeStream(stream);
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
catch (InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
}
|
||||
catch (ResourceNotFoundException ex) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System.clearProperty(SDKGlobalConfiguration.AWS_CBOR_DISABLE_SYSTEM_PROPERTY);
|
||||
this.resource.shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user