use of com.amazonaws.services.dynamodbv2.document.Item in project athenz by yahoo.
the class DynamoDBWorkloadRecordStoreConnectionTest method testGetWorkloadRecordsByService.
@Test
public void testGetWorkloadRecordsByService() {
long currTime = System.currentTimeMillis();
Mockito.doReturn("1234").when(item).getString("instanceId");
Mockito.doReturn("openstack").when(item).getString("provider");
Mockito.doReturn("10.10.10.11").when(item).getString("ip");
Mockito.doReturn("test-host").when(item).getString("hostname");
Mockito.doReturn(true).when(item).hasAttribute("hostname");
Mockito.doReturn(currTime).when(item).get("creationTime");
Mockito.doReturn(currTime).when(item).get("updateTime");
Mockito.doReturn(currTime).when(item).get("certExpiryTime");
Mockito.doReturn(currTime).when(item).getLong("creationTime");
Mockito.doReturn(currTime).when(item).getLong("updateTime");
Mockito.doReturn(currTime).when(item).getLong("certExpiryTime");
Mockito.doReturn(true).when(item).hasAttribute("certExpiryTime");
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(item);
Mockito.doReturn(itemCollection).when(serviceIndex).query(Mockito.any(QuerySpec.class));
DynamoDBWorkloadRecordStoreConnection dbConn = getDBConnection();
dbConn.setOperationTimeout(10);
List<WorkloadRecord> wlRecordList = dbConn.getWorkloadRecordsByService("athenz", "api");
Assert.assertNotNull(wlRecordList);
Assert.assertEquals(wlRecordList.get(0).getInstanceId(), "1234");
Assert.assertEquals(wlRecordList.get(0).getProvider(), "openstack");
Assert.assertEquals(wlRecordList.get(0).getIp(), "10.10.10.11");
Assert.assertEquals(wlRecordList.get(0).getHostname(), "test-host");
Assert.assertEquals(wlRecordList.get(0).getUpdateTime(), new Date(currTime));
Assert.assertEquals(wlRecordList.get(0).getCertExpiryTime(), new Date(currTime));
dbConn.close();
}
use of com.amazonaws.services.dynamodbv2.document.Item in project athenz by yahoo.
the class DynamoDBWorkloadRecordStoreConnectionTest method testUpdateWorkloadRecord.
@Test
public void testUpdateWorkloadRecord() {
DynamoDBWorkloadRecordStoreConnection dbConn = getDBConnection();
WorkloadRecord workloadRecord = new WorkloadRecord();
workloadRecord.setProvider("openstack");
long currTime = System.currentTimeMillis();
Date currDate = new Date(currTime);
workloadRecord.setUpdateTime(currDate);
UpdateItemSpec item = new UpdateItemSpec().withPrimaryKey("primaryKey", "athenz.api#1234#10.0.0.1").withAttributeUpdate(new AttributeUpdate("provider").put(workloadRecord.getProvider()), new AttributeUpdate("updateTime").put(workloadRecord.getUpdateTime()));
Mockito.doReturn(updateOutcome).when(table).updateItem(item);
boolean requestSuccess = dbConn.updateWorkloadRecord(workloadRecord);
Assert.assertTrue(requestSuccess);
dbConn.close();
}
use of com.amazonaws.services.dynamodbv2.document.Item in project athenz by yahoo.
the class DynamoDBWorkloadRecordStoreConnectionTest method testGetWorkloadRecordsByIpNotFoundException.
@Test
public void testGetWorkloadRecordsByIpNotFoundException() {
Mockito.doThrow(new AmazonDynamoDBException("item not found")).when(ipIndex).query(Mockito.any(QuerySpec.class));
DynamoDBWorkloadRecordStoreConnection dbConn = getDBConnection();
List<WorkloadRecord> wlRecordList = dbConn.getWorkloadRecordsByIp("10.0.0.1");
Assert.assertTrue(wlRecordList.isEmpty());
dbConn.close();
}
use of com.amazonaws.services.dynamodbv2.document.Item in project athenz by yahoo.
the class DynamoDBCertRecordStoreConnectionTest method testUpdateX509RecordNullableColumns.
@Test
public void testUpdateX509RecordNullableColumns() {
DynamoDBCertRecordStoreConnection dbConn = getDBConnection();
Date now = new Date();
X509CertRecord certRecord = getRecordNonNullableColumns(now);
certRecord.setLastNotifiedTime(null);
certRecord.setLastNotifiedServer(null);
certRecord.setExpiryTime(now);
certRecord.setHostName(null);
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(null));
Mockito.doReturn(updateOutcome).when(table).updateItem(item);
boolean requestSuccess = dbConn.updateX509CertRecord(certRecord);
assertTrue(requestSuccess);
dbConn.close();
}
use of com.amazonaws.services.dynamodbv2.document.Item in project athenz by yahoo.
the class DynamoDBCertRecordStoreConnectionTest method testUpdateX509RecordNoHostName.
@Test
public void testUpdateX509RecordNoHostName() {
DynamoDBCertRecordStoreConnection dbConn = getDBConnection();
Date now = new Date();
X509CertRecord certRecord = getRecordNonNullableColumns(now);
certRecord.setLastNotifiedTime(now);
certRecord.setLastNotifiedServer("last-notified-server");
certRecord.setExpiryTime(now);
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()));
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();
// Check everyone except the hostname (it will be filled with the primaryKey value as the hostName index doesn't allow nulls)
for (int i = 0; i < capturedAttributes.size() - 1; ++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());
}
// Make sure hostName received the value of the primaryKey
System.out.println("expected attr: hostName, value: athenz.provider:cn:1234");
assertEquals(capturedAttributes.get(capturedAttributes.size() - 1).getAttributeName(), "hostName");
assertEquals(capturedAttributes.get(capturedAttributes.size() - 1).getValue(), "athenz.provider:cn:1234");
dbConn.close();
}
Aggregations