Search in sources :

Example 16 with Bin

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);
}
Also used : HashMap(java.util.HashMap) Bin(com.aerospike.client.Bin) Value(com.aerospike.client.Value) Record(com.aerospike.client.Record) HashMap(java.util.HashMap) Map(java.util.Map) Key(com.aerospike.client.Key) Test(org.junit.Test)

Example 17 with Bin

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);
}
Also used : HashMap(java.util.HashMap) Bin(com.aerospike.client.Bin) Value(com.aerospike.client.Value) Record(com.aerospike.client.Record) HashMap(java.util.HashMap) Map(java.util.Map) Key(com.aerospike.client.Key) Test(org.junit.Test)

Example 18 with Bin

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);
}
Also used : Bin(com.aerospike.client.Bin) Record(com.aerospike.client.Record) Key(com.aerospike.client.Key) WritePolicy(com.aerospike.client.policy.WritePolicy) Test(org.junit.Test)

Example 19 with Bin

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);
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) Version(com.aerospike.client.util.Version) Bin(com.aerospike.client.Bin) Key(com.aerospike.client.Key) ThrowingRunnable(org.junit.function.ThrowingRunnable) Test(org.junit.Test)

Example 20 with Bin

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);
        }
    }
}
Also used : Bin(com.aerospike.client.Bin) ArrayList(java.util.ArrayList) Key(com.aerospike.client.Key) WritePolicy(com.aerospike.client.policy.WritePolicy) BeforeClass(org.junit.BeforeClass)

Aggregations

Bin (com.aerospike.client.Bin)151 Key (com.aerospike.client.Key)129 Record (com.aerospike.client.Record)70 Test (org.junit.Test)54 AerospikeException (com.aerospike.client.AerospikeException)34 ArrayList (java.util.ArrayList)31 WritePolicy (com.aerospike.client.policy.WritePolicy)27 HashMap (java.util.HashMap)22 Value (com.aerospike.client.Value)20 List (java.util.List)15 BeforeClass (org.junit.BeforeClass)14 Map (java.util.Map)13 Policy (com.aerospike.client.policy.Policy)12 IndexTask (com.aerospike.client.task.IndexTask)11 WriteListener (com.aerospike.client.listener.WriteListener)5 RegisterTask (com.aerospike.client.task.RegisterTask)5 AbstractMap (java.util.AbstractMap)4 TreeMap (java.util.TreeMap)4 CTX (com.aerospike.client.cdt.CTX)3 BitPolicy (com.aerospike.client.operation.BitPolicy)3