use of org.apache.avro.generic.IndexedRecord in project tdi-studio-se by Talend.
the class FlowVariablesProcessorTest method testProcessDataIterableSchemaNotInitialized.
/**
* Checks {@link FlowVariablesProcessor#processDataIterable(Iterable)} throws {@link NullPointerException}
* if {@link FlowVariablesProcessor#initSchema()} wasn't called before
*/
@Test(expected = NullPointerException.class)
public void testProcessDataIterableSchemaNotInitialized() {
Schema mainSchema = //
SchemaBuilder.record("Main").fields().name("name").type().stringType().noDefault().name("age").type().intType().noDefault().endRecord();
Schema outOfBandSchema = SchemaBuilder.record("OutOfBand").fields().name("id").type().intType().noDefault().endRecord();
Schema rootSchema = RootSchemaUtils.createRootSchema(mainSchema, outOfBandSchema);
IndexedRecord record = new GenericData.Record(rootSchema);
ArrayList<Object> records = new ArrayList<>();
records.add(record);
FlowVariablesProcessor flowVariablesProcessor = new FlowVariablesProcessor(runtimeContainer);
flowVariablesProcessor.processDataIterable(records);
}
use of org.apache.avro.generic.IndexedRecord in project tdi-studio-se by Talend.
the class FlowVariablesReaderTest method testGetCurrentRoot.
/**
* Checks {@link FlowVariablesReader#getCurrent()} returns Main data when
* wrapped {@link Reader} returns Root {@link IndexedRecord} and sets Flow variables data to {@link RuntimeContainer}
*/
@Test
public void testGetCurrentRoot() throws IOException {
Schema mainSchema = //
SchemaBuilder.record("Main").fields().name("name").type().stringType().noDefault().name("age").type().intType().noDefault().endRecord();
Schema outOfBandSchema = //
SchemaBuilder.record("OutOfBand").fields().name("id").type().intType().noDefault().endRecord();
Schema rootSchema = RootSchemaUtils.createRootSchema(mainSchema, outOfBandSchema);
IndexedRecord mainRecord = new GenericData.Record(mainSchema);
mainRecord.put(0, "Abraham Lincoln");
mainRecord.put(1, 208);
IndexedRecord outOfBandRecord = new GenericData.Record(outOfBandSchema);
outOfBandRecord.put(0, 123);
IndexedRecord rootRecord = new GenericData.Record(rootSchema);
rootRecord.put(0, mainRecord);
rootRecord.put(1, outOfBandRecord);
Reader<IndexedRecord> wrappedReader = mock(Reader.class);
when(wrappedReader.getCurrent()).thenReturn(rootRecord);
FlowVariablesReader reader = new FlowVariablesReader(wrappedReader, runtimeContainer);
Object actualData = reader.getCurrent();
assertEquals(mainRecord, actualData);
Object flowVariable = runtimeContainer.getComponentData("tComponent_1", "id");
assertNotNull(flowVariable);
assertThat(flowVariable, instanceOf(Integer.class));
assertEquals(123, flowVariable);
reader.close();
}
use of org.apache.avro.generic.IndexedRecord in project tdi-studio-se by Talend.
the class FlowVariablesReaderTest method testGetCurrentMain.
/**
* Checks {@link FlowVariablesReader#getCurrent()} returns Main data without any changes when
* wrapped {@link Reader} returns Main data
*/
@Test
public void testGetCurrentMain() throws IOException {
Schema mainSchema = //
SchemaBuilder.record("Main").fields().name("name").type().stringType().noDefault().name("age").type().intType().noDefault().endRecord();
IndexedRecord mainRecord = new GenericData.Record(mainSchema);
mainRecord.put(0, "Abraham Lincoln");
mainRecord.put(1, 208);
Reader<IndexedRecord> wrappedReader = mock(Reader.class);
when(wrappedReader.getCurrent()).thenReturn(mainRecord);
FlowVariablesReader reader = new FlowVariablesReader(wrappedReader, runtimeContainer);
Object actualMainData = reader.getCurrent();
assertEquals(mainRecord, actualMainData);
reader.close();
}
use of org.apache.avro.generic.IndexedRecord in project tdi-studio-se by Talend.
the class FlowVariablesWriterTest method testGetSuccessfulWrites.
/**
* Checks {@link FlowVariablesWriter#getSuccessfulWrites()} returns instance of {@link Iterable} with the only one
* Main {@link IndexedRecord} unwrapped from Root record
* and {@link RuntimeContainer} contains flow variable value after this method call
*/
@Test
public void testGetSuccessfulWrites() throws IOException {
Schema mainSchema = //
SchemaBuilder.record("Main").fields().name("name").type().stringType().noDefault().name("age").type().intType().noDefault().endRecord();
Schema outOfBandSchema = //
SchemaBuilder.record("OutOfBand").fields().name("id").type().intType().noDefault().endRecord();
Schema rootSchema = RootSchemaUtils.createRootSchema(mainSchema, outOfBandSchema);
IndexedRecord mainRecord = new GenericData.Record(mainSchema);
mainRecord.put(0, "Abraham Lincoln");
mainRecord.put(1, 208);
IndexedRecord outOfBandRecord = new GenericData.Record(outOfBandSchema);
outOfBandRecord.put(0, 123);
IndexedRecord rootRecord = new GenericData.Record(rootSchema);
rootRecord.put(0, mainRecord);
rootRecord.put(1, outOfBandRecord);
ArrayList<Object> records = new ArrayList<>();
records.add(rootRecord);
when(wrappedWriter.getSuccessfulWrites()).thenReturn(records);
FlowVariablesWriter<Object> writer = new FlowVariablesWriter<>(wrappedWriter, runtimeContainer);
Iterable<Object> actualDataIterable = writer.getSuccessfulWrites();
Iterator<Object> actualDataIterator = actualDataIterable.iterator();
assertTrue(actualDataIterator.hasNext());
Object actualData = actualDataIterator.next();
assertFalse(actualDataIterator.hasNext());
assertThat(actualData, instanceOf(IndexedRecord.class));
IndexedRecord actualMainRecord = (IndexedRecord) actualData;
assertEquals(mainRecord, actualMainRecord);
Object flowVariable = runtimeContainer.getComponentData("tComponent_1", "id");
assertNotNull(flowVariable);
assertThat(flowVariable, instanceOf(Integer.class));
assertEquals(123, flowVariable);
writer.close();
}
Aggregations