Search in sources :

Example 6 with WorkloadRecord

use of com.yahoo.athenz.common.server.workload.WorkloadRecord in project athenz by yahoo.

the class DynamoDBWorkloadRecordStoreConnectionTest method testGetWorkloadRecordsByServiceNotFoundException.

@Test
public void testGetWorkloadRecordsByServiceNotFoundException() {
    Mockito.doThrow(new AmazonDynamoDBException("item not found")).when(serviceIndex).query(Mockito.any(QuerySpec.class));
    DynamoDBWorkloadRecordStoreConnection dbConn = getDBConnection();
    List<WorkloadRecord> wlRecordList = dbConn.getWorkloadRecordsByService("athenz", "api");
    Assert.assertTrue(wlRecordList.isEmpty());
    dbConn.close();
}
Also used : AmazonDynamoDBException(com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException) QuerySpec(com.amazonaws.services.dynamodbv2.document.spec.QuerySpec) WorkloadRecord(com.yahoo.athenz.common.server.workload.WorkloadRecord) Test(org.testng.annotations.Test)

Example 7 with WorkloadRecord

use of com.yahoo.athenz.common.server.workload.WorkloadRecord in project athenz by yahoo.

the class DynamoDBWorkloadRecordStoreConnectionTest method testGetWorkloadRecordsByIp.

@Test
public void testGetWorkloadRecordsByIp() {
    long currTime = System.currentTimeMillis();
    Mockito.doReturn("1234").when(item).getString("instanceId");
    Mockito.doReturn("openstack").when(item).getString("provider");
    Mockito.doReturn("athenz.api").when(item).getString("service");
    Mockito.doReturn("test-host").when(item).getString("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");
    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(ipIndex).query(Mockito.any(QuerySpec.class));
    DynamoDBWorkloadRecordStoreConnection dbConn = getDBConnection();
    dbConn.setOperationTimeout(10);
    List<WorkloadRecord> wlRecordList = dbConn.getWorkloadRecordsByIp("10.0.0.1");
    Assert.assertNotNull(wlRecordList);
    Assert.assertEquals(wlRecordList.get(0).getInstanceId(), "1234");
    Assert.assertEquals(wlRecordList.get(0).getProvider(), "openstack");
    Assert.assertEquals(wlRecordList.get(0).getService(), "athenz.api");
    Assert.assertEquals(wlRecordList.get(0).getHostname(), "NA");
    Assert.assertEquals(wlRecordList.get(0).getUpdateTime(), new Date(currTime));
    Assert.assertEquals(wlRecordList.get(0).getCertExpiryTime(), new Date(0));
    dbConn.close();
}
Also used : QuerySpec(com.amazonaws.services.dynamodbv2.document.spec.QuerySpec) WorkloadRecord(com.yahoo.athenz.common.server.workload.WorkloadRecord) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 8 with WorkloadRecord

use of com.yahoo.athenz.common.server.workload.WorkloadRecord 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();
}
Also used : QuerySpec(com.amazonaws.services.dynamodbv2.document.spec.QuerySpec) WorkloadRecord(com.yahoo.athenz.common.server.workload.WorkloadRecord) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 9 with WorkloadRecord

use of com.yahoo.athenz.common.server.workload.WorkloadRecord 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();
}
Also used : UpdateItemSpec(com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec) WorkloadRecord(com.yahoo.athenz.common.server.workload.WorkloadRecord) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 10 with WorkloadRecord

use of com.yahoo.athenz.common.server.workload.WorkloadRecord in project athenz by yahoo.

the class DynamoDBWorkloadRecordStoreConnectionTest method testInsertWorkloadRecordException.

@Test
public void testInsertWorkloadRecordException() {
    WorkloadRecord workloadRecord = new WorkloadRecord();
    Mockito.doThrow(new AmazonDynamoDBException("invalid operation")).when(table).putItem(ArgumentMatchers.any(Item.class));
    DynamoDBWorkloadRecordStoreConnection dbConn = getDBConnection();
    boolean requestSuccess = dbConn.insertWorkloadRecord(workloadRecord);
    Assert.assertFalse(requestSuccess);
    dbConn.close();
}
Also used : AmazonDynamoDBException(com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException) WorkloadRecord(com.yahoo.athenz.common.server.workload.WorkloadRecord) Test(org.testng.annotations.Test)

Aggregations

WorkloadRecord (com.yahoo.athenz.common.server.workload.WorkloadRecord)27 Test (org.testng.annotations.Test)18 Date (java.util.Date)12 QuerySpec (com.amazonaws.services.dynamodbv2.document.spec.QuerySpec)4 AmazonDynamoDBException (com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException)4 WorkloadRecordStore (com.yahoo.athenz.common.server.workload.WorkloadRecordStore)3 WorkloadRecordStoreConnection (com.yahoo.athenz.common.server.workload.WorkloadRecordStoreConnection)3 UpdateItemSpec (com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec)2 java.sql (java.sql)2 ArrayList (java.util.ArrayList)2 DeserializationFeature (com.fasterxml.jackson.databind.DeserializationFeature)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 InetAddresses (com.google.common.net.InetAddresses)1 Authority (com.yahoo.athenz.auth.Authority)1 Authorizer (com.yahoo.athenz.auth.Authorizer)1 Principal (com.yahoo.athenz.auth.Principal)1 PrivateKeyStore (com.yahoo.athenz.auth.PrivateKeyStore)1 AthenzUtils (com.yahoo.athenz.auth.util.AthenzUtils)1 Crypto (com.yahoo.athenz.auth.util.Crypto)1 CryptoException (com.yahoo.athenz.auth.util.CryptoException)1