Search in sources :

Example 6 with ReplaceableAttribute

use of com.amazonaws.services.simpledb.model.ReplaceableAttribute in project simplejpa by appoxy.

the class DomainHelperTests method listAllItemsTests.

@Test
public void listAllItemsTests() {
    EntityManagerSimpleJPA em = (EntityManagerSimpleJPA) factory.createEntityManager();
    AmazonSimpleDB sdbClient = em.getSimpleDb();
    String domainName = "simplejpa-domainhelper-tests";
    sdbClient.createDomain(new CreateDomainRequest().withDomainName(domainName));
    try {
        for (int i = 0; i < 3; i++) {
            sdbClient.putAttributes(new PutAttributesRequest().withItemName("thing" + i).withDomainName(domainName).withAttributes(new ReplaceableAttribute("name", "value", true)));
        }
        List<Item> items = DomainHelper.listAllItems(sdbClient, domainName);
        Assert.assertEquals(3, items.size());
    } finally {
        sdbClient.deleteDomain(new DeleteDomainRequest().withDomainName(domainName));
    }
}
Also used : Item(com.amazonaws.services.simpledb.model.Item) DeleteDomainRequest(com.amazonaws.services.simpledb.model.DeleteDomainRequest) AmazonSimpleDB(com.amazonaws.services.simpledb.AmazonSimpleDB) CreateDomainRequest(com.amazonaws.services.simpledb.model.CreateDomainRequest) PutAttributesRequest(com.amazonaws.services.simpledb.model.PutAttributesRequest) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute) Test(org.junit.Test)

Example 7 with ReplaceableAttribute

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());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) UpdateCondition(com.amazonaws.services.simpledb.model.UpdateCondition) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute) Test(org.junit.Test)

Example 8 with ReplaceableAttribute

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());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) UpdateCondition(com.amazonaws.services.simpledb.model.UpdateCondition) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute) Test(org.junit.Test)

Example 9 with ReplaceableAttribute

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);
}
Also used : PutAttributesRequest(com.amazonaws.services.simpledb.model.PutAttributesRequest) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedList(java.util.LinkedList) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute)

Example 10 with ReplaceableAttribute

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);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) PutAttributesRequest(com.amazonaws.services.simpledb.model.PutAttributesRequest) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute) Test(org.testng.annotations.Test)

Aggregations

ReplaceableAttribute (com.amazonaws.services.simpledb.model.ReplaceableAttribute)25 PutAttributesRequest (com.amazonaws.services.simpledb.model.PutAttributesRequest)14 Test (org.junit.Test)12 AmazonSimpleDB (com.amazonaws.services.simpledb.AmazonSimpleDB)8 UpdateCondition (com.amazonaws.services.simpledb.model.UpdateCondition)8 ArrayList (java.util.ArrayList)7 Exchange (org.apache.camel.Exchange)5 Processor (org.apache.camel.Processor)5 CreateDomainRequest (com.amazonaws.services.simpledb.model.CreateDomainRequest)4 DeleteDomainRequest (com.amazonaws.services.simpledb.model.DeleteDomainRequest)4 Field (java.lang.reflect.Field)4 HashMap (java.util.HashMap)4 SienaException (siena.SienaException)4 Item (com.amazonaws.services.simpledb.model.Item)3 Collection (java.util.Collection)3 Attribute (com.amazonaws.services.simpledb.model.Attribute)2 DeleteAttributesRequest (com.amazonaws.services.simpledb.model.DeleteAttributesRequest)2 SelectResult (com.amazonaws.services.simpledb.model.SelectResult)2 IOException (java.io.IOException)2 LinkedHashMap (java.util.LinkedHashMap)2