Search in sources :

Example 1 with HadoopHashMultimap

use of org.apache.ignite.internal.processors.hadoop.shuffle.collections.HadoopHashMultimap in project ignite by apache.

the class HadoopHashMapSelfTest method testMapSimple.

/**
     * Test simple map.
     *
     * @throws Exception If failed.
     */
public void testMapSimple() throws Exception {
    GridUnsafeMemory mem = new GridUnsafeMemory(0);
    Random rnd = new Random();
    int mapSize = 16 << rnd.nextInt(3);
    HadoopTaskContext taskCtx = new TaskContext();
    final HadoopHashMultimap m = new HadoopHashMultimap(new JobInfo(), mem, mapSize);
    HadoopMultimap.Adder a = m.startAdding(taskCtx);
    Multimap<Integer, Integer> mm = ArrayListMultimap.create();
    for (int i = 0, vals = 4 * mapSize + rnd.nextInt(25); i < vals; i++) {
        int key = rnd.nextInt(mapSize);
        int val = rnd.nextInt();
        a.write(new IntWritable(key), new IntWritable(val));
        mm.put(key, val);
        X.println("k: " + key + " v: " + val);
        a.close();
        check(m, mm, taskCtx);
        a = m.startAdding(taskCtx);
    }
    //        a.add(new IntWritable(10), new IntWritable(2));
    //        mm.put(10, 2);
    //        check(m, mm);
    a.close();
    X.println("Alloc: " + mem.allocatedSize());
    m.close();
    assertEquals(0, mem.allocatedSize());
}
Also used : HadoopTaskContext(org.apache.ignite.internal.processors.hadoop.HadoopTaskContext) Random(java.util.Random) HadoopMultimap(org.apache.ignite.internal.processors.hadoop.shuffle.collections.HadoopMultimap) HadoopTaskContext(org.apache.ignite.internal.processors.hadoop.HadoopTaskContext) GridUnsafeMemory(org.apache.ignite.internal.util.offheap.unsafe.GridUnsafeMemory) HadoopHashMultimap(org.apache.ignite.internal.processors.hadoop.shuffle.collections.HadoopHashMultimap) IntWritable(org.apache.hadoop.io.IntWritable)

Aggregations

Random (java.util.Random)1 IntWritable (org.apache.hadoop.io.IntWritable)1 HadoopTaskContext (org.apache.ignite.internal.processors.hadoop.HadoopTaskContext)1 HadoopHashMultimap (org.apache.ignite.internal.processors.hadoop.shuffle.collections.HadoopHashMultimap)1 HadoopMultimap (org.apache.ignite.internal.processors.hadoop.shuffle.collections.HadoopMultimap)1 GridUnsafeMemory (org.apache.ignite.internal.util.offheap.unsafe.GridUnsafeMemory)1