Search in sources :

Example 1 with EnhancedObjectInputStream

use of org.talend.sdk.component.runtime.serialization.EnhancedObjectInputStream in project component-runtime by Talend.

the class BeamComponentExtensionTest method toMapper.

@Test
public void toMapper() throws IOException, ClassNotFoundException {
    final ComponentContextImpl context = new ComponentContextImpl(BeamSource.class);
    context.setCurrentExtension(extension);
    extension.onComponent(context);
    context.setCurrentExtension(null);
    assertTrue(context.isNoValidation());
    assertEquals(extension, context.getOwningExtension());
    final Mapper mapper = extension.convert(new ComponentExtension.ComponentInstance() {

        @Override
        public Object instance() {
            return new BeamSource(asList("a", "b"));
        }

        @Override
        public String plugin() {
            // path as id
            return jarLocation(BeamComponentExtensionTest.class).getAbsolutePath();
        }

        @Override
        public String family() {
            return "test";
        }

        @Override
        public String name() {
            return "extension";
        }
    }, Mapper.class);
    assertMapper(mapper);
    // ensure the mapper is serializable even if not intended to be used this way
    final byte[] bytes = Serializer.toBytes(mapper);
    try (final ObjectInputStream ois = new EnhancedObjectInputStream(new ByteArrayInputStream(bytes), Thread.currentThread().getContextClassLoader())) {
        final Serializable deserialized = Serializable.class.cast(ois.readObject());
        assertMapper(Mapper.class.cast(deserialized));
    }
}
Also used : Serializable(java.io.Serializable) EnhancedObjectInputStream(org.talend.sdk.component.runtime.serialization.EnhancedObjectInputStream) PartitionMapper(org.talend.sdk.component.api.input.PartitionMapper) Mapper(org.talend.sdk.component.runtime.input.Mapper) ComponentContextImpl(org.talend.sdk.component.runtime.manager.extension.ComponentContextImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) ComponentExtension(org.talend.sdk.component.spi.component.ComponentExtension) ObjectInputStream(java.io.ObjectInputStream) EnhancedObjectInputStream(org.talend.sdk.component.runtime.serialization.EnhancedObjectInputStream) Test(org.junit.jupiter.api.Test)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 Serializable (java.io.Serializable)1 Test (org.junit.jupiter.api.Test)1 PartitionMapper (org.talend.sdk.component.api.input.PartitionMapper)1 Mapper (org.talend.sdk.component.runtime.input.Mapper)1 ComponentContextImpl (org.talend.sdk.component.runtime.manager.extension.ComponentContextImpl)1 EnhancedObjectInputStream (org.talend.sdk.component.runtime.serialization.EnhancedObjectInputStream)1 ComponentExtension (org.talend.sdk.component.spi.component.ComponentExtension)1