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

The following examples show how to use software.amazon.awssdk.services.dynamodb.model.DeleteItemRequest. 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: DeleteItemOperation.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Override
public DeleteItemRequest generateRequest(TableSchema<T> tableSchema,
                                         OperationContext operationContext,
                                         DynamoDbEnhancedClientExtension extension) {

    if (!TableMetadata.primaryIndexName().equals(operationContext.indexName())) {
        throw new IllegalArgumentException("DeleteItem cannot be executed against a secondary index.");
    }

    DeleteItemRequest.Builder requestBuilder =
        DeleteItemRequest.builder()
                         .tableName(operationContext.tableName())
                         .key(this.request.key().keyMap(tableSchema, operationContext.indexName()))
                         .returnValues(ReturnValue.ALL_OLD);

    requestBuilder = addExpressionsIfExist(requestBuilder);

    return requestBuilder.build();
}
 
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 generateRequest_partitionAndSortKey() {
    FakeItemWithSort keyItem = createUniqueFakeItemWithSort();
    DeleteItemOperation<FakeItemWithSort> deleteItemOperation = DeleteItemOperation.create(
        DeleteItemEnhancedRequest.builder()
                                 .key(k -> k.partitionValue(keyItem.getId()).sortValue(keyItem.getSort()))
                                 .build());

    DeleteItemRequest request = deleteItemOperation.generateRequest(FakeItemWithSort.getTableSchema(),
                                                                   PRIMARY_CONTEXT,
                                                                    null);

    Map<String, AttributeValue> expectedKeyMap = new HashMap<>();
    expectedKeyMap.put("id", AttributeValue.builder().s(keyItem.getId()).build());
    expectedKeyMap.put("sort", AttributeValue.builder().s(keyItem.getSort()).build());
    DeleteItemRequest expectedRequest = DeleteItemRequest.builder()
                                                   .tableName(TABLE_NAME)
                                                   .key(expectedKeyMap)
                                                   .returnValues(ReturnValue.ALL_OLD)
                                                   .build();
    assertThat(request, is(expectedRequest));
}
 
Example #3
Source File: DeleteItemOperationTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void generateRequest_partitionKeyOnly() {
    FakeItem keyItem = createUniqueFakeItem();
    DeleteItemOperation<FakeItem> deleteItemOperation =
        DeleteItemOperation.create(DeleteItemEnhancedRequest.builder().key(k -> k.partitionValue(keyItem.getId())).build());

    DeleteItemRequest request = deleteItemOperation.generateRequest(FakeItem.getTableSchema(),
                                                                    PRIMARY_CONTEXT,
                                                                    null);

    Map<String, AttributeValue> expectedKeyMap = new HashMap<>();
    expectedKeyMap.put("id", AttributeValue.builder().s(keyItem.getId()).build());
    DeleteItemRequest expectedRequest = DeleteItemRequest.builder()
        .tableName(TABLE_NAME)
        .key(expectedKeyMap)
        .returnValues(ReturnValue.ALL_OLD)
        .build();
    assertThat(request, is(expectedRequest));
}
 
Example #4
Source File: DeleteItemOperationTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void generateRequest_withConditionExpression() {
    FakeItem keyItem = createUniqueFakeItem();
    DeleteItemOperation<FakeItem> deleteItemOperation =
        DeleteItemOperation.create(DeleteItemEnhancedRequest.builder()
                                                            .key(k -> k.partitionValue(keyItem.getId()))
                                                            .conditionExpression(CONDITION_EXPRESSION)
                                                            .build());

    DeleteItemRequest request = deleteItemOperation.generateRequest(FakeItem.getTableSchema(),
                                                                    PRIMARY_CONTEXT,
                                                                    null);

    assertThat(request.conditionExpression(), is(CONDITION_EXPRESSION.expression()));
    assertThat(request.expressionAttributeNames(), is(CONDITION_EXPRESSION.expressionNames()));
    assertThat(request.expressionAttributeValues(), is(CONDITION_EXPRESSION.expressionValues()));
}
 
