Search in sources :

Example 21 with SelectResult

use of com.amazonaws.services.simpledb.model.SelectResult in project SimianArmy by Netflix.

the class TestSimpleDBJanitorResourceTracker method mkSelectResult.

private SelectResult mkSelectResult(String id, AWSResourceType resourceType, Resource.CleanupState state, String description, String ownerEmail, String region, String terminationReason, Date expectedTerminationTime, Date markTime, boolean optOut, String fieldName, String fieldValue) {
    Item item = new Item();
    List<Attribute> attrs = new LinkedList<Attribute>();
    attrs.add(new Attribute(AWSResource.FIELD_RESOURCE_ID, id));
    attrs.add(new Attribute(AWSResource.FIELD_RESOURCE_TYPE, resourceType.name()));
    attrs.add(new Attribute(AWSResource.FIELD_DESCRIPTION, description));
    attrs.add(new Attribute(AWSResource.FIELD_REGION, region));
    attrs.add(new Attribute(AWSResource.FIELD_STATE, state.name()));
    attrs.add(new Attribute(AWSResource.FIELD_OWNER_EMAIL, ownerEmail));
    attrs.add(new Attribute(AWSResource.FIELD_TERMINATION_REASON, terminationReason));
    attrs.add(new Attribute(AWSResource.FIELD_EXPECTED_TERMINATION_TIME, AWSResource.DATE_FORMATTER.print(expectedTerminationTime.getTime())));
    attrs.add(new Attribute(AWSResource.FIELD_MARK_TIME, AWSResource.DATE_FORMATTER.print(markTime.getTime())));
    attrs.add(new Attribute(AWSResource.FIELD_OPT_OUT_OF_JANITOR, String.valueOf(optOut)));
    attrs.add(new Attribute(fieldName, fieldValue));
    item.setAttributes(attrs);
    item.setName(String.format("%s-%s-%s", resourceType.name(), id, region));
    SelectResult result = new SelectResult();
    result.setItems(Arrays.asList(item));
    return result;
}
Also used : Item(com.amazonaws.services.simpledb.model.Item) SelectResult(com.amazonaws.services.simpledb.model.SelectResult) Attribute(com.amazonaws.services.simpledb.model.Attribute) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute) LinkedList(java.util.LinkedList)

Example 22 with SelectResult

use of com.amazonaws.services.simpledb.model.SelectResult in project SimianArmy by Netflix.

the class TestSimpleDBJanitorResourceTracker method testGetResources.

@Test
public void testGetResources() {
    String id1 = "id-1";
    String id2 = "id-2";
    AWSResourceType resourceType = AWSResourceType.INSTANCE;
    Resource.CleanupState state = Resource.CleanupState.MARKED;
    String description = "This is a test resource.";
    String ownerEmail = "owner@test.com";
    String region = "us-east-1";
    String terminationReason = "This is a test termination reason.";
    DateTime now = DateTime.now();
    Date expectedTerminationTime = new Date(now.plusDays(10).getMillis());
    Date markTime = new Date(now.getMillis());
    String fieldName = "fieldName123";
    String fieldValue = "fieldValue456";
    SelectResult result1 = mkSelectResult(id1, resourceType, state, description, ownerEmail, region, terminationReason, expectedTerminationTime, markTime, false, fieldName, fieldValue);
    result1.setNextToken("nextToken");
    SelectResult result2 = mkSelectResult(id2, resourceType, state, description, ownerEmail, region, terminationReason, expectedTerminationTime, markTime, true, fieldName, fieldValue);
    ArgumentCaptor<SelectRequest> arg = ArgumentCaptor.forClass(SelectRequest.class);
    TestSimpleDBJanitorResourceTracker tracker = new TestSimpleDBJanitorResourceTracker();
    when(tracker.sdbMock.select(any(SelectRequest.class))).thenReturn(result1).thenReturn(result2);
    verifyResources(tracker.getResources(resourceType, state, region), id1, id2, resourceType, state, description, ownerEmail, region, terminationReason, expectedTerminationTime, markTime, fieldName, fieldValue);
    verify(tracker.sdbMock, times(2)).select(arg.capture());
}
Also used : SelectResult(com.amazonaws.services.simpledb.model.SelectResult) AWSResourceType(com.netflix.simianarmy.aws.AWSResourceType) AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) DateTime(org.joda.time.DateTime) Date(java.util.Date) SelectRequest(com.amazonaws.services.simpledb.model.SelectRequest) Test(org.testng.annotations.Test)

Aggregations

SelectResult (com.amazonaws.services.simpledb.model.SelectResult)22 SelectRequest (com.amazonaws.services.simpledb.model.SelectRequest)12 Item (com.amazonaws.services.simpledb.model.Item)11 AmazonClientException (com.amazonaws.AmazonClientException)7 ReplaceableAttribute (com.amazonaws.services.simpledb.model.ReplaceableAttribute)5 ArrayList (java.util.ArrayList)5 Attribute (com.amazonaws.services.simpledb.model.Attribute)4 SienaException (siena.SienaException)4 AmazonSimpleDB (com.amazonaws.services.simpledb.AmazonSimpleDB)3 LinkedList (java.util.LinkedList)3 CreateDomainRequest (com.amazonaws.services.simpledb.model.CreateDomainRequest)2 DeleteDomainRequest (com.amazonaws.services.simpledb.model.DeleteDomainRequest)2 PutAttributesRequest (com.amazonaws.services.simpledb.model.PutAttributesRequest)2 Date (java.util.Date)2 LinkedHashMap (java.util.LinkedHashMap)2 Test (org.junit.Test)2 Test (org.testng.annotations.Test)2 NoSuchDomainException (com.amazonaws.services.simpledb.model.NoSuchDomainException)1 EventType (com.netflix.simianarmy.EventType)1 MonkeyType (com.netflix.simianarmy.MonkeyType)1