public synchronized AmazonDynamoDBAsync getClient(final DynamoDBOptions options) { AmazonDynamoDBAsync client = clientCache.get(options); if (client == null) { if ((options.getRegion() == null) && ((options.getEndpoint() == null) || options.getEndpoint().isEmpty())) { throw new ParameterException("Compulsory to specify either the region or the endpoint"); } final ClientConfiguration clientConfig = options.getClientConfig(); final AmazonDynamoDBAsyncClientBuilder builder = AmazonDynamoDBAsyncClientBuilder.standard().withClientConfiguration(clientConfig); if ((options.getEndpoint() != null) && (options.getEndpoint().length() > 0)) { builder.withEndpointConfiguration( new EndpointConfiguration( options.getEndpoint(), options.getRegion() != null ? options.getRegion().getName() : "local")); } else { builder.withRegion(options.getRegion()); } client = builder.build(); clientCache.put(options, client); } return client; } }
@Override public Statement apply(Statement base, Description description) { assumeTrue(dynamoDbOnline.get(this.port)); String url = "http://localhost:" + this.port; this.amazonDynamoDB = AmazonDynamoDBAsyncClientBuilder.standard() .withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("", ""))) .withClientConfiguration( new ClientConfiguration() .withMaxErrorRetry(0) .withConnectionTimeout(1000)) .withEndpointConfiguration( new AwsClientBuilder.EndpointConfiguration(url, Regions.DEFAULT_REGION.getName())) .build(); try { this.amazonDynamoDB.listTables(); } catch (SdkClientException e) { logger.warn("Tests not running because no DynamoDb on " + url, e); assumeNoException(e); } return super.apply(base, description); }