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

The following examples show how to use software.amazon.awssdk.services.dynamodb.model.GetItemResponse. 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: AWSDynamoDAO.java    From para with Apache License 2.0 6 votes vote down vote up
private Map<String, AttributeValue> readRow(String key, String appid) {
	if (StringUtils.isBlank(key) || StringUtils.isBlank(appid)) {
		return null;
	}
	Map<String, AttributeValue> row = null;
	String table = getTableNameForAppid(appid);
	try {
		GetItemResponse res = client().getItem(b -> b.tableName(table).key(rowKey(key, appid)));
		if (res != null && res.item() != null && !res.item().isEmpty()) {
			row = res.item();
		}
	} catch (Exception e) {
		logger.error("Could not read row from DB - table={}, appid={}, key={}:", table, appid, key, e);
	}
	return (row == null || row.isEmpty()) ? null : row;
}
 
Example #2
Source File: ApplicationsServiceTest.java    From realworld-serverless-application with Apache License 2.0 6 votes vote down vote up
@Test
public void getApplication() {
  String userId = UUID.randomUUID().toString();
  String applicationId = UUID.randomUUID().toString();
  Map<String, AttributeValue> recordMap = keyMap(userId, applicationId);
  GetItemResponse response = GetItemResponse.builder()
        .item(recordMap)
        .build();
  when(principal.getName()).thenReturn(userId);
  when(dynamodb.getItem(any(GetItemRequest.class))).thenReturn(response);

  GetItemRequest expectedGetItemRequest = GetItemRequest.builder()
        .tableName(TABLE_NAME)
        .consistentRead(Boolean.TRUE)
        .key(recordMap)
        .build();

  Application application = service.getApplication(applicationId);
  ArgumentCaptor<GetItemRequest> getItemRequestArgumentCaptor = ArgumentCaptor.forClass(GetItemRequest.class);
  verify(dynamodb).getItem(getItemRequestArgumentCaptor.capture());

  assertThat(application.getApplicationId()).isEqualTo(applicationId);
  assertThat(getItemRequestArgumentCaptor.getValue()).isEqualTo(expectedGetItemRequest);
}
 
Example #3
Source File: GetItemOperationTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 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);
    GetItemOperation<FakeItem> getItemOperation =
        GetItemOperation.create(GetItemEnhancedRequest.builder().key(k -> k.partitionValue(baseFakeItem.getId())).build());
    GetItemResponse response = GetItemResponse.builder()
                                              .item(baseFakeItemMap)
                                              .build();
    when(mockDynamoDbEnhancedClientExtension.afterRead(any(DynamoDbExtensionContext.AfterRead.class)))
        .thenReturn(ReadModification.builder().transformedItem(fakeItemMap).build());

    FakeItem resultItem = getItemOperation.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 #4
Source File: GetItemOperationTest.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();
    GetItemOperation<FakeItem> getItemOperation =
        GetItemOperation.create(GetItemEnhancedRequest.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());
    GetItemResponse response = GetItemResponse.builder()
                                              .item(responseMap)
                                              .build();

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

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

  GetItemRequest getItemRequest =
      GetItemRequest.builder()
          .key(primaryKey)
          .tableName(tableName)
          .attributesToGet(Collections.singletonList(DynamoDBUtils.Attribute.JOB_SPEC.columnName))
          .build();

  CompletableFuture<GetItemResponse> ret = new CompletableFuture<>();
  Exception exception = new Exception();
  ret.completeExceptionally(exception);
  when(ddbClient.getItem(getItemRequest)).thenReturn(ret);

  CompletableFuture<Schedule> response = scheduleManager.getJob(token);
  assertSame(getException(response), exception);

  verify(ddbClient, times(1)).getItem(getItemRequest);
  verifyNoMoreInteractions(ddbClient);
}
 
Example #6
Source File: DynamodbResource.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@GET
@Path("blocking")
@Produces(TEXT_PLAIN)
public String testBlockingDynamo() {
    LOG.info("Testing Blocking Dynamodb client with table: " + BLOCKING_TABLE);

    String keyValue = UUID.randomUUID().toString();
    String rangeValue = UUID.randomUUID().toString();
    GetItemResponse item = null;

    if (DynamoDBUtils.createTableIfNotExists(dynamoClient, BLOCKING_TABLE)) {
        if (dynamoClient.putItem(DynamoDBUtils.createPutRequest(BLOCKING_TABLE, keyValue, rangeValue, "OK")) != null) {
            item = dynamoClient.getItem(DynamoDBUtils.createGetRequest(BLOCKING_TABLE, keyValue, rangeValue));
        }
    }

    if (item != null) {
        return item.item().get(DynamoDBUtils.PAYLOAD_NAME).s();
    } else {
        return "ERROR";
    }
}
 
