Search in sources :

Example 1 with Partitioner

use of org.apache.accumulo.core.util.LocalityGroupUtil.Partitioner in project accumulo by apache.

the class PartitionerTest method test1.

@Test
public void test1() {
    PreAllocatedArray<Map<ByteSequence, MutableLong>> groups = new PreAllocatedArray<>(2);
    groups.set(0, new HashMap<>());
    groups.get(0).put(new ArrayByteSequence("cf1"), new MutableLong(1));
    groups.get(0).put(new ArrayByteSequence("cf2"), new MutableLong(1));
    groups.set(1, new HashMap<>());
    groups.get(1).put(new ArrayByteSequence("cf3"), new MutableLong(1));
    Partitioner p1 = new Partitioner(groups);
    Mutation m1 = new Mutation("r1");
    m1.put("cf1", "cq1", "v1");
    Mutation m2 = new Mutation("r2");
    m2.put("cf1", "cq1", "v2");
    m2.put("cf2", "cq2", "v3");
    Mutation m3 = new Mutation("r3");
    m3.put("cf1", "cq1", "v4");
    m3.put("cf3", "cq2", "v5");
    Mutation m4 = new Mutation("r4");
    m4.put("cf1", "cq1", "v6");
    m4.put("cf3", "cq2", "v7");
    m4.put("cf5", "cq3", "v8");
    Mutation m5 = new Mutation("r5");
    m5.put("cf5", "cq3", "v9");
    List<Mutation> mutations = Arrays.asList(m1, m2, m3, m4, m5);
    PreAllocatedArray<List<Mutation>> partitioned = new PreAllocatedArray<>(3);
    for (int i = 0; i < partitioned.length; i++) {
        partitioned.set(i, new ArrayList<>());
    }
    p1.partition(mutations, partitioned);
    m1 = new Mutation("r1");
    m1.put("cf1", "cq1", "v1");
    m2 = new Mutation("r2");
    m2.put("cf1", "cq1", "v2");
    m2.put("cf2", "cq2", "v3");
    m3 = new Mutation("r3");
    m3.put("cf1", "cq1", "v4");
    m4 = new Mutation("r4");
    m4.put("cf1", "cq1", "v6");
    Assert.assertEquals(toKeySet(m1, m2, m3, m4), toKeySet(partitioned.get(0)));
    m3 = new Mutation("r3");
    m3.put("cf3", "cq2", "v5");
    m4 = new Mutation("r4");
    m4.put("cf3", "cq2", "v7");
    Assert.assertEquals(toKeySet(m3, m4), toKeySet(partitioned.get(1)));
    m4 = new Mutation("r4");
    m4.put("cf5", "cq3", "v8");
    Assert.assertEquals(toKeySet(m4, m5), toKeySet(partitioned.get(2)));
}
Also used : MutableLong(org.apache.commons.lang.mutable.MutableLong) ArrayList(java.util.ArrayList) List(java.util.List) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence) Mutation(org.apache.accumulo.core.data.Mutation) HashMap(java.util.HashMap) Map(java.util.Map) Partitioner(org.apache.accumulo.core.util.LocalityGroupUtil.Partitioner) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 ArrayByteSequence (org.apache.accumulo.core.data.ArrayByteSequence)1 Mutation (org.apache.accumulo.core.data.Mutation)1 Partitioner (org.apache.accumulo.core.util.LocalityGroupUtil.Partitioner)1 MutableLong (org.apache.commons.lang.mutable.MutableLong)1 Test (org.junit.Test)1