Search in sources :

Example 1 with WritableSerialization

use of org.apache.hadoop.io.serializer.WritableSerialization 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)

Aggregations

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