use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.
the class TestOperateMap method operateDoubleNestedMap.
@Test
public void operateDoubleNestedMap() {
Key key = new Key(args.namespace, args.set, "opmkey20");
client.delete(null, key);
Map<Value, Value> m11 = new HashMap<Value, Value>();
m11.put(Value.get("key111"), Value.get(1));
Map<Value, Value> m12 = new HashMap<Value, Value>();
m12.put(Value.get("key121"), Value.get(5));
Map<Value, Value> m1 = new HashMap<Value, Value>();
m1.put(Value.get("key11"), Value.get(m11));
m1.put(Value.get("key12"), Value.get(m12));
Map<Value, Value> m21 = new HashMap<Value, Value>();
m21.put(Value.get("key211"), Value.get(7));
Map<Value, Value> m2 = new HashMap<Value, Value>();
m2.put(Value.get("key21"), Value.get(m21));
Map<Value, Value> inputMap = new HashMap<Value, Value>();
inputMap.put(Value.get("key1"), Value.get(m1));
inputMap.put(Value.get("key2"), Value.get(m2));
// Create maps.
client.put(null, key, new Bin(binName, inputMap));
// Set map value to 11 for map key "key21" inside of map key "key2"
// and retrieve all maps.
Record record = client.operate(null, key, MapOperation.put(MapPolicy.Default, binName, Value.get("key121"), Value.get(11), CTX.mapKey(Value.get("key1")), CTX.mapRank(-1)), Operation.get(binName));
assertRecordFound(key, record);
// System.out.println("Record: " + record);
List<?> results = record.getList(binName);
int i = 0;
long count = (Long) results.get(i++);
assertEquals(1, count);
Map<?, ?> map = (Map<?, ?>) results.get(i++);
assertEquals(2, map.size());
map = (Map<?, ?>) map.get("key1");
assertEquals(2, map.size());
map = (Map<?, ?>) map.get("key12");
assertEquals(1, map.size());
long v = (Long) map.get("key121");
assertEquals(11, v);
}
use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.
the class TestOperateMap method operateMapCreateContext.
@Test
public void operateMapCreateContext() {
Key key = new Key(args.namespace, args.set, "opmkey22");
client.delete(null, key);
Map<Value, Value> m1 = new HashMap<Value, Value>();
m1.put(Value.get("key11"), Value.get(9));
m1.put(Value.get("key12"), Value.get(4));
Map<Value, Value> m2 = new HashMap<Value, Value>();
m2.put(Value.get("key21"), Value.get(3));
m2.put(Value.get("key22"), Value.get(5));
Map<Value, Value> inputMap = new HashMap<Value, Value>();
inputMap.put(Value.get("key1"), Value.get(m1));
inputMap.put(Value.get("key2"), Value.get(m2));
// Create maps.
client.put(null, key, new Bin(binName, inputMap));
// Set map value to 11 for map key "key21" inside of map key "key2"
// and retrieve all maps.
Record record = client.operate(null, key, MapOperation.create(binName, MapOrder.KEY_ORDERED, CTX.mapKey(Value.get("key3"))), MapOperation.put(MapPolicy.Default, binName, Value.get("key31"), Value.get(99), CTX.mapKey(Value.get("key3"))), // MapOperation.put(MapPolicy.Default, binName, Value.get("key31"), Value.get(99), CTX.mapKeyCreate(Value.get("key3"), MapOrder.KEY_ORDERED)),
Operation.get(binName));
assertRecordFound(key, record);
// System.out.println("Record: " + record);
List<?> results = record.getList(binName);
int i = 1;
long count = (Long) results.get(i++);
assertEquals(1, count);
Map<?, ?> map = (Map<?, ?>) results.get(i++);
assertEquals(3, map.size());
map = (Map<?, ?>) map.get("key3");
long v = (Long) map.get("key31");
assertEquals(99, v);
}
use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.
the class TestTouch method touch.
@Test
public void touch() {
Key key = new Key(args.namespace, args.set, "touchkey");
Bin bin = new Bin(args.getBinName("touchbin"), "touchvalue");
WritePolicy writePolicy = new WritePolicy();
writePolicy.expiration = 2;
client.put(writePolicy, key, bin);
writePolicy.expiration = 5;
Record record = client.operate(writePolicy, key, Operation.touch(), Operation.getHeader());
assertRecordFound(key, record);
assertNotEquals(0, record.expiration);
Util.sleep(3000);
record = client.get(null, key, bin.name);
assertRecordFound(key, record);
Util.sleep(4000);
record = client.get(null, key, bin.name);
assertNull(record);
}
use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.
the class TestAdd method addNullValue.
@Test
public void addNullValue() {
Version version = Version.getServerVersion(client, null);
// Do not run on servers < 3.6.1
if (version.isLess(3, 6, 1)) {
return;
}
Key key = new Key(args.namespace, args.set, "addkey");
String binName = args.getBinName("addbin");
// Delete record if it already exists.
client.delete(null, key);
Bin bin = new Bin(binName, (Long) null);
AerospikeException ae = assertThrows(AerospikeException.class, new ThrowingRunnable() {
public void run() {
client.add(null, key, bin);
}
});
assertEquals(ae.getResultCode(), ResultCode.PARAMETER_ERROR);
}
use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.
the class TestBatch method writeRecords.
@BeforeClass
public static void writeRecords() {
WritePolicy policy = new WritePolicy();
policy.expiration = 2592000;
for (int i = 1; i <= Size; i++) {
Key key = new Key(args.namespace, args.set, KeyPrefix + i);
Bin bin = new Bin(BinName, ValuePrefix + i);
List<Integer> list = new ArrayList<Integer>();
for (int j = 0; j < i; j++) {
list.add(j * i);
}
Bin listBin = new Bin(ListBin, list);
if (i != 6) {
client.put(policy, key, bin, listBin);
} else {
client.put(policy, key, new Bin(BinName, i), listBin);
}
}
}
Aggregations