Skip to content

Commit

Permalink
#114 dynamodb local integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jul 14, 2022
1 parent b4197dd commit 87fd7de
Show file tree
Hide file tree
Showing 5 changed files with 214 additions and 3 deletions.
91 changes: 90 additions & 1 deletion pom.xml
Expand Up @@ -144,7 +144,7 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<systemPropertyVariables combine.children="append">
<failsafe.port>${dynamodb.port}</failsafe.port>
</systemPropertyVariables>
</configuration>
Expand Down Expand Up @@ -222,6 +222,95 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
</plugins>
</build>
<profiles>
<profile>
<id>dynamodb-local</id>
<activation>
<property>
<name>!skipTests</name>
</property>
</activation>
<properties>
<failsafe.ddl.key>AAAAABBBBBAAAAABBBBB</failsafe.ddl.key>
<failsafe.ddl.secret>ABCDABCDABCDABCDABCDABCDABCDABCDABCDABCD</failsafe.ddl.secret>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.jcabi</groupId>
<artifactId>DynamoDBLocal</artifactId>
<version>2014-01-08</version>
<type>zip</type>
<outputDirectory>${project.build.directory}/dynamodb-dist</outputDirectory>
<overWrite>false</overWrite>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>reserver-dynamodb-port</id>
<goals>
<goal>reserve-network-port</goal>
</goals>
<configuration>
<portNames>
<portName>failsafe.ddl.port</portName>
</portNames>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-dynamodb-maven-plugin</artifactId>
<executions>
<execution>
<id>dynamodb-integration-test</id>
<goals>
<goal>start</goal>
<goal>create-tables</goal>
<goal>stop</goal>
</goals>
<configuration>
<port>${failsafe.ddl.port}</port>
<dist>${project.build.directory}/dynamodb-dist</dist>
<key>${failsafe.ddl.key}</key>
<secret>${failsafe.ddl.secret}</secret>
<tables>
<table>${basedir}/src/test/dynamodb/talks.json</table>
</tables>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<parallel>none</parallel>
<systemPropertyVariables combine.children="append">
<failsafe.ddl.port>${failsafe.ddl.port}</failsafe.ddl.port>
<failsafe.ddl.key>${failsafe.ddl.key}</failsafe.ddl.key>
<failsafe.ddl.secret>${failsafe.ddl.secret}</failsafe.ddl.secret>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>qulice</id>
<build>
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/jcabi/dynamo/AwsIterator.java
Expand Up @@ -183,9 +183,14 @@ public Item next() {
@SuppressWarnings("PMD.UseConcurrentHashMap")
public void remove() {
synchronized (this.dosage) {
final Dosage prev = this.dosage.get();
if (prev == null) {
throw new IllegalStateException(
"You can't call remove() until you call next()"
);
}
final AmazonDynamoDB aws = this.credentials.aws();
try {
final Dosage prev = this.dosage.get();
final List<Map<String, AttributeValue>> items =
new ArrayList<>(prev.items());
final Map<String, AttributeValue> item =
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/jcabi/dynamo/Credentials.java
Expand Up @@ -236,7 +236,7 @@ public AmazonDynamoDB aws() {
return AmazonDynamoDBClientBuilder.standard()
.withEndpointConfiguration(
new AwsClientBuilder.EndpointConfiguration(
this.endpoint, this.endpoint
this.endpoint, Regions.US_EAST_1.getName()
)
)
.withCredentials(
Expand Down
19 changes: 19 additions & 0 deletions src/test/dynamodb/talks.json
@@ -0,0 +1,19 @@
{
"TableName": "talks",
"AttributeDefinitions": [
{
"AttributeName": "room",
"AttributeType": "N"
}
],
"KeySchema": [
{
"AttributeName": "room",
"KeyType": "HASH"
}
],
"ProvisionedThroughput": {
"ReadCapacityUnits": "1",
"WriteCapacityUnits": "1"
}
}
98 changes: 98 additions & 0 deletions src/test/java/com/jcabi/dynamo/DynamodbLocalITCase.java
@@ -0,0 +1,98 @@
/*
* Copyright (c) 2012-2022, jcabi.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the jcabi.com nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcabi.dynamo;

import com.jcabi.aspects.Tv;
import java.util.Iterator;
import org.apache.commons.lang3.RandomStringUtils;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

/**
* Integration case with DynamoDB Local.
*
* @since 0.23
*/
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
public final class DynamodbLocalITCase {

@BeforeEach
public void itTestCheck() {
Assumptions.assumeFalse(
System.getProperty("failsafe.ddl.port", "").isEmpty()
|| System.getProperty("failsafe.ddl.key", "").isEmpty()
|| System.getProperty("failsafe.ddl.secret", "").isEmpty(),
"DynamoDbLocal is not up and running, that's why this test is skipped"
);
}

@Test
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
public void worksWithAmazon() throws Exception {
final Table tbl = new Region.Simple(
new Credentials.Direct(
new Credentials.Simple(
System.getProperty("failsafe.ddl.key"),
System.getProperty("failsafe.ddl.secret")
),
Integer.parseInt(System.getProperty("failsafe.ddl.port"))
)
).table("talks");
for (int idx = 0; idx < Tv.FIVE; ++idx) {
tbl.put(
new Attributes()
.with("room", idx)
.with("title", RandomStringUtils.randomAlphanumeric(Tv.TEN))
);
}
MatcherAssert.assertThat(
tbl.frame()
.where("room", Conditions.equalTo(0))
.through(new QueryValve().withLimit(1)),
Matchers.hasSize(1)
);
MatcherAssert.assertThat(
tbl.frame()
.where("room", Conditions.equalTo(0))
.through(new ScanValve())
.iterator().next()
.get("room")
.getN(),
Matchers.equalTo("0")
);
final Iterator<Item> items = tbl.frame().iterator();
items.next();
items.remove();
}

}

0 comments on commit 87fd7de

Please sign in to comment.