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);
}
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);
}
Aggregations