software.amazon.awssdk.utils.ImmutableMap Java Examples
The following examples show how to use
software.amazon.awssdk.utils.ImmutableMap.
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: DynamoJobMetaRepositoryTest.java From edison-microservice with Apache License 2.0 | 6 votes |
@Test public void shouldReturnJobMeta() { //given dynamoJobMetaRepository.setRunningJob("someJobType", "someJobId"); dynamoJobMetaRepository.disable("someJobType", "because"); dynamoJobMetaRepository.setValue("someJobType", "foo", "bar"); //when JobMeta jobMeta = dynamoJobMetaRepository.getJobMeta("someJobType"); //then assertThat(jobMeta.getJobType(), is("someJobType")); assertThat(jobMeta.isDisabled(), is(true)); assertThat(jobMeta.getDisabledComment(), is("because")); assertThat(jobMeta.isRunning(), is(true)); assertThat(jobMeta.getAll(), is(ImmutableMap.of("foo", "bar"))); }
Example #2
Source File: RequestOverrideConfigurationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
@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 |
@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: ClientOverrideConfigurationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
@Test public void settingCollection_shouldOverrideAddItem() { ClientOverrideConfiguration configuration = ClientOverrideConfiguration.builder() .putHeader("value", "foo") .headers(ImmutableMap.of("value", Arrays.asList ("hello", "world"))) .putAdvancedOption(SdkAdvancedClientOption .USER_AGENT_SUFFIX, "test") .advancedOptions(new HashMap<>()) .putAdvancedOption(SdkAdvancedClientOption .USER_AGENT_PREFIX, "test") .addExecutionInterceptor(new SlowExecutionInterceptor()) .executionInterceptors(new ArrayList<>()) .build(); assertThat(configuration.headers().get("value")).containsExactly("hello", "world"); assertFalse(configuration.advancedOption(SdkAdvancedClientOption.USER_AGENT_SUFFIX).isPresent()); assertThat(configuration.advancedOption(SdkAdvancedClientOption.USER_AGENT_PREFIX).get()).isEqualTo("test"); assertTrue(configuration.executionInterceptors().isEmpty()); }
Example #5
Source File: DynamoDBPositionsStorage.java From liiklus with MIT License | 6 votes |
@Override public CompletionStage<Map<Integer, Map<Integer, Long>>> findAllVersionsByGroup(String topic, String groupName) { var request = QueryRequest.builder() .tableName(tableName) .keyConditions(ImmutableMap.of( HASH_KEY_FIELD, condition(EQ, attribute(topic)), RANGE_KEY_FIELD, condition(BEGINS_WITH, attribute(groupName)) )) .build(); return Flux .from(dynamoDB.queryPaginator(request)) .flatMapIterable(QueryResponse::items) .map(item -> new AbstractMap.SimpleEntry<>( GroupId.ofString(item.get("groupId").s()), toPositions(item) )) .filter(it -> groupName.equals(it.getKey().getName())) .collectMap( it -> it.getKey().getVersion().orElse(0), Map.Entry::getValue ) .toFuture(); }
Example #6
Source File: DynamoJobRepository.java From edison-microservice with Apache License 2.0 | 6 votes |
@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 #7
Source File: MessageAttributesIntegrationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
/** * 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 #8
Source File: ServiceMetadataGenerator.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
private CodeBlock signingRegionOverrides(Partitions partitions) { Map<Partition, Service> serviceData = getServiceData(partitions); CodeBlock.Builder builder = CodeBlock.builder().add("$T.<String, String>builder()", ImmutableMap.class); serviceData.entrySet() .forEach(s -> s.getValue().getEndpoints() .entrySet() .stream() .filter(e -> e.getValue().getCredentialScope() != null) .filter(e -> e.getValue().getCredentialScope().getRegion() != null) .filter(r -> RegionValidationUtil.validRegion(r.getKey(), s.getKey().getRegionRegex())) .forEach(fm -> builder.add(".put(\"" + fm.getKey() + "\", \"" + fm.getValue().getCredentialScope().getRegion() + "\")"))); return builder.add(".build()").build(); }
Example #9
Source File: ServiceMetadataGenerator.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
private CodeBlock serviceEndpoints(Partitions partitions) { Map<Partition, Service> services = getServiceData(partitions); CodeBlock.Builder builder = CodeBlock.builder().add("$T.<String, String>builder()", ImmutableMap.class); services.entrySet() .forEach(s -> s.getValue().getEndpoints() .entrySet() .stream() .filter(e -> e.getValue().getHostname() != null) .filter(r -> RegionValidationUtil.validRegion(r.getKey(), s.getKey().getRegionRegex())) .forEach(e -> builder.add(".put(\"" + e.getKey() + "\", " + "\"" + e.getValue().getHostname() + "\")"))); return builder.add(".build()").build(); }
Example #10
Source File: ServiceMetadataProviderGenerator.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
private CodeBlock regions(Partitions partitions) { CodeBlock.Builder builder = CodeBlock.builder().add("$T.<String, ServiceMetadata>builder()", ImmutableMap.class); Set<String> seenServices = new HashSet<>(); partitions.getPartitions() .forEach(p -> p.getServices() .keySet() .forEach(s -> { if (!seenServices.contains(s)) { builder.add(".put($S, new $T())", s, serviceMetadataClass(s)); seenServices.add(s); } })); return builder.add(".build()").build(); }
Example #11
Source File: DynamoJobMetaRepository.java From edison-microservice with Apache License 2.0 | 5 votes |
private void removeAttribute(String jobType, String attributeKey) { dynamoDbClient.updateItem(UpdateItemRequest.builder() .tableName(tableName) .key(ImmutableMap.of(JOB_TYPE_KEY, AttributeValue.builder().s(jobType).build())) .attributeUpdates(ImmutableMap.of(attributeKey, AttributeValueUpdate.builder() .action(DELETE).build())) .build()); }
Example #12
Source File: AbstractDynamoRepository.java From edison-microservice with Apache License 2.0 | 5 votes |
void deleteEntriesPerBatch(List<WriteRequest> deleteRequests) { final int chunkSize = 25; final AtomicInteger counter = new AtomicInteger(); final Collection<List<WriteRequest>> deleteRequestsSplittedByChunkSize = deleteRequests.stream() .collect(Collectors.groupingBy(it -> counter.getAndIncrement() / chunkSize)) .values(); deleteRequestsSplittedByChunkSize.forEach (currentDeleteRequests -> dynamoDbClient.batchWriteItem( BatchWriteItemRequest.builder().requestItems( ImmutableMap.of(tableName, currentDeleteRequests)).build())); }
Example #13
Source File: DynamoJobRepository.java From edison-microservice with Apache License 2.0 | 5 votes |
@Override public void deleteAll() { final List<WriteRequest> deleteRequests = findAll().stream() .map(JobInfo::getJobId) .map(jobId -> WriteRequest.builder() .deleteRequest( DeleteRequest.builder() .key(ImmutableMap.of(ID.key(), AttributeValue.builder().s(jobId).build())) .build() ).build() ).collect(toList()); deleteEntriesPerBatch(deleteRequests); }
Example #14
Source File: DynamoJobMetaRepository.java From edison-microservice with Apache License 2.0 | 5 votes |
@Override public void deleteAll() { final List<WriteRequest> deleteRequests = findAllJobTypes().stream() .map(jobId -> WriteRequest.builder() .deleteRequest( DeleteRequest.builder() .key(ImmutableMap.of(JOB_TYPE_KEY, AttributeValue.builder().s(jobId).build())) .build() ).build() ).collect(toList()); deleteEntriesPerBatch(deleteRequests); }
Example #15
Source File: DynamoJobRepository.java From edison-microservice with Apache License 2.0 | 5 votes |
private List<JobInfo> findAll(final boolean withMessages) { Map<String, AttributeValue> lastKeyEvaluated = null; List<JobInfo> jobs = new ArrayList<>(); do { final ScanRequest.Builder findAllRequestBuilder = ScanRequest.builder() .tableName(tableName) .limit(pageSize) .exclusiveStartKey(lastKeyEvaluated); if (!withMessages) { String projectionExpressionBuilder = ID.key() + ", " + STARTED.key() + ", " + STOPPED.key() + ", " + JOB_TYPE.key() + ", #" + STATUS.key() + ", " + HOSTNAME.key() + ", " + LAST_UPDATED.key(); findAllRequestBuilder.projectionExpression(projectionExpressionBuilder) .expressionAttributeNames(ImmutableMap.of("#" + STATUS.key(), STATUS.key())); } final ScanResponse scan = dynamoDbClient.scan(findAllRequestBuilder.build()); lastKeyEvaluated = scan.lastEvaluatedKey(); List<JobInfo> newJobsFromThisPage = scan.items().stream().map(this::decode).collect(Collectors.toList()); jobs.addAll(newJobsFromThisPage); } while (lastKeyEvaluated != null && lastKeyEvaluated.size() > 0); return jobs; }
Example #16
Source File: DynamoJobMetaRepository.java From edison-microservice with Apache License 2.0 | 5 votes |
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); }
Example #17
Source File: StringAttributeConvertersTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Test public void stringAttributeConverterBehaves() { StringAttributeConverter converter = StringAttributeConverter.create(); String emptyChars = ""; String chars = "foo"; String numChars = "42"; assertThat(transformFrom(converter, chars).s()).isSameAs(chars); assertThat(transformFrom(converter, emptyChars).s()).isSameAs(emptyChars); assertThat(transformTo(converter, fromString(emptyChars))).isSameAs(emptyChars); assertThat(transformTo(converter, fromString(chars))).isSameAs(chars); assertThat(transformTo(converter, fromNumber(emptyChars))).isSameAs(emptyChars); assertThat(transformTo(converter, fromNumber(numChars))).isSameAs(numChars); assertThat(transformTo(converter, fromBytes(SdkBytes.fromUtf8String("foo")))).isEqualTo("Zm9v"); assertThat(transformTo(converter, fromBoolean(true))).isEqualTo("true"); assertThat(transformTo(converter, fromBoolean(false))).isEqualTo("false"); assertThat(transformTo(converter, fromMap(ImmutableMap.of("a", fromString("b").toAttributeValue(), "c", fromBytes(SdkBytes.fromUtf8String("d")).toAttributeValue())))) .isEqualTo("{a=b, c=ZA==}"); assertThat(transformTo(converter, fromListOfAttributeValues(fromString("a").toAttributeValue(), fromBytes(SdkBytes.fromUtf8String("d")).toAttributeValue()))) .isEqualTo("[a, ZA==]"); assertThat(transformTo(converter, fromSetOfStrings("a", "b"))).isEqualTo("[a, b]"); assertThat(transformTo(converter, fromSetOfBytes(SdkBytes.fromUtf8String("a"), SdkBytes.fromUtf8String("b")))) .isEqualTo("[YQ==,Yg==]"); assertThat(transformTo(converter, fromSetOfNumbers("1", "2"))).isEqualTo("[1, 2]"); }
Example #18
Source File: RequestOverrideConfigurationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@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 #19
Source File: ClientOverrideConfigurationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@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 #20
Source File: GetObjectAsyncIntegrationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Override public SdkResponse modifyResponse(Context.ModifyResponse context, ExecutionAttributes executionAttributes) { return ((GetObjectResponse) context.response()) .toBuilder() .metadata(ImmutableMap.of("x-amz-assert", "injected-value")) .build(); }
Example #21
Source File: PutItemRequestMarshallerTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
/**l * Regression test for TT0075355961 */ @Test public void onlyRemainingByteBufferDataIsMarshalled() throws IOException { final ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[] {0, 0, 0, 1, 1, 1}); // Consume some of the byte buffer byteBuffer.position(3); SdkHttpFullRequest marshalled = marshaller.marshall(PutItemRequest.builder().item( ImmutableMap.of("binaryProp", AttributeValue.builder().b(SdkBytes.fromByteBuffer(byteBuffer)).build())).build()); JsonNode marshalledContent = MAPPER.readTree(marshalled.contentStreamProvider().get().newStream()); String base64Binary = marshalledContent.get("Item").get("binaryProp").get("B").asText(); // Only the remaining data in the byte buffer should have been read and marshalled. assertEquals(BinaryUtils.toBase64(new byte[] {1, 1, 1}), base64Binary); }
Example #22
Source File: SubscribeToShardUnmarshallingTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
public MessageWriter writeError(String errorCode, String errorMessage) { new Message(ImmutableMap.of(":message-type", HeaderValue.fromString("error"), ":error-code", HeaderValue.fromString(errorCode), ":error-message", HeaderValue.fromString(errorMessage)), new byte[0]).encode(baos); return this; }
Example #23
Source File: ServiceMetadataGenerator.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
private CodeBlock partitionEndpoints(Partitions partitions) { Map<Partition, Service> services = getServiceData(partitions); CodeBlock.Builder builder = CodeBlock.builder().add("$T.<String, String>builder()", ImmutableMap.class); services.forEach((key, value) -> { if (value.getDefaults() != null && value.getDefaults().getHostname() != null) { builder.add(".put($S, $S)", key.getPartition(), value.getDefaults().getHostname()); } }); return builder.add(".build()").build(); }
Example #24
Source File: RegionMetadataProviderGenerator.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
private CodeBlock regions(Partitions partitions) { CodeBlock.Builder builder = CodeBlock.builder().add("$T.<Region, RegionMetadata>builder()", ImmutableMap.class); partitions.getPartitions() .forEach(p -> p.getRegions() .keySet() .forEach(r -> builder.add(".put(Region.$L, new $T())", regionClass(r), regionMetadataClass(r)))); return builder.add(".build()").build(); }
Example #25
Source File: SubscribeToShardUnmarshallingTest.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
public MessageWriter writeEvent(String eventType, String payload) { new Message(ImmutableMap.of(":message-type", HeaderValue.fromString("event"), ":event-type", HeaderValue.fromString(eventType)), payload.getBytes(StandardCharsets.UTF_8)).encode(baos); return this; }
Example #26
Source File: SubscribeToShardUnmarshallingTest.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
public MessageWriter writeException(String payload, String modeledExceptionName) { new Message(ImmutableMap.of(":message-type", HeaderValue.fromString("exception"), ":exception-type", HeaderValue.fromString(modeledExceptionName)), payload.getBytes(StandardCharsets.UTF_8)).encode(baos); return this; }
Example #27
Source File: SubscribeToShardUnmarshallingTest.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
public MessageWriter writeInitialResponse(byte[] payload) { new Message(ImmutableMap.of(":message-type", HeaderValue.fromString("event"), ":event-type", HeaderValue.fromString("initial-response")), payload).encode(baos); return this; }