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

The following examples show how to use software.amazon.awssdk.services.dynamodb.model.DeleteItemResponse. 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: DynamoDBTest.java    From dynein with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteDispatchedJob_failure() throws Exception {
  DyneinJobSpec jobSpec = getTestJobSpec(validToken, "test1");
  Schedule schedule = jobSpecToSchedule(jobSpec).withStatus(JobStatus.ACQUIRED);
  DeleteItemRequest request = getDeleteItemRequest(schedule);

  Exception exception = new Exception();
  CompletableFuture<DeleteItemResponse> response = new CompletableFuture<>();
  response.completeExceptionally(exception);
  when(ddbClient.deleteItem(request)).thenReturn(response);

  CompletableFuture<Void> ret = scheduleManager.deleteDispatchedJob(schedule);
  assertSame(getException(ret), exception);

  verify(ddbClient, times(1)).deleteItem(request);
  verifyNoMoreInteractions(ddbClient);
}
 
Example #2
Source File: DeleteItemOperationTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void transformResponse_correctlyTransformsIntoAnItem() {
    FakeItem keyItem = createUniqueFakeItem();
    DeleteItemOperation<FakeItem> deleteItemOperation =
        DeleteItemOperation.create(DeleteItemEnhancedRequest.builder().key(k -> k.partitionValue(keyItem.getId())).build());
    Map<String, AttributeValue> responseMap = new HashMap<>();
    responseMap.put("id", AttributeValue.builder().s(keyItem.getId()).build());
    responseMap.put("subclass_attribute", AttributeValue.builder().s("test-value").build());
    DeleteItemResponse response = DeleteItemResponse.builder()
                                                    .attributes(responseMap)
                                                    .build();

    FakeItem result = deleteItemOperation.transformResponse(response,
                                                            FakeItem.getTableSchema(),
                                                            PRIMARY_CONTEXT,
                                                            null);

    assertThat(result.getId(), is(keyItem.getId()));
    assertThat(result.getSubclassAttribute(), is("test-value"));
}
 
Example #3
Source File: DynamoDBTest.java    From dynein with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteJob_Failure() throws Exception {
  String token = getToken(2);
  JobTokenPayload tokenPayload = tokenManager.decodeToken(token);
  Map<String, AttributeValue> primaryKey =
      DynamoDBUtils.getPrimaryKeyFromToken(token, tokenPayload, maxShardId);

  Map<String, String> attributeNames = new HashMap<>();
  Map<String, AttributeValue> attributeValues = new HashMap<>();
  attributeNames.put("#jobStatus", DynamoDBUtils.Attribute.JOB_STATUS.columnName);
  attributeValues.put(
      ":scheduled", AttributeValue.builder().s(Schedule.JobStatus.SCHEDULED.toString()).build());

  DeleteItemRequest deleteItemRequest =
      DeleteItemRequest.builder()
          .tableName(tableName)
          .conditionExpression("#jobStatus = :scheduled")
          .key(primaryKey)
          .expressionAttributeNames(attributeNames)
          .expressionAttributeValues(attributeValues)
          .build();

  CompletableFuture<DeleteItemResponse> ret = new CompletableFuture<>();
  Exception exception = new Exception();
  ret.completeExceptionally(exception);
  when(ddbClient.deleteItem(deleteItemRequest)).thenReturn(ret);

  CompletableFuture<Void> response = scheduleManager.deleteJob(token);

  assertSame(getException(response), exception);
  verify(ddbClient, times(1)).deleteItem(deleteItemRequest);
  verifyNoMoreInteractions(ddbClient);
}
 
Example #4
Source File: DynamoDBTest.java    From dynein with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteDispatchedJob() throws Exception {
  DyneinJobSpec jobSpec = getTestJobSpec(validToken, "test1");
  Schedule schedule = jobSpecToSchedule(jobSpec).withStatus(JobStatus.ACQUIRED);
  DeleteItemRequest request = getDeleteItemRequest(schedule);

  when(ddbClient.deleteItem(request))
      .thenReturn(CompletableFuture.completedFuture(DeleteItemResponse.builder().build()));

  CompletableFuture<Void> ret = scheduleManager.deleteDispatchedJob(schedule);
  assertNull(ret.get(1, TimeUnit.SECONDS));

  verify(ddbClient, times(1)).deleteItem(request);
  verifyNoMoreInteractions(ddbClient);
}
 
Example #5
Source File: DeleteItemOperation.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Override
public T transformResponse(DeleteItemResponse response,
                           TableSchema<T> tableSchema,
                           OperationContext operationContext,
                           DynamoDbEnhancedClientExtension extension) {
    return EnhancedClientUtils.readAndTransformSingleItem(response.attributes(), tableSchema, operationContext, extension);
}
 
