Search in sources :

Example 1 with ProvisionedThroughputExceededException

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

the class DynamoDBNotificationsHelperTest method testUpdateLastNotifiedItemRetryFailed.

@Test
public void testUpdateLastNotifiedItemRetryFailed() throws InterruptedException {
    Date now = new Date(1591706189000L);
    long lastNotifiedTime = now.getTime();
    long yesterday = lastNotifiedTime - TimeUnit.DAYS.toMillis(1);
    long fiveDaysAgo = lastNotifiedTime - 5 * 24 * 60 * 60 * 1000;
    System.setProperty(ZTSConsts.ZTS_PROP_CERT_DYNAMODB_RETRIES, "2");
    System.setProperty(ZTSConsts.ZTS_PROP_CERT_DYNAMODB_RETRIES_SLEEP_MILLIS, "1000");
    DynamoDBNotificationsHelper dynamoDBNotificationsHelper = new DynamoDBNotificationsHelper();
    Map<String, AttributeValue> reNotified = ZTSTestUtils.generateAttributeValues("home.test.service3", "reNotified", Long.toString(fiveDaysAgo), Long.toString(fiveDaysAgo), "testServer", null, "testHost2");
    Item item = ItemUtils.toItem(reNotified);
    UpdateItemOutcome updateItemOutcome1 = Mockito.mock(UpdateItemOutcome.class);
    when(updateItemOutcome1.getItem()).thenReturn(item);
    Table table = Mockito.mock(Table.class);
    // After getting this error twice, we stop retrying
    Mockito.when(table.updateItem(any(UpdateItemSpec.class))).thenThrow(new ProvisionedThroughputExceededException("Provisioned Throughput Exceeded")).thenThrow(new ProvisionedThroughputExceededException("Provisioned Throughput Exceeded"));
    try {
        dynamoDBNotificationsHelper.updateLastNotifiedItem("lastNotifiedServer", lastNotifiedTime, yesterday, item, "primaryKey", table);
        fail();
    } catch (TimeoutException ex) {
        assertEquals("Failed too many retries. Check table provisioned throughput settings.", ex.getMessage());
    }
    System.clearProperty(ZTSConsts.ZTS_PROP_CERT_DYNAMODB_RETRIES);
    System.clearProperty(ZTSConsts.ZTS_PROP_CERT_DYNAMODB_RETRIES_SLEEP_MILLIS);
}
Also used : Item(com.amazonaws.services.dynamodbv2.document.Item) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) Table(com.amazonaws.services.dynamodbv2.document.Table) UpdateItemOutcome(com.amazonaws.services.dynamodbv2.document.UpdateItemOutcome) ProvisionedThroughputExceededException(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughputExceededException) TimeoutException(java.util.concurrent.TimeoutException) Test(org.testng.annotations.Test)

Example 2 with ProvisionedThroughputExceededException

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

the class DynamoDBNotificationsHelperTest method testUpdateLastNotifiedItemRetry.

@Test
public void testUpdateLastNotifiedItemRetry() throws TimeoutException, InterruptedException {
    Date now = new Date(1591706189000L);
    long lastNotifiedTime = now.getTime();
    long yesterday = lastNotifiedTime - TimeUnit.DAYS.toMillis(1);
    long fiveDaysAgo = lastNotifiedTime - 5 * 24 * 60 * 60 * 1000;
    DynamoDBNotificationsHelper dynamoDBNotificationsHelper = new DynamoDBNotificationsHelper();
    Map<String, AttributeValue> reNotified = ZTSTestUtils.generateAttributeValues("home.test.service3", "reNotified", Long.toString(fiveDaysAgo), Long.toString(fiveDaysAgo), "testServer", null, "testHost2");
    Item item = ItemUtils.toItem(reNotified);
    UpdateItemOutcome updateItemOutcome1 = Mockito.mock(UpdateItemOutcome.class);
    when(updateItemOutcome1.getItem()).thenReturn(item);
    Table table = Mockito.mock(Table.class);
    Mockito.when(table.updateItem(any(UpdateItemSpec.class))).thenThrow(new ProvisionedThroughputExceededException("Provisioned Throughput Exceeded")).thenReturn(updateItemOutcome1);
    Item updatedItem = dynamoDBNotificationsHelper.updateLastNotifiedItem("lastNotifiedServer", lastNotifiedTime, yesterday, item, "primaryKey", table);
    assertEquals(updatedItem, item);
}
Also used : Item(com.amazonaws.services.dynamodbv2.document.Item) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) Table(com.amazonaws.services.dynamodbv2.document.Table) UpdateItemOutcome(com.amazonaws.services.dynamodbv2.document.UpdateItemOutcome) ProvisionedThroughputExceededException(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughputExceededException) Test(org.testng.annotations.Test)

Aggregations

Item (com.amazonaws.services.dynamodbv2.document.Item)2 Table (com.amazonaws.services.dynamodbv2.document.Table)2 UpdateItemOutcome (com.amazonaws.services.dynamodbv2.document.UpdateItemOutcome)2 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)2 ProvisionedThroughputExceededException (com.amazonaws.services.dynamodbv2.model.ProvisionedThroughputExceededException)2 Test (org.testng.annotations.Test)2 TimeoutException (java.util.concurrent.TimeoutException)1