use of org.apache.nifi.processors.standard.db.impl.GenericDatabaseAdapter in project nifi by apache.
the class QueryDatabaseTableTest method testWithRuntimeException.
@Test
public void testWithRuntimeException() throws SQLException {
// load test data to database
final Connection con = ((DBCPService) runner.getControllerService("dbcp")).getConnection();
Statement stmt = con.createStatement();
try {
stmt.execute("drop table TEST_NULL_INT");
} catch (final SQLException sqle) {
// Ignore, usually due to Derby not having DROP TABLE IF EXISTS
}
stmt.execute("create table TEST_NULL_INT (id integer not null, val1 integer, val2 integer, constraint my_pk primary key (id))");
stmt.execute("insert into TEST_NULL_INT (id, val1, val2) VALUES (0, NULL, 1)");
stmt.execute("insert into TEST_NULL_INT (id, val1, val2) VALUES (1, 1, 1)");
runner.setIncomingConnection(false);
runner.setProperty(QueryDatabaseTable.TABLE_NAME, "TEST_NULL_INT");
runner.setProperty(AbstractDatabaseFetchProcessor.MAX_VALUE_COLUMN_NAMES, "id");
QueryDatabaseTable.dbAdapters.put(dbAdapter.getName(), new GenericDatabaseAdapter() {
@Override
public String getName() {
throw new DataFileWriter.AppendWriteException(null);
}
});
runner.run();
assertTrue(runner.getFlowFilesForRelationship(QueryDatabaseTable.REL_SUCCESS).isEmpty());
}
use of org.apache.nifi.processors.standard.db.impl.GenericDatabaseAdapter in project nifi by apache.
the class QueryDatabaseTableTest method setup.
@Before
public void setup() throws InitializationException, IOException {
final DBCPService dbcp = new DBCPServiceSimpleImpl();
final Map<String, String> dbcpProperties = new HashMap<>();
origDbAdapters = new HashMap<>(QueryDatabaseTable.dbAdapters);
dbAdapter = new GenericDatabaseAdapter();
QueryDatabaseTable.dbAdapters.put(dbAdapter.getName(), dbAdapter);
processor = new MockQueryDatabaseTable();
runner = TestRunners.newTestRunner(processor);
runner.addControllerService("dbcp", dbcp, dbcpProperties);
runner.enableControllerService(dbcp);
runner.setProperty(QueryDatabaseTable.DBCP_SERVICE, "dbcp");
runner.setProperty(QueryDatabaseTable.DB_TYPE, dbAdapter.getName());
runner.getStateManager().clear(Scope.CLUSTER);
}
Aggregations