Search in sources :

Example 21 with DynamoDbAsyncClient

use of software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient in project aws-doc-sdk-examples by awsdocs.

the class DynamoDBAsyncTest method DynamoDBAsyncGetItem.

@Test
@Order(2)
public void DynamoDBAsyncGetItem() {
    Region region = Region.US_WEST_2;
    DynamoDbAsyncClient client = DynamoDbAsyncClient.builder().region(region).build();
    DynamoDBAsyncGetItem.getItem(client, tableName, key, keyVal);
    System.out.println("Test 2 passed");
}
Also used : DynamoDbAsyncClient(software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient) Region(software.amazon.awssdk.regions.Region)

Example 22 with DynamoDbAsyncClient

use of software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient in project thunder by RohanNagar.

the class DynamoDbUsersDaoFactoryTest method testCreateUsersDaoTableNotExists.

@Test
void testCreateUsersDaoTableNotExists() {
    UsersDaoFactory usersDaoFactory = TestResources.readResourceYaml(UsersDaoFactory.class, "fixtures/configuration/dao/dynamodb-config.yaml");
    assertTrue(usersDaoFactory instanceof DynamoDbUsersDaoFactory);
    DynamoDbUsersDaoFactory dynamoDbUsersDaoFactory = (DynamoDbUsersDaoFactory) usersDaoFactory;
    // Set the client to already be created
    DynamoDbAsyncClient client = mock(DynamoDbAsyncClient.class);
    when(client.listTables()).thenReturn(CompletableFuture.completedFuture(ListTablesResponse.builder().tableNames("wrong-test-table").build()));
    dynamoDbUsersDaoFactory.dynamoDbClient = client;
    usersDaoFactory.createUsersDao(TestResources.MAPPER);
    // The table should have been created
    verify(client, times(1)).listTables();
    verify(client, times(1)).createTable(any(CreateTableRequest.class));
}
Also used : DynamoDbAsyncClient(software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient) UsersDaoFactory(com.sanctionco.thunder.dao.UsersDaoFactory) CreateTableRequest(software.amazon.awssdk.services.dynamodb.model.CreateTableRequest) Test(org.junit.jupiter.api.Test)

Example 23 with DynamoDbAsyncClient

use of software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient in project thunder by RohanNagar.

the class DynamoDbUsersDaoFactoryTest method testDynamoClientCreatedOnce.

@Test
void testDynamoClientCreatedOnce() {
    UsersDaoFactory usersDaoFactory = TestResources.readResourceYaml(UsersDaoFactory.class, "fixtures/configuration/dao/dynamodb-config.yaml");
    assertTrue(usersDaoFactory instanceof DynamoDbUsersDaoFactory);
    DynamoDbUsersDaoFactory dynamoDbUsersDaoFactory = (DynamoDbUsersDaoFactory) usersDaoFactory;
    // Create healthcheck twice. The first one should create the DynamoDB instance
    // and the second should re-use the created one.
    usersDaoFactory.createHealthCheck();
    DynamoDbAsyncClient createdClientAfterOne = dynamoDbUsersDaoFactory.dynamoDbClient;
    usersDaoFactory.createHealthCheck();
    DynamoDbAsyncClient createdClientAfterTwo = dynamoDbUsersDaoFactory.dynamoDbClient;
    assertSame(createdClientAfterOne, createdClientAfterTwo);
}
Also used : DynamoDbAsyncClient(software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient) UsersDaoFactory(com.sanctionco.thunder.dao.UsersDaoFactory) Test(org.junit.jupiter.api.Test)

Example 24 with DynamoDbAsyncClient

use of software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient in project aws-sdk-java-v2 by aws.

the class AsyncBatchGetItemTest method setup.

