Search in sources :

Example 26 with Statement

use of com.aerospike.client.query.Statement in project aerospike-client-java by aerospike.

the class AsyncQuery method runQuery.

private void runQuery(AerospikeClient client, EventLoop eventLoop, final String binName) {
    int begin = 26;
    int end = 34;
    console.info("Query for: ns=%s set=%s bin=%s >= %s <= %s", params.namespace, params.set, binName, begin, end);
    Statement stmt = new Statement();
    stmt.setNamespace(params.namespace);
    stmt.setSetName(params.set);
    stmt.setBinNames(binName);
    stmt.setFilter(Filter.range(binName, begin, end));
    final AtomicInteger count = new AtomicInteger();
    client.query(eventLoop, new RecordSequenceListener() {

        public void onRecord(Key key, Record record) throws AerospikeException {
            int result = record.getInt(binName);
            console.info("Record found: ns=%s set=%s bin=%s digest=%s value=%s", key.namespace, key.setName, binName, Buffer.bytesToHexString(key.digest), result);
            count.incrementAndGet();
        }

        public void onSuccess() {
            int size = count.get();
            if (size != 9) {
                console.error("Query count mismatch. Expected 9. Received " + size);
            }
            notifyComplete();
        }

        public void onFailure(AerospikeException e) {
            console.error("Query failed: " + Util.getErrorMessage(e));
            notifyComplete();
        }
    }, null, stmt);
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) RecordSequenceListener(com.aerospike.client.listener.RecordSequenceListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Statement(com.aerospike.client.query.Statement) Record(com.aerospike.client.Record) Key(com.aerospike.client.Key)

Example 27 with Statement

use of com.aerospike.client.query.Statement in project aerospike-client-java by aerospike.

the class TestAsyncQuery method runQuery.

private void runQuery() {
    int begin = 26;
    int end = 34;
    Statement stmt = new Statement();
    stmt.setNamespace(args.namespace);
    stmt.setSetName(args.set);
    stmt.setBinNames(binName);
    stmt.setFilter(Filter.range(binName, begin, end));
    final AtomicInteger count = new AtomicInteger();
    client.query(eventLoop, new RecordSequenceListener() {

        public void onRecord(Key key, Record record) throws AerospikeException {
            int result = record.getInt(binName);
            assertBetween(26, 34, result);
            count.incrementAndGet();
        }

        public void onSuccess() {
            int size = count.get();
            assertEquals(9, size);
            notifyComplete();
        }

        public void onFailure(AerospikeException e) {
            setError(e);
            notifyComplete();
        }
    }, null, stmt);
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) RecordSequenceListener(com.aerospike.client.listener.RecordSequenceListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Statement(com.aerospike.client.query.Statement) Record(com.aerospike.client.Record) Key(com.aerospike.client.Key)

Example 28 with Statement

use of com.aerospike.client.query.Statement in project aerospike-client-java by aerospike.

the class TestQueryExecute method queryExecute.

@Test
public void queryExecute() {
    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));
    ExecuteTask task = client.execute(null, stmt, "record_example", "processRecord", Value.get(binName1), Value.get(binName2), Value.get(100));
    task.waitTillComplete();
    validateRecords();
}
Also used : Statement(com.aerospike.client.query.Statement) ExecuteTask(com.aerospike.client.task.ExecuteTask) Test(org.junit.Test)

Example 29 with Statement

use of com.aerospike.client.query.Statement in project aerospike-client-java by aerospike.

the class TestQueryExecute method validateRecords.

private void validateRecords() {
    int begin = 1;
    int end = size + 100;
    Statement 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[] expectedList = new int[] { 1, 2, 3, 104, 5, 106, 7, 108, -1, 10 };
        int expectedSize = size - 1;
        int count = 0;
        while (rs.next()) {
            Record record = rs.getRecord();
            int value1 = record.getInt(binName1);
            int value2 = record.getInt(binName2);
            int val1 = value1;
            if (val1 == 9) {
                fail("Data mismatch. value1 " + val1 + " should not exist");
            }
            if (val1 == 5) {
                if (value2 != 0) {
                    fail("Data mismatch. value2 " + value2 + " should be null");
                }
            } else if (value1 != expectedList[value2 - 1]) {
                fail("Data mismatch. Expected " + expectedList[value2 - 1] + ". Received " + value1);
            }
            count++;
        }
        assertEquals(expectedSize, count);
    } finally {
        rs.close();
    }
}
Also used : Statement(com.aerospike.client.query.Statement) Record(com.aerospike.client.Record) RecordSet(com.aerospike.client.query.RecordSet)

Example 30 with Statement

use of com.aerospike.client.query.Statement in project aerospike-client-java by aerospike.

the class TestQueryInteger method queryInteger.

@Test
public void queryInteger() {
    int begin = 14;
    int end = 18;
    Statement stmt = new Statement();
    stmt.setNamespace(args.namespace);
    stmt.setSetName(args.set);
    stmt.setBinNames(binName);
    stmt.setFilter(Filter.range(binName, begin, end));
    RecordSet rs = client.query(null, stmt);
    try {
        int count = 0;
        while (rs.next()) {
            count++;
        }
        assertEquals(5, count);
    } finally {
        rs.close();
    }
}
Also used : Statement(com.aerospike.client.query.Statement) RecordSet(com.aerospike.client.query.RecordSet) Test(org.junit.Test)

Aggregations

Statement (com.aerospike.client.query.Statement)37 RecordSet (com.aerospike.client.query.RecordSet)26 Test (org.junit.Test)18 Record (com.aerospike.client.Record)16 Key (com.aerospike.client.Key)9 ResultSet (com.aerospike.client.query.ResultSet)7 Map (java.util.Map)6 AerospikeException (com.aerospike.client.AerospikeException)2 RecordSequenceListener (com.aerospike.client.listener.RecordSequenceListener)2 ExecuteTask (com.aerospike.client.task.ExecuteTask)2 HashMap (java.util.HashMap)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 HashSet (java.util.HashSet)1