Search in sources :

Example 1 with Key

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

the class TestLargeList method runWithSerializedBin.

@Test
@SuppressWarnings("unchecked")
public void runWithSerializedBin() throws IOException {
    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>();
    ByteArrayOutputStream byteStream = new ByteArrayOutputStream(500);
    DataOutputStream writer = new DataOutputStream(byteStream);
    Calendar timestamp1 = new GregorianCalendar(2014, 6, 25, 12, 18, 43);
    map.put("key", Value.get(timestamp1.getTimeInMillis()));
    // ticker
    writer.writeUTF("IBM");
    // qty
    writer.writeInt(100);
    // price
    writer.writeDouble(181.82);
    map.put("value", Value.get(byteStream.toByteArray()));
    list.add(Value.get(map));
    Calendar timestamp2 = new GregorianCalendar(2014, 6, 26, 9, 33, 17);
    map.put("key", Value.get(timestamp2.getTimeInMillis()));
    byteStream.reset();
    // ticker
    writer.writeUTF("GE");
    // qty
    writer.writeInt(500);
    // price
    writer.writeDouble(26.36);
    map.put("value", Value.get(byteStream.toByteArray()));
    list.add(Value.get(map));
    Calendar timestamp3 = new GregorianCalendar(2014, 6, 27, 14, 40, 19);
    map.put("key", Value.get(timestamp3.getTimeInMillis()));
    byteStream.reset();
    // ticker
    writer.writeUTF("AAPL");
    // qty
    writer.writeInt(75);
    // price
    writer.writeDouble(91.85);
    map.put("value", Value.get(byteStream.toByteArray()));
    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.
    validateWithSerializedBin(results, 0, timestamp2, "GE", 500, 26.36);
    validateWithSerializedBin(results, 1, timestamp3, "AAPL", 75, 91.85);
}
Also used : HashMap(java.util.HashMap) LargeList(com.aerospike.client.large.LargeList) DataOutputStream(java.io.DataOutputStream) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) ByteArrayOutputStream(java.io.ByteArrayOutputStream) 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 2 with Key

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

the class TestLargeList method filterLargeList.

@Test
public void filterLargeList() {
    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);
    int orig1 = 1;
    int orig2 = 2;
    int orig3 = 3;
    int orig4 = 4;
    // Write values.
    llist.add(Value.get(orig1), Value.get(orig2), Value.get(orig3), Value.get(orig4));
    // Filter on values
    List<?> filterList = llist.filter("largelist_example", "my_filter_func", Value.get(orig3));
    assertNotNull(filterList);
    assertEquals(1, filterList.size());
    Long v = (Long) filterList.get(0);
    assertEquals(orig3, v.intValue());
}
Also used : LargeList(com.aerospike.client.large.LargeList) Key(com.aerospike.client.Key) Test(org.junit.Test)

Example 3 with Key

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

the class TestLargeList method runVolumeInsert.

@Test
public void runVolumeInsert() {
    if (!args.validateLDT()) {
        return;
    }
    // This key has already been created in runSimpleExample().
    Key key = new Key(args.namespace, args.set, "setkey");
    int itemCount = 2000;
    LargeList llist2 = client.getLargeList(null, key, "NumberBin");
    for (int i = itemCount; i > 0; i--) {
        llist2.add(Value.get(i));
    }
    assertEquals(2000, llist2.size());
}
Also used : LargeList(com.aerospike.client.large.LargeList) Key(com.aerospike.client.Key) Test(org.junit.Test)

Example 4 with Key

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

the class TestLargeMap method largeMap.

@Test
public void largeMap() {
    if (!args.validateLDT()) {
        return;
    }
    Key key = new Key(args.namespace, args.set, "setkey");
    String binName = args.getBinName("setbin");
    // Delete record if it already exists.
    client.delete(null, key);
    // Initialize Large Map operator.
    com.aerospike.client.large.LargeMap lmap = client.getLargeMap(null, key, binName, null);
    // Write values.
    lmap.put(Value.get("lmapName1"), Value.get("lmapValue1"));
    lmap.put(Value.get("lmapName2"), Value.get("lmapValue2"));
    lmap.put(Value.get("lmapName3"), Value.get("lmapValue3"));
    // Remove last value.
    lmap.remove(Value.get("lmapName3"));
    assertEquals(2, lmap.size());
    Map<?, ?> mapReceived = lmap.get(Value.get("lmapName2"));
    String stringReceived = (String) mapReceived.get("lmapName2");
    assertEquals("lmapValue2", stringReceived);
}
Also used : Key(com.aerospike.client.Key) Test(org.junit.Test)

Example 5 with Key

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

the class TestLargeSet method largeSet.

@Test
public void largeSet() {
    if (!args.validateLDT()) {
        return;
    }
    Key key = new Key(args.namespace, args.set, "setkey");
    String binName = args.getBinName("setbin");
    // Delete record if it already exists.
    client.delete(null, key);
    // Initialize large set operator.
    com.aerospike.client.large.LargeSet set = client.getLargeSet(null, key, binName, null);
    // Write values.
    set.add(Value.get("setvalue1"));
    set.add(Value.get("setvalue2"));
    set.add(Value.get("setvalue3"));
    // Remove last value.
    set.remove(Value.get("setvalue3"));
    assertEquals(2, set.size());
    String received = (String) set.get(Value.get("setvalue2"));
    assertEquals("setvalue2", received);
}
Also used : Key(com.aerospike.client.Key) Test(org.junit.Test)

Aggregations

Key (com.aerospike.client.Key)253 Record (com.aerospike.client.Record)140 Bin (com.aerospike.client.Bin)129 Test (org.junit.Test)105 ArrayList (java.util.ArrayList)73 Value (com.aerospike.client.Value)61 AerospikeException (com.aerospike.client.AerospikeException)60 HashMap (java.util.HashMap)47 List (java.util.List)41 WritePolicy (com.aerospike.client.policy.WritePolicy)23 Map (java.util.Map)20 BeforeClass (org.junit.BeforeClass)14 Policy (com.aerospike.client.policy.Policy)12 IndexTask (com.aerospike.client.task.IndexTask)11 Statement (com.aerospike.client.query.Statement)10 RecordSet (com.aerospike.client.query.RecordSet)9 Collections.singletonList (java.util.Collections.singletonList)9 MapPolicy (com.aerospike.client.cdt.MapPolicy)7 BatchRead (com.aerospike.client.BatchRead)6 RegisterTask (com.aerospike.client.task.RegisterTask)6