Search in sources :

Example 16 with Expected

use of com.amazonaws.services.dynamodbv2.document.Expected in project beam by apache.

the class AttributeValueCoderTest method shouldPassForNumberType.

@Test
public void shouldPassForNumberType() throws IOException {
    AttributeValue expected = new AttributeValue();
    expected.setN("123");
    AttributeValueCoder coder = AttributeValueCoder.of();
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    coder.encode(expected, output);
    ByteArrayInputStream in = new ByteArrayInputStream(output.toByteArray());
    AttributeValue actual = coder.decode(in);
    Assert.assertEquals(expected, actual);
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 17 with Expected

use of com.amazonaws.services.dynamodbv2.document.Expected in project beam by apache.

the class AttributeValueCoderTest method shouldPassForOneListOfNumber.

@Test
public void shouldPassForOneListOfNumber() throws IOException {
    AttributeValue expected = new AttributeValue();
    expected.setNS(ImmutableList.of("123", "456"));
    AttributeValueCoder coder = AttributeValueCoder.of();
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    coder.encode(expected, output);
    ByteArrayInputStream in = new ByteArrayInputStream(output.toByteArray());
    AttributeValue actual = coder.decode(in);
    Assert.assertEquals(expected, actual);
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 18 with Expected

use of com.amazonaws.services.dynamodbv2.document.Expected in project beam by apache.

the class AttributeValueCoderTest method shouldPassForOneListOfByteArray.

@Test
public void shouldPassForOneListOfByteArray() throws IOException {
    AttributeValue expected = new AttributeValue();
    expected.setBS(ImmutableList.of(ByteBuffer.wrap("mylistbyte1".getBytes(StandardCharsets.UTF_8)), ByteBuffer.wrap("mylistbyte2".getBytes(StandardCharsets.UTF_8))));
    AttributeValueCoder coder = AttributeValueCoder.of();
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    coder.encode(expected, output);
    ByteArrayInputStream in = new ByteArrayInputStream(output.toByteArray());
    AttributeValue actual = coder.decode(in);
    Assert.assertEquals(expected, actual);
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 19 with Expected

use of com.amazonaws.services.dynamodbv2.document.Expected in project beam by apache.

the class AttributeValueCoderTest method shouldPassForByteArray.

@Test
public void shouldPassForByteArray() throws IOException {
    AttributeValue expected = new AttributeValue();
    expected.setB(ByteBuffer.wrap("hello".getBytes(StandardCharsets.UTF_8)));
    AttributeValueCoder coder = AttributeValueCoder.of();
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    coder.encode(expected, output);
    ByteArrayInputStream in = new ByteArrayInputStream(output.toByteArray());
    AttributeValue actual = coder.decode(in);
    Assert.assertEquals(expected, actual);
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 20 with Expected

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

the class DynamoDBCertRecordStoreConnectionTest method testUpdateX509Record.

@Test
public void testUpdateX509Record() {
    DynamoDBCertRecordStoreConnection dbConn = getDBConnection();
    Date now = new Date();
    X509CertRecord certRecord = getRecordNonNullableColumns(now);
    certRecord.setLastNotifiedTime(now);
    certRecord.setLastNotifiedServer("last-notified-server");
    certRecord.setExpiryTime(now);
    certRecord.setHostName("hostname");
    certRecord.setSvcDataUpdateTime(now);
    UpdateItemSpec item = new UpdateItemSpec().withPrimaryKey("primaryKey", "athenz.provider:cn:1234").withAttributeUpdate(new AttributeUpdate("instanceId").put(certRecord.getInstanceId()), new AttributeUpdate("provider").put(certRecord.getProvider()), new AttributeUpdate("service").put(certRecord.getService()), new AttributeUpdate("currentSerial").put(certRecord.getCurrentSerial()), new AttributeUpdate("currentIP").put(certRecord.getCurrentIP()), new AttributeUpdate("currentTime").put(certRecord.getCurrentTime().getTime()), new AttributeUpdate("currentDate").put(DynamoDBUtils.getIso8601FromDate(certRecord.getCurrentTime())), new AttributeUpdate("prevSerial").put(certRecord.getPrevSerial()), new AttributeUpdate("prevIP").put(certRecord.getPrevIP()), new AttributeUpdate("prevTime").put(certRecord.getPrevTime().getTime()), new AttributeUpdate("clientCert").put(certRecord.getClientCert()), new AttributeUpdate("ttl").put(certRecord.getCurrentTime().getTime() / 1000L + 3660 * 720), new AttributeUpdate("svcDataUpdateTime").put(certRecord.getSvcDataUpdateTime().getTime()), new AttributeUpdate("expiryTime").put(certRecord.getExpiryTime().getTime()), new AttributeUpdate("hostName").put(certRecord.getHostName()));
    Mockito.doReturn(updateOutcome).when(table).updateItem(item);
    boolean requestSuccess = dbConn.updateX509CertRecord(certRecord);
    assertTrue(requestSuccess);
    ArgumentCaptor<UpdateItemSpec> itemCaptor = ArgumentCaptor.forClass(UpdateItemSpec.class);
    Mockito.verify(table, times(1)).updateItem(itemCaptor.capture());
    List<UpdateItemSpec> allValues = itemCaptor.getAllValues();
    assertEquals(1, allValues.size());
    UpdateItemSpec capturedItem = allValues.get(0);
    assertEquals(capturedItem.getKeyComponents().toArray()[0].toString(), item.getKeyComponents().toArray()[0].toString());
    List<AttributeUpdate> capturedAttributes = capturedItem.getAttributeUpdate();
    List<AttributeUpdate> expectedAttributes = item.getAttributeUpdate();
    for (int i = 0; i < expectedAttributes.size(); ++i) {
        System.out.println("expected attr: " + expectedAttributes.get(i).getAttributeName() + ", value: " + expectedAttributes.get(i).getValue());
        assertEquals(capturedAttributes.get(i).getAttributeName(), expectedAttributes.get(i).getAttributeName());
        assertEquals(capturedAttributes.get(i).getValue(), expectedAttributes.get(i).getValue());
    }
    dbConn.close();
}
Also used : UpdateItemSpec(com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec) X509CertRecord(com.yahoo.athenz.common.server.cert.X509CertRecord) Test(org.testng.annotations.Test)

Aggregations

AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)14 Test (org.junit.Test)14 ByteArrayInputStream (java.io.ByteArrayInputStream)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 Expected (com.amazonaws.services.dynamodbv2.document.Expected)5 ConditionalCheckFailedException (com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException)5 AmazonClientException (com.amazonaws.AmazonClientException)4 UpdateItemSpec (com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec)4 HashMap (java.util.HashMap)4 Item (com.amazonaws.services.dynamodbv2.document.Item)3 ExpectedAttributeValue (com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue)3 AmazonServiceException (com.amazonaws.AmazonServiceException)2 AttributeUpdate (com.amazonaws.services.dynamodbv2.document.AttributeUpdate)2 X509CertRecord (com.yahoo.athenz.common.server.cert.X509CertRecord)2 DescribeAutoScalingGroupsRequest (com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest)1 DescribeAutoScalingGroupsResult (com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult)1 ListMetricsRequest (com.amazonaws.services.cloudwatch.model.ListMetricsRequest)1 ListMetricsResult (com.amazonaws.services.cloudwatch.model.ListMetricsResult)1 PutMetricDataRequest (com.amazonaws.services.cloudwatch.model.PutMetricDataRequest)1 PutMetricDataResult (com.amazonaws.services.cloudwatch.model.PutMetricDataResult)1