Search in sources :

Example 1 with ReRegion

use of com.jcabi.dynamo.retry.ReRegion in project wring by yegor256.

the class Dynamo method connect.

/**
 * Connect.
 * @return Region
 */
private static Region connect() {
    final String key = Manifests.read("Wring-DynamoKey");
    final Credentials creds = new Credentials.Simple(key, Manifests.read("Wring-DynamoSecret"));
    final Region region;
    if (key.startsWith("AAAAA")) {
        final String property = System.getProperty("dynamo.port");
        if (property == null) {
            throw new IllegalStateException("You're not supposed to run this test outside of Maven");
        }
        final int port = Integer.parseInt(property);
        region = new Region.Simple(new Credentials.Direct(creds, port));
        Logger.warn(Dynamo.class, "test DynamoDB at port #%d", port);
    } else {
        region = new Region.Prefixed(new ReRegion(new Region.Simple(creds)), "wring-");
    }
    Logger.info(Dynamo.class, "DynamoDB connected as %s", key);
    return region;
}
Also used : ReRegion(com.jcabi.dynamo.retry.ReRegion) ReRegion(com.jcabi.dynamo.retry.ReRegion) Region(com.jcabi.dynamo.Region) Credentials(com.jcabi.dynamo.Credentials)

Example 2 with ReRegion

use of com.jcabi.dynamo.retry.ReRegion in project jcabi-dynamo by jcabi.

the class RegionMock method get.

/**
 * Get region with a table.
 * @param table Table name
 * @return Region
 * @throws Exception If fails
 */
public Region get(final String table) throws Exception {
    final Region region = new Region.Simple(new Credentials.Direct(Credentials.TEST, this.prt));
    final MadeTable mocker = new MadeTable(region, new CreateTableRequest().withTableName(table).withProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(1L).withWriteCapacityUnits(1L)).withAttributeDefinitions(new AttributeDefinition().withAttributeName(this.ahash).withAttributeType(ScalarAttributeType.S), new AttributeDefinition().withAttributeName(this.arange).withAttributeType(ScalarAttributeType.N)).withKeySchema(new KeySchemaElement().withAttributeName(this.ahash).withKeyType(KeyType.HASH), new KeySchemaElement().withAttributeName(this.arange).withKeyType(KeyType.RANGE)));
    mocker.create();
    mocker.createIfAbsent();
    return new ReRegion(region);
}
Also used : MadeTable(com.jcabi.dynamo.mock.MadeTable) ReRegion(com.jcabi.dynamo.retry.ReRegion) ReRegion(com.jcabi.dynamo.retry.ReRegion) AttributeDefinition(com.amazonaws.services.dynamodbv2.model.AttributeDefinition) ProvisionedThroughput(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput) CreateTableRequest(com.amazonaws.services.dynamodbv2.model.CreateTableRequest) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement)

Aggregations

ReRegion (com.jcabi.dynamo.retry.ReRegion)2 AttributeDefinition (com.amazonaws.services.dynamodbv2.model.AttributeDefinition)1 CreateTableRequest (com.amazonaws.services.dynamodbv2.model.CreateTableRequest)1 KeySchemaElement (com.amazonaws.services.dynamodbv2.model.KeySchemaElement)1 ProvisionedThroughput (com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput)1 Credentials (com.jcabi.dynamo.Credentials)1 Region (com.jcabi.dynamo.Region)1 MadeTable (com.jcabi.dynamo.mock.MadeTable)1