本文整理汇总了Java中com.amazonaws.services.simpledb.model.ReplaceableAttribute.setValue方法的典型用法代码示例。如果您正苦于以下问题:Java ReplaceableAttribute.setValue方法的具体用法?Java ReplaceableAttribute.setValue怎么用?Java ReplaceableAttribute.setValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.simpledb.model.ReplaceableAttribute
的用法示例。
在下文中一共展示了ReplaceableAttribute.setValue方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPutThrowsWhenOptimisticPersisterUninitialised
import com.amazonaws.services.simpledb.model.ReplaceableAttribute; //导入方法依赖的package包/类
@Test
public void testPutThrowsWhenOptimisticPersisterUninitialised() throws Exception {
// ARRANGE
thrown.expect(Exception.class);
thrown.expectMessage("The optimistic persister has not been initialised");
// ACT
// Do not initialise the optimistic persister first - so put should throw
ReplaceableAttribute testAttribute = new ReplaceableAttribute();
testAttribute.setName("Name");
testAttribute.setValue("Value");
optimisticPersister.put(testItemName, Optional.of(42), testAttribute);
}
示例2: testPutThrowsWhenMaximumNumberOfAttributesIsAlreadyPresent
import com.amazonaws.services.simpledb.model.ReplaceableAttribute; //导入方法依赖的package包/类
@Test
public void testPutThrowsWhenMaximumNumberOfAttributesIsAlreadyPresent() throws Exception {
// ARRANGE
thrown.expect(Exception.class);
thrown.expectMessage("Database put failed");
// Initialiser persister with a max number of attributes equal to the
// current number (1 as there is only one active attribute) - so new put's
// will be rejected.
optimisticPersister.initialise(1, mockLogger);
// Configure attributes for database to return - the get is used for logging
// only, so does not really matter.
GetAttributesRequest simpleDBRequest = new GetAttributesRequest(testSimpleDBDomainName,
testItemName);
simpleDBRequest.setConsistentRead(true);
GetAttributesResult getAttributesResult = new GetAttributesResult();
getAttributesResult.setAttributes(allAttributes);
mockery.checking(new Expectations() {
{
allowing(mockSimpleDBClient).getAttributes(with(equal(simpleDBRequest)));
will(returnValue(getAttributesResult));
}
});
// ACT
ReplaceableAttribute testAttribute = new ReplaceableAttribute();
testAttribute.setName("Name");
testAttribute.setValue("Value");
// This should throw since we already have the max number of attributes.
optimisticPersister.put(testItemName, Optional.of(42), testAttribute);
}
示例3: expectCreateBookingToReturnUpdatedBookingsOrThrow
import com.amazonaws.services.simpledb.model.ReplaceableAttribute; //导入方法依赖的package包/类
private void expectCreateBookingToReturnUpdatedBookingsOrThrow(List<Booking> initialBookings,
Booking bookingToCreate, Optional<Exception> exceptionToThrow, int numCalls) throws Exception {
// The value we use here is arbitrary - what matters is that the call
// to put uses the same value that is returned from get - or else we would
// get a conditional check failed exception from SimpleDB.
Optional<Integer> expectedVersionNumber = Optional.of(4);
// Create booking attribute for the booking being created
String attributeName = bookingToCreate.getCourt().toString() + "-"
+ bookingToCreate.getCourtSpan().toString() + "-" + bookingToCreate.getSlot() + "-"
+ bookingToCreate.getSlotSpan().toString();
ReplaceableAttribute bookingAttribute = new ReplaceableAttribute();
bookingAttribute.setName(attributeName);
bookingAttribute.setValue(newName);
// Booking creation gets existing bookings before trying to make the new one
expectOptimisticPersisterGetToReturnVersionedAttributesOrThrow(expectedVersionNumber,
initialBookings, Optional.empty(), numCalls);
if (!exceptionToThrow.isPresent()) {
mockery.checking(new Expectations() {
{
exactly(numCalls).of(mockOptimisticPersister).put(with(equal(bookingToCreate.getDate())),
with(equal(expectedVersionNumber)), with(equal(bookingAttribute)));
}
});
} else {
mockery.checking(new Expectations() {
{
exactly(numCalls).of(mockOptimisticPersister).put(with(equal(bookingToCreate.getDate())),
with(equal(expectedVersionNumber)), with(equal(bookingAttribute)));
will(throwException(exceptionToThrow.get()));
}
});
}
bookingManager.setOptimisticPersister(mockOptimisticPersister);
}
示例4: expectToPutRuleToOptimisticPersister
import com.amazonaws.services.simpledb.model.ReplaceableAttribute; //导入方法依赖的package包/类
private void expectToPutRuleToOptimisticPersister(int expectedVersion, BookingRule ruleToPut)
throws Exception {
// Set up attributes to be returned from the database's booking rule item
ReplaceableAttribute attribute = new ReplaceableAttribute();
attribute.setName(getAttributeNameFromBookingRule(ruleToPut));
String[] datesToExclude = ruleToPut.getDatesToExclude();
attribute.setValue(StringUtils.join(datesToExclude, ","));
mockery.checking(new Expectations() {
{
oneOf(mockOptimisticPersister).put(with(equal(ruleItemName)),
with(Optional.of(expectedVersion)), with(equal(attribute)));
}
});
}
示例5: expectToAddOrDeleteRuleExclusionViaOptimisticPersister
import com.amazonaws.services.simpledb.model.ReplaceableAttribute; //导入方法依赖的package包/类
private void expectToAddOrDeleteRuleExclusionViaOptimisticPersister(int expectedVersion,
String dateToExclude, Boolean doAdd, BookingRule ruleToAddExclusionTo) throws Exception {
// Set up attribute to be put to the database's booking rule item
ReplaceableAttribute replaceableAttribute = new ReplaceableAttribute();
replaceableAttribute.setName(getAttributeNameFromBookingRule(ruleToAddExclusionTo));
List<String> datesToExclude = new ArrayList<>();
datesToExclude.addAll(Arrays.asList(ruleToAddExclusionTo.getDatesToExclude()));
if (doAdd) {
datesToExclude.add(dateToExclude);
} else {
datesToExclude.remove(dateToExclude);
}
if (datesToExclude.size() > 0) {
replaceableAttribute.setValue(StringUtils.join(datesToExclude.toArray(), ","));
} else {
replaceableAttribute.setValue("");
}
replaceableAttribute.setReplace(true);
mockery.checking(new Expectations() {
{
oneOf(mockOptimisticPersister).put(with(equal(ruleItemName)),
with(Optional.of(expectedVersion)), with(equal(replaceableAttribute)));
}
});
}
示例6: testSetLifecycleStateCorrectlyCallsTheOptimisticPersister_retired_with_url
import com.amazonaws.services.simpledb.model.ReplaceableAttribute; //导入方法依赖的package包/类
@Test
public void testSetLifecycleStateCorrectlyCallsTheOptimisticPersister_retired_with_url()
throws Exception {
// Tests happy path for setting RETIRED state - where we also supply a
// forwarding Url for the new site.
// ARRANGE
lifecycleManager.initialise(mockLogger);
// Set up a test lifecycle-state item - with an arbitrary version number.
ImmutablePair<Optional<Integer>, Set<Attribute>> testItem = new ImmutablePair<Optional<Integer>, Set<Attribute>>(
Optional.of(42), new HashSet<Attribute>());
ReplaceableAttribute newStateAttribute = new ReplaceableAttribute();
newStateAttribute.setName("State");
newStateAttribute.setValue("RETIRED");
newStateAttribute.setReplace(true);
ReplaceableAttribute newUrlAttribute = new ReplaceableAttribute();
newUrlAttribute.setName("Url");
newUrlAttribute.setValue(exampleForwardingUrl);
newUrlAttribute.setReplace(true);
mockery.checking(new Expectations() {
{
exactly(1).of(mockOptimisticPersister).get(with(equal("LifecycleState")));
will(returnValue(testItem));
exactly(1).of(mockOptimisticPersister).put(with(equal("LifecycleState")),
with(equal(Optional.of(42))), with(equal(newStateAttribute)));
will(returnValue(43));
exactly(1).of(mockOptimisticPersister).put(with(equal("LifecycleState")),
with(equal(Optional.of(43))), with(equal(newUrlAttribute)));
}
});
// ACT
lifecycleManager.setLifecycleState(LifecycleState.RETIRED, Optional.of(exampleForwardingUrl));
}
示例7: doTestSetLifecycleStateCorrectlyCallsTheOptimisticPersister
import com.amazonaws.services.simpledb.model.ReplaceableAttribute; //导入方法依赖的package包/类
private void doTestSetLifecycleStateCorrectlyCallsTheOptimisticPersister(
LifecycleState lifecycleState) throws Exception {
// ARRANGE
lifecycleManager.initialise(mockLogger);
// Set up a test lifecycle-state item - with an arbitrary version number.
ImmutablePair<Optional<Integer>, Set<Attribute>> testItem = new ImmutablePair<Optional<Integer>, Set<Attribute>>(
Optional.of(42), new HashSet<Attribute>());
ReplaceableAttribute newStateAttribute = new ReplaceableAttribute();
newStateAttribute.setName("State");
newStateAttribute.setValue(lifecycleState.name());
newStateAttribute.setReplace(true);
mockery.checking(new Expectations() {
{
exactly(1).of(mockOptimisticPersister).get(with(equal("LifecycleState")));
will(returnValue(testItem));
exactly(1).of(mockOptimisticPersister).put(with(equal("LifecycleState")),
with(equal(Optional.of(42))), with(equal(newStateAttribute)));
// Don't want to put the Url attribute in this case - since we're not
// retiring.
never(mockOptimisticPersister).put(with(equal("LifecycleState")),
with(equal(Optional.of(43))), with(anything()));
}
});
// ACT
lifecycleManager.setLifecycleState(lifecycleState, Optional.empty());
}
示例8: setLifecycleState
import com.amazonaws.services.simpledb.model.ReplaceableAttribute; //导入方法依赖的package包/类
@Override
public void setLifecycleState(LifecycleState lifecycleState, Optional<String> newServiceUrl)
throws Exception {
if (!initialised) {
throw new IllegalStateException("The lifecycle manager has not been initialised");
}
if (lifecycleState.equals(LifecycleState.RETIRED)) {
String message = null;
if (!newServiceUrl.isPresent() || !newServiceUrl.get().startsWith("http")) {
if (!newServiceUrl.isPresent()) {
message = "Throwing exception as url to new service has not been provided when setting lifecycle state to RETIRED";
} else if (!newServiceUrl.get().startsWith("http")) {
// Insist on correct format for the forwarding url.
message = "Throwing exception as url to new service when setting lifecycle state to RETIRED does not start with http";
}
logger.log(message);
throw new Exception(
"Must provide valid url to new service when setting lifecycle state to RETIRED");
}
}
// Get attribute - so can set version correctly. We assume only one person
// (i.e. the site admin) will ever be calling this at one time, but we
// nevertheless supply the version - so we can use the optimistic persister.
ImmutablePair<Optional<Integer>, Set<Attribute>> lifecycleStateItem = getOptimisticPersister()
.get(lifecycleItemName);
logger.log("About to set lifecycle state in database to: " + lifecycleState.name());
ReplaceableAttribute lifecycleAttribute = new ReplaceableAttribute();
lifecycleAttribute.setName("State");
lifecycleAttribute.setValue(lifecycleState.name());
lifecycleAttribute.setReplace(true);
int newVersion = getOptimisticPersister().put(lifecycleItemName, lifecycleStateItem.left,
lifecycleAttribute);
logger.log("Updated lifecycle state in database to: " + lifecycleState.name());
if (newServiceUrl.isPresent()) {
logger.log("About to set lifecycle state url in database to: " + newServiceUrl.get());
ReplaceableAttribute urlAttribute = new ReplaceableAttribute();
urlAttribute.setName("Url");
urlAttribute.setValue(newServiceUrl.get());
urlAttribute.setReplace(true);
getOptimisticPersister().put(lifecycleItemName, Optional.of(newVersion), urlAttribute);
logger.log("Updated lifecycle state url in database to: " + newServiceUrl.get());
}
}
示例9: testPutDoesNotThrowWhenMaximumNumberOfAttributesIsAlreadyPresentIfPutIsToInactivate
import com.amazonaws.services.simpledb.model.ReplaceableAttribute; //导入方法依赖的package包/类
@Test
public void testPutDoesNotThrowWhenMaximumNumberOfAttributesIsAlreadyPresentIfPutIsToInactivate()
throws Exception {
// Our 2-stage deletion process involves an initial put to 'inactivate' the
// attribute being deleted. We must allow such put's to exceed the limit -
// or else we could never delete attributes when we're over the limit.
// ARRANGE
// Initialiser persister with a max number of attributes equal to the
// current number (1 as there is only one active attribute) - so new put's
// will be rejected, unless they're inactivating puts.
optimisticPersister.initialise(1, mockLogger);
// Configure attributes for database to return - the get is used for logging
// only, so does not really matter.
GetAttributesRequest simpleDBRequest = new GetAttributesRequest(testSimpleDBDomainName,
testItemName);
simpleDBRequest.setConsistentRead(true);
GetAttributesResult getAttributesResult = new GetAttributesResult();
getAttributesResult.setAttributes(allAttributes);
mockery.checking(new Expectations() {
{
allowing(mockSimpleDBClient).getAttributes(with(equal(simpleDBRequest)));
will(returnValue(getAttributesResult));
}
});
// Don't care about further calls to SimpleDB.
mockery.checking(new Expectations() {
{
ignoring(mockSimpleDBClient);
}
});
// ACT
// Use an 'inactivating' put i.e. value prefixed with 'Inactive'
ReplaceableAttribute testAttribute = new ReplaceableAttribute();
testAttribute.setName("Name");
testAttribute.setValue("InactiveValue");
// This should not throw even though we already have the max number of
// attributes.
optimisticPersister.put(testItemName, Optional.of(42), testAttribute);
}
示例10: doTestPutUsesCorrectVersionWhenCallingTheDatabase
import com.amazonaws.services.simpledb.model.ReplaceableAttribute; //导入方法依赖的package包/类
private void doTestPutUsesCorrectVersionWhenCallingTheDatabase(Optional<Integer> version)
throws Exception {
// ARRANGE
initialiseOptimisticPersister();
// Configure attributes for database to return - the get is used for logging
// only, so does not really matter.
GetAttributesRequest simpleDBRequest = new GetAttributesRequest(testSimpleDBDomainName,
testItemName);
simpleDBRequest.setConsistentRead(true);
GetAttributesResult getAttributesResult = new GetAttributesResult();
mockery.checking(new Expectations() {
{
allowing(mockSimpleDBClient).getAttributes(with(equal(simpleDBRequest)));
will(returnValue(getAttributesResult));
}
});
// Configure expectations for the put:
UpdateCondition updateCondition = new UpdateCondition();
updateCondition.setName(versionAttributeName);
ReplaceableAttribute versionAttribute = new ReplaceableAttribute();
versionAttribute.setName(versionAttributeName);
versionAttribute.setReplace(true);
if (!version.isPresent()) {
// A version number attribute did not exist - so it still should not
updateCondition.setExists(false);
// Set initial value for our version number attribute
versionAttribute.setValue("0");
} else {
// A version number attribute exists - so it should be unchanged
updateCondition.setValue(Integer.toString(version.get()));
// Bump up our version number attribute
versionAttribute.setValue(Integer.toString(version.get() + 1));
}
List<ReplaceableAttribute> replaceableAttributes = new ArrayList<>();
replaceableAttributes.add(versionAttribute);
// Add the new attribute
ReplaceableAttribute testAttribute = new ReplaceableAttribute();
testAttribute.setName("Name");
testAttribute.setValue("Value");
replaceableAttributes.add(testAttribute);
PutAttributesRequest simpleDBPutRequest = new PutAttributesRequest(testSimpleDBDomainName,
testItemName, replaceableAttributes, updateCondition);
mockery.checking(new Expectations() {
{
oneOf(mockSimpleDBClient).putAttributes(with(equal(simpleDBPutRequest)));
}
});
// ACT
optimisticPersister.put(testItemName, version, testAttribute);
}
示例11: doTestPutHandlesExceptionsCorrectly
import com.amazonaws.services.simpledb.model.ReplaceableAttribute; //导入方法依赖的package包/类
private void doTestPutHandlesExceptionsCorrectly(Boolean isConditionalCheckFailedException)
throws Exception {
// The persister should forward all simpleDB exceptions to us, but it should
// convert ConditionalCheckFailed exceptions before forwarding, as clients
// will likely want to handle that case differently.
// ARRANGE
thrown.expect(Exception.class);
thrown.expectMessage(isConditionalCheckFailedException ? "Database put failed" : "Boom!");
initialiseOptimisticPersister();
// Configure attributes for database to return - the get is used for logging
// only, so does not really matter.
GetAttributesRequest simpleDBRequest = new GetAttributesRequest(testSimpleDBDomainName,
testItemName);
simpleDBRequest.setConsistentRead(true);
GetAttributesResult getAttributesResult = new GetAttributesResult();
mockery.checking(new Expectations() {
{
allowing(mockSimpleDBClient).getAttributes(with(equal(simpleDBRequest)));
will(returnValue(getAttributesResult));
}
});
// Make the simpleDB call throw the correct exception
AmazonServiceException exception = new AmazonServiceException("Boom!");
exception.setErrorCode(isConditionalCheckFailedException ? "ConditionalCheckFailed"
: "SomeOtherArbitraryCode");
mockery.checking(new Expectations() {
{
oneOf(mockSimpleDBClient).putAttributes(with(anything()));
will(throwException(exception));
}
});
ReplaceableAttribute testAttribute = new ReplaceableAttribute();
testAttribute.setName("Name");
testAttribute.setValue("Value");
// ACT
optimisticPersister.put(testItemName, Optional.of(42), testAttribute);
}
示例12: testPutReturnsCorrectVersion
import com.amazonaws.services.simpledb.model.ReplaceableAttribute; //导入方法依赖的package包/类
@Test
public void testPutReturnsCorrectVersion() throws Exception {
// A successful put should return the version that the put-to item has after
// the put - i.e. one higher than it had initially.
// ARRANGE
initialiseOptimisticPersister();
// Configure attributes for database to return - the get is used for logging
// only, so does not really matter.
GetAttributesRequest simpleDBRequest = new GetAttributesRequest(testSimpleDBDomainName,
testItemName);
simpleDBRequest.setConsistentRead(true);
GetAttributesResult getAttributesResult = new GetAttributesResult();
mockery.checking(new Expectations() {
{
allowing(mockSimpleDBClient).getAttributes(with(equal(simpleDBRequest)));
will(returnValue(getAttributesResult));
}
});
mockery.checking(new Expectations() {
{
allowing(mockSimpleDBClient).putAttributes(with(anything()));
}
});
ReplaceableAttribute testAttribute = new ReplaceableAttribute();
testAttribute.setName("Name");
testAttribute.setValue("Value");
int initialVersion = 42; // Arbitrary
// ACT
int finalVersion = optimisticPersister.put(testItemName, Optional.of(initialVersion),
testAttribute);
// ASSERT
assertTrue("The returned version should be one higher than the initial version",
finalVersion == (initialVersion + 1));
}