@Before
public void setup() {
    DynamoDbAsyncClient dynamoDbClient = DynamoDbAsyncClient.builder().region(Region.US_WEST_2).credentialsProvider(() -> AwsBasicCredentials.create("foo", "bar")).endpointOverride(URI.create("http://localhost:" + wireMock.port())).endpointDiscoveryEnabled(false).build();
    enhancedClient = DynamoDbEnhancedAsyncClient.builder().dynamoDbClient(dynamoDbClient).build();
    StaticTableSchema<Record> tableSchema = StaticTableSchema.builder(Record.class).newItemSupplier(Record::new).addAttribute(Integer.class, a -> a.name("id").getter(Record::getId).setter(Record::setId).tags(primaryPartitionKey())).build();
    table = enhancedClient.table("table", tableSchema);
}
Also used : Record(software.amazon.awssdk.enhanced.dynamodb.mocktests.BatchGetTestUtils.Record) ReadBatch(software.amazon.awssdk.enhanced.dynamodb.model.ReadBatch) BatchGetResultPagePublisher(software.amazon.awssdk.enhanced.dynamodb.model.BatchGetResultPagePublisher) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DynamoDbAsyncClient(software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient) BatchGetTestUtils.stubResponseWithUnprocessedKeys(software.amazon.awssdk.enhanced.dynamodb.mocktests.BatchGetTestUtils.stubResponseWithUnprocessedKeys) Test(org.junit.Test) SdkPublisher(software.amazon.awssdk.core.async.SdkPublisher) DynamoDbEnhancedAsyncClient(software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedAsyncClient) BatchGetResultPage(software.amazon.awssdk.enhanced.dynamodb.model.BatchGetResultPage) StaticAttributeTags.primaryPartitionKey(software.amazon.awssdk.enhanced.dynamodb.mapper.StaticAttributeTags.primaryPartitionKey) WireMockRule(com.github.tomakehurst.wiremock.junit.WireMockRule) List(java.util.List) Rule(org.junit.Rule) After(org.junit.After) BatchGetTestUtils.stubSuccessfulResponse(software.amazon.awssdk.enhanced.dynamodb.mocktests.BatchGetTestUtils.stubSuccessfulResponse) DynamoDbAsyncTable(software.amazon.awssdk.enhanced.dynamodb.DynamoDbAsyncTable) URI(java.net.URI) StaticTableSchema(software.amazon.awssdk.enhanced.dynamodb.mapper.StaticTableSchema) AwsBasicCredentials(software.amazon.awssdk.auth.credentials.AwsBasicCredentials) Region(software.amazon.awssdk.regions.Region) LocalDynamoDbAsyncTestBase.drainPublisher(software.amazon.awssdk.enhanced.dynamodb.functionaltests.LocalDynamoDbAsyncTestBase.drainPublisher) Before(org.junit.Before) DynamoDbAsyncClient(software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient) Record(software.amazon.awssdk.enhanced.dynamodb.mocktests.BatchGetTestUtils.Record) Before(org.junit.Before)

Example 25 with DynamoDbAsyncClient

use of software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient in project openhab-addons by openhab.

the class DynamoDBTableNameResolverTest method resolveMaybeLegacy.

/**
 * @param legacyService service that has the client to use
 * @param executor
 * @return
 */
private ExpectedTableSchema resolveMaybeLegacy(DynamoDBPersistenceService legacyService, ExecutorService executor) {
    DynamoDBTableNameResolver resolver = new DynamoDBTableNameResolver(ExpectedTableSchema.MAYBE_LEGACY, DynamoDBConfig.DEFAULT_TABLE_NAME, DynamoDBConfig.DEFAULT_TABLE_PREFIX);
    assertFalse(resolver.isFullyResolved());
    try {
        DynamoDbAsyncClient localClient = legacyService.getLowLevelClient();
        if (localClient == null) {
            fail("local client is null");
            throw new RuntimeException();
        }
        boolean resolved = resolver.resolveSchema(localClient, b -> b.overrideConfiguration(legacyService::overrideConfig), executor).get();
        assertTrue(resolved);
        return resolver.getTableSchema();
    } catch (InterruptedException | ExecutionException e) {
        fail(e.getMessage());
        // Make compiler happy
        throw new IllegalStateException();
    }
}
Also used : FilterCriteria(org.openhab.core.persistence.FilterCriteria) NonNullByDefault(org.eclipse.jdt.annotation.NonNullByDefault) DynamoDbAsyncClient(software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient) Executors(java.util.concurrent.Executors) ArrayList(java.util.ArrayList) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test) List(java.util.List) Assertions(org.junit.jupiter.api.Assertions) Assumptions.assumeTrue(org.junit.jupiter.api.Assumptions.assumeTrue) DecimalType(org.openhab.core.library.types.DecimalType) NonNull(org.eclipse.jdt.annotation.NonNull) NumberItem(org.openhab.core.library.items.NumberItem) ExecutorService(java.util.concurrent.ExecutorService) DynamoDbAsyncClient(software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

DynamoDbAsyncClient (software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient)32 Region (software.amazon.awssdk.regions.Region)9 ExecutorService (java.util.concurrent.ExecutorService)7 Test (org.junit.jupiter.api.Test)6 List (java.util.List)5 ClientConfiguration (com.amazonaws.ClientConfiguration)4 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)4 ClientResources (io.lettuce.core.resource.ClientResources)4 URI (java.net.URI)4 Map (java.util.Map)4 ListTablesResponse (software.amazon.awssdk.services.dynamodb.model.ListTablesResponse)4 Context (io.vertx.core.Context)3 Timeout (io.vertx.junit5.Timeout)3 VertxTestContext (io.vertx.junit5.VertxTestContext)3 Clock (java.time.Clock)3 Set (java.util.Set)3 ExecutionException (java.util.concurrent.ExecutionException)3 Order (org.junit.jupiter.api.Order)3 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)3 ExternalServiceCredentialGenerator (org.whispersystems.textsecuregcm.auth.ExternalServiceCredentialGenerator)3