use of software.amazon.awssdk.services.dynamodb.model.BatchGetItemRequest in project aws-sdk-java-v2 by aws.
the class DynamoServiceIntegrationTest method testRequestEntityTooLargeErrorHandling.
/**
* Tests that we properly handle error responses for request entities that
* are too large.
*/
// DISABLED because DynamoDB apparently upped their max request size; we
// should be hitting this with a unit test that simulates an appropriate
// SdkServiceException.
// @Test
public void testRequestEntityTooLargeErrorHandling() throws Exception {
Map<String, KeysAndAttributes> items = new HashMap<String, KeysAndAttributes>();
for (int i = 0; i < 1024; i++) {
KeysAndAttributes kaa = KeysAndAttributes.builder().build();
StringBuilder bigString = new StringBuilder();
for (int j = 0; j < 1024; j++) {
bigString.append("a");
}
bigString.append(i);
items.put(bigString.toString(), kaa);
}
BatchGetItemRequest request = BatchGetItemRequest.builder().requestItems(items).build();
try {
dynamo.batchGetItem(request);
} catch (AwsServiceException exception) {
assertNotNull(exception.getMessage());
assertEquals("Request entity too large", exception.awsErrorDetails().errorCode());
assertEquals(413, exception.statusCode());
}
}
use of software.amazon.awssdk.services.dynamodb.model.BatchGetItemRequest in project aws-sdk-java-v2 by aws.
the class BatchGetItemOperationTest method getServiceCall_usingShortcutForm_makesTheRightCallAndReturnsResponse.
@Test
public void getServiceCall_usingShortcutForm_makesTheRightCallAndReturnsResponse() {
BatchGetItemEnhancedRequest batchGetItemEnhancedRequest = BatchGetItemEnhancedRequest.builder().readBatches(ReadBatch.builder(FakeItem.class).mappedTableResource(fakeItemMappedTable).addGetItem(FAKE_ITEM_KEYS.get(0)).build()).build();
BatchGetItemOperation operation = BatchGetItemOperation.create(batchGetItemEnhancedRequest);
BatchGetItemRequest batchGetItemRequest = BatchGetItemRequest.builder().requestItems(singletonMap("test-table", KeysAndAttributes.builder().keys(singletonList(FAKE_ITEM_MAPS.get(0))).build())).build();
BatchGetItemIterable expectedResponse = mock(BatchGetItemIterable.class);
when(mockDynamoDbClient.batchGetItemPaginator(any(BatchGetItemRequest.class))).thenReturn(expectedResponse);
SdkIterable<BatchGetItemResponse> response = operation.serviceCall(mockDynamoDbClient).apply(batchGetItemRequest);
assertThat(response, sameInstance(expectedResponse));
verify(mockDynamoDbClient).batchGetItemPaginator(batchGetItemRequest);
}
use of software.amazon.awssdk.services.dynamodb.model.BatchGetItemRequest in project aws-sdk-java-v2 by aws.
the class BatchGetItemOperationTest method generateRequest_multipleBatches_multipleTableSchemas.
@Test
public void generateRequest_multipleBatches_multipleTableSchemas() {
BatchGetItemEnhancedRequest batchGetItemEnhancedRequest = BatchGetItemEnhancedRequest.builder().readBatches(ReadBatch.builder(FakeItem.class).mappedTableResource(fakeItemMappedTable).addGetItem(r -> r.key(FAKE_ITEM_KEYS.get(0))).addGetItem(r -> r.key(FAKE_ITEM_KEYS.get(1))).addGetItem(r -> r.key(FAKE_ITEM_KEYS.get(2))).build(), ReadBatch.builder(FakeItemWithSort.class).mappedTableResource(fakeItemWithSortMappedTable).addGetItem(r -> r.key(FAKESORT_ITEM_KEYS.get(0))).addGetItem(r -> r.key(FAKESORT_ITEM_KEYS.get(1))).addGetItem(r -> r.key(FAKESORT_ITEM_KEYS.get(2))).build()).build();
BatchGetItemOperation operation = BatchGetItemOperation.create(batchGetItemEnhancedRequest);
BatchGetItemRequest batchGetItemRequest = operation.generateRequest(mockExtension);
KeysAndAttributes keysAndAttributes1 = batchGetItemRequest.requestItems().get(TABLE_NAME);
KeysAndAttributes keysAndAttributes2 = batchGetItemRequest.requestItems().get(TABLE_NAME_2);
assertThat(keysAndAttributes1.keys(), containsInAnyOrder(FAKE_ITEM_MAPS.subList(0, 3).toArray()));
assertThat(keysAndAttributes2.keys(), containsInAnyOrder(FAKESORT_ITEM_MAPS.subList(0, 3).toArray()));
assertThat(keysAndAttributes1.consistentRead(), is(nullValue()));
assertThat(keysAndAttributes2.consistentRead(), is(nullValue()));
verifyNoMoreInteractions(mockExtension);
}
use of software.amazon.awssdk.services.dynamodb.model.BatchGetItemRequest in project aws-sdk-java-v2 by aws.
the class DynamoServiceIntegrationTest method testNullQueryKeyErrorHandling.
@Test
@SuppressWarnings("unchecked")
public void testNullQueryKeyErrorHandling() {
Map<String, AttributeValue> item = new HashMap<String, AttributeValue>();
// Put a valid item first
item.put(HASH_KEY_NAME, AttributeValue.builder().s("bar").build());
item.put("age", AttributeValue.builder().s("30").build());
PutItemRequest putItemRequest = PutItemRequest.builder().tableName(tableName).item(item).returnValues(ReturnValue.ALL_OLD.toString()).build();
dynamo.putItem(putItemRequest);
Map<String, KeysAndAttributes> items = new HashMap<String, KeysAndAttributes>();
// Put a valid key and a null one
items.put(tableName, KeysAndAttributes.builder().keys(mapKey(HASH_KEY_NAME, AttributeValue.builder().s("bar").build()), null).build());
BatchGetItemRequest request = BatchGetItemRequest.builder().requestItems(items).build();
try {
dynamo.batchGetItem(request);
} catch (AwsServiceException exception) {
assertEquals("ValidationException", exception.awsErrorDetails().errorCode());
}
Map<String, List<WriteRequest>> requestItems = new HashMap<String, List<WriteRequest>>();
List<WriteRequest> writeRequests = new ArrayList<WriteRequest>();
Map<String, AttributeValue> writeAttributes = new HashMap<String, AttributeValue>();
writeAttributes.put(HASH_KEY_NAME, AttributeValue.builder().s("" + System.currentTimeMillis()).build());
writeAttributes.put("bar", AttributeValue.builder().s("" + System.currentTimeMillis()).build());
writeRequests.add(WriteRequest.builder().putRequest(PutRequest.builder().item(writeAttributes).build()).build());
writeRequests.add(WriteRequest.builder().putRequest(PutRequest.builder().item(null).build()).build());
requestItems.put(tableName, writeRequests);
try {
dynamo.batchWriteItem(BatchWriteItemRequest.builder().requestItems(requestItems).build());
} catch (AwsServiceException exception) {
assertEquals("ValidationException", exception.awsErrorDetails().errorCode());
}
}
use of software.amazon.awssdk.services.dynamodb.model.BatchGetItemRequest in project aws-sdk-java-v2 by aws.
the class BatchGetItemOperationTest method getServiceCall_usingKeyItemForm_makesTheRightCallAndReturnsResponse.
@Test
public void getServiceCall_usingKeyItemForm_makesTheRightCallAndReturnsResponse() {
BatchGetItemEnhancedRequest batchGetItemEnhancedRequest = BatchGetItemEnhancedRequest.builder().readBatches(ReadBatch.builder(FakeItem.class).mappedTableResource(fakeItemMappedTable).addGetItem(FAKE_ITEMS.get(0)).build()).build();
BatchGetItemOperation operation = BatchGetItemOperation.create(batchGetItemEnhancedRequest);
BatchGetItemRequest batchGetItemRequest = BatchGetItemRequest.builder().requestItems(singletonMap("test-table", KeysAndAttributes.builder().keys(singletonList(FAKE_ITEM_MAPS.get(0))).build())).build();
BatchGetItemIterable expectedResponse = mock(BatchGetItemIterable.class);
when(mockDynamoDbClient.batchGetItemPaginator(any(BatchGetItemRequest.class))).thenReturn(expectedResponse);
SdkIterable<BatchGetItemResponse> response = operation.serviceCall(mockDynamoDbClient).apply(batchGetItemRequest);
assertThat(response, sameInstance(expectedResponse));
verify(mockDynamoDbClient).batchGetItemPaginator(batchGetItemRequest);
}
Aggregations