use of org.talend.components.api.exception.ComponentException in project components by Talend.
the class JDBCRowTestIT method test_die_on_error_as_output.
@SuppressWarnings("rawtypes")
@Test
public void test_die_on_error_as_output() throws Exception {
TJDBCRowDefinition definition = new TJDBCRowDefinition();
TJDBCRowProperties properties = DBTestUtils.createCommonJDBCRowProperties(allSetting, definition);
Schema schema = DBTestUtils.createTestSchema(tablename);
properties.main.schema.setValue(schema);
properties.updateOutputSchemas();
properties.tableSelection.tablename.setValue(tablename);
properties.sql.setValue("insert into " + tablename + " values(?,?)");
properties.dieOnError.setValue(true);
randomCommit(properties);
properties.usePreparedStatement.setValue(true);
properties.preparedStatementTable.indexs.setValue(Arrays.asList(1, 2));
properties.preparedStatementTable.types.setValue(Arrays.asList(PreparedStatementTable.Type.Int.name(), PreparedStatementTable.Type.String.name()));
properties.preparedStatementTable.values.setValue(Arrays.<Object>asList(4, "a too long value"));
JDBCRowSink sink = new JDBCRowSink();
sink.initialize(null, properties);
ValidationResult result = sink.validate(null);
Assert.assertTrue(result.getStatus() == ValidationResult.Result.OK);
WriteOperation operation = sink.createWriteOperation();
JDBCRowWriter writer = (JDBCRowWriter) operation.createWriter(null);
try {
writer.open("wid");
IndexedRecord r1 = new GenericData.Record(properties.main.schema.getValue());
r1.put(0, 4);
r1.put(1, "xiaoming");
writer.write(r1);
writer.close();
} catch (ComponentException e) {
ExceptionContext context = e.getContext();
Assert.assertTrue(context != null);
String contextMessage = context.toString();
Assert.assertTrue(contextMessage != null && !contextMessage.isEmpty());
Assert.assertNotNull(e.getCause());
} finally {
writer.close();
}
}
use of org.talend.components.api.exception.ComponentException in project components by Talend.
the class JDBCOutputTestIT method testDieOnError.
@Test(expected = ComponentException.class)
public void testDieOnError() throws Exception {
TJDBCOutputDefinition definition = new TJDBCOutputDefinition();
TJDBCOutputProperties properties = DBTestUtils.createCommonJDBCOutputProperties(allSetting, definition);
Schema schema = DBTestUtils.createTestSchema2(tablename);
properties.main.schema.setValue(schema);
properties.updateOutputSchemas();
properties.tableSelection.tablename.setValue(tablename);
DataAction action = DBTestUtils.randomDataActionExceptDelete();
properties.dataAction.setValue(action);
properties.dieOnError.setValue(true);
properties.useBatch.setValue(DBTestUtils.randomBoolean());
properties.batchSize.setValue(DBTestUtils.randomInt());
// we set it like this to avoid the dead lock when this case :
// when die on error and not auto commit mode, we throw the exception, but not call commit or rollback in the finally
// part, it may make the dead lock for derby
// in all the javajet db components, we have this issue too, but different db, different result, in my view, we should
// process
// it, will create another test to show the dead lock issue for derby
// or set value to 0 mean use the default commit mode, for derby, it's auto commit
properties.commitEvery.setValue(null);
JDBCOutputWriter writer = DBTestUtils.createCommonJDBCOutputWriter(definition, properties);
try {
writer.open("wid");
IndexedRecord r1 = new GenericData.Record(properties.main.schema.getValue());
r1.put(0, 1);
r1.put(1, "xiaoming");
writer.write(r1);
DBTestUtils.assertSuccessRecord(writer, r1);
IndexedRecord r2 = new GenericData.Record(properties.main.schema.getValue());
r2.put(0, 2);
r2.put(1, "too long value");
writer.write(r2);
writer.close();
Assert.fail("should not run here");
} catch (ComponentException e) {
ExceptionContext context = e.getContext();
Assert.assertTrue(context != null);
String contextMessage = context.toString();
Assert.assertTrue(contextMessage != null && !contextMessage.isEmpty());
Assert.assertNotNull(e.getCause());
throw e;
} finally {
writer.close();
}
}
use of org.talend.components.api.exception.ComponentException in project components by Talend.
the class JmsDatastoreRuntime method getConnectionFactory.
public ConnectionFactory getConnectionFactory() {
Context context;
Hashtable<String, String> env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, properties.contextProvider.getValue());
env.put(Context.PROVIDER_URL, properties.serverUrl.getValue());
ConnectionFactory connection = null;
try {
context = new InitialContext(env);
connection = (ConnectionFactory) context.lookup("ConnectionFactory");
} catch (NamingException e) {
throw new ComponentException(e);
}
return connection;
}
use of org.talend.components.api.exception.ComponentException in project components by Talend.
the class JmsDatastoreRuntime method doHealthChecks.
@Override
public Iterable<ValidationResult> doHealthChecks(RuntimeContainer container) {
try {
// create connection factory
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(properties.serverUrl.getValue());
// Create a Connection
Connection connection = connectionFactory.createConnection();
connection.start();
connection.close();
if (connection != null) {
return Arrays.asList(ValidationResult.OK);
}
} catch (JMSException e) {
throw new ComponentException(e);
}
return null;
}
use of org.talend.components.api.exception.ComponentException in project components by Talend.
the class KafkaInputDefinition method getRuntimeInfo.
@Override
public RuntimeInfo getRuntimeInfo(ExecutionEngine engine, ComponentProperties properties, ConnectorTopology connectorTopology) {
assertEngineCompatibility(engine);
assertConnectorTopologyCompatibility(connectorTopology);
try {
return new JarRuntimeInfo(new URL(KafkaFamilyDefinition.MAVEN_DEFAULT_RUNTIME_URI), DependenciesReader.computeDependenciesFilePath(KafkaFamilyDefinition.MAVEN_GROUP_ID, KafkaFamilyDefinition.MAVEN_DEFAULT_RUNTIME_ARTIFACT_ID), RUNTIME);
} catch (MalformedURLException e) {
throw new ComponentException(e);
}
}
Aggregations