use of com.aerospike.client.Record in project aerospike-client-java by aerospike.
the class PutGet method runSingleBinTest.
/**
* Execute put and get on a server configured as single-bin.
*/
private void runSingleBinTest(AerospikeClient client, Parameters params) throws Exception {
Key key = new Key(params.namespace, params.set, "putgetkey");
Bin bin = new Bin("", "value");
console.info("Single Bin Put: namespace=%s set=%s key=%s value=%s", key.namespace, key.setName, key.userKey, bin.value);
client.put(params.writePolicy, key, bin);
console.info("Single Bin Get: namespace=%s set=%s key=%s", key.namespace, key.setName, key.userKey);
Record record = client.get(params.policy, key);
if (record == null) {
throw new Exception(String.format("Failed to get: namespace=%s set=%s key=%s", key.namespace, key.setName, key.userKey));
}
validateBin(key, bin, record);
}
use of com.aerospike.client.Record in project aerospike-client-java by aerospike.
the class QueryCollection method runQuery.
private void runQuery(AerospikeClient client, Parameters params, String indexName, String binName, String queryMapKey) throws Exception {
console.info("Query for: ns=%s set=%s index=%s bin=%s mapkey contains=%s", params.namespace, params.set, indexName, binName, queryMapKey);
Statement stmt = new Statement();
stmt.setNamespace(params.namespace);
stmt.setSetName(params.set);
stmt.setBinNames(binName);
stmt.setFilter(Filter.contains(binName, IndexCollectionType.MAPKEYS, queryMapKey));
RecordSet rs = client.query(null, stmt);
try {
int count = 0;
while (rs.next()) {
// Key key = rs.getKey();
Record record = rs.getRecord();
Map<?, ?> result = (Map<?, ?>) record.getValue(binName);
if (result.containsKey(queryMapKey)) {
/*console.info("Record found: ns=%s set=%s bin=%s key=%s value=%s",
key.namespace, key.setName, binName, Buffer.bytesToHexString(key.digest), result);
*/
} else {
console.error("Query mismatch: Expected mapKey %s. Received %s.", queryMapKey, result);
}
count++;
}
if (count == 0) {
console.error("Query failed. No records returned.");
} else {
console.info("Number of records %d", count);
}
} finally {
rs.close();
}
}
use of com.aerospike.client.Record in project aerospike-client-java by aerospike.
the class QueryGeoCollection method runQuery.
private void runQuery(AerospikeClient client, Parameters params, String binName, String binName2, IndexCollectionType indexType) throws Exception {
console.info("Query for: ns=%s set=%s bin=%s %s within <region>", params.namespace, params.set, binName, indexType.toString());
StringBuilder rgnsb = generateQueryRegion();
Statement stmt = new Statement();
stmt.setNamespace(params.namespace);
stmt.setSetName(params.set);
stmt.setFilter(Filter.geoWithinRegion(binName, indexType, rgnsb.toString()));
RecordSet rs = client.query(null, stmt);
try {
int count = 0;
Set<String> uniques = new HashSet<String>();
while (rs.next()) {
Record record = rs.getRecord();
uniques.add(record.getString(binName2));
count++;
}
if (count != 697) {
console.error("Query failed. %d records expected. %d returned.", 697, count);
} else if (uniques.size() != 21) {
console.error("Query failed. %d unique records expected. %d unique returned.", 21, uniques.size());
} else {
console.info("query succeeded with %d records %d unique", count, uniques.size());
}
} finally {
rs.close();
}
}
use of com.aerospike.client.Record in project aerospike-client-java by aerospike.
the class TestAdd method add.
@Test
public void add() {
Key key = new Key(args.namespace, args.set, "addkey");
String binName = args.getBinName("addbin");
// Delete record if it already exists.
client.delete(null, key);
// Perform some adds and check results.
Bin bin = new Bin(binName, 10);
client.add(null, key, bin);
bin = new Bin(binName, 5);
client.add(null, key, bin);
Record record = client.get(null, key, bin.name);
assertBinEqual(key, record, bin.name, 15);
// Test add and get combined.
bin = new Bin(binName, 30);
record = client.operate(null, key, Operation.add(bin), Operation.get(bin.name));
assertBinEqual(key, record, bin.name, 45);
}
use of com.aerospike.client.Record in project aerospike-client-java by aerospike.
the class QueryRegion method runRadiusQuery.
private void runRadiusQuery(AerospikeClient client, Parameters params, String indexName, String binName) throws Exception {
double lon = -122.0;
double lat = 37.5;
double radius = 50000.0;
console.info("QueryRadius for: ns=%s set=%s index=%s bin=%s within long=%f lat=%f radius=%f", params.namespace, params.set, indexName, binName, lon, lat, radius);
Statement stmt = new Statement();
stmt.setNamespace(params.namespace);
stmt.setSetName(params.set);
stmt.setBinNames(binName);
stmt.setFilter(Filter.geoWithinRadius(binName, lon, lat, radius));
RecordSet rs = client.query(null, stmt);
try {
int count = 0;
while (rs.next()) {
Key key = rs.getKey();
Record record = rs.getRecord();
String result = record.getGeoJSONString(binName);
console.info("Record found: ns=%s set=%s bin=%s digest=%s value=%s", key.namespace, key.setName, binName, Buffer.bytesToHexString(key.digest), result);
count++;
}
if (count != 4) {
console.error("Query count mismatch. Expected 4. Received " + count);
}
} finally {
rs.close();
}
}
Aggregations