Example #5
Source File: DeleteItemOperation.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
private DeleteItemRequest.Builder addExpressionsIfExist(DeleteItemRequest.Builder requestBuilder) {
    if (this.request.conditionExpression() != null) {
        requestBuilder = requestBuilder.conditionExpression(this.request.conditionExpression().expression());
        Map<String, String> expressionNames = this.request.conditionExpression().expressionNames();
        Map<String, AttributeValue> expressionValues = this.request.conditionExpression().expressionValues();

        // Avoiding adding empty collections that the low level SDK will propagate to DynamoDb where it causes error.
        if (expressionNames != null && !expressionNames.isEmpty()) {
            requestBuilder = requestBuilder.expressionAttributeNames(expressionNames);
        }

        if (expressionValues != null && !expressionValues.isEmpty()) {
            requestBuilder = requestBuilder.expressionAttributeValues(expressionValues);
        }
    }
    return requestBuilder;
}
 
Example #6
Source File: DeleteItemOperation.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Override
public TransactWriteItem generateTransactWriteItem(TableSchema<T> tableSchema,
                                                   OperationContext operationContext,
                                                   DynamoDbEnhancedClientExtension dynamoDbEnhancedClientExtension) {
    DeleteItemRequest deleteItemRequest = generateRequest(tableSchema, operationContext, dynamoDbEnhancedClientExtension);

    Delete delete = Delete.builder()
                          .key(deleteItemRequest.key())
                          .tableName(deleteItemRequest.tableName())
                          .conditionExpression(deleteItemRequest.conditionExpression())
                          .expressionAttributeValues(deleteItemRequest.expressionAttributeValues())
                          .expressionAttributeNames(deleteItemRequest.expressionAttributeNames())
                          .build();

    return TransactWriteItem.builder()
                            .delete(delete)
                            .build();
}
 
Example #7
Source File: DeleteItemOperationTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void generateRequest_withMinimalConditionExpression() {
    FakeItem keyItem = createUniqueFakeItem();
    DeleteItemOperation<FakeItem> deleteItemOperation =
        DeleteItemOperation.create(DeleteItemEnhancedRequest.builder()
                                                            .key(k -> k.partitionValue(keyItem.getId()))
                                                            .conditionExpression(MINIMAL_CONDITION_EXPRESSION)
                                                            .build());

    DeleteItemRequest request = deleteItemOperation.generateRequest(FakeItem.getTableSchema(),
                                                                    PRIMARY_CONTEXT,
                                                                    null);

    assertThat(request.conditionExpression(), is(MINIMAL_CONDITION_EXPRESSION.expression()));
    assertThat(request.expressionAttributeNames(), is(emptyMap()));
    assertThat(request.expressionAttributeValues(), is(emptyMap()));
}
 
Example #8
Source File: DeleteItemOperationTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void generateRequest_withExtension_doesNotModifyKey() {
    FakeItem baseFakeItem = createUniqueFakeItem();
    Map<String, AttributeValue> keyMap = FakeItem.getTableSchema().itemToMap(baseFakeItem, singletonList("id"));
    DeleteItemOperation<FakeItem> deleteItemOperation =
        DeleteItemOperation.create(DeleteItemEnhancedRequest.builder()
                                                            .key(k -> k.partitionValue(baseFakeItem.getId()))
                                                            .build());


    DeleteItemRequest request = deleteItemOperation.generateRequest(FakeItem.getTableSchema(),
                                                                    PRIMARY_CONTEXT,
                                                                    mockDynamoDbEnhancedClientExtension);

    assertThat(request.key(), is(keyMap));
    verify(mockDynamoDbEnhancedClientExtension, never()).beforeWrite(any(DynamoDbExtensionContext.BeforeWrite.class));
}
 
Example #9
Source File: DynamoDBTest.java    From dynein with Apache License 2.0 6 votes vote down vote up
private DeleteItemRequest getDeleteItemRequest(Schedule schedule) {
  Map<String, AttributeValue> primaryKey = DynamoDBUtils.getPrimaryKey(schedule);
  Map<String, String> attributeNames = new HashMap<>();
  Map<String, AttributeValue> attributeValues = new HashMap<>();
  attributeNames.put("#jobStatus", DynamoDBUtils.Attribute.JOB_STATUS.columnName);
  attributeValues.put(
      ":acquired", AttributeValue.builder().s(Schedule.JobStatus.ACQUIRED.toString()).build());

  return DeleteItemRequest.builder()
      .tableName(tableName)
      .conditionExpression("#jobStatus = :acquired")
      .key(primaryKey)
      .expressionAttributeNames(attributeNames)
      .expressionAttributeValues(attributeValues)
      .build();
}
 
