use of com.aerospike.client.AerospikeException in project YCSB by brianfrankcooper.
the class AerospikeClient method init.
@Override
public void init() throws DBException {
insertPolicy.recordExistsAction = RecordExistsAction.CREATE_ONLY;
updatePolicy.recordExistsAction = RecordExistsAction.REPLACE_ONLY;
Properties props = getProperties();
namespace = props.getProperty("as.namespace", DEFAULT_NAMESPACE);
String host = props.getProperty("as.host", DEFAULT_HOST);
String user = props.getProperty("as.user");
String password = props.getProperty("as.password");
int port = Integer.parseInt(props.getProperty("as.port", DEFAULT_PORT));
int timeout = Integer.parseInt(props.getProperty("as.timeout", DEFAULT_TIMEOUT));
readPolicy.timeout = timeout;
insertPolicy.timeout = timeout;
updatePolicy.timeout = timeout;
deletePolicy.timeout = timeout;
ClientPolicy clientPolicy = new ClientPolicy();
if (user != null && password != null) {
clientPolicy.user = user;
clientPolicy.password = password;
}
try {
client = new com.aerospike.client.AerospikeClient(clientPolicy, host, port);
} catch (AerospikeException e) {
throw new DBException(String.format("Error while creating Aerospike " + "client for %s:%d.", host, port), e);
}
}
use of com.aerospike.client.AerospikeException in project aerospike-client-java by aerospike.
the class TestGeneration method generation.
@Test
public void generation() {
Key key = new Key(args.namespace, args.set, "genkey");
String binName = args.getBinName("genbin");
// Delete record if it already exists.
client.delete(null, key);
// Set some values for the same record.
Bin bin = new Bin(binName, "genvalue1");
client.put(null, key, bin);
bin = new Bin(binName, "genvalue2");
client.put(null, key, bin);
// Retrieve record and its generation count.
Record record = client.get(null, key, bin.name);
assertBinEqual(key, record, bin);
// Set record and fail if it's not the expected generation.
bin = new Bin(binName, "genvalue3");
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;
try {
client.put(writePolicy, key, bin);
fail("Should have received generation error instead of success.");
} catch (AerospikeException ae) {
if (ae.getResultCode() != ResultCode.GENERATION_ERROR) {
fail("Unexpected return code: namespace=" + key.namespace + " set=" + key.setName + " key=" + key.userKey + " bin=" + bin.name + " value=" + bin.value + " code=" + ae.getResultCode());
}
}
// Verify results.
record = client.get(null, key, bin.name);
assertBinEqual(key, record, bin.name, "genvalue3");
}
use of com.aerospike.client.AerospikeException in project aerospike-client-java by aerospike.
the class TestQueryExecute method prepare.
@BeforeClass
public static void prepare() {
RegisterTask rtask = client.register(null, TestQueryExecute.class.getClassLoader(), "udf/record_example.lua", "record_example.lua", Language.LUA);
rtask.waitTillComplete();
Policy policy = new Policy();
// Do not timeout on index create.
policy.socketTimeout = 0;
try {
IndexTask itask = client.createIndex(policy, args.namespace, args.set, indexName, binName1, IndexType.NUMERIC);
itask.waitTillComplete();
} catch (AerospikeException ae) {
if (ae.getResultCode() != ResultCode.INDEX_ALREADY_EXISTS) {
throw ae;
}
}
for (int i = 1; i <= size; i++) {
Key key = new Key(args.namespace, args.set, keyPrefix + i);
client.put(null, key, new Bin(binName1, i), new Bin(binName2, i));
}
}
use of com.aerospike.client.AerospikeException in project aerospike-client-java by aerospike.
the class TestQueryGeo method prepare.
@BeforeClass
public static void prepare() {
Policy policy = new Policy();
// Do not timeout on index create.
policy.socketTimeout = 0;
try {
IndexTask task = client.createIndex(policy, args.namespace, setName, indexName, binName, IndexType.GEO2DSPHERE);
task.waitTillComplete();
} catch (AerospikeException ae) {
if (ae.getResultCode() != ResultCode.INDEX_ALREADY_EXISTS) {
throw ae;
}
}
// Insert points
for (int i = 1; i <= size; i++) {
Key key = new Key(args.namespace, setNamePoints, i);
double lng = -122 + (0.1 * i);
double lat = 37.5 + (0.1 * i);
String loc = "{ \"type\": \"Point\", \"coordinates\": [" + lng + ", " + lat + "] }";
Bin bin = Bin.asGeoJSON("loc", loc);
client.put(null, key, bin);
}
// Insert regions
double[][] starbucks = { { -122.1708441, 37.4241193 }, { -122.1492040, 37.4273569 }, { -122.1441078, 37.4268202 }, { -122.1251714, 37.4130590 }, { -122.0964289, 37.4218102 }, { -122.0776641, 37.4158199 }, { -122.0943475, 37.4114654 }, { -122.1122861, 37.4028493 }, { -122.0947230, 37.3909250 }, { -122.0831037, 37.3876090 }, { -122.0707119, 37.3787855 }, { -122.0303178, 37.3882739 }, { -122.0464861, 37.3786236 }, { -122.0582128, 37.3726980 }, { -122.0365083, 37.3676930 } };
for (int i = 0; i < starbucks.length; i++) {
Key key = new Key(args.namespace, setNameRegions, i);
String loc = "{ \"type\": \"AeroCircle\", \"coordinates\": [[" + starbucks[i][0] + ", " + starbucks[i][1] + "], 3000.0 ] }";
Bin bin = Bin.asGeoJSON("loc", loc);
client.put(null, key, bin);
}
}
use of com.aerospike.client.AerospikeException in project aerospike-client-java by aerospike.
the class TestQueryKey method prepare.
@BeforeClass
public static void prepare() {
Policy policy = new Policy();
// Do not timeout on index create.
policy.socketTimeout = 0;
try {
IndexTask itask = client.createIndex(policy, args.namespace, args.set, indexName, binName, IndexType.NUMERIC);
itask.waitTillComplete();
} catch (AerospikeException ae) {
if (ae.getResultCode() != ResultCode.INDEX_ALREADY_EXISTS) {
throw ae;
}
}
WritePolicy writePolicy = new WritePolicy();
writePolicy.sendKey = true;
for (int i = 1; i <= size; i++) {
Key key = new Key(args.namespace, args.set, keyPrefix + i);
Bin bin = new Bin(binName, i);
client.put(writePolicy, key, bin);
}
}
Aggregations