Search in sources :

Example 1 with ThrowingSupplier

use of org.apache.beam.sdk.util.ThrowingSupplier in project beam by apache.

the class AwsModuleTest method withSystemPropertyOverrides.

private <T> T withSystemPropertyOverrides(Properties overrides, ThrowingSupplier<T> fun) throws Exception {
    Properties systemProps = System.getProperties();
    Properties previousProps = new Properties();
    systemProps.entrySet().stream().filter(e -> overrides.containsKey(e.getKey())).forEach(e -> previousProps.put(e.getKey(), e.getValue()));
    overrides.forEach(systemProps::put);
    try {
        return fun.get();
    } finally {
        overrides.forEach(systemProps::remove);
        previousProps.forEach(systemProps::put);
    }
}
Also used : Module(com.fasterxml.jackson.databind.Module) ThrowingSupplier(org.apache.beam.sdk.util.ThrowingSupplier) AWS_REGION(software.amazon.awssdk.core.SdkSystemSetting.AWS_REGION) AwsCredentialsProvider(software.amazon.awssdk.auth.credentials.AwsCredentialsProvider) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AWS_SECRET_ACCESS_KEY(software.amazon.awssdk.core.SdkSystemSetting.AWS_SECRET_ACCESS_KEY) AssumeRoleRequest(software.amazon.awssdk.services.sts.model.AssumeRoleRequest) RunWith(org.junit.runner.RunWith) ProfileCredentialsProvider(software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider) AwsSessionCredentials(software.amazon.awssdk.auth.credentials.AwsSessionCredentials) StaticCredentialsProvider(software.amazon.awssdk.auth.credentials.StaticCredentialsProvider) SystemPropertyCredentialsProvider(software.amazon.awssdk.auth.credentials.SystemPropertyCredentialsProvider) Supplier(java.util.function.Supplier) Regions(com.amazonaws.regions.Regions) SSECustomerKey(org.apache.beam.sdk.io.aws2.s3.SSECustomerKey) URI(java.net.URI) StsClient(software.amazon.awssdk.services.sts.StsClient) ProxyConfiguration(software.amazon.awssdk.http.apache.ProxyConfiguration) Properties(java.util.Properties) HttpClientConfiguration(org.apache.beam.sdk.io.aws2.common.HttpClientConfiguration) EnvironmentVariableCredentialsProvider(software.amazon.awssdk.auth.credentials.EnvironmentVariableCredentialsProvider) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) StsAssumeRoleCredentialsProvider(software.amazon.awssdk.services.sts.auth.StsAssumeRoleCredentialsProvider) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) DefaultCredentialsProvider(software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) FieldUtils.readField(org.apache.beam.repackaged.core.org.apache.commons.lang3.reflect.FieldUtils.readField) AWS_ACCESS_KEY_ID(software.amazon.awssdk.core.SdkSystemSetting.AWS_ACCESS_KEY_ID) List(java.util.List) Matchers.hasItem(org.hamcrest.Matchers.hasItem) MatcherAssert(org.hamcrest.MatcherAssert) ReflectHelpers(org.apache.beam.sdk.util.common.ReflectHelpers) ContainerCredentialsProvider(software.amazon.awssdk.auth.credentials.ContainerCredentialsProvider) AwsBasicCredentials(software.amazon.awssdk.auth.credentials.AwsBasicCredentials) Assert.assertEquals(org.junit.Assert.assertEquals) Properties(java.util.Properties)

Aggregations

Regions (com.amazonaws.regions.Regions)1 Module (com.fasterxml.jackson.databind.Module)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 URI (java.net.URI)1 List (java.util.List)1 Properties (java.util.Properties)1 Supplier (java.util.function.Supplier)1 FieldUtils.readField (org.apache.beam.repackaged.core.org.apache.commons.lang3.reflect.FieldUtils.readField)1 HttpClientConfiguration (org.apache.beam.sdk.io.aws2.common.HttpClientConfiguration)1 SSECustomerKey (org.apache.beam.sdk.io.aws2.s3.SSECustomerKey)1 ThrowingSupplier (org.apache.beam.sdk.util.ThrowingSupplier)1 ReflectHelpers (org.apache.beam.sdk.util.common.ReflectHelpers)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 MatcherAssert (org.hamcrest.MatcherAssert)1 Matchers.hasItem (org.hamcrest.Matchers.hasItem)1 Matchers.instanceOf (org.hamcrest.Matchers.instanceOf)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Test (org.junit.Test)1 RunWith (org.junit.runner.RunWith)1 JUnit4 (org.junit.runners.JUnit4)1