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());
}
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);
}
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();
}
}
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;
}
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);
}
Aggregations