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);
}
}
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);
}
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);
}
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))));
}
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"));
}
Aggregations