Example #10
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 #11
Source File: DeleteItem.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
public static void deleteDymamoDBItem(DynamoDbClient ddb, String tableName, String key, String keyVal) {

        HashMap<String,AttributeValue> keyToGet =
                new HashMap<String,AttributeValue>();

        keyToGet.put(key, AttributeValue.builder()
                .s(keyVal)
                .build());

        DeleteItemRequest deleteReq = DeleteItemRequest.builder()
                .tableName(tableName)
                .key(keyToGet)
                .build();

        try {
            ddb.deleteItem(deleteReq);
        } catch (DynamoDbException e) {
            System.err.println(e.getMessage());
            System.exit(1);
        }

        // snippet-end:[dynamodb.java2.delete_item.main]
    }
 
Example #12
Source File: DynamoDBLeaseRefresherTest.java    From amazon-kinesis-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteLeaseTimesOut() throws Exception {
    TimeoutException te = setRuleForDependencyTimeout();
    when(leaseSerializer.getDynamoHashKey(any(Lease.class))).thenReturn(Collections.emptyMap());

    when(dynamoDbClient.deleteItem(any(DeleteItemRequest.class))).thenReturn(mockDeleteFuture);
    when(mockDeleteFuture.get(anyLong(), any())).thenThrow(te);

    verifyCancel(mockDeleteFuture, () -> leaseRefresher.deleteLease(lease));
}
 
Example #13
Source File: DeleteItemOperationTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void generateTransactWriteItem_basicRequest() {
    FakeItem fakeItem = createUniqueFakeItem();
    Map<String, AttributeValue> fakeItemMap = FakeItem.getTableSchema().itemToMap(fakeItem, true);
    DeleteItemOperation<FakeItem> deleteItemOperation =
        spy(DeleteItemOperation.create(DeleteItemEnhancedRequest.builder()
                                                                .key(k -> k.partitionValue(fakeItem.getId()))
                                                                .build()));
    OperationContext context = DefaultOperationContext.create(TABLE_NAME, TableMetadata.primaryIndexName());

    DeleteItemRequest deleteItemRequest = DeleteItemRequest.builder()
                                                           .tableName(TABLE_NAME)
                                                           .key(fakeItemMap)
                                                           .build();
    doReturn(deleteItemRequest).when(deleteItemOperation).generateRequest(any(), any(), any());

    TransactWriteItem actualResult = deleteItemOperation.generateTransactWriteItem(FakeItem.getTableSchema(),
                                                                                   context,
                                                                                   mockDynamoDbEnhancedClientExtension);

    TransactWriteItem expectedResult = TransactWriteItem.builder()
                                                        .delete(Delete.builder()
                                                                      .key(fakeItemMap)
                                                                      .tableName(TABLE_NAME)
                                                                      .build())
                                                        .build();
    assertThat(actualResult, is(expectedResult));
    verify(deleteItemOperation).generateRequest(FakeItem.getTableSchema(), context, mockDynamoDbEnhancedClientExtension);
}
 
