use of com.amazonaws.services.simpledb.model.ReplaceableAttribute in project camel by apache.
the class SdbComponentSpringTest method putAttributes.
@Test
public void putAttributes() {
final List<ReplaceableAttribute> replaceableAttributes = Arrays.asList(new ReplaceableAttribute[] { new ReplaceableAttribute("NAME1", "VALUE1", true) });
final UpdateCondition updateCondition = new UpdateCondition("NAME1", "VALUE1", true);
template.send("direct:start", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(SdbConstants.OPERATION, SdbOperations.PutAttributes);
exchange.getIn().setHeader(SdbConstants.ITEM_NAME, "ITEM1");
exchange.getIn().setHeader(SdbConstants.UPDATE_CONDITION, updateCondition);
exchange.getIn().setHeader(SdbConstants.REPLACEABLE_ATTRIBUTES, replaceableAttributes);
}
});
assertEquals("TestDomain", amazonSDBClient.putAttributesRequest.getDomainName());
assertEquals("ITEM1", amazonSDBClient.putAttributesRequest.getItemName());
assertEquals(updateCondition, amazonSDBClient.putAttributesRequest.getExpected());
assertEquals(replaceableAttributes, amazonSDBClient.putAttributesRequest.getAttributes());
}
use of com.amazonaws.services.simpledb.model.ReplaceableAttribute in project camel by apache.
the class SdbComponentTest method putAttributes.
@Test
public void putAttributes() {
final List<ReplaceableAttribute> replaceableAttributes = Arrays.asList(new ReplaceableAttribute[] { new ReplaceableAttribute("NAME1", "VALUE1", true) });
final UpdateCondition updateCondition = new UpdateCondition("NAME1", "VALUE1", true);
template.send("direct:start", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(SdbConstants.OPERATION, SdbOperations.PutAttributes);
exchange.getIn().setHeader(SdbConstants.ITEM_NAME, "ITEM1");
exchange.getIn().setHeader(SdbConstants.UPDATE_CONDITION, updateCondition);
exchange.getIn().setHeader(SdbConstants.REPLACEABLE_ATTRIBUTES, replaceableAttributes);
}
});
assertEquals("TestDomain", amazonSDBClient.putAttributesRequest.getDomainName());
assertEquals("ITEM1", amazonSDBClient.putAttributesRequest.getItemName());
assertEquals(updateCondition, amazonSDBClient.putAttributesRequest.getExpected());
assertEquals(replaceableAttributes, amazonSDBClient.putAttributesRequest.getAttributes());
}
use of com.amazonaws.services.simpledb.model.ReplaceableAttribute in project SimianArmy by Netflix.
the class SimpleDBRecorder method recordEvent.
/** {@inheritDoc} */
@Override
public void recordEvent(Event evt) {
String evtTime = String.valueOf(evt.eventTime().getTime());
List<ReplaceableAttribute> attrs = new LinkedList<ReplaceableAttribute>();
attrs.add(new ReplaceableAttribute(Keys.id.name(), evt.id(), true));
attrs.add(new ReplaceableAttribute(Keys.eventTime.name(), evtTime, true));
attrs.add(new ReplaceableAttribute(Keys.region.name(), evt.region(), true));
attrs.add(new ReplaceableAttribute(Keys.recordType.name(), "MonkeyEvent", true));
attrs.add(new ReplaceableAttribute(Keys.monkeyType.name(), enumToValue(evt.monkeyType()), true));
attrs.add(new ReplaceableAttribute(Keys.eventType.name(), enumToValue(evt.eventType()), true));
for (Map.Entry<String, String> pair : evt.fields().entrySet()) {
if (pair.getValue() == null || pair.getValue().equals("") || Keys.KEYSET.contains(pair.getKey())) {
continue;
}
attrs.add(new ReplaceableAttribute(pair.getKey(), pair.getValue(), true));
}
// Let pk contain the timestamp so that the same resource can have multiple events.
String pk = String.format("%s-%s-%s-%s", evt.monkeyType().name(), evt.id(), region, evtTime);
PutAttributesRequest putReq = new PutAttributesRequest(domain, pk, attrs);
sdbClient().putAttributes(putReq);
}
use of com.amazonaws.services.simpledb.model.ReplaceableAttribute in project SimianArmy by Netflix.
the class TestSimpleDBRecorder method testRecordEvent.
@Test
public void testRecordEvent() {
ArgumentCaptor<PutAttributesRequest> arg = ArgumentCaptor.forClass(PutAttributesRequest.class);
Event evt = newEvent(Type.MONKEY, EventTypes.EVENT, "region", "testId");
evt.addField("field1", "value1");
evt.addField("field2", "value2");
// this will be ignored as it conflicts with reserved key
evt.addField("id", "ignoreThis");
recordEvent(evt);
verify(sdbMock).putAttributes(arg.capture());
PutAttributesRequest req = arg.getValue();
Assert.assertEquals(req.getDomainName(), "DOMAIN");
Assert.assertEquals(req.getItemName(), "MONKEY-testId-region-" + evt.eventTime().getTime());
Map<String, String> map = new HashMap<String, String>();
for (ReplaceableAttribute attr : req.getAttributes()) {
map.put(attr.getName(), attr.getValue());
}
Assert.assertEquals(map.remove("id"), "testId");
Assert.assertEquals(map.remove("eventTime"), String.valueOf(evt.eventTime().getTime()));
Assert.assertEquals(map.remove("region"), "region");
Assert.assertEquals(map.remove("recordType"), "MonkeyEvent");
Assert.assertEquals(map.remove("monkeyType"), "MONKEY|com.netflix.simianarmy.aws.TestSimpleDBRecorder$Type");
Assert.assertEquals(map.remove("eventType"), "EVENT|com.netflix.simianarmy.aws.TestSimpleDBRecorder$EventTypes");
Assert.assertEquals(map.remove("field1"), "value1");
Assert.assertEquals(map.remove("field2"), "value2");
Assert.assertEquals(map.size(), 0);
}
use of com.amazonaws.services.simpledb.model.ReplaceableAttribute in project siena by mandubian.
the class SdbNativeSerializer method embed.
public static void embed(PutAttributesRequest req, String embeddingColumnName, Object embeddedObj) {
Class<?> clazz = embeddedObj.getClass();
if (clazz.isArray() || Collection.class.isAssignableFrom(clazz)) {
throw new SienaException("can't serializer Array/Collection in native mode");
}
for (Field f : ClassInfo.getClassInfo(clazz).updateFields) {
String propValue = SdbMappingUtils.objectFieldToString(embeddedObj, f);
if (propValue != null) {
ReplaceableAttribute attr = new ReplaceableAttribute(getEmbeddedAttributeName(embeddingColumnName, f), propValue, true);
req.withAttributes(attr);
} else {
if (ClassInfo.isEmbeddedNative(f)) {
SdbNativeSerializer.embed(req, getEmbeddedAttributeName(embeddingColumnName, f), Util.readField(embeddedObj, f));
}
}
}
}
Aggregations