Example #7
Source File: EmptyStringTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void getEmptyString() {
    Map<String, AttributeValue> itemMap = new HashMap<>();
    itemMap.put("id", AttributeValue.builder().s("id123").build());
    itemMap.put("s", EMPTY_STRING);

    GetItemResponse response = GetItemResponse.builder()
                                              .item(itemMap)
                                              .build();

    when(mockDynamoDbClient.getItem(any(GetItemRequest.class))).thenReturn(response);

    TestBean result = dynamoDbTable.getItem(r -> r.key(k -> k.partitionValue("id123")));

    assertThat(result.getId()).isEqualTo("id123");
    assertThat(result.getS()).isEmpty();
}
 
Example #8
Source File: EmptyBinaryTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void getEmptyBytes() {
    Map<String, AttributeValue> itemMap = new HashMap<>();
    itemMap.put("id", AttributeValue.builder().s("id123").build());
    itemMap.put("b", EMPTY_BINARY);

    GetItemResponse response = GetItemResponse.builder()
                                              .item(itemMap)
                                              .build();

    when(mockDynamoDbClient.getItem(any(GetItemRequest.class))).thenReturn(response);

    TestBean result = dynamoDbTable.getItem(r -> r.key(k -> k.partitionValue("id123")));

    assertThat(result.getId()).isEqualTo("id123");
    assertThat(result.getB()).isEqualTo(EMPTY_BYTES);
}
 
Example #9
Source File: ApplicationsServiceTest.java    From realworld-serverless-application with Apache License 2.0 5 votes vote down vote up
@Test
public void getApplication_empty_notFound() {
  String userId = UUID.randomUUID().toString();
  String applicationId = UUID.randomUUID().toString();
  GetItemResponse response = GetItemResponse.builder().item(new HashMap<>()).build();
  when(principal.getName()).thenReturn(userId);
  when(dynamodb.getItem(any(GetItemRequest.class))).thenReturn(response);

  assertThatThrownBy(() -> service.getApplication(applicationId))
        .isInstanceOf(NotFoundApiException.class);
}
 
Example #10
Source File: DynamoDBLockProviderIntegrationTest.java    From ShedLock with Apache License 2.0 5 votes vote down vote up
private Map<String, AttributeValue> getLockItem(String lockName) {
    GetItemRequest request = GetItemRequest.builder()
        .tableName(TABLE_NAME)
        .key(Collections.singletonMap(ID, AttributeValue.builder()
            .s(lockName)
            .build()))
        .build();
    GetItemResponse response = dynamodb.getItem(request);
    return response.item();
}
 
Example #11
Source File: V2DynamoDbAttributeValue.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
private static HttpResponseHandler<GetItemResponse> getItemResponseJsonResponseHandler() {
    return JSON_PROTOCOL_FACTORY.createResponseHandler(JsonOperationMetadata.builder()
                                                                            .isPayloadJson(true)
                                                                            .hasStreamingSuccessResponse(false)
                                                                            .build(),
                                                       GetItemResponse::builder);
}
 
Example #12
Source File: EnhancedClientGetV1MapperComparisonBenchmark.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
TestItem(TableSchema<?> schema,
                 GetItemResponse v2Response,

                 Object v1Key,
                 GetItemResult v1Response) {
    this.schema = schema;
    this.v2Response = v2Response;

    this.v1Key = v1Key;
    this.v1Response = v1Response;
}
 
Example #13
Source File: GetItemOperationTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void transformResponse_noItem() {
    FakeItem keyItem = createUniqueFakeItem();
    GetItemOperation<FakeItem> getItemOperation =
        GetItemOperation.create(GetItemEnhancedRequest.builder().key(k -> k.partitionValue(keyItem.getId())).build());
    GetItemResponse response = GetItemResponse.builder().build();

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

    assertThat(result, is(nullValue()));
}
 