Example #6
Source File: DeleteItemOperationTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void getServiceCall_makesTheRightCallAndReturnsResponse() {
    FakeItem keyItem = createUniqueFakeItem();
    DeleteItemOperation<FakeItem> deleteItemOperation =
        DeleteItemOperation.create(DeleteItemEnhancedRequest.builder().key(k -> k.partitionValue(keyItem.getId())).build());
    DeleteItemRequest deleteItemRequest = DeleteItemRequest.builder().tableName(TABLE_NAME).build();
    DeleteItemResponse expectedResponse = DeleteItemResponse.builder().build();
    when(mockDynamoDbClient.deleteItem(any(DeleteItemRequest.class))).thenReturn(expectedResponse);

    DeleteItemResponse response = deleteItemOperation.serviceCall(mockDynamoDbClient).apply(deleteItemRequest);

    assertThat(response, sameInstance(expectedResponse));
    verify(mockDynamoDbClient).deleteItem(deleteItemRequest);
}
 
Example #7
Source File: DeleteItemOperationTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void transformResponse_noResults_returnsNull() {
    FakeItem keyItem = createUniqueFakeItem();
    DeleteItemOperation<FakeItem> deleteItemOperation =
        DeleteItemOperation.create(DeleteItemEnhancedRequest.builder().key(k -> k.partitionValue(keyItem.getId())).build());
    DeleteItemResponse response = DeleteItemResponse.builder()
                                                    .build();

    FakeItem result = deleteItemOperation.transformResponse(response,
                                                            FakeItem.getTableSchema(),
                                                            PRIMARY_CONTEXT,
                                                            null);

    assertThat(result, is(nullValue()));
}
 
Example #8
Source File: DeleteItemOperationTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void transformResponse_withExtension_appliesItemModification() {
    FakeItem baseFakeItem = createUniqueFakeItem();
    FakeItem fakeItem = createUniqueFakeItem();
    Map<String, AttributeValue> baseFakeItemMap = FakeItem.getTableSchema().itemToMap(baseFakeItem, false);
    Map<String, AttributeValue> fakeItemMap = FakeItem.getTableSchema().itemToMap(fakeItem, false);
    DeleteItemOperation<FakeItem> deleteItemOperation =
        DeleteItemOperation.create(DeleteItemEnhancedRequest.builder()
                                                            .key(k -> k.partitionValue(baseFakeItem.getId()))
                                                            .build());

    DeleteItemResponse response = DeleteItemResponse.builder()
                                                    .attributes(baseFakeItemMap)
                                                    .build();
    when(mockDynamoDbEnhancedClientExtension.afterRead(any(DynamoDbExtensionContext.AfterRead.class)))
        .thenReturn(ReadModification.builder().transformedItem(fakeItemMap).build());

    FakeItem resultItem = deleteItemOperation.transformResponse(response,
                                                                FakeItem.getTableSchema(),
                                                                PRIMARY_CONTEXT,
                                                                mockDynamoDbEnhancedClientExtension);

    assertThat(resultItem, is(fakeItem));
    verify(mockDynamoDbEnhancedClientExtension).afterRead(DefaultDynamoDbExtensionContext.builder()
                                                                                         .tableMetadata(FakeItem.getTableMetadata())
                                                                                         .operationContext(PRIMARY_CONTEXT)
                                                                                         .items(baseFakeItemMap).build());
}
 
Example #9
Source File: DeleteItemOperation.java    From aws-sdk-java-v2 with Apache License 2.0 4 votes vote down vote up
@Override
public Function<DeleteItemRequest, DeleteItemResponse> serviceCall(DynamoDbClient dynamoDbClient) {
    return dynamoDbClient::deleteItem;
}
 
Example #10
Source File: DeleteItemOperation.java    From aws-sdk-java-v2 with Apache License 2.0 4 votes vote down vote up
@Override
public Function<DeleteItemRequest, CompletableFuture<DeleteItemResponse>> asyncServiceCall(
    DynamoDbAsyncClient dynamoDbAsyncClient) {

    return dynamoDbAsyncClient::deleteItem;
}
 
Example #11
Source File: V2TestDynamoDbDeleteItemClient.java    From aws-sdk-java-v2 with Apache License 2.0 4 votes vote down vote up
@Override
public DeleteItemResponse deleteItem(DeleteItemRequest deleteItemRequest) {
    bh.consume(deleteItemRequest);
    return DELETE_ITEM_RESPONSE;
}