Java Code Examples for software.amazon.awssdk.utils.ImmutableMap#of()

The following examples show how to use software.amazon.awssdk.utils.ImmutableMap#of() . 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: MessageAttributesIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
/**
 * Makes sure we don't modify the state of ByteBuffer backed attributes in anyway internally
 * before returning the result to the customer. See https://github.com/aws/aws-sdk-java/pull/459
 * for reference
 */
@Test
public void receiveMessage_WithBinaryAttributeValue_DoesNotChangeStateOfByteBuffer() {
    byte[] bytes = new byte[]{1, 1, 1, 0, 0, 0};
    String byteBufferAttrName = "byte-buffer-attr";
    Map<String, MessageAttributeValue> attrs = ImmutableMap.of(byteBufferAttrName,
                                                               MessageAttributeValue.builder().dataType("Binary").binaryValue(SdkBytes.fromByteArray(bytes)).build());

    sqsAsync.sendMessage(SendMessageRequest.builder().queueUrl(queueUrl).messageBody("test")
            .messageAttributes(attrs)
            .build());
    // Long poll to make sure we get the message back
    List<Message> messages = sqsAsync.receiveMessage(
            ReceiveMessageRequest.builder().queueUrl(queueUrl).messageAttributeNames("All").waitTimeSeconds(20).build()).join()
            .messages();

    ByteBuffer actualByteBuffer = messages.get(0).messageAttributes().get(byteBufferAttrName).binaryValue().asByteBuffer();
    assertEquals(bytes.length, actualByteBuffer.remaining());
}
 
Example 2
Source File: RequestOverrideConfigurationTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void settingCollection_shouldOverrideAddItem() {
    ImmutableMap<String, List<String>> map =
        ImmutableMap.of(HEADER, Arrays.asList("hello", "world"));
    ImmutableMap<String, List<String>> queryMap =
        ImmutableMap.of(QUERY_PARAM, Arrays.asList("hello", "world"));
    RequestOverrideConfiguration configuration = SdkRequestOverrideConfiguration.builder()
                                                                                .putHeader(HEADER, "blah")
                                                                                .headers(map)
                                                                                .putRawQueryParameter(QUERY_PARAM, "blah")
                                                                                .rawQueryParameters(queryMap)
                                                                                .build();

    assertThat(configuration.headers().get(HEADER)).containsExactly("hello", "world");
    assertThat(configuration.rawQueryParameters().get(QUERY_PARAM)).containsExactly("hello", "world");
}
 
Example 3
Source File: DynamoJobRepository.java    From edison-microservice with Apache License 2.0 6 votes vote down vote up
@Override
public List<JobInfo> findRunningWithoutUpdateSince(OffsetDateTime timeOffset) {
    Map<String, AttributeValue> lastKeyEvaluated = null;
    List<JobInfo> jobs = new ArrayList<>();
    Map<String, AttributeValue> expressionAttributeValues = ImmutableMap.of(
            ":val", AttributeValue.builder().n(String.valueOf(timeOffset.toInstant().toEpochMilli())).build()
    );
    do {
        final ScanRequest query = ScanRequest.builder()
                .tableName(tableName)
                .limit(pageSize)
                .exclusiveStartKey(lastKeyEvaluated)
                .expressionAttributeValues(expressionAttributeValues)
                .filterExpression(LAST_UPDATED_EPOCH.key() + " < :val and attribute_not_exists(" + STOPPED.key() + ")")
                .build();

        final ScanResponse response = dynamoDbClient.scan(query);
        lastKeyEvaluated = response.lastEvaluatedKey();
        List<JobInfo> newJobsFromThisPage = response.items().stream().map(this::decode).collect(toList());
        jobs.addAll(newJobsFromThisPage);
    } while (lastKeyEvaluated != null && lastKeyEvaluated.size() > 0);
    return jobs;
}
 
Example 4
Source File: DynamoJobRepository.java    From edison-microservice with Apache License 2.0 6 votes vote down vote up
@Override
public List<JobInfo> findByType(String jobType) {
    Map<String, AttributeValue> lastKeyEvaluated = null;
    List<JobInfo> jobs = new ArrayList<>();
    Map<String, AttributeValue> expressionAttributeValues = ImmutableMap.of(
            ":jobType", AttributeValue.builder().s(jobType).build()
    );
    do {
        final ScanRequest query = ScanRequest.builder()
                .tableName(tableName)
                .limit(pageSize)
                .exclusiveStartKey(lastKeyEvaluated)
                .expressionAttributeValues(expressionAttributeValues)
                .filterExpression(JOB_TYPE.key() + " = :jobType")
                .build();

        final ScanResponse response = dynamoDbClient.scan(query);
        lastKeyEvaluated = response.lastEvaluatedKey();
        List<JobInfo> newJobsFromThisPage = response.items().stream().map(this::decode).collect(toList());
        jobs.addAll(newJobsFromThisPage);
    } while (lastKeyEvaluated != null && lastKeyEvaluated.size() > 0);
    return jobs;
}
 
Example 5
Source File: ClientOverrideConfigurationTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void addSameItemAfterSetCollection_shouldOverride() {
    ImmutableMap<String, List<String>> map =
        ImmutableMap.of("value", Arrays.asList("hello", "world"));
    ClientOverrideConfiguration configuration = ClientOverrideConfiguration.builder()
                                                                           .headers(map)
                                                                           .putHeader("value", "blah")
                                                                           .build();

    assertThat(configuration.headers().get("value")).containsExactly("blah");
}
 
Example 6
Source File: RequestOverrideConfigurationTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void addSameItemAfterSetCollection_shouldOverride() {
    ImmutableMap<String, List<String>> map =
        ImmutableMap.of(HEADER, Arrays.asList("hello", "world"));
    RequestOverrideConfiguration configuration = SdkRequestOverrideConfiguration.builder()
                                                                                .headers(map)
                                                                                .putHeader(HEADER, "blah")
                                                                                .build();

    assertThat(configuration.headers().get(HEADER)).containsExactly("blah");
}
 
Example 7
Source File: DynamoJobMetaRepository.java    From edison-microservice with Apache License 2.0 5 votes vote down vote up
private GetItemResponse getItem(String jobType) {
    ImmutableMap<String, AttributeValue> itemRequestKey = ImmutableMap.of(JOB_TYPE_KEY, toAttributeValue(jobType));
    GetItemRequest itemRequest = GetItemRequest.builder()
            .tableName(tableName)
            .key(itemRequestKey)
            .build();
    return dynamoDbClient.getItem(itemRequest);
}