Example #14
Source File: GetItemOperationTest.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();
    GetItemOperation<FakeItem> getItemOperation =
        GetItemOperation.create(GetItemEnhancedRequest.builder().key(k -> k.partitionValue(keyItem.getId())).build());
    GetItemRequest getItemRequest = GetItemRequest.builder().tableName(TABLE_NAME).build();
    GetItemResponse expectedResponse = GetItemResponse.builder().build();
    when(mockDynamoDbClient.getItem(any(GetItemRequest.class))).thenReturn(expectedResponse);

    GetItemResponse response = getItemOperation.serviceCall(mockDynamoDbClient).apply(getItemRequest);

    assertThat(response, sameInstance(expectedResponse));
    verify(mockDynamoDbClient).getItem(getItemRequest);
}
 
Example #15
Source File: GetItemOperation.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Override
public T transformResponse(GetItemResponse response,
                           TableSchema<T> tableSchema,
                           OperationContext context,
                           DynamoDbEnhancedClientExtension extension) {
    return EnhancedClientUtils.readAndTransformSingleItem(response.item(), tableSchema, context, extension);
}
 
Example #16
Source File: ApplicationsServiceTest.java    From realworld-serverless-application with Apache License 2.0 5 votes vote down vote up
@Test
public void updateApplication_homePageUrl() {
  String userId = UUID.randomUUID().toString();
  String applicationId = UUID.randomUUID().toString();
  String homePageUrl = 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();
  Map<String, AttributeValue> updateMap = new HashMap<>();
  updateMap.put(":nv", AttributeValue.builder().n("2").build());
  updateMap.put(":v", AttributeValue.builder().n("1").build());
  updateMap.put(":h", AttributeValue.builder().s(homePageUrl).build());

  when(principal.getName()).thenReturn(userId);
  when(dynamodb.getItem(any(GetItemRequest.class))).thenReturn(response);

  UpdateApplicationInput input = new UpdateApplicationInput().homePageUrl(homePageUrl);
  UpdateItemRequest expectedUpdateItemRequest = UpdateItemRequest.builder()
        .tableName(TABLE_NAME)
        .key(keyMap(userId, applicationId))
        .updateExpression("SET homePageUrl = :h,version = :nv")
        .expressionAttributeValues(updateMap)
        .conditionExpression("version = :v")
        .build();

  Application application = service.updateApplication(input, applicationId);
  ArgumentCaptor<UpdateItemRequest> updateItemRequestArgumentCaptor = ArgumentCaptor.forClass(UpdateItemRequest.class);
  verify(dynamodb).updateItem(updateItemRequestArgumentCaptor.capture());

  UpdateItemRequest updateItemRequest = updateItemRequestArgumentCaptor.getValue();
  assertThat(updateItemRequest).isEqualTo(expectedUpdateItemRequest);
  assertThat(application.getApplicationId()).isEqualTo(applicationId);
  assertThat(application.getHomePageUrl()).isEqualTo(homePageUrl);
}
 
Example #17
Source File: ApplicationsServiceTest.java    From realworld-serverless-application with Apache License 2.0 5 votes vote down vote up
@Test
public void getApplication_null_notFound() {
  String userId = UUID.randomUUID().toString();
  String applicationId = UUID.randomUUID().toString();
  GetItemResponse response = GetItemResponse.builder().build();
  when(principal.getName()).thenReturn(userId);
  when(dynamodb.getItem(any(GetItemRequest.class))).thenReturn(response);

  assertThatThrownBy(() -> service.getApplication(applicationId))
        .isInstanceOf(NotFoundApiException.class);
}
 
