Search in sources :

Example 6 with Parameters

use of org.testng.annotations.Parameters in project elasticsearch-jdbc by jprante.

the class AbstractColumnStrategyTest method beforeMethod.

@BeforeMethod
@Parameters({ "starturl", "user", "password", "create" })
public void beforeMethod(String starturl, String user, String password, @Optional String resourceName) throws Exception {
    startNodes();
    logger.info("nodes started");
    source = newSource();
    source.setUrl(starturl).setUser(user).setPassword(password).setLocale(Locale.getDefault()).setTimeZone(TimeZone.getDefault());
    logger.info("create table {}", resourceName);
    if (resourceName == null || "".equals(resourceName)) {
        return;
    }
    Connection connection = source.getConnectionForWriting();
    if (connection == null) {
        throw new IOException("no connection");
    }
    sqlScript(connection, resourceName);
    source.closeWriting();
}
Also used : Connection(java.sql.Connection) IOException(java.io.IOException) Parameters(org.testng.annotations.Parameters) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 7 with Parameters

use of org.testng.annotations.Parameters in project elasticsearch-jdbc by jprante.

the class ColumnStrategyContextTests method testReadLastRunTime.

@Test
@Parameters({ "existedWhereClause" })
@SuppressWarnings("unchecked")
public void testReadLastRunTime(String resource) throws Exception {
    Settings settings = createSettings(resource);
    final DateTime lastRunAt = new DateTime(new DateTime().getMillis() - 600);
    context = newContext();
    MockJDBCSource source = new MockJDBCSource() {

        @Override
        public void fetch() {
            DateTime readlastRunAt = context.getLastRunTimestamp();
            assertNotNull(readlastRunAt);
            assertEquals(readlastRunAt, lastRunAt);
        }
    };
    MockSink mockSink = new MockSink();
    context.setSettings(settings).setSink(mockSink).setSource(source);
    //mockSink.setIngestFactory(createIngestFactory(settings));
    context.setLastRunTimeStamp(lastRunAt);
    context.execute();
}
Also used : MockSink(org.xbib.elasticsearch.jdbc.strategy.mock.MockSink) MockJDBCSource(org.xbib.elasticsearch.jdbc.strategy.mock.MockJDBCSource) Settings(org.elasticsearch.common.settings.Settings) DateTime(org.joda.time.DateTime) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Example 8 with Parameters

use of org.testng.annotations.Parameters in project elasticsearch-jdbc by jprante.

the class StandardCounterTests method testCounter.

@Test
@Parameters({ "task1", "sql1", "sql2" })
public void testCounter(String resource, String sql1, String sql2) throws Exception {
    logger.info("creating random products: {}", sql2);
    createRandomProductsJob(sql2, 100);
    logger.info("random products created");
    Connection connection = source.getConnectionForReading();
    logger.info("counting random products: {}", sql1);
    ResultSet results = connection.createStatement().executeQuery(sql1);
    if (!connection.getAutoCommit()) {
        connection.commit();
    }
    int count = results.next() ? results.getInt(1) : -1;
    logger.info("random product count: {}", count);
    source.close(results);
    source.closeReading();
    assertEquals(count, 100);
    perform(resource);
    assertHits("1", 100);
    // count docs in source table, must be null
    connection = source.getConnectionForReading();
    // sql1 = select count(*)
    results = connection.createStatement().executeQuery(sql1);
    if (!connection.getAutoCommit()) {
        connection.commit();
    }
    count = results.next() ? results.getInt(1) : -1;
    results.close();
    assertEquals(count, 0);
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Example 9 with Parameters

use of org.testng.annotations.Parameters in project elasticsearch-jdbc by jprante.

the class StandardScheduleTests method testTimestamps.

/**
     * Test read and write of timestamps in a table. We create 100 timestamps over hour interval,
     * current timestamp $now is in the center.
     * Selecting timestamps from $now, there should be at least 50 rows/hits per run, if $now works.
     *
     * @param resource the JSON resource
     * @param sql           the sql statement to select timestamps
     * @throws Exception
     */
@Test
@Parameters({ "task7", "sql2" })
public void testTimestamps(String resource, String sql) throws Exception {
    // TODO make timezone/locale configurable for better randomized testing
    createTimestampedLogs(sql, 100, "iw_IL", "Asia/Jerusalem");
    JDBCImporter importer = createImporter(resource);
    // run more than twice
    Thread.sleep(12500L);
    importer.shutdown();
    long hits = client("1").prepareSearch(index).execute().actionGet().getHits().getTotalHits();
    // just an estimation, at least two runs should deliver 50 hits each.
    logger.info("found {} hits", hits);
    assertTrue(hits > 99L);
}
Also used : JDBCImporter(org.xbib.tools.JDBCImporter) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Example 10 with Parameters

use of org.testng.annotations.Parameters in project elasticsearch-jdbc by jprante.

the class AbstractSourceTest method afterMethod.

@AfterMethod
@Parameters({ "stopurl", "user", "password", "delete" })
public void afterMethod(String stopurl, String user, String password, @Optional String resourceName) throws Exception {
    logger.info("remove table {}", resourceName);
    if (resourceName == null || "".equals(resourceName)) {
        return;
    }
    // before dropping tables, open read connection must be closed to avoid hangs in mysql/postgresql
    logger.debug("closing reads...");
    source.closeReading();
    logger.debug("connecting for close...");
    Connection connection = source.getConnectionForWriting();
    if (connection == null) {
        throw new IOException("no connection");
    }
    logger.debug("cleaning...");
    // clean up tables
    sqlScript(connection, resourceName);
    logger.debug("closing writes...");
    source.closeWriting();
    // we can drop database by a magic 'stop' URL
    source = newSource().setUrl(stopurl).setUser(user).setPassword(password).setLocale(Locale.getDefault()).setTimeZone(TimeZone.getDefault());
    try {
        logger.info("connecting to stop URL...");
        // activate stop URL
        source.getConnectionForWriting();
    } catch (Exception e) {
    // exception is expected, ignore
    }
    // close open write connection
    source.closeWriting();
}
Also used : Connection(java.sql.Connection) IOException(java.io.IOException) SQLException(java.sql.SQLException) IOException(java.io.IOException) AfterMethod(org.testng.annotations.AfterMethod) Parameters(org.testng.annotations.Parameters)

Aggregations

Parameters (org.testng.annotations.Parameters)628 Test (org.testng.annotations.Test)610 BaseTest (org.xdi.oxauth.BaseTest)511 Response (javax.ws.rs.core.Response)271 Builder (javax.ws.rs.client.Invocation.Builder)270 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)270 ResponseType (org.xdi.oxauth.model.common.ResponseType)259 JSONException (org.codehaus.jettison.json.JSONException)238 OxAuthCryptoProvider (org.xdi.oxauth.model.crypto.OxAuthCryptoProvider)196 JSONObject (org.codehaus.jettison.json.JSONObject)191 URISyntaxException (java.net.URISyntaxException)119 RegisterResponse (org.xdi.oxauth.client.RegisterResponse)110 RegisterRequest (org.xdi.oxauth.client.RegisterRequest)96 JwtAuthorizationRequest (org.xdi.oxauth.client.model.authorize.JwtAuthorizationRequest)92 AuthorizationRequest (org.xdi.oxauth.client.AuthorizationRequest)86 URI (java.net.URI)85 Jwt (org.xdi.oxauth.model.jwt.Jwt)81 Claim (org.xdi.oxauth.client.model.authorize.Claim)80 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)73 REGISTRATION_CLIENT_URI (org.xdi.oxauth.model.register.RegisterResponseParam.REGISTRATION_CLIENT_URI)73