Search in sources :

Example 1 with TransactionConflictException

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

the class DynamoDBCertRecordStoreConnectionTest method testUpdateUnrefreshedCertificatesNotificationTimestampHostException.

@Test
public void testUpdateUnrefreshedCertificatesNotificationTimestampHostException() {
    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));
    Mockito.doThrow(new TransactionConflictException("error")).when(hostNameIndex).query(any(QuerySpec.class));
    List<X509CertRecord> result = dbConn.updateUnrefreshedCertificatesNotificationTimestamp("serverTest", 1591706189000L, "providerTest");
    assertEquals(result.size(), 0);
    dbConn.close();
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) 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)

Example 2 with TransactionConflictException

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

the class DynamoDBCertRecordStoreConnectionTest method testUpdateUnrefreshedCertificatesNotificationTimestampTimeException.

@Test
public void testUpdateUnrefreshedCertificatesNotificationTimestampTimeException() {
    DynamoDBCertRecordStoreConnection dbConn = getDBConnection();
    Mockito.doThrow(new TransactionConflictException("error")).when(currentTimeIndex).query(any(QuerySpec.class));
    List<X509CertRecord> result = dbConn.updateUnrefreshedCertificatesNotificationTimestamp("serverTest", 1591706189000L, "providerTest");
    assertEquals(result.size(), 0);
    dbConn.close();
}
Also used : TransactionConflictException(com.amazonaws.services.dynamodbv2.model.TransactionConflictException) QuerySpec(com.amazonaws.services.dynamodbv2.document.spec.QuerySpec) X509CertRecord(com.yahoo.athenz.common.server.cert.X509CertRecord) Test(org.testng.annotations.Test)

Example 3 with TransactionConflictException

use of com.amazonaws.services.dynamodbv2.model.TransactionConflictException 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)3 TransactionConflictException (com.amazonaws.services.dynamodbv2.model.TransactionConflictException)3 X509CertRecord (com.yahoo.athenz.common.server.cert.X509CertRecord)3 Test (org.testng.annotations.Test)3 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 UpdateItemSpec (com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec)1