use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.
the class TestListMap method mapStrings.
@Test
public void mapStrings() {
Key key = new Key(args.namespace, args.set, "mapkey1");
client.delete(null, key);
HashMap<String, String> map = new HashMap<String, String>();
map.put("key1", "string1");
map.put("key2", "loooooooooooooooooooooooooongerstring2");
map.put("key3", "string3");
Bin bin = new Bin(args.getBinName("mapbin1"), map);
client.put(null, key, bin);
Record record = client.get(null, key, bin.name);
Map<?, ?> receivedMap = (Map<?, ?>) record.getValue(bin.name);
assertEquals(3, receivedMap.size());
assertEquals("string1", receivedMap.get("key1"));
assertEquals("loooooooooooooooooooooooooongerstring2", receivedMap.get("key2"));
assertEquals("string3", receivedMap.get("key3"));
}
use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.
the class TestListMap method listStrings.
@Test
public void listStrings() {
Key key = new Key(args.namespace, args.set, "listkey1");
client.delete(null, key);
ArrayList<String> list = new ArrayList<String>();
list.add("string1");
list.add("string2");
list.add("string3");
Bin bin = new Bin(args.getBinName("listbin1"), list);
client.put(null, key, bin);
Record record = client.get(null, key, bin.name);
List<?> receivedList = (List<?>) record.getValue(bin.name);
assertEquals(3, receivedList.size());
assertEquals("string1", receivedList.get(0));
assertEquals("string2", receivedList.get(1));
assertEquals("string3", receivedList.get(2));
}
use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.
the class TestListMap method listMapCombined.
@Test
public void listMapCombined() {
Key key = new Key(args.namespace, args.set, "listmapkey");
client.delete(null, key);
byte[] blob = new byte[] { 3, 52, 125 };
ArrayList<Object> inner = new ArrayList<Object>();
inner.add("string2");
inner.add(5);
HashMap<Object, Object> innerMap = new HashMap<Object, Object>();
innerMap.put("a", 1);
innerMap.put(2, "b");
innerMap.put(3, blob);
innerMap.put("list", inner);
ArrayList<Object> list = new ArrayList<Object>();
list.add("string1");
list.add(8);
list.add(inner);
list.add(innerMap);
Bin bin = new Bin(args.getBinName("listmapbin"), list);
client.put(null, key, bin);
Record record = client.get(null, key, bin.name);
List<?> received = (List<?>) record.getValue(bin.name);
assertEquals(4, received.size());
assertEquals("string1", received.get(0));
// Server convert numbers to long, so must expect long.
assertEquals(8L, received.get(1));
List<?> receivedInner = (List<?>) received.get(2);
assertEquals(2, receivedInner.size());
assertEquals("string2", receivedInner.get(0));
assertEquals(5L, receivedInner.get(1));
Map<?, ?> receivedMap = (Map<?, ?>) received.get(3);
assertEquals(4, receivedMap.size());
assertEquals(1L, receivedMap.get("a"));
assertEquals("b", receivedMap.get(2L));
assertArrayEquals(blob, (byte[]) receivedMap.get(3L));
List<?> receivedInner2 = (List<?>) receivedMap.get("list");
assertEquals(2, receivedInner2.size());
assertEquals("string2", receivedInner2.get(0));
assertEquals(5L, receivedInner2.get(1));
}
use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.
the class TestListMap method sortedMapReplace.
@Test
public void sortedMapReplace() {
Key key = new Key(args.namespace, args.set, "mapkey3");
client.delete(null, key);
List<Entry<Integer, String>> list = new ArrayList<Entry<Integer, String>>();
list.add(new AbstractMap.SimpleEntry<Integer, String>(1, "s1"));
list.add(new AbstractMap.SimpleEntry<Integer, String>(2, "s2"));
list.add(new AbstractMap.SimpleEntry<Integer, String>(3, "s3"));
WritePolicy policy = new WritePolicy();
policy.recordExistsAction = RecordExistsAction.REPLACE;
Bin bin = new Bin("mapbin", list, MapOrder.KEY_VALUE_ORDERED);
client.put(policy, key, bin);
Record record = client.get(null, key, bin.name);
// System.out.println(record);
// It's unfortunate that the client returns a tree map here because
// KEY_VALUE_ORDERED is sorted by key and then by value. TreeMap
// does not support this sorting behavior...
//
// TODO: Return List<Entry<?,?>> for KEY_VALUE_ORDERED maps. This
// would be a breaking change.
TreeMap<?, ?> receivedMap = (TreeMap<?, ?>) record.getValue(bin.name);
assertEquals(3, receivedMap.size());
assertEquals("s1", receivedMap.get((long) 1));
assertEquals("s2", receivedMap.get((long) 2));
assertEquals("s3", receivedMap.get((long) 3));
}
use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.
the class TestListMap method mapComplex.
@Test
public void mapComplex() {
Key key = new Key(args.namespace, args.set, "mapkey2");
client.delete(null, key);
byte[] blob = new byte[] { 3, 52, 125 };
List<Integer> list = new ArrayList<Integer>();
list.add(100034);
list.add(12384955);
list.add(3);
list.add(512);
HashMap<Object, Object> map = new HashMap<Object, Object>();
map.put("key1", "string1");
map.put("key2", 2);
map.put("key3", blob);
// map.put("key4", Value.getAsList(list)) works too
map.put("key4", list);
map.put("key5", true);
map.put("key6", false);
Bin bin = new Bin(args.getBinName("mapbin2"), map);
client.put(null, key, bin);
Record record = client.get(null, key, bin.name);
Map<?, ?> receivedMap = (Map<?, ?>) record.getValue(bin.name);
assertEquals(6, receivedMap.size());
assertEquals("string1", receivedMap.get("key1"));
// Server convert numbers to long, so must expect long.
assertEquals(2L, receivedMap.get("key2"));
assertArrayEquals(blob, (byte[]) receivedMap.get("key3"));
List<?> receivedInner = (List<?>) receivedMap.get("key4");
assertEquals(4, receivedInner.size());
assertEquals(100034L, receivedInner.get(0));
assertEquals(12384955L, receivedInner.get(1));
assertEquals(3L, receivedInner.get(2));
assertEquals(512L, receivedInner.get(3));
assertEquals(true, receivedMap.get("key5"));
assertEquals(false, receivedMap.get("key6"));
}
Aggregations