Search in sources :

Example 6 with LargeList

use of com.aerospike.client.large.LargeList in project aerospike-client-java by aerospike.

the class RWTaskSync method largeListGet.

@Override
protected void largeListGet(Key key) {
    LargeList list = client.getLargeList(args.writePolicy, key, "listltracker");
    List<?> results;
    long begin = System.nanoTime();
    if (counters.read.latency != null) {
        results = list.range(Value.get(1000), Value.get(begin));
        long elapsed = System.nanoTime() - begin;
        counters.read.latency.add(elapsed);
    } else {
        results = list.range(Value.get(1000), Value.get(begin));
    }
    processLargeRead(key, results);
}
Also used : LargeList(com.aerospike.client.large.LargeList)

Example 7 with LargeList

use of com.aerospike.client.large.LargeList in project aerospike-client-java by aerospike.

the class TestLargeList method distinctBinsLargeList.

@Test
@SuppressWarnings("unchecked")
public void distinctBinsLargeList() {
    if (!args.validateLDT()) {
        return;
    }
    Key key = new Key(args.namespace, args.set, "accountId");
    // Delete record if it already exists.
    client.delete(null, key);
    // Initialize large list operator.
    LargeList list = client.getLargeList(null, key, "trades");
    // Write trades
    Map<String, Value> map = new HashMap<String, Value>();
    Calendar timestamp1 = new GregorianCalendar(2014, 6, 25, 12, 18, 43);
    map.put("key", Value.get(timestamp1.getTimeInMillis()));
    map.put("ticker", Value.get("IBM"));
    map.put("qty", Value.get(100));
    map.put("price", Value.get(Double.doubleToLongBits(181.82)));
    list.add(Value.get(map));
    Calendar timestamp2 = new GregorianCalendar(2014, 6, 26, 9, 33, 17);
    map.put("key", Value.get(timestamp2.getTimeInMillis()));
    map.put("ticker", Value.get("GE"));
    map.put("qty", Value.get(500));
    map.put("price", Value.get(Double.doubleToLongBits(26.36)));
    list.add(Value.get(map));
    Calendar timestamp3 = new GregorianCalendar(2014, 6, 27, 14, 40, 19);
    map.put("key", Value.get(timestamp3.getTimeInMillis()));
    map.put("ticker", Value.get("AAPL"));
    map.put("qty", Value.get(75));
    map.put("price", Value.get(Double.doubleToLongBits(91.85)));
    list.add(Value.get(map));
    // Verify list size
    int size = list.size();
    assertEquals(3, size);
    // Filter on range of timestamps
    Calendar begin = new GregorianCalendar(2014, 6, 26);
    Calendar end = new GregorianCalendar(2014, 6, 28);
    List<Map<String, Object>> results = (List<Map<String, Object>>) list.range(Value.get(begin.getTimeInMillis()), Value.get(end.getTimeInMillis()));
    assertNotNull(results);
    assertEquals(2, results.size());
    // Verify data.
    validateWithDistinctBins(results, 0, timestamp2, "GE", 500, 26.36);
    validateWithDistinctBins(results, 1, timestamp3, "AAPL", 75, 91.85);
    List<Map<String, Object>> rows = (List<Map<String, Object>>) list.scan();
    for (Map<String, Object> row : rows) {
        for (@SuppressWarnings("unused") Map.Entry<String, Object> entry : row.entrySet()) {
        //console.Info(entry.Key.ToString());
        //console.Info(entry.Value.ToString());
        }
    }
}
Also used : HashMap(java.util.HashMap) LargeList(com.aerospike.client.large.LargeList) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) Value(com.aerospike.client.Value) ArrayList(java.util.ArrayList) LargeList(com.aerospike.client.large.LargeList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Key(com.aerospike.client.Key) Test(org.junit.Test)

Example 8 with LargeList

use of com.aerospike.client.large.LargeList in project aerospike-client-java by aerospike.

the class TestLargeList method simpleLargeList.

@Test
public void simpleLargeList() {
    if (!args.validateLDT()) {
        return;
    }
    Key key = new Key(args.namespace, args.set, "setkey");
    // Delete record if it already exists.
    client.delete(null, key);
    // Initialize large set operator.
    LargeList llist = client.getLargeList(null, key, binName);
    String orig1 = "llistValue1";
    String orig2 = "llistValue2";
    String orig3 = "llistValue3";
    // Write values.
    llist.add(Value.get(orig1));
    llist.add(Value.get(orig2));
    llist.add(Value.get(orig3));
    // Perform exists.
    boolean b = llist.exists(Value.get(orig2));
    assertTrue(b);
    b = llist.exists(Value.get("notfound"));
    assertFalse(b);
    // Test record not found.
    LargeList nflist = client.getLargeList(null, new Key(args.namespace, args.set, "sfdfdqw"), binName);
    try {
        b = nflist.exists(Value.get(orig2));
        assertFalse(b);
    } catch (AerospikeException ae) {
        assertEquals(ResultCode.KEY_NOT_FOUND_ERROR, ae.getResultCode());
    }
    List<Value> klist = new ArrayList<Value>();
    klist.add(Value.get(orig2));
    klist.add(Value.get(orig1));
    klist.add(Value.get("notfound"));
    List<Boolean> blist = llist.exists(klist);
    assertTrue(blist.get(0));
    assertTrue(blist.get(1));
    assertFalse(blist.get(2));
    // Test record not found.
    try {
        List<Boolean> blist2 = nflist.exists(klist);
        assertFalse(blist2.get(0));
        assertFalse(blist2.get(1));
        assertFalse(blist2.get(2));
    } catch (AerospikeException ae) {
        assertEquals(ResultCode.KEY_NOT_FOUND_ERROR, ae.getResultCode());
    }
    // Perform a Range Query -- look for "llistValue2" to "llistValue3"
    List<?> rangeList = llist.range(Value.get(orig2), Value.get(orig3));
    assertNotNull(rangeList);
    assertEquals(2, rangeList.size());
    String v2 = (String) rangeList.get(0);
    String v3 = (String) rangeList.get(1);
    assertEquals(orig2, v2);
    assertEquals(orig3, v3);
    // Remove last value.
    llist.remove(Value.get(orig3));
    int size = llist.size();
    assertEquals(2, size);
    List<?> listReceived = llist.find(Value.get(orig2));
    String expected = orig2;
    assertNotNull(listReceived);
    String stringReceived = (String) listReceived.get(0);
    assertNotNull(stringReceived);
    assertEquals(expected, stringReceived);
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) LargeList(com.aerospike.client.large.LargeList) ArrayList(java.util.ArrayList) Value(com.aerospike.client.Value) Key(com.aerospike.client.Key) Test(org.junit.Test)

Aggregations

LargeList (com.aerospike.client.large.LargeList)8 Key (com.aerospike.client.Key)5 Value (com.aerospike.client.Value)5 Test (org.junit.Test)5 HashMap (java.util.HashMap)4 ArrayList (java.util.ArrayList)3 Calendar (java.util.Calendar)2 GregorianCalendar (java.util.GregorianCalendar)2 List (java.util.List)2 Map (java.util.Map)2 AerospikeException (com.aerospike.client.AerospikeException)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1