Search in sources :

Example 1 with HadoopSplitWrapper

use of org.apache.ignite.internal.processors.hadoop.HadoopSplitWrapper in project ignite by apache.

the class HadoopUtils method wrapSplit.

/**
     * Wraps native split.
     *
     * @param id Split ID.
     * @param split Split.
     * @param hosts Hosts.
     * @throws IOException If failed.
     */
public static HadoopSplitWrapper wrapSplit(int id, Object split, String[] hosts) throws IOException {
    ByteArrayOutputStream arr = new ByteArrayOutputStream();
    ObjectOutput out = new ObjectOutputStream(arr);
    assert split instanceof Writable;
    ((Writable) split).write(out);
    out.flush();
    return new HadoopSplitWrapper(id, split.getClass().getName(), arr.toByteArray(), hosts);
}
Also used : HadoopSplitWrapper(org.apache.ignite.internal.processors.hadoop.HadoopSplitWrapper) ObjectOutput(java.io.ObjectOutput) Writable(org.apache.hadoop.io.Writable) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream)

Example 2 with HadoopSplitWrapper

use of org.apache.ignite.internal.processors.hadoop.HadoopSplitWrapper in project ignite by apache.

the class HadoopSplitWrapperSelfTest method testSerialization.

/**
     * Tests serialization of wrapper and the wrapped native split.
     * @throws Exception If fails.
     */
public void testSerialization() throws Exception {
    FileSplit nativeSplit = new FileSplit(new Path("/path/to/file"), 100, 500, new String[] { "host1", "host2" });
    assertEquals("/path/to/file:100+500", nativeSplit.toString());
    HadoopSplitWrapper split = HadoopUtils.wrapSplit(10, nativeSplit, nativeSplit.getLocations());
    assertEquals("[host1, host2]", Arrays.toString(split.hosts()));
    ByteArrayOutputStream buf = new ByteArrayOutputStream();
    ObjectOutput out = new ObjectOutputStream(buf);
    out.writeObject(split);
    ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buf.toByteArray()));
    final HadoopSplitWrapper res = (HadoopSplitWrapper) in.readObject();
    assertEquals("/path/to/file:100+500", HadoopUtils.unwrapSplit(res).toString());
    GridTestUtils.assertThrows(log, new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            res.hosts();
            return null;
        }
    }, AssertionError.class, null);
}
Also used : Path(org.apache.hadoop.fs.Path) ObjectOutput(java.io.ObjectOutput) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileSplit(org.apache.hadoop.mapreduce.lib.input.FileSplit) ObjectOutputStream(java.io.ObjectOutputStream) HadoopSplitWrapper(org.apache.ignite.internal.processors.hadoop.HadoopSplitWrapper) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInput(java.io.ObjectInput) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ObjectOutput (java.io.ObjectOutput)2 ObjectOutputStream (java.io.ObjectOutputStream)2 HadoopSplitWrapper (org.apache.ignite.internal.processors.hadoop.HadoopSplitWrapper)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ObjectInput (java.io.ObjectInput)1 ObjectInputStream (java.io.ObjectInputStream)1 Path (org.apache.hadoop.fs.Path)1 Writable (org.apache.hadoop.io.Writable)1 FileSplit (org.apache.hadoop.mapreduce.lib.input.FileSplit)1