software.amazon.awssdk.services.dynamodb.model.ResourceNotFoundException Java Examples

The following examples show how to use software.amazon.awssdk.services.dynamodb.model.ResourceNotFoundException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DynamoDBLeaseRefresherTest.java    From amazon-kinesis-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateLeaseTableBillingMode() throws Exception {
    leaseRefresher = new DynamoDBLeaseRefresher(TABLE_NAME, dynamoDbClient, leaseSerializer, CONSISTENT_READS,
            tableCreatorCallback, LeaseManagementConfig.DEFAULT_REQUEST_TIMEOUT, BillingMode.PAY_PER_REQUEST);

    TimeoutException te = setRuleForDependencyTimeout();

    when(dynamoDbClient.describeTable(any(DescribeTableRequest.class))).thenReturn(mockDescribeTableFuture);
    when(mockDescribeTableFuture.get(anyLong(), any()))
            .thenThrow(ResourceNotFoundException.builder().message("Table doesn't exist").build());

    when(dynamoDbClient.createTable(any(CreateTableRequest.class))).thenReturn(mockCreateTableFuture);
    when(mockCreateTableFuture.get(anyLong(), any())).thenThrow(te);

    verifyCancel(mockCreateTableFuture, () -> leaseRefresher.createLeaseTableIfNotExists(10L, 10L));
}
 
Example #2
Source File: DynamoDbJavaClientExceptionIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testResourceNotFoundException() {
    try {
        ddb.describeTable(DescribeTableRequest.builder().tableName(UUID.randomUUID().toString()).build());
        Assert.fail("ResourceNotFoundException is expected.");
    } catch (ResourceNotFoundException e) {
        Assert.assertNotNull(e.awsErrorDetails().errorCode());
        Assert.assertNotNull(e.awsErrorDetails().errorMessage());
        Assert.assertNotNull(e.awsErrorDetails().rawResponse());
    }
}
 
Example #3
Source File: TableUtils.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * Wait for the table to reach the desired status and returns the table
 * description
 *
 * @param dynamo
 *            Dynamo client to use
 * @param tableName
 *            Table name to poll status of
 * @param desiredStatus
 *            Desired {@link TableStatus} to wait for. If null this method
 *            simply waits until DescribeTable returns something non-null
 *            (i.e. any status)
 * @param timeout
 *            Timeout in milliseconds to continue to poll for desired status
 * @param interval
 *            Time to wait in milliseconds between poll attempts
 * @return Null if DescribeTables never returns a result, otherwise the
 *         result of the last poll attempt (which may or may not have the
 *         desired state)
 * @throws {@link
 *             IllegalArgumentException} If timeout or interval is invalid
 */
private static TableDescription waitForTableDescription(final DynamoDbClient dynamo, final String tableName,
                                                        TableStatus desiredStatus, final int timeout, final int interval)
        throws InterruptedException, IllegalArgumentException {
    if (timeout < 0) {
        throw new IllegalArgumentException("Timeout must be >= 0");
    }
    if (interval <= 0 || interval >= timeout) {
        throw new IllegalArgumentException("Interval must be > 0 and < timeout");
    }
    long startTime = System.currentTimeMillis();
    long endTime = startTime + timeout;

    TableDescription table = null;
    while (System.currentTimeMillis() < endTime) {
        try {
            table = dynamo.describeTable(DescribeTableRequest.builder().tableName(tableName).build()).table();
            if (desiredStatus == null || table.tableStatus().equals(desiredStatus)) {
                return table;

            }
        } catch (ResourceNotFoundException rnfe) {
            // ResourceNotFound means the table doesn't exist yet,
            // so ignore this error and just keep polling.
        }

        Thread.sleep(interval);
    }
    return table;
}
 
Example #4
Source File: TableUtils.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * Deletes the table and ignores any errors if it doesn't exist.
 * @param dynamo The Dynamo client to use.
 * @param deleteTableRequest The delete table request.
 * @return True if deleted, false otherwise.
 */
public static boolean deleteTableIfExists(final DynamoDbClient dynamo, final DeleteTableRequest deleteTableRequest) {
    try {
        dynamo.deleteTable(deleteTableRequest);
        return true;
    } catch (final ResourceNotFoundException e) {
        if (log.isTraceEnabled()) {
            log.trace("Table " + deleteTableRequest.tableName() + " does not exist", e);
        }
    }
    return false;
}
 
Example #5
Source File: DynamoDBLeaseRefresherTest.java    From amazon-kinesis-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateLeaseTableTimesOut() throws Exception {
    TimeoutException te = setRuleForDependencyTimeout();

    when(dynamoDbClient.describeTable(any(DescribeTableRequest.class))).thenReturn(mockDescribeTableFuture);
    when(mockDescribeTableFuture.get(anyLong(), any()))
            .thenThrow(ResourceNotFoundException.builder().message("Table doesn't exist").build());

    when(dynamoDbClient.createTable(any(CreateTableRequest.class))).thenReturn(mockCreateTableFuture);
    when(mockCreateTableFuture.get(anyLong(), any())).thenThrow(te);

    verifyCancel(mockCreateTableFuture, () -> leaseRefresher.createLeaseTableIfNotExists(10L, 10L));
}