Example #14
Source File: DeleteItemOperationTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void generateTransactWriteItem_conditionalRequest() {
    FakeItem fakeItem = createUniqueFakeItem();
    Map<String, AttributeValue> fakeItemMap = FakeItem.getTableSchema().itemToMap(fakeItem, true);
    DeleteItemOperation<FakeItem> deleteItemOperation =
        spy(DeleteItemOperation.create(DeleteItemEnhancedRequest.builder()
                                                                .key(k -> k.partitionValue(fakeItem.getId()))
                                                                .build()));
    OperationContext context = DefaultOperationContext.create(TABLE_NAME, TableMetadata.primaryIndexName());

    String conditionExpression = "condition-expression";
    Map<String, AttributeValue> attributeValues = Collections.singletonMap("key", stringValue("value1"));
    Map<String, String> attributeNames = Collections.singletonMap("key", "value2");

    DeleteItemRequest deleteItemRequest = DeleteItemRequest.builder()
                                                           .tableName(TABLE_NAME)
                                                           .key(fakeItemMap)
                                                           .conditionExpression(conditionExpression)
                                                           .expressionAttributeValues(attributeValues)
                                                           .expressionAttributeNames(attributeNames)
                                                           .build();
    doReturn(deleteItemRequest).when(deleteItemOperation).generateRequest(any(), any(), any());

    TransactWriteItem actualResult = deleteItemOperation.generateTransactWriteItem(FakeItem.getTableSchema(),
                                                                                   context,
                                                                                   mockDynamoDbEnhancedClientExtension);

    TransactWriteItem expectedResult = TransactWriteItem.builder()
                                                        .delete(Delete.builder()
                                                                      .key(fakeItemMap)
                                                                      .tableName(TABLE_NAME)
                                                                      .conditionExpression(conditionExpression)
                                                                      .expressionAttributeNames(attributeNames)
                                                                      .expressionAttributeValues(attributeValues)
                                                                      .build())
                                                        .build();
    assertThat(actualResult, is(expectedResult));
    verify(deleteItemOperation).generateRequest(FakeItem.getTableSchema(), context, mockDynamoDbEnhancedClientExtension);
}
 
Example #15
Source File: DynamoDBLockProviderIntegrationTest.java    From ShedLock with Apache License 2.0 5 votes vote down vote up
@AfterEach
public void truncateLockTable() {
    List<Map<String, AttributeValue>> items = dynamodb.scan(ScanRequest.builder().tableName(TABLE_NAME).build()).items();
    for (Map<String, AttributeValue> item : items) {
        dynamodb.deleteItem(DeleteItemRequest.builder()
            .tableName(TABLE_NAME)
            .key(Collections.singletonMap(ID, item.get(ID)))
            .build());
    }
}
 
Example #16
Source File: DynamoDBLeaseRefresherTest.java    From amazon-kinesis-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteAllLeasesTimesOut() throws Exception {
    TimeoutException te = setRuleForDependencyTimeout();
    when(dynamoDbClient.scan(any(ScanRequest.class))).thenReturn(mockScanFuture);
    when(mockScanFuture.get(anyLong(), any())).thenReturn(ScanResponse.builder().items(Collections.emptyMap()).build());
    when(leaseSerializer.fromDynamoRecord(any())).thenReturn(lease);
    when(leaseSerializer.getDynamoHashKey(any(Lease.class))).thenReturn(Collections.emptyMap());

    when(dynamoDbClient.deleteItem(any(DeleteItemRequest.class))).thenReturn(mockDeleteFuture);
    when(mockDeleteFuture.get(anyLong(), any())).thenThrow(te);

    verifyCancel(mockDeleteFuture, () -> leaseRefresher.deleteAll());
}
 
Example #17
Source File: ApplicationsService.java    From realworld-serverless-application with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteApplication(final String applicationId) {
  log.info("Deleting application {}", applicationId);
  ApplicationRecord applicationRecord = loadApplication(applicationId);
  Map<String, AttributeValue> expressionAttributeValues = new HashMap<>();
  expressionAttributeValues.put(":v", AttributeValue.builder()
        .n(applicationRecord.getVersion().toString())
        .build());
  dynamodb.deleteItem(DeleteItemRequest.builder()
        .tableName(tableName)
        .key(toKeyRecord(applicationId))
        .conditionExpression(String.format("%s = :v", ApplicationRecord.VERSION_ATTRIBUTE_NAME))
        .expressionAttributeValues(expressionAttributeValues)
        .build());
}
 
Example #18
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 #19
Source File: DeleteItemOperation.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Override
public WriteRequest generateWriteRequest(TableSchema<T> tableSchema,
                                         OperationContext operationContext,
                                         DynamoDbEnhancedClientExtension extension) {
    DeleteItemRequest deleteItemRequest = generateRequest(tableSchema, operationContext, extension);

    return WriteRequest.builder()
                       .deleteRequest(DeleteRequest.builder().key(deleteItemRequest.key()).build())
                       .build();
}
 
