Search in sources :

Example 51 with Operation

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

the class TestAsyncBatch method asyncBatchReadComplex.

@Test
public void asyncBatchReadComplex() throws Exception {
    // Batch gets into one call.
    // Batch allows multiple namespaces in one call, but example test environment may only have one namespace.
    // bin * 8
    Expression exp = Exp.build(Exp.mul(Exp.intBin(BinName), Exp.val(8)));
    Operation[] ops = Operation.array(ExpOperation.read(BinName, exp, ExpReadFlags.DEFAULT));
    String[] bins = new String[] { BinName };
    List<BatchRead> records = new ArrayList<BatchRead>();
    records.add(new BatchRead(new Key(args.namespace, args.set, KeyPrefix + 1), bins));
    records.add(new BatchRead(new Key(args.namespace, args.set, KeyPrefix + 2), true));
    records.add(new BatchRead(new Key(args.namespace, args.set, KeyPrefix + 3), true));
    records.add(new BatchRead(new Key(args.namespace, args.set, KeyPrefix + 4), false));
    records.add(new BatchRead(new Key(args.namespace, args.set, KeyPrefix + 5), true));
    records.add(new BatchRead(new Key(args.namespace, args.set, KeyPrefix + 6), ops));
    records.add(new BatchRead(new Key(args.namespace, args.set, KeyPrefix + 7), bins));
    // This record should be found, but the requested bin will not be found.
    records.add(new BatchRead(new Key(args.namespace, args.set, KeyPrefix + 8), new String[] { "binnotfound" }));
    // This record should not be found.
    records.add(new BatchRead(new Key(args.namespace, args.set, "keynotfound"), bins));
    // Execute batch.
    client.get(eventLoop, new BatchListListener() {

        public void onSuccess(List<BatchRead> records) {
            // Show results.
            int found = 0;
            int count = 0;
            for (BatchRead record : records) {
                Record rec = record.record;
                count++;
                if (rec != null) {
                    found++;
                    if (count != 4 && count != 6 && count <= 7) {
                        Object value = rec.getValue(BinName);
                        if (!assertEquals(ValuePrefix + count, value)) {
                            notifyComplete();
                            return;
                        }
                    } else if (count == 6) {
                        int value = rec.getInt(BinName);
                        if (!assertEquals(48, value)) {
                            notifyComplete();
                            return;
                        }
                    } else {
                        Object value = rec.getValue(BinName);
                        if (!assertNull(value)) {
                            notifyComplete();
                            return;
                        }
                    }
                }
            }
            assertEquals(8, found);
            notifyComplete();
        }

        public void onFailure(AerospikeException e) {
            setError(e);
            notifyComplete();
        }
    }, null, records);
    waitTillComplete();
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) ArrayList(java.util.ArrayList) BatchRead(com.aerospike.client.BatchRead) ListOperation(com.aerospike.client.cdt.ListOperation) ExpOperation(com.aerospike.client.exp.ExpOperation) Operation(com.aerospike.client.Operation) BatchListListener(com.aerospike.client.listener.BatchListListener) Expression(com.aerospike.client.exp.Expression) Record(com.aerospike.client.Record) Key(com.aerospike.client.Key) Test(org.junit.Test)

Aggregations

Operation (com.aerospike.client.Operation)51 Packer (com.aerospike.client.util.Packer)36 Record (com.aerospike.client.Record)6 ArrayList (java.util.ArrayList)6 Key (com.aerospike.client.Key)5 BatchRead (com.aerospike.client.BatchRead)4 CommandExp (com.aerospike.client.exp.CommandExp)4 ListOperation (com.aerospike.client.cdt.ListOperation)3 ExpOperation (com.aerospike.client.exp.ExpOperation)3 Expression (com.aerospike.client.exp.Expression)3 HLLOperation (com.aerospike.client.operation.HLLOperation)3 HLLPolicy (com.aerospike.client.operation.HLLPolicy)3 List (java.util.List)2 Test (org.junit.Test)2 AerospikeException (com.aerospike.client.AerospikeException)1 Bin (com.aerospike.client.Bin)1 Value (com.aerospike.client.Value)1 HLLValue (com.aerospike.client.Value.HLLValue)1 StringValue (com.aerospike.client.Value.StringValue)1 BatchListListener (com.aerospike.client.listener.BatchListListener)1