@Test public void packIntCompat() throws IOException { DataOutputByteArray b = new DataOutputByteArray(); b.packInt(2111); b.packInt(100); b.packInt(1111); DataInputByteArray b2 = new DataInputByteArray(b.buf); assertEquals(2111, b2.unpackInt()); assertEquals(100, b2.unpackInt()); assertEquals(1111, b2.unpackInt()); DataInputByteBuffer b3 = new DataInputByteBuffer(ByteBuffer.wrap(b.buf), 0); assertEquals(2111, b3.unpackInt()); assertEquals(100, b3.unpackInt()); assertEquals(1111, b3.unpackInt()); }
@Test(timeout = 5000) public void testGetBytePayload() throws IOException { int numBuckets = 10; VertexManagerPluginContext context = mock(VertexManagerPluginContext.class); CustomVertexConfiguration vertexConf = new CustomVertexConfiguration(numBuckets, TezWork.VertexType.INITIALIZED_EDGES); DataOutputBuffer dob = new DataOutputBuffer(); vertexConf.write(dob); UserPayload payload = UserPayload.create(ByteBuffer.wrap(dob.getData())); when(context.getUserPayload()).thenReturn(payload); CustomPartitionVertex vm = new CustomPartitionVertex(context); vm.initialize(); // prepare empty routing table Multimap<Integer, Integer> routingTable = HashMultimap.<Integer, Integer>create(); payload = vm.getBytePayload(routingTable); // get conf from user payload CustomEdgeConfiguration edgeConf = new CustomEdgeConfiguration(); DataInputByteBuffer dibb = new DataInputByteBuffer(); dibb.reset(payload.getPayload()); edgeConf.readFields(dibb); assertEquals(numBuckets, edgeConf.getNumBuckets()); }