Search in sources :

Example 1 with IntSerde

use of org.apache.apex.malhar.lib.utils.serde.IntSerde in project apex-malhar by apache.

the class SpillableArrayListMultimapImplTest method simpleMultiKeyTestHelper.

public long simpleMultiKeyTestHelper(SpillableStateStore store, SpillableArrayListMultimapImpl<String, String> map, String key, long nextWindowId) {
    StringSerde serdeString = new StringSerde();
    IntSerde serdeInt = new IntSerde();
    SerializationBuffer buffer = new SerializationBuffer(new WindowedBlockStream());
    serdeString.serialize(key, buffer);
    Slice keySlice = buffer.toSlice();
    byte[] keyBytes = SliceUtils.concatenate(ID1, keySlice.toByteArray());
    nextWindowId++;
    store.beginWindow(nextWindowId);
    map.beginWindow(nextWindowId);
    Assert.assertNull(map.get(key));
    Assert.assertFalse(map.containsKey(key));
    map.put(key, "a");
    Assert.assertTrue(map.containsKey(key));
    List<String> list1 = map.get(key);
    Assert.assertEquals(1, list1.size());
    Assert.assertEquals("a", list1.get(0));
    list1.addAll(Lists.newArrayList("a", "b", "c", "d", "e", "f", "g"));
    Assert.assertEquals(8, list1.size());
    Assert.assertEquals("a", list1.get(0));
    Assert.assertEquals("a", list1.get(1));
    Assert.assertEquals("b", list1.get(2));
    Assert.assertEquals("c", list1.get(3));
    Assert.assertEquals("d", list1.get(4));
    Assert.assertEquals("e", list1.get(5));
    Assert.assertEquals("f", list1.get(6));
    Assert.assertEquals("g", list1.get(7));
    map.endWindow();
    store.endWindow();
    nextWindowId++;
    store.beginWindow(nextWindowId);
    map.beginWindow(nextWindowId);
    SpillableTestUtils.checkValue(store, 0L, SliceUtils.concatenate(keyBytes, SpillableArrayListMultimapImpl.SIZE_KEY_SUFFIX), 8, 0, serdeInt);
    SpillableTestUtils.checkValue(store, 0L, keyBytes, 0, Lists.<String>newArrayList("a", "a", "b", "c", "d", "e", "f", "g"));
    List<String> list2 = map.get(key);
    Assert.assertEquals(8, list2.size());
    Assert.assertEquals("a", list2.get(0));
    Assert.assertEquals("a", list2.get(1));
    Assert.assertEquals("b", list2.get(2));
    Assert.assertEquals("c", list2.get(3));
    Assert.assertEquals("d", list2.get(4));
    Assert.assertEquals("e", list2.get(5));
    Assert.assertEquals("f", list2.get(6));
    Assert.assertEquals("g", list2.get(7));
    list2.add("tt");
    list2.add("ab");
    list2.add("99");
    list2.add("oo");
    Assert.assertEquals("tt", list2.get(8));
    Assert.assertEquals("ab", list2.get(9));
    Assert.assertEquals("99", list2.get(10));
    Assert.assertEquals("oo", list2.get(11));
    Assert.assertEquals(12, list2.size());
    map.endWindow();
    store.endWindow();
    nextWindowId++;
    store.beginWindow(nextWindowId);
    map.beginWindow(nextWindowId);
    Assert.assertEquals(12, list2.size());
    SpillableTestUtils.checkValue(store, 0L, SliceUtils.concatenate(keyBytes, SpillableArrayListMultimapImpl.SIZE_KEY_SUFFIX), 12, 0, serdeInt);
    SpillableTestUtils.checkValue(store, 0L, keyBytes, 0, Lists.<String>newArrayList("a", "a", "b", "c", "d", "e", "f", "g", "tt", "ab", "99", "oo"));
    List<String> list3 = map.get(key);
    list3.set(1, "111");
    list3.set(3, "222");
    list3.set(5, "333");
    list3.set(11, "444");
    Assert.assertEquals("a", list3.get(0));
    Assert.assertEquals("111", list3.get(1));
    Assert.assertEquals("b", list3.get(2));
    Assert.assertEquals("222", list3.get(3));
    Assert.assertEquals("d", list3.get(4));
    Assert.assertEquals("333", list3.get(5));
    Assert.assertEquals("f", list3.get(6));
    Assert.assertEquals("g", list3.get(7));
    Assert.assertEquals("tt", list3.get(8));
    Assert.assertEquals("ab", list3.get(9));
    Assert.assertEquals("99", list3.get(10));
    Assert.assertEquals("444", list3.get(11));
    Assert.assertEquals(12, list2.size());
    map.endWindow();
    store.endWindow();
    nextWindowId++;
    store.beginWindow(nextWindowId);
    map.beginWindow(nextWindowId);
    SpillableTestUtils.checkValue(store, 0L, SliceUtils.concatenate(keyBytes, SpillableArrayListMultimapImpl.SIZE_KEY_SUFFIX), 12, 0, serdeInt);
    SpillableTestUtils.checkValue(store, 0L, keyBytes, 0, Lists.<String>newArrayList("a", "111", "b", "222", "d", "333", "f", "g", "tt", "ab", "99", "444"));
    map.endWindow();
    store.endWindow();
    return nextWindowId;
}
Also used : SerializationBuffer(org.apache.apex.malhar.lib.utils.serde.SerializationBuffer) WindowedBlockStream(org.apache.apex.malhar.lib.utils.serde.WindowedBlockStream) StringSerde(org.apache.apex.malhar.lib.utils.serde.StringSerde) IntSerde(org.apache.apex.malhar.lib.utils.serde.IntSerde) Slice(com.datatorrent.netlet.util.Slice)

Aggregations

Slice (com.datatorrent.netlet.util.Slice)1 IntSerde (org.apache.apex.malhar.lib.utils.serde.IntSerde)1 SerializationBuffer (org.apache.apex.malhar.lib.utils.serde.SerializationBuffer)1 StringSerde (org.apache.apex.malhar.lib.utils.serde.StringSerde)1 WindowedBlockStream (org.apache.apex.malhar.lib.utils.serde.WindowedBlockStream)1