Skip to content

Commit

Permalink
Merge pull request #185 from zznate/counters_fix_for_long
Browse files Browse the repository at this point in the history
Counters are now properly treated as longs
  • Loading branch information
zznate committed Apr 10, 2013
2 parents b3b7540 + 10f39f2 commit 4befa65
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/usergrid/vx/experimental/Operations.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static IntraOp sliceByNames( Object rowkey, List columnList){
.set(WANTEDCOLS, columnList).set("rowkey",rowkey); .set(WANTEDCOLS, columnList).set("rowkey",rowkey);
} }


public static IntraOp counter( Object rowkey, Object columnName, long value) { public static IntraOp counter( Object rowkey, Object columnName, Long value) {
Preconditions.checkArgument(rowkey != null,"A row key is required for {}", IntraOp.Type.COUNTER); Preconditions.checkArgument(rowkey != null,"A row key is required for {}", IntraOp.Type.COUNTER);
Preconditions.checkArgument(columnName != null,"A column name is required for {}", IntraOp.Type.COUNTER); Preconditions.checkArgument(columnName != null,"A column name is required for {}", IntraOp.Type.COUNTER);
return new IntraOp(IntraOp.Type.COUNTER) return new IntraOp(IntraOp.Type.COUNTER)
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.apache.cassandra.db.IMutation; import org.apache.cassandra.db.IMutation;
import org.apache.cassandra.db.RowMutation; import org.apache.cassandra.db.RowMutation;
import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.db.filter.QueryPath;
import org.vertx.java.core.Handler;
import org.vertx.java.core.eventbus.Message; import org.vertx.java.core.eventbus.Message;
import org.vertx.java.core.json.JsonObject; import org.vertx.java.core.json.JsonObject;


Expand All @@ -14,12 +13,11 @@
/** /**
* Handler class for counter writes * Handler class for counter writes
* *
* @author zznate
*/ */
public class CounterHandler implements Handler<Message<JsonObject>> { public class CounterHandler extends AbstractIntravertHandler {


@Override @Override
public void handle(Message<JsonObject> event) { public void handleUser(Message<JsonObject> event) {
Integer id = event.body.getInteger("id"); Integer id = event.body.getInteger("id");
JsonObject params = event.body.getObject("op"); JsonObject params = event.body.getObject("op");
JsonObject state = event.body.getObject("state"); JsonObject state = event.body.getObject("state");
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -795,26 +795,26 @@ public void sliceNamesTest() throws Exception {
} }


@Test @Test
@Ignore
@RequiresColumnFamily(ksName = "myks", cfName = "mycountercf", isCounter = true) @RequiresColumnFamily(ksName = "myks", cfName = "mycountercf", isCounter = true)
public void counterNoodling() throws Exception { public void counterNoodling() throws Exception {
IntraReq req = new IntraReq(); IntraReq req = new IntraReq();
req.add(Operations.assumeOp("myks", "mycountercf", "value", "LongType")) req.add(Operations.assumeOp("myks", "mycountercf", "value", "LongType"))
.add(Operations.assumeOp("myks", "mycountercf", "column", "UTF8Type")) .add(Operations.assumeOp("myks", "mycountercf", "column", "UTF8Type"))
.add(Operations.setKeyspaceOp("myks")) .add(Operations.setKeyspaceOp("myks"))
.add(Operations.setColumnFamilyOp("mycountercf")) .add(Operations.setColumnFamilyOp("mycountercf"))
.add(Operations.counter("counter_key", "counter_name_1", 1).set("timeout", 30000)) .add(Operations.counter("counter_key", "counter_name_1", 1L).set("timeout", 30000))
// 4 // 4
.add(Operations.getOp("counter_key", "counter_name_1")) .add(Operations.getOp("counter_key", "counter_name_1"))
.add(Operations.counter("counter_key", "counter_name_1", 4).set("timeout", 30000)) .add(Operations.counter("counter_key", "counter_name_1", new Long((long) Integer.MAX_VALUE+10L)).set("timeout", 30000))
.add(Operations.getOp("counter_key", "counter_name_1")); .add(Operations.getOp("counter_key", "counter_name_1"));


IntraClient2 ic2 = new IntraClient2("localhost", 8080); IntraClient2 ic2 = new IntraClient2("localhost", 8080);
IntraRes res = ic2.sendBlocking(req); IntraRes res = ic2.sendBlocking(req);
List<Map> results = (List<Map>) res.getOpsRes().get(5); List<Map> results = (List<Map>) res.getOpsRes().get(5);
logger.info("has results {}", results); logger.info("has results {}", results);
Assert.assertEquals(1L, results.get(0).get("value")); Assert.assertEquals(1, results.get(0).get("value"));
results = (List<Map>) res.getOpsRes().get(7); results = (List<Map>) res.getOpsRes().get(7);
Assert.assertEquals(5L, results.get(0).get("value")); Assert.assertEquals(2147483658L, results.get(0).get("value"));
Assert.assertTrue( (Long) results.get(0).get("value") > Integer.MAX_VALUE );
} }
} }

0 comments on commit 4befa65

Please sign in to comment.