Search in sources :

Example 6 with Attributes

use of com.jcabi.dynamo.Attributes in project jcabi-dynamo by jcabi.

the class ReRegionTest method retriesAwsCalls.

/**
 * ReRegion can retry on some AWS calls.
 * @throws Exception If some problem inside
 */
@Test
public void retriesAwsCalls() throws Exception {
    final Table table = Mockito.mock(Table.class);
    final Attributes attrs = new Attributes();
    final String msg = "hey you";
    Mockito.doThrow(new AmazonClientException(msg)).when(table).put(attrs);
    final Region origin = Mockito.mock(Region.class);
    Mockito.doReturn(table).when(origin).table(Mockito.anyString());
    final Region region = new ReRegion(origin);
    try {
        region.table("test").put(attrs);
        Assert.fail("exception expected here");
    } catch (final AmazonClientException ex) {
        assert ex.getMessage().equals(msg);
    }
    Mockito.verify(table, Mockito.times(Tv.THREE)).put(attrs);
}
Also used : Table(com.jcabi.dynamo.Table) AmazonClientException(com.amazonaws.AmazonClientException) Attributes(com.jcabi.dynamo.Attributes) Region(com.jcabi.dynamo.Region) Test(org.junit.Test)

Example 7 with Attributes

use of com.jcabi.dynamo.Attributes in project jcabi-dynamo by jcabi.

the class H2DataTest method storesToFile.

/**
 * H2Data can store to a file.
 * @throws Exception If some problem inside
 * @see <a href="https://code.google.com/p/h2database/issues/detail?id=447">
 *  Google Code: DB file extension customizability</a>
 */
@Test
@Ignore
public void storesToFile() throws Exception {
    final File file = this.temp.newFile();
    final String table = "tbl";
    final String key = "key1";
    final MkData data = new H2Data(file).with(table, new String[] { key }, new String[0]);
    data.put(table, new Attributes().with(key, "x2"));
    MatcherAssert.assertThat(file.exists(), Matchers.is(true));
    MatcherAssert.assertThat(file.length(), Matchers.greaterThan(0L));
}
Also used : Attributes(com.jcabi.dynamo.Attributes) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with Attributes

use of com.jcabi.dynamo.Attributes in project jcabi-dynamo by jcabi.

the class H2DataTest method updatesTableAttributes.

/**
 * H2Data can update table attributes.
 * @throws Exception In case test fails
 */
@Test
public void updatesTableAttributes() throws Exception {
    final String table = "tests";
    final String key = "tid";
    final int number = 43;
    final String attr = "descr";
    final String value = "Dummy\n\t\u20ac text";
    final String updated = "Updated";
    final MkData data = new H2Data().with(table, new String[] { key }, attr);
    data.put(table, new Attributes().with(key, number).with(attr, value));
    data.update(table, new Attributes().with(key, number), new AttributeUpdates().with(attr, "something else"));
    data.update(table, new Attributes().with(key, number), new AttributeUpdates().with(attr, updated));
    final Iterable<Attributes> result = data.iterate(table, new Conditions().with(key, Conditions.equalTo(number)));
    MatcherAssert.assertThat(result.iterator().next(), Matchers.hasEntry(Matchers.equalTo(attr), Matchers.equalTo(new AttributeValue(updated))));
    MatcherAssert.assertThat(result, Matchers.<Attributes>iterableWithSize(1));
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) Attributes(com.jcabi.dynamo.Attributes) AttributeUpdates(com.jcabi.dynamo.AttributeUpdates) Conditions(com.jcabi.dynamo.Conditions) Test(org.junit.Test)

Example 9 with Attributes

use of com.jcabi.dynamo.Attributes in project jcabi-dynamo by jcabi.

the class MkRegionTest method storesAndReadsSingleAttribute.

/**
 * MkRegion can store and read items.
 * @throws Exception If some problem inside
 */
@Test
public void storesAndReadsSingleAttribute() throws Exception {
    final String table = "ideas";
    final String key = "number";
    final String attr = "total";
    final Region region = new MkRegion(new H2Data().with(table, new String[] { key }, attr));
    final Table tbl = region.table(table);
    tbl.put(new Attributes().with(key, "32443").with(attr, "0"));
    final Item item = tbl.frame().iterator().next();
    item.put(attr, new AttributeValueUpdate().withValue(new AttributeValue().withN("2")).withAction(AttributeAction.PUT));
    MatcherAssert.assertThat(item.get(attr).getN(), Matchers.equalTo("2"));
}
Also used : Item(com.jcabi.dynamo.Item) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) Table(com.jcabi.dynamo.Table) AttributeValueUpdate(com.amazonaws.services.dynamodbv2.model.AttributeValueUpdate) Attributes(com.jcabi.dynamo.Attributes) Region(com.jcabi.dynamo.Region) Test(org.junit.Test)

Aggregations

Attributes (com.jcabi.dynamo.Attributes)9 Test (org.junit.Test)7 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)5 Table (com.jcabi.dynamo.Table)4 AttributeValueUpdate (com.amazonaws.services.dynamodbv2.model.AttributeValueUpdate)3 Item (com.jcabi.dynamo.Item)3 Region (com.jcabi.dynamo.Region)3 AttributeUpdates (com.jcabi.dynamo.AttributeUpdates)2 Conditions (com.jcabi.dynamo.Conditions)2 AmazonClientException (com.amazonaws.AmazonClientException)1 File (java.io.File)1 IOException (java.io.IOException)1 Date (java.util.Date)1 InputOf (org.cactoos.io.InputOf)1 Ignore (org.junit.Ignore)1