use of org.apache.ignite.internal.util.io.GridDataInput in project ignite by apache.
the class HadoopConcurrentHashMultimapSelftest method check.
private void check(HadoopConcurrentHashMultimap m, Multimap<Integer, Integer> mm, final Multimap<Integer, Integer> vis, HadoopTaskContext taskCtx) throws Exception {
final HadoopTaskInput in = m.input(taskCtx);
Map<Integer, Collection<Integer>> mmm = mm.asMap();
int keys = 0;
while (in.next()) {
keys++;
IntWritable k = (IntWritable) in.key();
assertNotNull(k);
Deque<Integer> vs = new LinkedList<>();
Iterator<?> it = in.values();
while (it.hasNext()) vs.addFirst(((IntWritable) it.next()).get());
Collection<Integer> exp = mmm.get(k.get());
assertEquals(exp, vs);
}
assertEquals(mmm.size(), keys);
assertEquals(m.keys(), keys);
X.println("keys: " + keys + " cap: " + m.capacity());
// Check visitor.
final byte[] buf = new byte[4];
final GridDataInput dataInput = new GridUnsafeDataInput();
m.visit(false, new HadoopConcurrentHashMultimap.Visitor() {
/**
*/
IntWritable key = new IntWritable();
/**
*/
IntWritable val = new IntWritable();
@Override
public void onKey(long keyPtr, int keySize) {
read(keyPtr, keySize, key);
}
@Override
public void onValue(long valPtr, int valSize) {
read(valPtr, valSize, val);
vis.put(key.get(), val.get());
}
private void read(long ptr, int size, Writable w) {
assert size == 4 : size;
GridUnsafe.copyOffheapHeap(ptr, buf, GridUnsafe.BYTE_ARR_OFF, size);
dataInput.bytes(buf, size);
try {
w.readFields(dataInput);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
// X.println("vis: " + vis);
assertEquals(mm, vis);
in.close();
}
use of org.apache.ignite.internal.util.io.GridDataInput in project ignite by apache.
the class HadoopSkipListSelfTest method check.
/**
* Check.
* @param m The multimap.
* @param mm The multimap storing expectations.
* @param vis The multimap to store visitor results.
* @param taskCtx The task context.
* @throws Exception On error.
*/
private void check(HadoopMultimap m, Multimap<Integer, Integer> mm, final Multimap<Integer, Integer> vis, HadoopTaskContext taskCtx) throws Exception {
final HadoopTaskInput in = m.input(taskCtx);
Map<Integer, Collection<Integer>> mmm = mm.asMap();
int keys = 0;
int prevKey = Integer.MIN_VALUE;
while (in.next()) {
keys++;
IntWritable k = (IntWritable) in.key();
assertNotNull(k);
assertTrue(k.get() > prevKey);
prevKey = k.get();
Deque<Integer> vs = new LinkedList<>();
Iterator<?> it = in.values();
while (it.hasNext()) vs.addFirst(((IntWritable) it.next()).get());
Collection<Integer> exp = mmm.get(k.get());
assertEquals(exp, vs);
}
assertEquals(mmm.size(), keys);
// ! assertEquals(m.keys(), keys);
// Check visitor.
final byte[] buf = new byte[4];
final GridDataInput dataInput = new GridUnsafeDataInput();
m.visit(false, new HadoopMultimap.Visitor() {
/**
*/
IntWritable key = new IntWritable();
/**
*/
IntWritable val = new IntWritable();
@Override
public void onKey(long keyPtr, int keySize) {
read(keyPtr, keySize, key);
}
@Override
public void onValue(long valPtr, int valSize) {
read(valPtr, valSize, val);
vis.put(key.get(), val.get());
}
private void read(long ptr, int size, Writable w) {
assert size == 4 : size;
GridUnsafe.copyOffheapHeap(ptr, buf, GridUnsafe.BYTE_ARR_OFF, size);
dataInput.bytes(buf, size);
try {
w.readFields(dataInput);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
// X.println("vis: " + vis);
assertEquals(mm, vis);
in.close();
}
Aggregations