use of com.amazonaws.services.dynamodbv2.document.Expected in project camel by apache.
the class DeleteItemCommandTest method execute.
@Test
public void execute() {
Map<String, AttributeValue> key = new HashMap<String, AttributeValue>();
key.put("1", new AttributeValue("Key_1"));
exchange.getIn().setHeader(DdbConstants.KEY, key);
Map<String, ExpectedAttributeValue> updateCondition = new HashMap<String, ExpectedAttributeValue>();
updateCondition.put("name", new ExpectedAttributeValue(new AttributeValue("expected value")));
exchange.getIn().setHeader(DdbConstants.UPDATE_CONDITION, updateCondition);
exchange.getIn().setHeader(DdbConstants.RETURN_VALUES, "ALL_OLD");
command.execute();
assertEquals("DOMAIN1", ddbClient.deleteItemRequest.getTableName());
assertEquals(key, ddbClient.deleteItemRequest.getKey());
assertEquals(updateCondition, ddbClient.deleteItemRequest.getExpected());
assertEquals("ALL_OLD", ddbClient.deleteItemRequest.getReturnValues());
assertEquals(new AttributeValue("attrValue"), exchange.getIn().getHeader(DdbConstants.ATTRIBUTES, Map.class).get("attrName"));
}
use of com.amazonaws.services.dynamodbv2.document.Expected in project iep by Netflix.
the class PaginationTest method route53ResourceRecordSets.
@Test
public void route53ResourceRecordSets() throws Exception {
SortedSet<String> pages = newPageSet(5);
final Iterator<String> reqIt = pages.iterator();
final Iterator<String> resIt = pages.iterator();
Function<ListResourceRecordSetsRequest, ListResourceRecordSetsResult> f = r -> {
if (r.getStartRecordName() != null) {
String expected = reqIt.next();
Assert.assertEquals(expected + "-id", r.getStartRecordIdentifier());
Assert.assertEquals(expected + "-name", r.getStartRecordName());
Assert.assertEquals(expected + "-type", r.getStartRecordType());
}
String next = resIt.hasNext() ? resIt.next() : null;
return new ListResourceRecordSetsResult().withNextRecordIdentifier((next != null) ? next + "-id" : null).withNextRecordName((next != null) ? next + "-name" : null).withNextRecordType((next != null) ? next + "-type" : null);
};
Publisher<ListResourceRecordSetsResult> publisher = Pagination.createPublisher(new ListResourceRecordSetsRequest(), f);
Iterable<String> iter = Flowable.fromPublisher(publisher).filter(r -> r.getNextRecordName() != null).map(ListResourceRecordSetsResult::getNextRecordName).blockingIterable();
SortedSet<String> results = new TreeSet<>();
for (String s : iter) {
results.add(s.substring(0, 5));
}
Assert.assertEquals(pages, results);
Assert.assertFalse(reqIt.hasNext());
}
use of com.amazonaws.services.dynamodbv2.document.Expected in project spring-integration-aws by spring-projects.
the class DynamoDbMetaDataStore method putIfAbsent.
@Override
public String putIfAbsent(String key, String value) {
Assert.hasText(key, "'key' must not be empty.");
Assert.hasText(value, "'value' must not be empty.");
awaitForActive();
try {
this.table.updateItem(new UpdateItemSpec().withPrimaryKey(KEY, key).withAttributeUpdate(new AttributeUpdate(VALUE).put(value)).withExpected(new Expected(KEY).notExist()));
return null;
} catch (ConditionalCheckFailedException e) {
return get(key);
}
}
use of com.amazonaws.services.dynamodbv2.document.Expected in project spring-integration-aws by spring-projects.
the class DynamoDbMetaDataStore method replace.
@Override
public boolean replace(String key, String oldValue, String newValue) {
Assert.hasText(key, "'key' must not be empty.");
Assert.hasText(oldValue, "'value' must not be empty.");
Assert.hasText(newValue, "'newValue' must not be empty.");
awaitForActive();
try {
return this.table.updateItem(new UpdateItemSpec().withPrimaryKey(KEY, key).withAttributeUpdate(new AttributeUpdate(VALUE).put(newValue)).withExpected(new Expected(VALUE).eq(oldValue)).withReturnValues(ReturnValue.UPDATED_NEW)).getItem() != null;
} catch (ConditionalCheckFailedException e) {
return false;
}
}
use of com.amazonaws.services.dynamodbv2.document.Expected in project thunder by RohanNagar.
the class UsersDao method insert.
/**
* Insert a new PilotUser into the data store.
*
* @param user The object to insert.
* @return The PilotUser object that was created.
* @throws DatabaseException If the user already exists or if the database is down.
*/
public PilotUser insert(PilotUser user) {
checkNotNull(user);
long now = Instant.now().toEpochMilli();
Item item = new Item().withPrimaryKey("email", user.getEmail().getAddress()).withString("id", UUID.randomUUID().toString()).withString("version", UUID.randomUUID().toString()).withLong("creation_time", now).withLong("update_time", now).withJSON("document", toJson(mapper, user));
try {
table.putItem(item, new Expected("email").notExist());
} catch (ConditionalCheckFailedException e) {
LOG.error("The user {} already exists in the database. Throwing DatabaseException.", user.getEmail());
throw new DatabaseException("The user already exists.", DatabaseError.CONFLICT);
} catch (AmazonServiceException e) {
LOG.error("The database rejected the create request.", e);
throw new DatabaseException("The database rejected the create request.", DatabaseError.REQUEST_REJECTED);
} catch (AmazonClientException e) {
LOG.error("The database is currently unresponsive.", e);
throw new DatabaseException("The database is currently unavailable.", DatabaseError.DATABASE_DOWN);
}
return user;
}
Aggregations