use of com.amazonaws.services.dynamodbv2.document.Table in project jcabi-dynamo by jcabi.
the class RegionITCase method worksWithAmazon.
/**
* Region.Simple can work with AWS.
* @throws Exception If some problem inside
*/
@Test
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
public void worksWithAmazon() throws Exception {
final String name = RandomStringUtils.randomAlphabetic(Tv.EIGHT);
final RegionMock mock = new RegionMock();
final Table tbl = mock.get(name).table(name);
final String attr = RandomStringUtils.randomAlphabetic(Tv.EIGHT);
final String value = RandomStringUtils.randomAlphanumeric(Tv.TEN);
final String hash = RandomStringUtils.randomAlphanumeric(Tv.TEN);
for (int idx = 0; idx < Tv.FIVE; ++idx) {
tbl.put(new Attributes().with(mock.hash(), hash).with(mock.range(), idx).with(attr, value));
}
MatcherAssert.assertThat(tbl.frame().where(mock.hash(), Conditions.equalTo(hash)).through(new QueryValve().withLimit(1)), Matchers.hasSize(Tv.FIVE));
final Frame frame = tbl.frame().where(attr, Conditions.equalTo(value)).through(new ScanValve().withLimit(Tv.TEN).withAttributeToGet(attr));
MatcherAssert.assertThat(frame, Matchers.hasSize(Tv.FIVE));
final Iterator<Item> items = frame.iterator();
final Item item = items.next();
final int range = Integer.parseInt(item.get(mock.range()).getN());
MatcherAssert.assertThat(item.get(attr).getS(), Matchers.equalTo(value));
item.put(attr, new AttributeValueUpdate(new AttributeValue("empty"), AttributeAction.PUT));
MatcherAssert.assertThat(tbl.frame().where(mock.hash(), hash).where(mock.range(), Conditions.equalTo(range)).through(new ScanValve()).iterator().next().get(attr).getS(), Matchers.not(Matchers.equalTo(value)));
items.remove();
}
use of com.amazonaws.services.dynamodbv2.document.Table in project jcabi-dynamo by jcabi.
the class H2DataTest method updatesTableAttributes.
/**
* H2Data can update table attributes.
* @throws Exception In case test fails
*/
@Test
public void updatesTableAttributes() throws Exception {
final String table = "tests";
final String key = "tid";
final int number = 43;
final String attr = "descr";
final String value = "Dummy\n\t\u20ac text";
final String updated = "Updated";
final MkData data = new H2Data().with(table, new String[] { key }, attr);
data.put(table, new Attributes().with(key, number).with(attr, value));
data.update(table, new Attributes().with(key, number), new AttributeUpdates().with(attr, "something else"));
data.update(table, new Attributes().with(key, number), new AttributeUpdates().with(attr, updated));
final Iterable<Attributes> result = data.iterate(table, new Conditions().with(key, Conditions.equalTo(number)));
MatcherAssert.assertThat(result.iterator().next(), Matchers.hasEntry(Matchers.equalTo(attr), Matchers.equalTo(new AttributeValue(updated))));
MatcherAssert.assertThat(result, Matchers.<Attributes>iterableWithSize(1));
}
use of com.amazonaws.services.dynamodbv2.document.Table in project jcabi-dynamo by jcabi.
the class MkRegionTest method storesAndReadsSingleAttribute.
/**
* MkRegion can store and read items.
* @throws Exception If some problem inside
*/
@Test
public void storesAndReadsSingleAttribute() throws Exception {
final String table = "ideas";
final String key = "number";
final String attr = "total";
final Region region = new MkRegion(new H2Data().with(table, new String[] { key }, attr));
final Table tbl = region.table(table);
tbl.put(new Attributes().with(key, "32443").with(attr, "0"));
final Item item = tbl.frame().iterator().next();
item.put(attr, new AttributeValueUpdate().withValue(new AttributeValue().withN("2")).withAction(AttributeAction.PUT));
MatcherAssert.assertThat(item.get(attr).getN(), Matchers.equalTo("2"));
}
use of com.amazonaws.services.dynamodbv2.document.Table in project tutorials by eugenp.
the class ProductInfoRepositoryIntegrationTest method setup.
@Before
public void setup() {
try {
repository = new ProductInfoRepository();
repository.setMapper(dynamoDBMapper);
CreateTableRequest tableRequest = dynamoDBMapper.generateCreateTableRequest(ProductInfo.class);
tableRequest.setProvisionedThroughput(new ProvisionedThroughput(1L, 1L));
amazonDynamoDB.createTable(tableRequest);
} catch (ResourceInUseException e) {
// Do nothing, table already created
}
// TODO How to handle different environments. i.e. AVOID deleting all entries in ProductInfo on table
dynamoDBMapper.batchDelete((List<ProductInfo>) repository.findAll());
}
use of com.amazonaws.services.dynamodbv2.document.Table in project spring-integration-aws by spring-projects.
the class DynamoDbMetaDataStore method afterPropertiesSet.
@Override
public void afterPropertiesSet() throws Exception {
try {
this.table.describe();
this.createTableLatch.countDown();
return;
} catch (ResourceNotFoundException e) {
if (logger.isInfoEnabled()) {
logger.info("No table '" + this.table.getTableName() + "'. Creating one...");
}
}
CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(this.table.getTableName()).withKeySchema(new KeySchemaElement(KEY, KeyType.HASH)).withAttributeDefinitions(new AttributeDefinition(KEY, ScalarAttributeType.S)).withProvisionedThroughput(new ProvisionedThroughput(this.readCapacity, this.writeCapacity));
this.dynamoDB.createTableAsync(createTableRequest, new AsyncHandler<CreateTableRequest, CreateTableResult>() {
@Override
public void onError(Exception e) {
logger.error("Cannot create DynamoDb table: " + DynamoDbMetaDataStore.this.table.getTableName(), e);
DynamoDbMetaDataStore.this.createTableLatch.countDown();
}
@Override
public void onSuccess(CreateTableRequest request, CreateTableResult createTableResult) {
Waiter<DescribeTableRequest> waiter = DynamoDbMetaDataStore.this.dynamoDB.waiters().tableExists();
WaiterParameters<DescribeTableRequest> waiterParameters = new WaiterParameters<>(new DescribeTableRequest(DynamoDbMetaDataStore.this.table.getTableName())).withPollingStrategy(new PollingStrategy(new MaxAttemptsRetryStrategy(DynamoDbMetaDataStore.this.createTableRetries), new FixedDelayStrategy(DynamoDbMetaDataStore.this.createTableDelay)));
waiter.runAsync(waiterParameters, new WaiterHandler<DescribeTableRequest>() {
@Override
public void onWaitSuccess(DescribeTableRequest request) {
DynamoDbMetaDataStore.this.createTableLatch.countDown();
DynamoDbMetaDataStore.this.table.describe();
}
@Override
public void onWaitFailure(Exception e) {
logger.error("Cannot describe DynamoDb table: " + DynamoDbMetaDataStore.this.table.getTableName(), e);
DynamoDbMetaDataStore.this.createTableLatch.countDown();
}
});
}
});
}
Aggregations