Search in sources :

Example 16 with QueryOutcome

use of com.amazonaws.services.dynamodbv2.document.QueryOutcome in project aws-doc-sdk-examples by awsdocs.

the class DocumentAPIQuery method findRepliesPostedWithinTimePeriod.

private static void findRepliesPostedWithinTimePeriod(String forumName, String threadSubject) {
    Table table = dynamoDB.getTable(tableName);
    long startDateMilli = (new Date()).getTime() - (15L * 24L * 60L * 60L * 1000L);
    long endDateMilli = (new Date()).getTime() - (5L * 24L * 60L * 60L * 1000L);
    java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
    String startDate = df.format(startDateMilli);
    String endDate = df.format(endDateMilli);
    String replyId = forumName + "#" + threadSubject;
    QuerySpec spec = new QuerySpec().withProjectionExpression("Message, ReplyDateTime, PostedBy").withKeyConditionExpression("Id = :v_id and ReplyDateTime between :v_start_dt and :v_end_dt").withValueMap(new ValueMap().withString(":v_id", replyId).withString(":v_start_dt", startDate).withString(":v_end_dt", endDate));
    ItemCollection<QueryOutcome> items = table.query(spec);
    System.out.println("\nfindRepliesPostedWithinTimePeriod results:");
    Iterator<Item> iterator = items.iterator();
    while (iterator.hasNext()) {
        System.out.println(iterator.next().toJSONPretty());
    }
}
Also used : Table(com.amazonaws.services.dynamodbv2.document.Table) ValueMap(com.amazonaws.services.dynamodbv2.document.utils.ValueMap) SimpleDateFormat(java.text.SimpleDateFormat) QueryOutcome(com.amazonaws.services.dynamodbv2.document.QueryOutcome) Date(java.util.Date) Item(com.amazonaws.services.dynamodbv2.document.Item) QuerySpec(com.amazonaws.services.dynamodbv2.document.spec.QuerySpec) SimpleDateFormat(java.text.SimpleDateFormat)

Example 17 with QueryOutcome

use of com.amazonaws.services.dynamodbv2.document.QueryOutcome in project aws-doc-sdk-examples by awsdocs.

the class DocumentAPIQuery method findRepliesUsingAFilterExpression.

private static void findRepliesUsingAFilterExpression(String forumName, String threadSubject) {
    Table table = dynamoDB.getTable(tableName);
    String replyId = forumName + "#" + threadSubject;
    QuerySpec spec = new QuerySpec().withProjectionExpression("Message, ReplyDateTime, PostedBy").withKeyConditionExpression("Id = :v_id").withFilterExpression("PostedBy = :v_postedby").withValueMap(new ValueMap().withString(":v_id", replyId).withString(":v_postedby", "User B"));
    ItemCollection<QueryOutcome> items = table.query(spec);
    System.out.println("\nfindRepliesUsingAFilterExpression results:");
    Iterator<Item> iterator = items.iterator();
    while (iterator.hasNext()) {
        System.out.println(iterator.next().toJSONPretty());
    }
}
Also used : Item(com.amazonaws.services.dynamodbv2.document.Item) Table(com.amazonaws.services.dynamodbv2.document.Table) ValueMap(com.amazonaws.services.dynamodbv2.document.utils.ValueMap) QueryOutcome(com.amazonaws.services.dynamodbv2.document.QueryOutcome) QuerySpec(com.amazonaws.services.dynamodbv2.document.spec.QuerySpec)

Example 18 with QueryOutcome

use of com.amazonaws.services.dynamodbv2.document.QueryOutcome in project athenz by yahoo.

the class DynamoDBCertRecordStoreConnectionTest method testUpdateUnrefreshedCertificatesNotificationTimestampUpdateException.

@Test
public void testUpdateUnrefreshedCertificatesNotificationTimestampUpdateException() {
    DynamoDBCertRecordStoreConnection dbConn = getDBConnection();
    Date now = new Date(1591706189000L);
    long nowL = now.getTime();
    long fiveDaysAgo = nowL - 5 * 24 * 60 * 60 * 1000;
    Map<String, AttributeValue> reNotified = ZTSTestUtils.generateAttributeValues("home.test.service3", "reNotified", Long.toString(fiveDaysAgo), Long.toString(fiveDaysAgo), "testServer", null, "testHost2");
    Item item1 = ItemUtils.toItem(reNotified);
    ItemCollection<QueryOutcome> itemCollection = Mockito.mock(ItemCollection.class);
    IteratorSupport<Item, QueryOutcome> iteratorSupport = Mockito.mock(IteratorSupport.class);
    when(itemCollection.iterator()).thenReturn(iteratorSupport);
    when(iteratorSupport.hasNext()).thenReturn(true, false);
    when(iteratorSupport.next()).thenReturn(item1);
    Mockito.doReturn(itemCollection).when(currentTimeIndex).query(any(QuerySpec.class));
    ItemCollection<QueryOutcome> itemCollection2 = Mockito.mock(ItemCollection.class);
    IteratorSupport<Item, QueryOutcome> iteratorSupport2 = Mockito.mock(IteratorSupport.class);
    when(itemCollection2.iterator()).thenReturn(iteratorSupport2);
    when(iteratorSupport2.hasNext()).thenReturn(true, false);
    when(iteratorSupport2.next()).thenReturn(item1);
    Mockito.doReturn(itemCollection2).when(hostNameIndex).query(any(QuerySpec.class));
    Mockito.doThrow(new TransactionConflictException("error")).when(table).updateItem(any(UpdateItemSpec.class));
    List<X509CertRecord> result = dbConn.updateUnrefreshedCertificatesNotificationTimestamp("serverTest", 1591706189000L, "providerTest");
    assertEquals(result.size(), 0);
    dbConn.close();
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) UpdateItemSpec(com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec) TransactionConflictException(com.amazonaws.services.dynamodbv2.model.TransactionConflictException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) X509CertRecord(com.yahoo.athenz.common.server.cert.X509CertRecord) QuerySpec(com.amazonaws.services.dynamodbv2.document.spec.QuerySpec) Test(org.testng.annotations.Test)

Aggregations

QuerySpec (com.amazonaws.services.dynamodbv2.document.spec.QuerySpec)18 Item (com.amazonaws.services.dynamodbv2.document.Item)10 QueryOutcome (com.amazonaws.services.dynamodbv2.document.QueryOutcome)10 Table (com.amazonaws.services.dynamodbv2.document.Table)10 ValueMap (com.amazonaws.services.dynamodbv2.document.utils.ValueMap)10 Test (org.testng.annotations.Test)6 Date (java.util.Date)5 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)4 X509CertRecord (com.yahoo.athenz.common.server.cert.X509CertRecord)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 UpdateItemSpec (com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Index (com.amazonaws.services.dynamodbv2.document.Index)2 ConditionalCheckFailedException (com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException)2 TransactionConflictException (com.amazonaws.services.dynamodbv2.model.TransactionConflictException)2 WorkloadRecord (com.yahoo.athenz.common.server.workload.WorkloadRecord)2 HashMap (java.util.HashMap)2 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)1 DynamoDB (com.amazonaws.services.dynamodbv2.document.DynamoDB)1 ItemCollection (com.amazonaws.services.dynamodbv2.document.ItemCollection)1