Example #18
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 #19
Source File: ApplicationsServiceTest.java    From realworld-serverless-application with Apache License 2.0 5 votes vote down vote up
@Test
public void updateApplication_author() {
  String userId = UUID.randomUUID().toString();
  String applicationId = UUID.randomUUID().toString();
  String author = 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();
  Map<String, AttributeValue> updateMap = new HashMap<>();
  updateMap.put(":nv", AttributeValue.builder().n("2").build());
  updateMap.put(":v", AttributeValue.builder().n("1").build());
  updateMap.put(":a", AttributeValue.builder().s(author).build());

  when(principal.getName()).thenReturn(userId);
  when(dynamodb.getItem(any(GetItemRequest.class))).thenReturn(response);

  UpdateApplicationInput input = new UpdateApplicationInput().author(author);
  UpdateItemRequest expectedUpdateItemRequest = UpdateItemRequest.builder()
        .tableName(TABLE_NAME)
        .key(keyMap(userId, applicationId))
        .updateExpression("SET author = :a,version = :nv")
        .expressionAttributeValues(updateMap)
        .conditionExpression("version = :v")
        .build();

  Application application = service.updateApplication(input, applicationId);
  ArgumentCaptor<UpdateItemRequest> updateItemRequestArgumentCaptor = ArgumentCaptor.forClass(UpdateItemRequest.class);
  verify(dynamodb).updateItem(updateItemRequestArgumentCaptor.capture());

  UpdateItemRequest updateItemRequest = updateItemRequestArgumentCaptor.getValue();
  assertThat(updateItemRequest).isEqualTo(expectedUpdateItemRequest);
  assertThat(application.getApplicationId()).isEqualTo(applicationId);
  assertThat(application.getAuthor()).isEqualTo(author);
}
 
Example #20
Source File: ApplicationsServiceTest.java    From realworld-serverless-application with Apache License 2.0 5 votes vote down vote up
@Test
public void updateApplication_description() {
  String userId = UUID.randomUUID().toString();
  String applicationId = UUID.randomUUID().toString();
  String description = 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();
  Map<String, AttributeValue> updateMap = new HashMap<>();
  updateMap.put(":nv", AttributeValue.builder().n("2").build());
  updateMap.put(":v", AttributeValue.builder().n("1").build());
  updateMap.put(":d", AttributeValue.builder().s(description).build());

  when(principal.getName()).thenReturn(userId);
  when(dynamodb.getItem(any(GetItemRequest.class))).thenReturn(response);

  UpdateApplicationInput input = new UpdateApplicationInput().description(description);
  UpdateItemRequest expectedUpdateItemRequest = UpdateItemRequest.builder()
        .tableName(TABLE_NAME)
        .key(keyMap(userId, applicationId))
        .updateExpression("SET description = :d,version = :nv")
        .expressionAttributeValues(updateMap)
        .conditionExpression("version = :v")
        .build();

  Application application = service.updateApplication(input, applicationId);
  ArgumentCaptor<UpdateItemRequest> updateItemRequestArgumentCaptor = ArgumentCaptor.forClass(UpdateItemRequest.class);
  verify(dynamodb).updateItem(updateItemRequestArgumentCaptor.capture());

  UpdateItemRequest updateItemRequest = updateItemRequestArgumentCaptor.getValue();
  assertThat(updateItemRequest).isEqualTo(expectedUpdateItemRequest);
  assertThat(application.getApplicationId()).isEqualTo(applicationId);
  assertThat(application.getDescription()).isEqualTo(description);
}
 
Example #21
Source File: EmptyAttributeTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void asyncClient_getItem_emptyBinary() {
    stubFor(any(urlEqualTo("/"))
                .willReturn(aResponse().withStatus(200).withBody("{\"Item\": {\"attribute\": {\"B\": \"\"}}}")));

    GetItemResponse response = dynamoDbAsyncClient.getItem(r -> r.tableName("test")).join();
    assertThat(response.item()).containsKey("attribute");
    AttributeValue attributeValue = response.item().get("attribute");
    assertThat(attributeValue.b().asByteArray()).isEmpty();
}
 
Example #22
Source File: DynamoDBTest.java    From dynein with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetJob() throws Exception {
  DyneinJobSpec jobSpec = getTestJobSpec(validToken, "test1");
  Schedule schedule = jobSpecToSchedule(jobSpec);

  JobTokenPayload tokenPayload = tokenManager.decodeToken(validToken);
  Map<String, AttributeValue> primaryKey =
      DynamoDBUtils.getPrimaryKeyFromToken(validToken, tokenPayload, maxShardId);

  GetItemRequest getItemRequest =
      GetItemRequest.builder()
          .key(primaryKey)
          .tableName(tableName)
          .attributesToGet(Collections.singletonList(DynamoDBUtils.Attribute.JOB_SPEC.columnName))
          .build();

  when(ddbClient.getItem(getItemRequest))
      .thenReturn(
          CompletableFuture.completedFuture(
              GetItemResponse.builder()
                  .item(
                      ImmutableMap.of(
                          DynamoDBUtils.Attribute.JOB_SPEC.columnName,
                          AttributeValue.builder().s(schedule.getJobSpec()).build()))
                  .build()));

  CompletableFuture<Schedule> response = scheduleManager.getJob(validToken);

  Assert.assertEquals(response.get(1000, TimeUnit.MILLISECONDS), schedule);

  verify(ddbClient, times(1)).getItem(getItemRequest);
  verifyNoMoreInteractions(ddbClient);
}
 
