use of org.talend.components.api.container.DefaultComponentRuntimeContainerImpl in project components by Talend.
the class SalesforceWriterTestIT method testSinkAllWithStringValue.
/*
* With current API like date/datetime/int/.... string value can't be write to server side So we need convert the field
* value type.
*/
@Test
public void testSinkAllWithStringValue() throws Exception {
// Component framework objects.
ComponentDefinition sfDef = new TSalesforceOutputDefinition();
TSalesforceOutputProperties sfProps = (TSalesforceOutputProperties) sfDef.createRuntimeProperties();
SalesforceTestBase.setupProps(sfProps.connection, false);
sfProps.module.setValue("moduleName", "Event");
sfProps.module.main.schema.setValue(SCHEMA_INSERT_EVENT);
sfProps.ceaseForError.setValue(true);
// Automatically generate the out schemas.
sfProps.module.schemaListener.afterSchema();
DefaultComponentRuntimeContainerImpl container = new DefaultComponentRuntimeContainerImpl();
List<IndexedRecord> records = new ArrayList<>();
String random = createNewRandom();
IndexedRecord r1 = new GenericData.Record(SCHEMA_INSERT_EVENT);
r1.put(0, "2011-02-02T02:02:02");
r1.put(1, "2011-02-02T22:02:02.000Z");
r1.put(2, "2011-02-02");
r1.put(3, "1200");
r1.put(4, "true");
r1.put(5, random);
// Rejected and successful writes are reset on the next record.
IndexedRecord r2 = new GenericData.Record(SCHEMA_INSERT_EVENT);
r2.put(0, "2016-02-02T02:02:02.000Z");
r2.put(1, "2016-02-02T12:02:02");
r2.put(2, "2016-02-02");
r2.put(3, "600");
r2.put(4, "0");
r2.put(5, random);
records.add(r1);
records.add(r2);
SalesforceSink salesforceSink = new SalesforceSink();
salesforceSink.initialize(adaptor, sfProps);
salesforceSink.validate(adaptor);
Writer<Result> batchWriter = salesforceSink.createWriteOperation().createWriter(adaptor);
writeRows(batchWriter, records);
assertEquals(2, ((SalesforceWriter) batchWriter).getSuccessfulWrites().size());
TSalesforceInputProperties sfInputProps = getSalesforceInputProperties();
sfInputProps.copyValuesFrom(sfProps);
sfInputProps.condition.setValue("Subject = '" + random + "' ORDER BY DurationInMinutes ASC");
sfInputProps.module.main.schema.setValue(SCHEMA_INPUT_AND_DELETE_EVENT);
List<IndexedRecord> inpuRecords = readRows(sfInputProps);
try {
assertEquals(2, inpuRecords.size());
IndexedRecord inputRecords_1 = inpuRecords.get(0);
IndexedRecord inputRecords_2 = inpuRecords.get(1);
assertEquals(random, inputRecords_1.get(6));
assertEquals(random, inputRecords_2.get(6));
// we use containsInAnyOrder because we are not garanteed to have the same order every run.
assertThat(Arrays.asList("2011-02-02T02:02:02.000Z", "2016-02-02T02:02:02.000Z"), containsInAnyOrder(inputRecords_1.get(1), inputRecords_2.get(1)));
assertThat(Arrays.asList("2011-02-02T22:02:02.000Z", "2016-02-02T12:02:02.000Z"), containsInAnyOrder(inputRecords_1.get(2), inputRecords_2.get(2)));
assertThat(Arrays.asList("2011-02-02", "2016-02-02"), containsInAnyOrder(inputRecords_1.get(3), inputRecords_2.get(3)));
assertThat(Arrays.asList("1200", "600"), containsInAnyOrder(inputRecords_1.get(4), inputRecords_2.get(4)));
assertThat(Arrays.asList("true", "false"), containsInAnyOrder(inputRecords_1.get(5), inputRecords_2.get(5)));
} finally {
deleteRows(inpuRecords, sfInputProps);
}
}
use of org.talend.components.api.container.DefaultComponentRuntimeContainerImpl in project components by Talend.
the class SnowflakeReadersTestIT method testCloseExistingConnection.
@Test
public void testCloseExistingConnection() throws Throwable {
SnowflakeConnectionProperties connProps = (SnowflakeConnectionProperties) getComponentService().getComponentProperties(TSnowflakeConnectionDefinition.COMPONENT_NAME);
setupProps(connProps);
final String currentComponentName = TSnowflakeConnectionDefinition.COMPONENT_NAME + "_1";
RuntimeContainer connContainer = new DefaultComponentRuntimeContainerImpl() {
@Override
public String getCurrentComponentId() {
return currentComponentName;
}
};
SnowflakeSourceOrSink snowflakeSourceOrSink = new SnowflakeSourceOrSink();
snowflakeSourceOrSink.initialize(connContainer, connProps);
assertEquals(ValidationResult.Result.OK, snowflakeSourceOrSink.validate(connContainer).getStatus());
TSnowflakeCloseProperties closeProps = (TSnowflakeCloseProperties) getComponentService().getComponentProperties(TSnowflakeCloseDefinition.COMPONENT_NAME);
closeProps.referencedComponent.componentInstanceId.setValue(currentComponentName);
SnowflakeCloseSourceOrSink snowflakeCloseSourceOrSink = new SnowflakeCloseSourceOrSink();
snowflakeCloseSourceOrSink.initialize(connContainer, closeProps);
assertEquals(ValidationResult.Result.OK, snowflakeCloseSourceOrSink.validate(connContainer).getStatus());
}
use of org.talend.components.api.container.DefaultComponentRuntimeContainerImpl in project components by Talend.
the class SnowflakeReadersTestIT method testUseExistingConnection.
@Test
public void testUseExistingConnection() throws Throwable {
SnowflakeConnectionProperties connProps = (SnowflakeConnectionProperties) getComponentService().getComponentProperties(TSnowflakeConnectionDefinition.COMPONENT_NAME);
setupProps(connProps);
final String currentComponentName = TSnowflakeConnectionDefinition.COMPONENT_NAME + "_1";
RuntimeContainer connContainer = new DefaultComponentRuntimeContainerImpl() {
@Override
public String getCurrentComponentId() {
return currentComponentName;
}
};
SnowflakeSourceOrSink SnowflakeSourceOrSink = new SnowflakeSourceOrSink();
SnowflakeSourceOrSink.initialize(connContainer, connProps);
assertEquals(ValidationResult.Result.OK, SnowflakeSourceOrSink.validate(connContainer).getStatus());
// Input component get connection from the tSnowflakeConnection
TSnowflakeInputProperties inProps = (TSnowflakeInputProperties) getComponentService().getComponentProperties(TSnowflakeInputDefinition.COMPONENT_NAME);
inProps.connection.referencedComponent.componentInstanceId.setValue(currentComponentName);
SnowflakeSourceOrSink SnowflakeInputSourceOrSink = new SnowflakeSourceOrSink();
SnowflakeInputSourceOrSink.initialize(connContainer, inProps);
assertEquals(ValidationResult.Result.OK, SnowflakeInputSourceOrSink.validate(connContainer).getStatus());
}
use of org.talend.components.api.container.DefaultComponentRuntimeContainerImpl in project components by Talend.
the class SnowflakeReadersTestIT method testSameConnectionForSeveralReaders.
@Test(expected = IOException.class)
public void testSameConnectionForSeveralReaders() throws Throwable {
SnowflakeConnectionProperties connProps = (SnowflakeConnectionProperties) getComponentService().getComponentProperties(TSnowflakeConnectionDefinition.COMPONENT_NAME);
setupProps(connProps);
final String currentComponentName = TSnowflakeConnectionDefinition.COMPONENT_NAME + "_1";
RuntimeContainer connContainer = new DefaultComponentRuntimeContainerImpl() {
@Override
public String getCurrentComponentId() {
return currentComponentName;
}
};
SnowflakeSourceOrSink SnowflakeSourceOrSink = new SnowflakeSourceOrSink();
SnowflakeSourceOrSink.initialize(connContainer, connProps);
assertEquals(ValidationResult.Result.OK, SnowflakeSourceOrSink.validate(connContainer).getStatus());
TSnowflakeOutputProperties props = (TSnowflakeOutputProperties) getComponentService().getComponentProperties(TSnowflakeOutputDefinition.COMPONENT_NAME);
setupProps(props.getConnectionProperties());
setupTableWithStaticValues(props);
props.connection.referencedComponent.componentInstanceId.setValue(currentComponentName);
List<IndexedRecord> rows = readRows(props, connContainer);
assertEquals(100, rows.size());
// Read second time with the same properties but with new reader.
rows = readRows(props, connContainer);
assertEquals(100, rows.size());
TSnowflakeCloseProperties closeProps = (TSnowflakeCloseProperties) getComponentService().getComponentProperties(TSnowflakeCloseDefinition.COMPONENT_NAME);
closeProps.referencedComponent.componentInstanceId.setValue(currentComponentName);
SnowflakeCloseSourceOrSink snowflakeCloseSourceOrSink = new SnowflakeCloseSourceOrSink();
snowflakeCloseSourceOrSink.initialize(connContainer, closeProps);
assertEquals(ValidationResult.Result.OK, snowflakeCloseSourceOrSink.validate(connContainer).getStatus());
// After close, exception should be thrown by the reader, if we try to read with the same connection.
rows = readRows(props, connContainer);
}
use of org.talend.components.api.container.DefaultComponentRuntimeContainerImpl in project components by Talend.
the class SnowflakeWritersTestIT method testOutputFeedback.
@Test
public void testOutputFeedback() throws Throwable {
TSnowflakeOutputProperties props = (TSnowflakeOutputProperties) getComponentService().getComponentProperties(TSnowflakeOutputDefinition.COMPONENT_NAME);
setupProps(props.getConnectionProperties());
setupTableWithStaticValues(props);
props.outputAction.setStoredValue(TSnowflakeOutputProperties.OutputAction.INSERT);
DefaultComponentRuntimeContainerImpl container = new DefaultComponentRuntimeContainerImpl();
// Initialize the Sink, WriteOperation and Writer
SnowflakeSink sfSink = new SnowflakeSink();
sfSink.initialize(container, props);
sfSink.validate(container);
SnowflakeWriteOperation sfWriteOp = sfSink.createWriteOperation();
sfWriteOp.initialize(container);
SnowflakeWriter sfWriter = sfSink.createWriteOperation().createWriter(container);
sfWriter.open("uid1");
List<IndexedRecord> rows = makeRows(2);
IndexedRecord r = rows.get(0);
r.put(0, "badId");
r.put(2, "badBoolean");
r.put(4, "badDate");
r.put(5, "badTime");
r.put(6, "badTimestamp");
sfWriter.write(r);
sfWriter.write(rows.get(1));
Result wr1 = sfWriter.close();
// The rejected writes would come in here
Iterable<IndexedRecord> rejected = sfWriter.getRejectedWrites();
Iterator<IndexedRecord> it = rejected.iterator();
IndexedRecord rej;
rej = it.next();
// row
assertEquals("1", rej.get(1));
// character
assertEquals("1", rej.get(3));
assertThat((String) rej.get(4), containsString("Numeric value 'badId'"));
// byte offset
assertEquals("0", rej.get(5));
// line
assertEquals("1", rej.get(6));
// code
assertEquals("100038", rej.get(8));
rej = it.next();
// row
assertEquals("1", rej.get(1));
// character
assertEquals("13", rej.get(3));
assertThat((String) rej.get(4), containsString("Boolean value 'badBoolean'"));
// byte offset
assertEquals("12", rej.get(5));
// line
assertEquals("1", rej.get(6));
// code
assertEquals("100037", rej.get(8));
rej = it.next();
// row
assertEquals("1", rej.get(1));
// character
assertEquals("32", rej.get(3));
assertThat((String) rej.get(4), containsString("Date 'badDate'"));
// byte offset
assertEquals("31", rej.get(5));
// line
assertEquals("1", rej.get(6));
// code
assertEquals("100040", rej.get(8));
rej = it.next();
// row
assertEquals("1", rej.get(1));
// character
assertEquals("40", rej.get(3));
assertThat((String) rej.get(4), containsString("Time 'badTime'"));
// byte offset
assertEquals("39", rej.get(5));
// line
assertEquals("1", rej.get(6));
// code
assertEquals("100108", rej.get(8));
rej = it.next();
// row
assertEquals("1", rej.get(1));
// character
assertEquals("48", rej.get(3));
assertThat((String) rej.get(4), containsString("Timestamp 'badTimestamp'"));
// byte offset
assertEquals("47", rej.get(5));
// line
assertEquals("1", rej.get(6));
// code
assertEquals("100035", rej.get(8));
assertFalse(it.hasNext());
assertEquals(1, wr1.getSuccessCount());
assertEquals(1, wr1.getRejectCount());
assertEquals(2, wr1.getTotalCount());
sfWriteOp.finalize(Arrays.asList(wr1), container);
}
Aggregations