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");
}
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));
}
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);
}
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);
}
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();
}
}
Aggregations