Mock AWS Kinesis maven plugin

Mock kinesis is a library intended to run with the maven-failsafe-plugin to act as a fake aws kinesis endpoint for your integration tests.

License

License

Categories

Categories

Maven Build Tools
GroupId

GroupId

com.mypurecloud
ArtifactId

ArtifactId

mock-kinesis-maven-plugin
Last Version

Last Version

1.2.0
Release Date

Release Date

Type

Type

maven-plugin
Description

Description

Mock AWS Kinesis maven plugin
Mock kinesis is a library intended to run with the maven-failsafe-plugin to act as a fake aws kinesis endpoint for your integration tests.
Project URL

Project URL

https://github.com/MyPureCloud/mock-kinesis-maven-plugin
Source Code Management

Source Code Management

http://github.com/MyPureCloud/mock-kinesis-maven-plugin/

Download mock-kinesis-maven-plugin

How to add to project

<plugin>
    <groupId>com.mypurecloud</groupId>
    <artifactId>mock-kinesis-maven-plugin</artifactId>
    <version>1.2.0</version>
</plugin>

Dependencies

compile (7)

Group / Artifact Type Version
org.eclipse.jetty : jetty-server jar 9.4.0.v20161208
org.eclipse.jetty : jetty-servlet jar 9.4.0.v20161208
com.fasterxml.jackson.core : jackson-databind jar 2.7.4
commons-io : commons-io jar 2.4
com.squareup.okhttp3 : okhttp jar 3.9.0
com.fasterxml.jackson.dataformat : jackson-dataformat-cbor jar 2.7.4
org.apache.maven : maven-plugin-api jar 3.3.3

provided (1)

Group / Artifact Type Version
org.apache.maven.plugin-tools : maven-plugin-annotations jar 3.4

test (2)

Group / Artifact Type Version
junit : junit jar 4.8.2
org.mockito : mockito-core jar 2.8.47

Project Modules

There are no modules declared in this project.

Mock-kinesis

Mock kinesis is a library intended to run with the maven-failsafe-plugin to act as a fake kinesis endpoint for your integration tests.

Installation

Maven:

<dependency>
    <groupId>com.mypurecloud</groupId>
    <artifactId>mock-kinesis-maven-plugin</artifactId>
    <version>${mock.kinesis.version}</version>
</dependency>
 

and then under

<plugin>
    <groupId>com.genesys.purecloud</groupId>
    <artifactId>mock-kinesis-maven-plugin</artifactId>
    <version>${mock.kinesis.version}</version>
    <executions>
        <execution>
            <goals>
                <goal>start</goal>
            </goals>
            <configuration>
                <port>${it.kinesis.port}</port>
                <streamname>kinesis-mock</streamname>
            </configuration>
        </execution>
    </executions>
</plugin>

This starts mock kinesis listening on port 8899 and then adds a new stream called 'kinesis-mock'.

Usage

In your application's code

System.setProperty("com.amazonaws.sdk.disableCbor", "true");
clientBuilder.setEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("http://localhost:8899", "us-east-1"));

The MockKinesisClient class will wrap http calls to the server that you can use to change error rates, clear streams or get messages that were sent to the stream. An example test case would look like this:

@Test
public void testSmallBatchOfRequests() throws JSONException, IOException, ExecutionException, InterruptedException {
    MockKinesisClient client = new MockKinesisClient(8899);
    client.clearStreams();  //clear all records
    client.setRateLimitErrorRate(streamName, 0); //set error rate to 0

    functionThatTriggersMessagesSentToKinesis();

    Thread.sleep(waitForEventsToFlushInMs);// wait for all records to be sent
    List<PutRecordRequest> records = client.getRecordsForStream(streamName); // get records from stream

    assertEquals(1, records.size());

}

Error Responses

There are two configuration options for mock kinesis to return error codes: MockKinesisClient.setRateLimitErrorRate and MockKinesisClient.setErrorRate

setRateLimitErrorRate will return rate limiting error codes "KMSThrottlingException", "ProvisionedThroughputExceededException" where setErrorRate will return a random error code from "InvalidArgumentException","KMSAccessDeniedException","KMSDisabledException","KMSInvalidStateException","KMSNotFoundException","KMSOptInRequired"

A Note on CBOR Content Type

Kinesis uses the (CBOR)[http://cbor.io/] content type by default. Mock kinesis doesn't yet support decoding that content type so when setting up your client, you first have to set the system property to turn it off.

System.setProperty("com.amazonaws.sdk.disableCbor", "true");

Messages with CBOR enter the server with Content-type set to application/x-amz-cbor-1.1 normal json messages will have the content type application/x-amz-json-1.1

Kinesis Producer Library

If using this with KPL, you will need to set the following properties

kplConfig.setKinesisEndpoint("localhost");
kplConfig.setKinesisPort(8899);
kplConfig.setVerifyCertificate(false);

System.setProperty("com.amazonaws.sdk.disableCbor", "true");
System.setProperty(DISABLE_CERT_CHECKING_SYSTEM_PROPERTY, "");

kplConfig.setVerifyCertificate(false);
com.mypurecloud

Genesys Cloud

Versions

Version
1.2.0
1.1.1
1.1.0
1.0.2
1.0.1