/** * See PIG-2936. The purpose of this test is to ensure that Tuples are being serialized in the * specific way that we expect. */ @Test public void testTupleSerializationSpecific() throws Exception { byte[] flags = { BinInterSedes.TUPLE_0, BinInterSedes.TUPLE_1, BinInterSedes.TUPLE_2, BinInterSedes.TUPLE_3, BinInterSedes.TUPLE_4, BinInterSedes.TUPLE_5, BinInterSedes.TUPLE_6, BinInterSedes.TUPLE_7, BinInterSedes.TUPLE_8, BinInterSedes.TUPLE_9, }; for (int i = 0; i < flags.length; i++) { Tuple t = mTupleFactory.newTuple(i); ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutput out = new DataOutputStream(baos); out.writeByte(flags[i]); for (int j = 0; j < i; j++) { Integer val = Integer.valueOf(random.nextInt()); bis.writeDatum(out, val); t.set(j, val); } testSerTuple(t, baos.toByteArray()); } }
private void testSerTuple(Tuple t, byte[] expected) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutput out = new DataOutputStream(baos); bis.writeDatum(out, t); Tuple t2 = (Tuple) bis.readDatum(new DataInputStream(new ByteArrayInputStream(baos.toByteArray()))); assertEquals(t, t2); }