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();
}
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();
}
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);
}
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);
}
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();
}
Aggregations