Search in sources :

Example 1 with JdbcSession

use of com.jcabi.jdbc.JdbcSession in project phoenix by apache.

the class DataIngestIT method testRWWorkload.

@Test
public void testRWWorkload() throws Exception {
    Connection connection = util.getConnection();
    WorkloadExecutor executor = new WorkloadExecutor();
    DataModel dataModel = parser.getDataModelByName("test_scenario");
    List<DataModel> dataModels = new ArrayList<>();
    dataModels.add(dataModel);
    QueryExecutor qe = new QueryExecutor(parser, util, executor, dataModels, null, false);
    executor.add(qe);
    Scenario scenario = parser.getScenarioByName("testScenarioRW");
    String sql = "select count(*) from " + scenario.getTableName();
    try {
        // Wait for data to load up.
        executor.get();
        executor.shutdown();
        // Verify data has been loaded
        Integer count = new JdbcSession(connection).sql(sql).select(new Outcome<Integer>() {

            @Override
            public Integer handle(ResultSet resultSet, Statement statement) throws SQLException {
                while (resultSet.next()) {
                    return resultSet.getInt(1);
                }
                return null;
            }
        });
        assertNotNull("Could not retrieve count. " + count);
        // It would be better to sum up all the rowcounts for the scenarios, but this is fine
        assertTrue("Could not query any rows for in " + scenario.getTableName(), count > 0);
    } catch (Exception e) {
        fail("Failed to load data. An exception was thrown: " + e.getMessage());
    }
}
Also used : JdbcSession(com.jcabi.jdbc.JdbcSession) SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) WorkloadExecutor(org.apache.phoenix.pherf.workload.WorkloadExecutor) SQLException(java.sql.SQLException) Scenario(org.apache.phoenix.pherf.configuration.Scenario) DataModel(org.apache.phoenix.pherf.configuration.DataModel) QueryExecutor(org.apache.phoenix.pherf.workload.QueryExecutor) ResultSet(java.sql.ResultSet) Test(org.junit.Test)

Example 2 with JdbcSession

use of com.jcabi.jdbc.JdbcSession in project phoenix by apache.

the class DataIngestIT method assertExpectedNumberOfRecordsWritten.

private void assertExpectedNumberOfRecordsWritten(Scenario scenario) throws Exception, SQLException {
    Connection connection = util.getConnection(scenario.getTenantId());
    String sql = "select count(*) from " + scenario.getTableName();
    Integer count = new JdbcSession(connection).sql(sql).select(new Outcome<Integer>() {

        @Override
        public Integer handle(ResultSet resultSet, Statement statement) throws SQLException {
            while (resultSet.next()) {
                return resultSet.getInt(1);
            }
            return null;
        }
    });
    assertNotNull("Could not retrieve count. " + count);
    assertEquals("Expected 100 rows to have been inserted", scenario.getRowCount(), count.intValue());
}
Also used : JdbcSession(com.jcabi.jdbc.JdbcSession) SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet)

Aggregations

JdbcSession (com.jcabi.jdbc.JdbcSession)2 Connection (java.sql.Connection)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Statement (java.sql.Statement)2 ArrayList (java.util.ArrayList)1 DataModel (org.apache.phoenix.pherf.configuration.DataModel)1 Scenario (org.apache.phoenix.pherf.configuration.Scenario)1 QueryExecutor (org.apache.phoenix.pherf.workload.QueryExecutor)1 WorkloadExecutor (org.apache.phoenix.pherf.workload.WorkloadExecutor)1 Test (org.junit.Test)1