Example #20
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 #21
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 #22
Source File: DynamoDBTest.java    From dynein with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteJob() throws Exception {
  String token = getToken(1);
  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();

  when(ddbClient.deleteItem(deleteItemRequest))
      .thenReturn(CompletableFuture.completedFuture(null));

  CompletableFuture<Void> response = scheduleManager.deleteJob(token);
  response.get(1000, TimeUnit.MILLISECONDS);
  verify(ddbClient, times(1)).deleteItem(deleteItemRequest);
  verifyNoMoreInteractions(ddbClient);
}
 
Example #23
Source File: DynamoDBScheduleManager.java    From dynein with Apache License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<Void> deleteDispatchedJob(Schedule schedule) {
  Map<String, AttributeValue> primaryKey = DynamoDBUtils.getPrimaryKey(schedule);
  Map<String, AttributeValue> attributeValues =
      DynamoDBUtils.attributeValuesMap(
          ImmutableMap.of(Value.ACQUIRED_STATUS, Schedule.JobStatus.ACQUIRED.toString()));
  DeleteItemRequest deleteItemRequest =
      DeleteItemRequest.builder()
          .tableName(ddbConfig.getSchedulesTableName())
          .conditionExpression(
              Condition.of(Attribute.JOB_STATUS, "=", Value.ACQUIRED_STATUS).toString())
          .key(primaryKey)
          .expressionAttributeNames(DynamoDBUtils.getJobStatusAttributeMap())
          .expressionAttributeValues(attributeValues)
          .build();

  return ddbClient
      .deleteItem(deleteItemRequest)
      .whenComplete(
          (response, exception) -> {
            DyneinJobSpec jobSpec = jobSpecTransformer.deserializeJobSpec(schedule.getJobSpec());
            if (exception != null) {
              log.error(
                  "Error deleting job {} from table {}",
                  jobSpec.getJobToken(),
                  ddbConfig.getSchedulesTableName(),
                  exception);
              metrics.deleteDispatchedJobError(exception, jobSpec.getQueueName());
            } else {
              log.info(
                  "Deleted job {} from table {}",
                  jobSpec.getJobToken(),
                  ddbConfig.getSchedulesTableName());
              metrics.deleteDispatchedJob(jobSpec.getQueueName());
            }
          })
      .thenApply(response -> null);
}
 
Example #24
Source File: ApplicationsServiceTest.java    From realworld-serverless-application with Apache License 2.0 5 votes vote down vote up
@Test
public void deleteApplication() {
  String userId = UUID.randomUUID().toString();
  String applicationId = UUID.randomUUID().toString();
  Long version = 1L;
  Map<String, AttributeValue> recordMap = keyMap(userId, applicationId);
  recordMap.put("version", AttributeValue.builder().n(version.toString()).build());
  GetItemResponse response = GetItemResponse.builder()
        .item(recordMap)
        .build();
  when(principal.getName()).thenReturn(userId);
  when(dynamodb.getItem(any(GetItemRequest.class))).thenReturn(response);

  Map<String, AttributeValue> expectedAttributeValueMap = new HashMap<>();
  expectedAttributeValueMap.put(":v", AttributeValue.builder().n(version.toString()).build());
  DeleteItemRequest expectedDeleteItemRequest = DeleteItemRequest.builder()
        .tableName(TABLE_NAME)
        .key(keyMap(userId, applicationId))
        .conditionExpression("version = :v")
        .expressionAttributeValues(expectedAttributeValueMap)
        .build();

  service.deleteApplication(applicationId);
  ArgumentCaptor<DeleteItemRequest> deleteItemRequestArgumentCaptor = ArgumentCaptor.forClass(DeleteItemRequest.class);
  verify(dynamodb).deleteItem(deleteItemRequestArgumentCaptor.capture());

  DeleteItemRequest deleteItemRequest = deleteItemRequestArgumentCaptor.getValue();
  assertThat(deleteItemRequest).isEqualTo(expectedDeleteItemRequest);
}
 
Example #25
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 #26
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 #27
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;
}