Search in sources :

Example 46 with AmazonDynamoDB

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

the class DynamoDbConfigurationSourceTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    AmazonDynamoDB mockBasicDbClient = mock(AmazonDynamoDB.class);
    when(mockBasicDbClient.scan(any(ScanRequest.class))).thenReturn(DynamoDbMocks.basicScanResult1, DynamoDbMocks.basicScanResult2);
    DynamoDbConfigurationSource testConfigSource = new DynamoDbConfigurationSource(mockBasicDbClient);
    PollResult result = testConfigSource.poll(false, null);
    assertEquals(3, result.getComplete().size());
    assertEquals("bar", result.getComplete().get("foo"));
    assertEquals("goo", result.getComplete().get("goo"));
    assertEquals("who", result.getComplete().get("boo"));
    result = testConfigSource.poll(false, null);
    assertEquals(3, result.getComplete().size());
    assertEquals("bar", result.getComplete().get("foo"));
    assertEquals("foo", result.getComplete().get("goo"));
    assertEquals("who", result.getComplete().get("boo"));
}
Also used : ScanRequest(com.amazonaws.services.dynamodbv2.model.ScanRequest) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) PollResult(com.netflix.config.PollResult) Test(org.junit.Test)

Example 47 with AmazonDynamoDB

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

the class DynamoDbDeploymentContextTableCacheTest method testPoll.

@Test
public void testPoll() throws Exception {
    AmazonDynamoDB mockContextDbClient = mock(AmazonDynamoDB.class);
    when(mockContextDbClient.scan(any(ScanRequest.class))).thenReturn(DynamoDbMocks.contextScanResult1, DynamoDbMocks.contextScanResult2);
    DynamoDbDeploymentContextTableCache cache = new DynamoDbDeploymentContextTableCache(mockContextDbClient, 100, 100);
    Collection<PropertyWithDeploymentContext> props = cache.getProperties();
    assertEquals(4, props.size());
    assertTrue(props.contains(test1));
    assertTrue(props.contains(test2));
    assertTrue(props.contains(test5));
    assertTrue(props.contains(test6));
    Thread.sleep(150);
    props = cache.getProperties();
    assertEquals(5, props.size());
    assertTrue(props.contains(test1));
    assertTrue(props.contains(test3));
    assertTrue(props.contains(test4));
    assertTrue(props.contains(test5));
    assertTrue(props.contains(test6));
}
Also used : ScanRequest(com.amazonaws.services.dynamodbv2.model.ScanRequest) PropertyWithDeploymentContext(com.netflix.config.PropertyWithDeploymentContext) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) Test(org.junit.Test)

Example 48 with AmazonDynamoDB

use of com.amazonaws.services.dynamodbv2.AmazonDynamoDB in project cas by apereo.

the class DynamoDbCloudConfigBootstrapConfiguration method createSettingsTable.

@SneakyThrows
private static void createSettingsTable(final AmazonDynamoDB amazonDynamoDBClient, final boolean deleteTables) {
    final String name = ColumnNames.ID.getColumnName();
    final CreateTableRequest request = new CreateTableRequest().withAttributeDefinitions(new AttributeDefinition(name, ScalarAttributeType.S)).withKeySchema(new KeySchemaElement(name, KeyType.HASH)).withProvisionedThroughput(new ProvisionedThroughput(PROVISIONED_THROUGHPUT, PROVISIONED_THROUGHPUT)).withTableName(TABLE_NAME);
    if (deleteTables) {
        final DeleteTableRequest delete = new DeleteTableRequest(request.getTableName());
        LOGGER.debug("Sending delete request [{}] to remove table if necessary", delete);
        TableUtils.deleteTableIfExists(amazonDynamoDBClient, delete);
    }
    LOGGER.debug("Sending delete request [{}] to create table", request);
    TableUtils.createTableIfNotExists(amazonDynamoDBClient, request);
    LOGGER.debug("Waiting until table [{}] becomes active...", request.getTableName());
    TableUtils.waitUntilActive(amazonDynamoDBClient, request.getTableName());
    final DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(request.getTableName());
    LOGGER.debug("Sending request [{}] to obtain table description...", describeTableRequest);
    final TableDescription tableDescription = amazonDynamoDBClient.describeTable(describeTableRequest).getTable();
    LOGGER.debug("Located newly created table with description: [{}]", tableDescription);
}
Also used : DeleteTableRequest(com.amazonaws.services.dynamodbv2.model.DeleteTableRequest) AttributeDefinition(com.amazonaws.services.dynamodbv2.model.AttributeDefinition) ProvisionedThroughput(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput) DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest) CreateTableRequest(com.amazonaws.services.dynamodbv2.model.CreateTableRequest) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement) SneakyThrows(lombok.SneakyThrows)

Example 49 with AmazonDynamoDB

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

the class DynaliteContainerTest method simpleTestWithManualClientCreation.

@Test
public void simpleTestWithManualClientCreation() {
    final AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().withEndpointConfiguration(dynamoDB.getEndpointConfiguration()).withCredentials(dynamoDB.getCredentials()).build();
    runTest(client);
}
Also used : AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) Test(org.junit.Test)

Example 50 with AmazonDynamoDB

use of com.amazonaws.services.dynamodbv2.AmazonDynamoDB in project wildfly-camel by wildfly-extras.

the class DynamoDBUtils method createTable.

public static TableDescription createTable(AmazonDynamoDB client, String tableName) throws InterruptedException {
    CreateTableRequest tableReq = new CreateTableRequest().withTableName(tableName).withKeySchema(new KeySchemaElement("Id", KeyType.HASH)).withAttributeDefinitions(new AttributeDefinition("Id", ScalarAttributeType.N)).withProvisionedThroughput(new ProvisionedThroughput(10L, 10L)).withStreamSpecification(new StreamSpecification().withStreamEnabled(true).withStreamViewType(StreamViewType.NEW_AND_OLD_IMAGES));
    DynamoDB dynamoDB = new DynamoDB(client);
    Table table = dynamoDB.createTable(tableReq);
    return table.waitForActive();
}
Also used : Table(com.amazonaws.services.dynamodbv2.document.Table) StreamSpecification(com.amazonaws.services.dynamodbv2.model.StreamSpecification) AttributeDefinition(com.amazonaws.services.dynamodbv2.model.AttributeDefinition) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) DynamoDB(com.amazonaws.services.dynamodbv2.document.DynamoDB) ProvisionedThroughput(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput) CreateTableRequest(com.amazonaws.services.dynamodbv2.model.CreateTableRequest) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement)

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