Skip to content

Commit

Permalink
#84 merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Yegor Bugayenko committed Nov 18, 2016
2 parents 9361237 + e9466c8 commit a3e4660
Show file tree
Hide file tree
Showing 9 changed files with 414 additions and 33 deletions.
2 changes: 1 addition & 1 deletion PUZZLES.md
Expand Up @@ -9,7 +9,7 @@ There are 1 active puzzles (10 total):
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<del>8-81cf3845</del> [`ReTable.java:101-102`](../master/src/main/java/com/jcabi/dynamo/retry/ReTable.java#L101-L102)<br/>
&nbsp;&nbsp;&nbsp;&nbsp;[<del>10</del>](https://github.com/jcabi/jcabi-dynamo/issues/10) [`?`](../master/?)<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<del>10-d74a245f</del> [`Throughput.java:76-76`](../master/src/main/java/com/jcabi/dynamo/Throughput.java#L76-L76)<br/>
&nbsp;&nbsp;&nbsp;&nbsp;[#56](https://github.com/jcabi/jcabi-dynamo/issues/56):[<del>56</del>](https://github.com/jcabi/jcabi-dynamo/issues/56) [`?`](../master/?)<br/>
&nbsp;&nbsp;&nbsp;&nbsp;[<del>56</del>](https://github.com/jcabi/jcabi-dynamo/issues/56) [`?`](../master/?)<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<del>56-be65f863</del> [`AwsIteratorITCase.java:51-53`](../master/src/test/java/com/jcabi/dynamo/AwsIteratorITCase.java#L51-L53)<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<del>56-9ee1f8fe</del> [`RegionITCase.java:53-56`](../master/src/test/java/com/jcabi/dynamo/RegionITCase.java#L53-L56)<br/>
&nbsp;&nbsp;&nbsp;&nbsp;[#75](https://github.com/jcabi/jcabi-dynamo/issues/75):[**10-41088ed2**](https://github.com/jcabi/jcabi-dynamo/issues/75) [`Throughput.java:72-74`](../master/src/main/java/com/jcabi/dynamo/Throughput.java#L72-L74)<br/>
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -7,7 +7,7 @@
[![Build Status](https://travis-ci.org/jcabi/jcabi-dynamo.svg?branch=master)](https://travis-ci.org/jcabi/jcabi-dynamo)
[![Build status](https://ci.appveyor.com/api/projects/status/6hiv73p1f55qttdy/branch/master?svg=true)](https://ci.appveyor.com/project/yegor256/jcabi-dynamo/branch/master)
[![Coverage Status](https://coveralls.io/repos/jcabi/jcabi-dynamo/badge.svg?branch=__rultor&service=github)](https://coveralls.io/github/jcabi/jcabi-dynamo?branch=__rultor)
[![JavaDoc](https://img.shields.io/badge/javadoc-html-blue.svg)](http://www.javadoc.io/doc/com.jcabi/jcabi-dynamo)
[![Javadoc](https://javadoc-emblem.rhcloud.com/doc/com.jcabi/jcabi-dynamo/badge.svg)](http://www.javadoc.io/doc/com.jcabi/jcabi-dynamo)

[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.jcabi/jcabi-dynamo/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.jcabi/jcabi-dynamo)
[![Dependencies](https://www.versioneye.com/user/projects/561aa22ba193340f280010b7/badge.svg?style=flat)](https://www.versioneye.com/user/projects/561aa22ba193340f280010b7)
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/com/jcabi/dynamo/AwsItem.java
Expand Up @@ -126,7 +126,10 @@ public boolean has(final String attr) throws IOException {
has = result.getItem().get(attrib) != null;
Logger.info(
this, "#has('%s'): %B from DynamoDB, %s, in %[ms]s",
attr, has, AwsTable.print(result.getConsumedCapacity()),
attr, has,
new PrintableConsumedCapacity(
result.getConsumedCapacity()
).print(),
System.currentTimeMillis() - start
);
} catch (final AmazonClientException ex) {
Expand Down Expand Up @@ -164,7 +167,10 @@ public AttributeValue get(final String attr) throws IOException {
this,
// @checkstyle LineLength (1 line)
"#get('%s'): loaded '%[text]s' from DynamoDB, %s, in %[ms]s",
attrib, value, AwsTable.print(result.getConsumedCapacity()),
attrib, value,
new PrintableConsumedCapacity(
result.getConsumedCapacity()
).print(),
System.currentTimeMillis() - start
);
} catch (final AmazonClientException ex) {
Expand Down Expand Up @@ -210,7 +216,10 @@ public Map<String, AttributeValue> put(
final UpdateItemResult result = aws.updateItem(request);
Logger.info(
this, "#put('%s'): updated item to DynamoDB, %s, in %[ms]s",
attrs, AwsTable.print(result.getConsumedCapacity()),
attrs,
new PrintableConsumedCapacity(
result.getConsumedCapacity()
).print(),
System.currentTimeMillis() - start
);
return result.getAttributes();
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/jcabi/dynamo/AwsIterator.java
Expand Up @@ -208,7 +208,10 @@ public void remove() {
Logger.info(
this,
"#remove(): item #%d removed from DynamoDB, %s, in %[ms]s",
this.position, AwsTable.print(res.getConsumedCapacity()),
this.position,
new PrintableConsumedCapacity(
res.getConsumedCapacity()
).print(),
System.currentTimeMillis() - start
);
} finally {
Expand Down
25 changes: 6 additions & 19 deletions src/main/java/com/jcabi/dynamo/AwsTable.java
Expand Up @@ -32,7 +32,6 @@
import com.amazonaws.AmazonClientException;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
import com.amazonaws.services.dynamodbv2.model.ConsumedCapacity;
import com.amazonaws.services.dynamodbv2.model.DeleteItemRequest;
import com.amazonaws.services.dynamodbv2.model.DeleteItemResult;
import com.amazonaws.services.dynamodbv2.model.DescribeTableRequest;
Expand Down Expand Up @@ -111,7 +110,9 @@ public Item put(final Map<String, AttributeValue> attributes)
Logger.info(
this, "#put('%[text]s'): created item in '%s', %s, in %[ms]s",
attributes, this.self,
AwsTable.print(result.getConsumedCapacity()),
new PrintableConsumedCapacity(
result.getConsumedCapacity()
).print(),
System.currentTimeMillis() - start
);
return new AwsItem(
Expand Down Expand Up @@ -185,22 +186,6 @@ public Collection<String> keys() throws IOException {
}
}

/**
* Print consumed capacity nicely.
* @param capacity Consumed capacity or NULL
* @return Suffix to add to a log line
*/
public static String print(
final ConsumedCapacity capacity) {
final String txt;
if (capacity == null) {
txt = "no units";
} else {
txt = String.format("%.2f units", capacity.getCapacityUnits());
}
return txt;
}

@Override
public void delete(final Map<String, AttributeValue> attributes)
throws IOException {
Expand All @@ -217,7 +202,9 @@ public void delete(final Map<String, AttributeValue> attributes)
this,
"#delete('%[text]s'): deleted item in '%s', %s, in %[ms]s",
attributes, this.self,
AwsTable.print(result.getConsumedCapacity()),
new PrintableConsumedCapacity(
result.getConsumedCapacity()
).print(),
System.currentTimeMillis() - start
);
} catch (final AmazonClientException ex) {
Expand Down
69 changes: 69 additions & 0 deletions src/main/java/com/jcabi/dynamo/PrintableConsumedCapacity.java
@@ -0,0 +1,69 @@
/**
* Copyright (c) 2012-2015, jcabi.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the jcabi.com nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcabi.dynamo;

import com.amazonaws.services.dynamodbv2.model.ConsumedCapacity;

/**
* Printable consumed capacity.
*
* @author Piotr Pradzynski (prondzyn@gmail.com)
* @version $Id$
* @since 0.22
*/
final class PrintableConsumedCapacity {

/**
* Consumed capacity.
*/
private final ConsumedCapacity capacity;

/**
* Default ctor.
* @param capacity Consumed capacity
*/
PrintableConsumedCapacity(final ConsumedCapacity capacity) {
this.capacity = capacity;
}

/**
* Print consumed capacity nicely.
* @return Suffix to add to a log line
*/
public String print() {
final String txt;
if (this.capacity == null) {
txt = "";
} else {
txt = String.format("%.2f units", this.capacity.getCapacityUnits());
}
return txt;
}
}
12 changes: 9 additions & 3 deletions src/main/java/com/jcabi/dynamo/QueryValve.java
Expand Up @@ -160,7 +160,9 @@ public Dosage fetch(final Credentials credentials, final String table,
this,
"#items(): loaded %d item(s) from '%s' using %s, %s, in %[ms]s",
result.getCount(), table, conditions,
AwsTable.print(result.getConsumedCapacity()),
new PrintableConsumedCapacity(
result.getConsumedCapacity()
).print(),
System.currentTimeMillis() - start
);
return new QueryValve.NextDosage(credentials, request, result);
Expand Down Expand Up @@ -200,7 +202,9 @@ public int count(final Credentials credentials, final String table,
// @checkstyle LineLength (1 line)
"#total(): COUNT=%d in '%s' using %s, %s, in %[ms]s",
count, request.getTableName(), request.getQueryFilter(),
AwsTable.print(rslt.getConsumedCapacity()),
new PrintableConsumedCapacity(
rslt.getConsumedCapacity()
).print(),
System.currentTimeMillis() - start
);
return count;
Expand Down Expand Up @@ -384,7 +388,9 @@ public Dosage next() {
"#next(): loaded %d item(s) from '%s' using %s, %s, in %[ms]s",
rslt.getCount(), rqst.getTableName(),
rqst.getKeyConditions(),
AwsTable.print(rslt.getConsumedCapacity()),
new PrintableConsumedCapacity(
rslt.getConsumedCapacity()
).print(),
System.currentTimeMillis() - start
);
return new QueryValve.NextDosage(this.credentials, rqst, rslt);
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/com/jcabi/dynamo/ScanValve.java
Expand Up @@ -117,7 +117,9 @@ public Dosage fetch(final Credentials credentials,
this,
"#items(): loaded %d item(s) from '%s' using %s, %s, in %[ms]s",
result.getCount(), table, conditions,
AwsTable.print(result.getConsumedCapacity()),
new PrintableConsumedCapacity(
result.getConsumedCapacity()
).print(),
System.currentTimeMillis() - start
);
return new ScanValve.NextDosage(credentials, request, result);
Expand Down Expand Up @@ -146,14 +148,16 @@ public int count(final Credentials credentials, final String table,
.withSelect(Select.COUNT)
.withLimit(Integer.MAX_VALUE);
final long start = System.currentTimeMillis();
final ScanResult rslt = aws.scan(request);
final int count = rslt.getCount();
final ScanResult result = aws.scan(request);
final int count = result.getCount();
Logger.info(
this,
// @checkstyle LineLength (1 line)
"#total(): COUNT=%d in '%s' using %s, %s, in %[ms]s",
count, request.getTableName(), request.getFilterExpression(),
AwsTable.print(rslt.getConsumedCapacity()),
new PrintableConsumedCapacity(
result.getConsumedCapacity()
).print(),
System.currentTimeMillis() - start
);
return count;
Expand Down Expand Up @@ -259,7 +263,9 @@ public Dosage next() {
// @checkstyle LineLength (1 line)
"#next(): loaded %d item(s) from '%s' using %s, %s, in %[ms]s",
rslt.getCount(), rqst.getTableName(), rqst.getScanFilter(),
AwsTable.print(rslt.getConsumedCapacity()),
new PrintableConsumedCapacity(
rslt.getConsumedCapacity()
).print(),
System.currentTimeMillis() - start
);
return new ScanValve.NextDosage(this.credentials, rqst, rslt);
Expand Down

0 comments on commit a3e4660

Please sign in to comment.