Search in sources :

Example 1 with GenericDatabaseAdapter

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());
}
Also used : SQLException(java.sql.SQLException) GenericDatabaseAdapter(org.apache.nifi.processors.standard.db.impl.GenericDatabaseAdapter) Statement(java.sql.Statement) DataFileWriter(org.apache.avro.file.DataFileWriter) Connection(java.sql.Connection) DBCPService(org.apache.nifi.dbcp.DBCPService) Test(org.junit.Test)

Example 2 with GenericDatabaseAdapter

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);
}
Also used : HashMap(java.util.HashMap) GenericDatabaseAdapter(org.apache.nifi.processors.standard.db.impl.GenericDatabaseAdapter) DBCPService(org.apache.nifi.dbcp.DBCPService) Before(org.junit.Before)

Aggregations

DBCPService (org.apache.nifi.dbcp.DBCPService)2 GenericDatabaseAdapter (org.apache.nifi.processors.standard.db.impl.GenericDatabaseAdapter)2 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 HashMap (java.util.HashMap)1 DataFileWriter (org.apache.avro.file.DataFileWriter)1 Before (org.junit.Before)1 Test (org.junit.Test)1