Search in sources :

Example 46 with Bin

use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.

the class TestBitExp method callModify.

@Test
public void callModify() {
    Key key = new Key(args.namespace, args.set, 5001);
    client.delete(null, key);
    Bin bin = new Bin(binA, new byte[] { 0x01, 0x42, 0x03, 0x04, 0x05 });
    client.put(null, key, bin);
    resize(key);
    insert(key);
    remove(key);
    set(key);
    or(key);
    xor(key);
    and(key);
    not(key);
    lshift(key);
    rshift(key);
    add(key);
    subtract(key);
    setInt(key);
}
Also used : Bin(com.aerospike.client.Bin) Key(com.aerospike.client.Key) Test(org.junit.Test)

Example 47 with Bin

use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.

the class TestUDF method writeUsingUdf.

@Test
public void writeUsingUdf() {
    Key key = new Key(args.namespace, args.set, "udfkey1");
    Bin bin = new Bin(args.getBinName("udfbin1"), "string value");
    client.execute(null, key, "record_example", "writeBin", Value.get(bin.name), bin.value);
    Record record = client.get(null, key, bin.name);
    assertBinEqual(key, record, bin);
}
Also used : Bin(com.aerospike.client.Bin) Record(com.aerospike.client.Record) Key(com.aerospike.client.Key) Test(org.junit.Test)

Example 48 with Bin

use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.

the class TestQueryFilter method writeRecord.

private static void writeRecord(String userKey, String name, String password) {
    Key key = new Key(args.namespace, args.set, userKey);
    Bin bin1 = new Bin("name", name);
    Bin bin2 = new Bin("password", password);
    client.put(null, key, bin1, bin2);
}
Also used : Bin(com.aerospike.client.Bin) Key(com.aerospike.client.Key)

Example 49 with Bin

use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.

the class TestQueryExecute method queryExecuteOperate.

@Test
public void queryExecuteOperate() {
    int begin = 3;
    int end = 9;
    Statement stmt = new Statement();
    stmt.setNamespace(args.namespace);
    stmt.setSetName(args.set);
    stmt.setFilter(Filter.range(binName1, begin, end));
    Bin bin = new Bin("foo", "bar");
    ExecuteTask task = client.execute(null, stmt, Operation.put(bin));
    task.waitTillComplete(3000, 3000);
    String expected = bin.value.toString();
    stmt = new Statement();
    stmt.setNamespace(args.namespace);
    stmt.setSetName(args.set);
    stmt.setFilter(Filter.range(binName1, begin, end));
    RecordSet rs = client.query(null, stmt);
    try {
        int count = 0;
        while (rs.next()) {
            Record record = rs.getRecord();
            String value = record.getString(bin.name);
            if (value == null) {
                fail("Bin " + bin.name + " not found");
            }
            if (!value.equals(expected)) {
                fail("Data mismatch. Expected " + expected + ". Received " + value);
            }
            count++;
        }
        assertEquals(end - begin + 1, count);
    } finally {
        rs.close();
    }
}
Also used : Statement(com.aerospike.client.query.Statement) Bin(com.aerospike.client.Bin) Record(com.aerospike.client.Record) RecordSet(com.aerospike.client.query.RecordSet) ExecuteTask(com.aerospike.client.task.ExecuteTask) Test(org.junit.Test)

Example 50 with Bin

use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.

the class TestQueryFilterExp 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.NUMERIC);
        task.waitTillComplete();
    } catch (AerospikeException ae) {
        if (ae.getResultCode() != ResultCode.INDEX_ALREADY_EXISTS) {
            throw ae;
        }
    }
    // Write records with string keys
    for (int i = 1; i <= size; i++) {
        Key key = new Key(args.namespace, setName, keyPrefix + i);
        List<Integer> list = null;
        Map<String, String> map = null;
        if (i == 1) {
            list = new ArrayList<Integer>(5);
            list.add(1);
            list.add(2);
            list.add(4);
            list.add(9);
            list.add(20);
        // map will be null, which means mapbin will not exist in this record.
        } else if (i == 2) {
            list = new ArrayList<Integer>(3);
            list.add(5);
            list.add(9);
            list.add(100);
        // map will be null, which means mapbin will not exist in this record.
        } else if (i == 3) {
            map = new HashMap<String, String>();
            map.put("A", "AAA");
            map.put("B", "BBB");
            map.put("C", "BBB");
        // list will be null, which means listbin will not exist in this record.
        } else {
            list = new ArrayList<Integer>(0);
            map = new HashMap<String, String>(0);
        }
        client.put(null, key, new Bin(binName, i), new Bin("bin2", i), new Bin("listbin", list), new Bin("mapbin", map));
    }
}
Also used : Policy(com.aerospike.client.policy.Policy) QueryPolicy(com.aerospike.client.policy.QueryPolicy) AerospikeException(com.aerospike.client.AerospikeException) Bin(com.aerospike.client.Bin) IndexTask(com.aerospike.client.task.IndexTask) ArrayList(java.util.ArrayList) Key(com.aerospike.client.Key) 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