Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added counterhandler and coverage for such. closes #114
- Loading branch information
Showing
9 changed files
with
181 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/org/usergrid/vx/server/operations/CounterHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.usergrid.vx.server.operations; | ||
|
||
import org.apache.cassandra.db.ConsistencyLevel; | ||
import org.apache.cassandra.db.CounterMutation; | ||
import org.apache.cassandra.db.IMutation; | ||
import org.apache.cassandra.db.RowMutation; | ||
import org.apache.cassandra.db.filter.QueryPath; | ||
import org.usergrid.vx.experimental.IntraOp; | ||
import org.usergrid.vx.experimental.IntraService; | ||
import org.vertx.java.core.Handler; | ||
import org.vertx.java.core.eventbus.Message; | ||
import org.vertx.java.core.json.JsonObject; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Handler class for counter writes | ||
* | ||
* @author zznate | ||
*/ | ||
public class CounterHandler implements Handler<Message<JsonObject>> { | ||
|
||
@Override | ||
public void handle(Message<JsonObject> event) { | ||
Integer id = event.body.getInteger("id"); | ||
JsonObject params = event.body.getObject("op"); | ||
JsonObject state = event.body.getObject("state"); | ||
|
||
RowMutation rm = new RowMutation(HandlerUtils.determineKs(params,state), | ||
IntraService.byteBufferForObject(params.getString("rowkey"))); | ||
|
||
rm.addCounter(new QueryPath( | ||
HandlerUtils.determineCf(params,state), | ||
null, | ||
IntraService.byteBufferForObject(params.getString("name"))), | ||
Long.parseLong(params.toMap().get("value").toString())); | ||
List<IMutation> mutations = new ArrayList(1); | ||
// TODO fix hard-coded consistency | ||
mutations.add(new CounterMutation(rm, ConsistencyLevel.ONE)); | ||
HandlerUtils.write(mutations, event, id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/test/resources/org/usergrid/vx/experimental/counter_get.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{"e": [ | ||
{ | ||
"type": "SETKEYSPACE", | ||
"op": { | ||
"keyspace": "myks" | ||
} | ||
}, | ||
{ | ||
"type": "SETCOLUMNFAMILY", | ||
"op": { | ||
"columnfamily": "mycountercf" | ||
} | ||
}, | ||
{ | ||
"type": "ASSUME", | ||
"op": { | ||
"keyspace": "myks", | ||
"columnfamily": "mycountercf", | ||
"type": "column", | ||
"clazz": "UTF8Type" | ||
} | ||
}, | ||
{ | ||
"type": "ASSUME", | ||
"op": { | ||
"keyspace": "myks", | ||
"columnfamily": "mycountercf", | ||
"type": "value", | ||
"clazz": "LongType" | ||
} | ||
}, | ||
{ | ||
"type": "GET", | ||
"op": { | ||
"rowkey": "row_key1", | ||
"name": "column1" | ||
} | ||
} | ||
]} |
14 changes: 14 additions & 0 deletions
14
src/test/resources/org/usergrid/vx/experimental/counter_get_response.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"opsRes":{ | ||
"0":"OK", | ||
"1":"OK", | ||
"2":"OK", | ||
"3":"OK", | ||
"4":[ | ||
{ | ||
"name":"column1", | ||
"value":4 | ||
} | ||
]}, | ||
"exception":null, "exceptionId":null | ||
} |
22 changes: 22 additions & 0 deletions
22
src/test/resources/org/usergrid/vx/experimental/counter_set.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{"e": [ | ||
{ | ||
"type": "SETKEYSPACE", | ||
"op": { | ||
"keyspace": "myks" | ||
} | ||
}, | ||
{ | ||
"type": "SETCOLUMNFAMILY", | ||
"op": { | ||
"columnfamily": "mycountercf" | ||
} | ||
}, | ||
{ | ||
"type": "COUNTER", | ||
"op": { | ||
"rowkey": "row_key1", | ||
"name": "column1", | ||
"value": "4" | ||
} | ||
} | ||
]} |