Search in sources :

Example 1 with Attributes

use of com.jcabi.dynamo.Attributes in project wring by yegor256.

the class DyEvents method post.

@Override
public void post(final String title, final String text) throws IOException {
    final Iterator<Item> items = this.items(title);
    if (items.hasNext()) {
        final Item item = items.next();
        item.put(new AttributeUpdates().with("rank", new AttributeValueUpdate().withValue(new AttributeValue().withN("1")).withAction(AttributeAction.ADD)).with("text", new AttributeValueUpdate().withAction(AttributeAction.PUT).withValue(new AttributeValue().withS(DyEvents.concat(item.get("text").getS(), text)))));
        Logger.info(this, "Event updated for %s: \"%s\"", this.urn, title);
    } else {
        final int rank;
        if (title.startsWith("io.wring.agents.")) {
            rank = -Tv.THOUSAND;
        } else {
            rank = 1;
        }
        this.table().put(new Attributes().with("urn", this.urn).with("title", title).with("text", text).with("rank", rank).with("time", System.currentTimeMillis()));
        Logger.info(this, "Event created for %s: \"%s\"", this.urn, title);
    }
}
Also used : Item(com.jcabi.dynamo.Item) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) AttributeValueUpdate(com.amazonaws.services.dynamodbv2.model.AttributeValueUpdate) Attributes(com.jcabi.dynamo.Attributes) AttributeUpdates(com.jcabi.dynamo.AttributeUpdates)

Example 2 with Attributes

use of com.jcabi.dynamo.Attributes in project wring by yegor256.

the class DyPipes method add.

@Override
public void add(final String json) throws IOException {
    Json.createReader(new InputOf(json).stream()).readObject();
    final long num = System.currentTimeMillis();
    this.table().put(new Attributes().with("urn", this.urn).with("id", num).with("json", json).with("status", String.format("Created at %s", new Date())).with("time", System.currentTimeMillis()));
    Logger.info(this, "New pipe #%d created by %s", num, this.urn);
}
Also used : Attributes(com.jcabi.dynamo.Attributes) InputOf(org.cactoos.io.InputOf) Date(java.util.Date)

Example 3 with Attributes

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

the class ReTableTest method retriesDelete.

/**
 * ReTable can retry delete calls to method delete.
 * @throws Exception If some problem inside
 */
@Test
public void retriesDelete() throws Exception {
    final Table table = Mockito.mock(Table.class);
    final Attributes attrs = new Attributes();
    final String msg = "Exception!";
    Mockito.doThrow(new IOException(msg)).when(table).delete(attrs);
    final Table retry = new ReTable(table);
    try {
        retry.delete(attrs);
    } catch (final IOException ex) {
        MatcherAssert.assertThat(ex.getMessage(), Matchers.equalTo(msg));
    }
    Mockito.verify(table, Mockito.times(Tv.THREE)).delete(attrs);
}
Also used : Table(com.jcabi.dynamo.Table) Attributes(com.jcabi.dynamo.Attributes) IOException(java.io.IOException) Test(org.junit.Test)

Example 4 with Attributes

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

the class H2DataTest method storesAndReadsAttributes.

/**
 * H2Data can store and fetch.
 * @throws Exception If some problem inside
 */
@Test
public void storesAndReadsAttributes() throws Exception {
    final String table = "users";
    final String key = "id";
    final int number = 43;
    final String attr = "desc";
    final String value = "some\n\t\u20ac text";
    final MkData data = new H2Data().with(table, new String[] { key }, new String[] { attr });
    data.put(table, new Attributes().with(key, number).with(attr, value));
    MatcherAssert.assertThat(data.iterate(table, new Conditions().with(key, Conditions.equalTo(number))).iterator().next(), Matchers.hasEntry(Matchers.equalTo(attr), Matchers.equalTo(new AttributeValue(value))));
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) Attributes(com.jcabi.dynamo.Attributes) Conditions(com.jcabi.dynamo.Conditions) Test(org.junit.Test)

Example 5 with Attributes

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

the class MkRegionTest method storesAndReadsAttributes.

/**
 * MkRegion can store and read items.
 * @throws Exception If some problem inside
 */
@Test
public void storesAndReadsAttributes() throws Exception {
    final String name = "users";
    final String key = "id";
    final String attr = "description";
    final String nattr = "thenumber";
    final Region region = new MkRegion(new H2Data().with(name, new String[] { key }, attr, nattr));
    final Table table = region.table(name);
    table.put(new Attributes().with(key, "32443").with(attr, "first value to \n\t€ save").with(nattr, "150"));
    final Item item = table.frame().iterator().next();
    MatcherAssert.assertThat(item.has(attr), Matchers.is(true));
    MatcherAssert.assertThat(item.get(attr).getS(), Matchers.containsString("\n\t\u20ac save"));
    item.put(attr, new AttributeValueUpdate().withValue(new AttributeValue("this is another value")));
    MatcherAssert.assertThat(item.get(attr).getS(), Matchers.containsString("another value"));
    MatcherAssert.assertThat(item.get(nattr).getN(), Matchers.endsWith("50"));
}
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