Search in sources :

Example 1 with AmazonDynamoDBException

use of com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException 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 2 with AmazonDynamoDBException

use of com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException 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)

Example 3 with AmazonDynamoDBException

use of com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException 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();
}
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 4 with AmazonDynamoDBException

use of com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException in project athenz by yahoo.

the class DynamoDBCertRecordStoreConnectionTest method testUpdateUnrefreshedCertificatesNotificationTimestampUpdateDynamoDBException.

@Test
public void testUpdateUnrefreshedCertificatesNotificationTimestampUpdateDynamoDBException() {
    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 AmazonDynamoDBException("invalid operation")).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) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) X509CertRecord(com.yahoo.athenz.common.server.cert.X509CertRecord) AmazonDynamoDBException(com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException) QuerySpec(com.amazonaws.services.dynamodbv2.document.spec.QuerySpec) Test(org.testng.annotations.Test)

Example 5 with AmazonDynamoDBException

use of com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException in project athenz by yahoo.

the class DynamoDBSSHRecordStoreConnectionTest method testDeleteSSHRecordException.

@Test
public void testDeleteSSHRecordException() {
    Mockito.doThrow(new AmazonDynamoDBException("invalid operation")).when(table).deleteItem(ArgumentMatchers.any(DeleteItemSpec.class));
    DynamoDBSSHRecordStoreConnection dbConn = new DynamoDBSSHRecordStoreConnection(dynamoDB, tableName);
    boolean requestSuccess = dbConn.deleteSSHCertRecord("12345", "cn");
    assertFalse(requestSuccess);
    dbConn.close();
}
Also used : DeleteItemSpec(com.amazonaws.services.dynamodbv2.document.spec.DeleteItemSpec) AmazonDynamoDBException(com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException) Test(org.testng.annotations.Test)

Aggregations

AmazonDynamoDBException (com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException)16 Test (org.testng.annotations.Test)13 UpdateItemSpec (com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec)4 X509CertRecord (com.yahoo.athenz.common.server.cert.X509CertRecord)4 WorkloadRecord (com.yahoo.athenz.common.server.workload.WorkloadRecord)4 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)3 QuerySpec (com.amazonaws.services.dynamodbv2.document.spec.QuerySpec)3 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)3 SSHCertRecord (com.yahoo.athenz.common.server.ssh.SSHCertRecord)3 DeleteItemSpec (com.amazonaws.services.dynamodbv2.document.spec.DeleteItemSpec)2 DynamoDBMapper (com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper)1 QueryRequest (com.amazonaws.services.dynamodbv2.model.QueryRequest)1 QueryResult (com.amazonaws.services.dynamodbv2.model.QueryResult)1 ScanRequest (com.amazonaws.services.dynamodbv2.model.ScanRequest)1 ScanResult (com.amazonaws.services.dynamodbv2.model.ScanResult)1 HashMap (java.util.HashMap)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1