Package com.jcabi.dynamo.mock
Class MadeTable
- java.lang.Object
-
- com.jcabi.dynamo.mock.MadeTable
-
public final class MadeTable extends Object
A Table that can be made and dropped.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": "*" } ] }
- Since:
- 0.8
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
create()
Create table.void
createIfAbsent()
Create table if it's absent.void
drop()
Drop table.boolean
exists()
The table exists?
-
-
-
Constructor Detail
-
MadeTable
public MadeTable(Region reg, com.amazonaws.services.dynamodbv2.model.CreateTableRequest req)
Public ctor.- Parameters:
reg
- Regionreq
- Request
-
-
Method Detail
-
createIfAbsent
public void createIfAbsent() throws InterruptedException
Create table if it's absent.- Throws:
InterruptedException
- If something fails- Since:
- 0.9
-
create
public void create() throws InterruptedException
Create table.- Throws:
InterruptedException
- If something fails
-
drop
public void drop() throws InterruptedException
Drop table.- Throws:
InterruptedException
- If something fails
-
exists
public boolean exists()
The table exists?- Returns:
- TRUE if it exists in DynamoDB
- Since:
- 0.9
-
-