Search in sources :

Example 1 with HadoopSerializationWrapper

use of org.apache.ignite.internal.processors.hadoop.impl.v2.HadoopSerializationWrapper in project ignite by apache.

the class HadoopSerializationWrapperSelfTest method testIntWritableSerialization.

/**
 * Tests read/write of IntWritable via native WritableSerialization.
 * @throws Exception If fails.
 */
public void testIntWritableSerialization() throws Exception {
    HadoopSerialization ser = new HadoopSerializationWrapper(new WritableSerialization(), IntWritable.class);
    ByteArrayOutputStream buf = new ByteArrayOutputStream();
    DataOutput out = new DataOutputStream(buf);
    ser.write(out, new IntWritable(3));
    ser.write(out, new IntWritable(-5));
    assertEquals("[0, 0, 0, 3, -1, -1, -1, -5]", Arrays.toString(buf.toByteArray()));
    DataInput in = new DataInputStream(new ByteArrayInputStream(buf.toByteArray()));
    assertEquals(3, ((IntWritable) ser.read(in, null)).get());
    assertEquals(-5, ((IntWritable) ser.read(in, null)).get());
}
Also used : DataInput(java.io.DataInput) DataOutput(java.io.DataOutput) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) HadoopSerializationWrapper(org.apache.ignite.internal.processors.hadoop.impl.v2.HadoopSerializationWrapper) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HadoopSerialization(org.apache.ignite.internal.processors.hadoop.HadoopSerialization) DataInputStream(java.io.DataInputStream) WritableSerialization(org.apache.hadoop.io.serializer.WritableSerialization) IntWritable(org.apache.hadoop.io.IntWritable)

Example 2 with HadoopSerializationWrapper

use of org.apache.ignite.internal.processors.hadoop.impl.v2.HadoopSerializationWrapper in project ignite by apache.

the class HadoopSerializationWrapperSelfTest method testIntJavaSerialization.

/**
 * Tests read/write of Integer via native JavaleSerialization.
 * @throws Exception If fails.
 */
public void testIntJavaSerialization() throws Exception {
    HadoopSerialization ser = new HadoopSerializationWrapper(new JavaSerialization(), Integer.class);
    ByteArrayOutputStream buf = new ByteArrayOutputStream();
    DataOutput out = new DataOutputStream(buf);
    ser.write(out, 3);
    ser.write(out, -5);
    ser.close();
    DataInput in = new DataInputStream(new ByteArrayInputStream(buf.toByteArray()));
    assertEquals(3, ((Integer) ser.read(in, null)).intValue());
    assertEquals(-5, ((Integer) ser.read(in, null)).intValue());
}
Also used : DataInput(java.io.DataInput) DataOutput(java.io.DataOutput) JavaSerialization(org.apache.hadoop.io.serializer.JavaSerialization) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) HadoopSerializationWrapper(org.apache.ignite.internal.processors.hadoop.impl.v2.HadoopSerializationWrapper) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HadoopSerialization(org.apache.ignite.internal.processors.hadoop.HadoopSerialization) DataInputStream(java.io.DataInputStream)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 DataInput (java.io.DataInput)2 DataInputStream (java.io.DataInputStream)2 DataOutput (java.io.DataOutput)2 DataOutputStream (java.io.DataOutputStream)2 HadoopSerialization (org.apache.ignite.internal.processors.hadoop.HadoopSerialization)2 HadoopSerializationWrapper (org.apache.ignite.internal.processors.hadoop.impl.v2.HadoopSerializationWrapper)2 IntWritable (org.apache.hadoop.io.IntWritable)1 JavaSerialization (org.apache.hadoop.io.serializer.JavaSerialization)1 WritableSerialization (org.apache.hadoop.io.serializer.WritableSerialization)1