Search in sources :

Example 1 with TezEntityDescriptorProto

use of org.apache.tez.dag.api.records.DAGProtos.TezEntityDescriptorProto in project tez by apache.

the class TestDagTypeConverters method testTezEntityDescriptorSerialization.

@Test(timeout = 5000)
public void testTezEntityDescriptorSerialization() throws IOException {
    UserPayload payload = UserPayload.create(ByteBuffer.wrap(new String("Foobar").getBytes()), 100);
    String historytext = "Bar123";
    EntityDescriptor entityDescriptor = InputDescriptor.create("inputClazz").setUserPayload(payload).setHistoryText(historytext);
    TezEntityDescriptorProto proto = DagTypeConverters.convertToDAGPlan(entityDescriptor);
    Assert.assertEquals(payload.getVersion(), proto.getTezUserPayload().getVersion());
    Assert.assertArrayEquals(payload.deepCopyAsArray(), proto.getTezUserPayload().getUserPayload().toByteArray());
    assertTrue(proto.hasHistoryText());
    Assert.assertNotEquals(historytext, proto.getHistoryText());
    Assert.assertEquals(historytext, new String(TezCommonUtils.decompressByteStringToByteArray(proto.getHistoryText())));
    // Ensure that the history text is not deserialized
    InputDescriptor inputDescriptor = DagTypeConverters.convertInputDescriptorFromDAGPlan(proto);
    Assert.assertNull(inputDescriptor.getHistoryText());
    // Check history text value
    String actualHistoryText = DagTypeConverters.getHistoryTextFromProto(proto, TezCommonUtils.newInflater());
    Assert.assertEquals(historytext, actualHistoryText);
}
Also used : TezEntityDescriptorProto(org.apache.tez.dag.api.records.DAGProtos.TezEntityDescriptorProto) Test(org.junit.Test)

Example 2 with TezEntityDescriptorProto

use of org.apache.tez.dag.api.records.DAGProtos.TezEntityDescriptorProto in project tez by apache.

the class TestDagTypeConverters method verifyPlugins.

private void verifyPlugins(List<TezNamedEntityDescriptorProto> entities, int expectedCount, String baseString, boolean hasPayload) {
    assertEquals(expectedCount, entities.size());
    for (int i = 0; i < expectedCount; i++) {
        assertEquals(indexedEntity(baseString, i), entities.get(i).getName());
        TezEntityDescriptorProto subEntityProto = entities.get(i).getEntityDescriptor();
        assertEquals(append(indexedEntity(baseString, i), classSuffix), subEntityProto.getClassName());
        assertEquals(hasPayload, subEntityProto.hasTezUserPayload());
        if (hasPayload) {
            UserPayload userPayload = UserPayload.create(subEntityProto.getTezUserPayload().getUserPayload().asReadOnlyByteBuffer(), subEntityProto.getTezUserPayload().getVersion());
            ByteBuffer bb = userPayload.getPayload();
            assertNotNull(bb);
            assertEquals(i, bb.getInt());
        }
    }
}
Also used : TezEntityDescriptorProto(org.apache.tez.dag.api.records.DAGProtos.TezEntityDescriptorProto) ByteBuffer(java.nio.ByteBuffer)

Aggregations

TezEntityDescriptorProto (org.apache.tez.dag.api.records.DAGProtos.TezEntityDescriptorProto)2 ByteBuffer (java.nio.ByteBuffer)1 Test (org.junit.Test)1