Search in sources :

Example 6 with AmazonDynamoDB

use of com.amazonaws.services.dynamodbv2.AmazonDynamoDB in project archaius by Netflix.

the class DynamoBackedConfigurationTest method testPropertyChange.

@Test
public void testPropertyChange() throws Exception {
    AmazonDynamoDB mockBasicDbClient = mock(AmazonDynamoDB.class);
    // 3 of the first config to cover: object creation, threadRun at 0 delay, load properties
    when(mockBasicDbClient.scan(any(ScanRequest.class))).thenReturn(DynamoDbMocks.basicScanResult1, DynamoDbMocks.basicScanResult1, DynamoDbMocks.basicScanResult1, DynamoDbMocks.basicScanResult2);
    DynamoDbConfigurationSource source = new DynamoDbConfigurationSource(mockBasicDbClient);
    FixedDelayPollingScheduler scheduler = new FixedDelayPollingScheduler(0, 500, false);
    DynamicConfiguration dynamicConfig = new DynamicConfiguration(source, scheduler);
    ConfigurationManager.loadPropertiesFromConfiguration(dynamicConfig);
    DynamicStringProperty test1 = DynamicPropertyFactory.getInstance().getStringProperty("foo", "");
    DynamicStringProperty test2 = DynamicPropertyFactory.getInstance().getStringProperty("goo", "");
    DynamicStringProperty test3 = DynamicPropertyFactory.getInstance().getStringProperty("boo", "");
    assertEquals("bar", test1.get());
    assertEquals("goo", test2.get());
    assertEquals("who", test3.get());
    Thread.sleep(1250);
    assertEquals("bar", test1.get());
    assertEquals("foo", test2.get());
    assertEquals("who", test3.get());
}
Also used : ScanRequest(com.amazonaws.services.dynamodbv2.model.ScanRequest) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) Test(org.junit.Test)

Example 7 with AmazonDynamoDB

use of com.amazonaws.services.dynamodbv2.AmazonDynamoDB in project testcontainers-java by testcontainers.

the class DynaliteContainerTest method simpleTestWithProvidedClient.

@Test
public void simpleTestWithProvidedClient() {
    final AmazonDynamoDB client = dynamoDB.getClient();
    runTest(client);
}
Also used : AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) Test(org.junit.Test)

Example 8 with AmazonDynamoDB

use of com.amazonaws.services.dynamodbv2.AmazonDynamoDB in project jcabi-dynamo by jcabi.

the class ScanValve method count.

@Override
public int count(final Credentials credentials, final String table, final Map<String, Condition> conditions) {
    final AmazonDynamoDB aws = credentials.aws();
    try {
        final ScanRequest request = new ScanRequest().withTableName(table).withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL).withScanFilter(conditions).withSelect(Select.COUNT).withLimit(Integer.MAX_VALUE);
        final long start = System.currentTimeMillis();
        final ScanResult result = aws.scan(request);
        final int count = result.getCount();
        Logger.info(this, // @checkstyle LineLength (1 line)
        "#total(): COUNT=%d in '%s' using %s, %s, in %[ms]s", count, request.getTableName(), request.getFilterExpression(), new PrintableConsumedCapacity(result.getConsumedCapacity()).print(), System.currentTimeMillis() - start);
        return count;
    } finally {
        aws.shutdown();
    }
}
Also used : ScanRequest(com.amazonaws.services.dynamodbv2.model.ScanRequest) ScanResult(com.amazonaws.services.dynamodbv2.model.ScanResult) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB)

Example 9 with AmazonDynamoDB

use of com.amazonaws.services.dynamodbv2.AmazonDynamoDB in project jcabi-dynamo by jcabi.

the class MadeTable method exists.

/**
 * The table exists?
 * @return TRUE if it exists in DynamoDB
 * @since 0.9
 */
public boolean exists() {
    final AmazonDynamoDB aws = this.region.aws();
    final String name = this.request.getTableName();
    boolean exists;
    try {
        aws.describeTable(name);
        exists = true;
        Logger.info(this, "DynamoDB table '%s' already exists", name);
    } catch (final ResourceNotFoundException ex) {
        exists = false;
        Logger.info(this, "DynamoDB table '%s' doesn't exist: %s", name, ex.getLocalizedMessage());
    }
    return exists;
}
Also used : AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) ResourceNotFoundException(com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException)

Example 10 with AmazonDynamoDB

use of com.amazonaws.services.dynamodbv2.AmazonDynamoDB in project jcabi-dynamo by jcabi.

the class MadeTable method drop.

/**
 * Drop table.
 * @throws InterruptedException If something fails
 */
public void drop() throws InterruptedException {
    final AmazonDynamoDB aws = this.region.aws();
    final String name = this.request.getTableName();
    aws.deleteTable(new DeleteTableRequest().withTableName(name));
    Logger.info(this, "DynamoDB table '%s' deletion requested", name);
    while (this.exists()) {
        Logger.info(this, "DynamoDB table '%s' still exists", name);
        TimeUnit.SECONDS.sleep((long) Tv.TEN);
    }
    Logger.info(this, "DynamoDB table '%s' deleted", name);
}
Also used : DeleteTableRequest(com.amazonaws.services.dynamodbv2.model.DeleteTableRequest) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB)

Aggregations

AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)70 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)16 DynamoDB (com.amazonaws.services.dynamodbv2.document.DynamoDB)14 Test (org.junit.Test)13 Table (com.amazonaws.services.dynamodbv2.document.Table)12 IOException (java.io.IOException)12 AmazonServiceException (com.amazonaws.AmazonServiceException)11 ProvisionedThroughput (com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput)11 HashMap (java.util.HashMap)11 AmazonClientException (com.amazonaws.AmazonClientException)10 KeySchemaElement (com.amazonaws.services.dynamodbv2.model.KeySchemaElement)10 CreateTableRequest (com.amazonaws.services.dynamodbv2.model.CreateTableRequest)9 ScanRequest (com.amazonaws.services.dynamodbv2.model.ScanRequest)9 AttributeDefinition (com.amazonaws.services.dynamodbv2.model.AttributeDefinition)8 ToString (lombok.ToString)7 DescribeTableRequest (com.amazonaws.services.dynamodbv2.model.DescribeTableRequest)6 ArrayList (java.util.ArrayList)6 DynamoDBMapper (com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper)5 ValueMap (com.amazonaws.services.dynamodbv2.document.utils.ValueMap)5 DescribeTableResult (com.amazonaws.services.dynamodbv2.model.DescribeTableResult)5