use of com.aerospike.client.AerospikeException in project aerospike-client-java by aerospike.
the class AsyncQuery method createIndex.
private void createIndex(AerospikeClient client, String indexName, String binName) {
console.info("Create index: ns=%s set=%s index=%s bin=%s", params.namespace, params.set, indexName, binName);
Policy policy = new Policy();
// Do not timeout on index create.
policy.socketTimeout = 0;
try {
IndexTask task = client.createIndex(policy, params.namespace, params.set, indexName, binName, IndexType.NUMERIC);
task.waitTillComplete();
} catch (AerospikeException ae) {
if (ae.getResultCode() != ResultCode.INDEX_ALREADY_EXISTS) {
throw ae;
}
}
}
use of com.aerospike.client.AerospikeException in project aerospike-client-java by aerospike.
the class Generation method runExample.
/**
* Exercise record generation functionality.
*/
@Override
public void runExample(AerospikeClient client, Parameters params) throws Exception {
Key key = new Key(params.namespace, params.set, "genkey");
String binName = params.getBinName("genbin");
// Delete record if it already exists.
client.delete(params.writePolicy, key);
// Set some values for the same record.
Bin bin = new Bin(binName, "genvalue1");
console.info("Put: namespace=%s set=%s key=%s bin=%s value=%s", key.namespace, key.setName, key.userKey, bin.name, bin.value);
client.put(params.writePolicy, key, bin);
bin = new Bin(binName, "genvalue2");
console.info("Put: namespace=%s set=%s key=%s bin=%s value=%s", key.namespace, key.setName, key.userKey, bin.name, bin.value);
client.put(params.writePolicy, key, bin);
// Retrieve record and its generation count.
Record record = client.get(params.policy, key, bin.name);
if (record == null) {
throw new Exception(String.format("Failed to get: namespace=%s set=%s key=%s", key.namespace, key.setName, key.userKey));
}
Object received = record.getValue(bin.name);
String expected = bin.value.toString();
if (received.equals(expected)) {
console.info("Get successful: namespace=%s set=%s key=%s bin=%s value=%s generation=%d", key.namespace, key.setName, key.userKey, bin.name, received, record.generation);
} else {
throw new Exception(String.format("Get mismatch: Expected %s. Received %s.", expected, received));
}
// Set record and fail if it's not the expected generation.
bin = new Bin(binName, "genvalue3");
console.info("Put: namespace=%s set=%s key=%s bin=%s value=%s expected generation=%d", key.namespace, key.setName, key.userKey, bin.name, bin.value, record.generation);
WritePolicy writePolicy = new WritePolicy();
writePolicy.generationPolicy = GenerationPolicy.EXPECT_GEN_EQUAL;
writePolicy.generation = record.generation;
client.put(writePolicy, key, bin);
// Set record with invalid generation and check results .
bin = new Bin(binName, "genvalue4");
writePolicy.generation = 9999;
console.info("Put: namespace=%s set=%s key=%s bin=%s value=%s expected generation=%d", key.namespace, key.setName, key.userKey, bin.name, bin.value, writePolicy.generation);
try {
client.put(writePolicy, key, bin);
throw new Exception("Should have received generation error instead of success.");
} catch (AerospikeException ae) {
if (ae.getResultCode() == ResultCode.GENERATION_ERROR) {
console.info("Success: Generation error returned as expected.");
} else {
throw new Exception(String.format("Unexpected set return code: namespace=%s set=%s key=%s bin=%s value=%s code=%s", key.namespace, key.setName, key.userKey, bin.name, bin.value, ae.getResultCode()));
}
}
// Verify results.
record = client.get(params.policy, key, bin.name);
if (record == null) {
throw new Exception(String.format("Failed to get: namespace=%s set=%s key=%s", key.namespace, key.setName, key.userKey));
}
received = record.getValue(bin.name);
expected = "genvalue3";
if (received.equals(expected)) {
console.info("Get successful: namespace=%s set=%s key=%s bin=%s value=%s generation=%d", key.namespace, key.setName, key.userKey, bin.name, received, record.generation);
} else {
throw new Exception(String.format("Get mismatch: Expected %s. Received %s.", expected, received));
}
}
use of com.aerospike.client.AerospikeException in project aerospike-client-java by aerospike.
the class QueryAverage method createIndex.
private void createIndex(AerospikeClient client, Parameters params, String indexName, String binName) throws Exception {
console.info("Create index: ns=%s set=%s index=%s bin=%s", params.namespace, params.set, indexName, binName);
Policy policy = new Policy();
// Do not timeout on index create.
policy.socketTimeout = 0;
try {
IndexTask task = client.createIndex(policy, params.namespace, params.set, indexName, binName, IndexType.NUMERIC);
task.waitTillComplete();
} catch (AerospikeException ae) {
if (ae.getResultCode() != ResultCode.INDEX_ALREADY_EXISTS) {
throw ae;
}
}
}
use of com.aerospike.client.AerospikeException in project aerospike-client-java by aerospike.
the class QueryInteger method createIndex.
private void createIndex(AerospikeClient client, Parameters params, String indexName, String binName) throws Exception {
console.info("Create index: ns=%s set=%s index=%s bin=%s", params.namespace, params.set, indexName, binName);
Policy policy = new Policy();
// Do not timeout on index create.
policy.socketTimeout = 0;
try {
IndexTask task = client.createIndex(policy, params.namespace, params.set, indexName, binName, IndexType.NUMERIC);
task.waitTillComplete();
} catch (AerospikeException ae) {
if (ae.getResultCode() != ResultCode.INDEX_ALREADY_EXISTS) {
throw ae;
}
}
}
use of com.aerospike.client.AerospikeException in project aerospike-client-java by aerospike.
the class QueryPredExp method createIndex.
private void createIndex(AerospikeClient client, Parameters params, String indexName, String binName) throws Exception {
console.info("Create index: ns=%s set=%s index=%s bin=%s", params.namespace, params.set, indexName, binName);
Policy policy = new Policy();
// Do not timeout on index create.
policy.socketTimeout = 0;
try {
IndexTask task = client.createIndex(policy, params.namespace, params.set, indexName, binName, IndexType.NUMERIC);
task.waitTillComplete();
} catch (AerospikeException ae) {
if (ae.getResultCode() != ResultCode.INDEX_ALREADY_EXISTS) {
throw ae;
}
}
}
Aggregations