Example #23
Source File: ArmeriaSdkHttpClientIntegrationTest.java    From curiostack with MIT License 5 votes vote down vote up
@Test
void normal() {
  server.enqueue(HttpResponse.of(HttpStatus.OK));

  GetItemResponse response =
      dynamoDbAsync
          .getItem(GetItemRequest.builder().tableName("test").key(ImmutableMap.of()).build())
          .join();
  assertThat(response.sdkHttpResponse().isSuccessful()).isTrue();

  AggregatedHttpRequest request = server.takeRequest().request();
  assertThat(request.headers().get(HttpHeaderNames.USER_AGENT)).contains("http/ArmeriaAsync");
}
 
Example #24
Source File: EmptyAttributeTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void syncClient_getItem_emptyString() {
    stubFor(any(urlEqualTo("/"))
            .willReturn(aResponse().withStatus(200).withBody("{\"Item\": {\"attribute\": {\"S\": \"\"}}}")));

    GetItemResponse response = dynamoDbClient.getItem(r -> r.tableName("test"));
    assertThat(response.item()).containsKey("attribute");
    AttributeValue attributeValue = response.item().get("attribute");
    assertThat(attributeValue.s()).isEmpty();
}
 
Example #25
Source File: EmptyAttributeTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void asyncClient_getItem_emptyString() {
    stubFor(any(urlEqualTo("/"))
                .willReturn(aResponse().withStatus(200).withBody("{\"Item\": {\"attribute\": {\"S\": \"\"}}}")));

    GetItemResponse response = dynamoDbAsyncClient.getItem(r -> r.tableName("test")).join();
    assertThat(response.item()).containsKey("attribute");
    AttributeValue attributeValue = response.item().get("attribute");
    assertThat(attributeValue.s()).isEmpty();
}
 
Example #26
Source File: EmptyAttributeTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void syncClient_getItem_emptyBinary() {
    stubFor(any(urlEqualTo("/"))
                .willReturn(aResponse().withStatus(200).withBody("{\"Item\": {\"attribute\": {\"B\": \"\"}}}")));

    GetItemResponse response = dynamoDbClient.getItem(r -> r.tableName("test"));
    assertThat(response.item()).containsKey("attribute");
    AttributeValue attributeValue = response.item().get("attribute");
    assertThat(attributeValue.b().asByteArray()).isEmpty();
}
 
Example #27
Source File: V2TestDynamoDbGetItemClient.java    From aws-sdk-java-v2 with Apache License 2.0 4 votes vote down vote up
public V2TestDynamoDbGetItemClient(Blackhole bh, GetItemResponse getItemResponse) {
    super(bh);
    this.getItemResponse = getItemResponse;
}
 
Example #28
Source File: V2TestDynamoDbGetItemClient.java    From aws-sdk-java-v2 with Apache License 2.0 4 votes vote down vote up
@Override
public GetItemResponse getItem(GetItemRequest getItemRequest) {
    bh.consume(getItemRequest);
    return getItemResponse;
}
 
Example #29
Source File: EnhancedClientGetV1MapperComparisonBenchmark.java    From aws-sdk-java-v2 with Apache License 2.0 4 votes vote down vote up
private static DynamoDbClient getV2Client(Blackhole bh, GetItemResponse getItemResponse) {
    return new V2TestDynamoDbGetItemClient(bh, getItemResponse);
}
 
Example #30
Source File: GetItemOperation.java    From aws-sdk-java-v2 with Apache License 2.0 4 votes vote down vote up
@Override
public Function<GetItemRequest, CompletableFuture<GetItemResponse>> asyncServiceCall(
    DynamoDbAsyncClient dynamoDbAsyncClient) {

    return dynamoDbAsyncClient::getItem;
}