public final class MadeTable extends Object
Use it like this in your integration test:
public class FooITCase { private Region region; private MadeTable table; @Before public void prepare() { this.region = new Region.Simple(..your IT credentials..); this.table = new MadeTable(this.region, new CreateTableRequest()...); this.table.createIfAbsent(); } @After public void dropTable() { this.table.drop(); } @Test public void createsAndDeletesItems() { Foo foo = new Foo(this.region); foo.doSomething(); } }
In this example, a new DynamoDB table will be created before every test method, and dropped when it's finished. This may be not the best approach performance wise, since every table creation takes at least ten seconds (at the time of writing). To speed things up a little, you can create table before the entire test case and drop when all methods are completed:
public class FooITCase { private static Region region; private static MadeTable table; @BeforeClass public static void prepare() { FooITCase.region = new Region.Simple(..your IT credentials..); FooITCase.table = new MadeTable( FooITCase.region, new CreateTableRequest()... ); FooITCase.table.createIfAbsent(); } @AfterClass public static void dropTable() { FooITCase.table.drop(); } @Test public void createsAndDeletesItems() { Foo foo = new Foo(FooITCase.region); foo.doSomething(); } }
You IAM user policy would look like this (XXXXX should be replaced by your AWS account number):
{ "Statement": [ { "Action": "dynamodb:*", "Effect": "Allow", "Resource": "arn:aws:dynamodb:us-east-1:XXXXX:table/test-*" }, { "Action": "dynamodb:ListTables", "Effect": "Allow", "Resource": "*" } ] }
Constructor and Description |
---|
MadeTable(Region reg,
com.amazonaws.services.dynamodbv2.model.CreateTableRequest req)
Public ctor.
|
Modifier and Type | Method and Description |
---|---|
void |
create()
Create table.
|
void |
createIfAbsent()
Create table if it's absent.
|
void |
drop()
Drop table.
|
boolean |
exists()
The table exists?
|
public MadeTable(Region reg, com.amazonaws.services.dynamodbv2.model.CreateTableRequest req)
reg
- Regionreq
- Requestpublic void createIfAbsent() throws InterruptedException
InterruptedException
- If something failspublic void create() throws InterruptedException
InterruptedException
- If something failspublic void drop() throws InterruptedException
InterruptedException
- If something failspublic boolean exists()
Copyright © 2012–2014 jcabi.com. All rights reserved.