Add random fetchSize

Original commit: elastic/x-pack-elasticsearch@1f8197b04f
This commit is contained in:
Costin Leau 2017-07-18 23:15:40 +03:00
parent d010f181bc
commit 8acacc4f7d
3 changed files with 15 additions and 14 deletions

View File

@ -15,6 +15,8 @@ import org.junit.ClassRule;
import java.nio.file.Path;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import java.util.Locale;
@ -59,8 +61,9 @@ public class SqlSpecIT extends SpecBaseIntegrationTestCase {
Connection es = esJdbc()) {
ResultSet expected, actual;
try {
expected = h2.createStatement().executeQuery(query);
actual = es.createStatement().executeQuery(query);
expected = executeQuery(h2);
actual = executeQuery(es);
assertResultSets(expected, actual);
} catch (AssertionError ae) {
throw reworkException(new AssertionError(errorMessage(ae), ae.getCause()));
@ -70,6 +73,12 @@ public class SqlSpecIT extends SpecBaseIntegrationTestCase {
}
}
private ResultSet executeQuery(Connection con) throws SQLException {
Statement statement = con.createStatement();
statement.setFetchSize(randomInt(10));
return statement.executeQuery(query);
}
String errorMessage(Throwable th) {
return format(Locale.ROOT, "test%s@%s:%d failed\n\"%s\"\n%s", testName, source.getFileName().toString(), lineNumber, query, th.getMessage());
}

View File

@ -6,10 +6,10 @@
package org.elasticsearch.xpack.sql.jdbc.framework;
import org.elasticsearch.client.ResponseException;
import org.elasticsearch.common.Booleans;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.PathUtils;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import java.io.IOException;
@ -30,7 +30,7 @@ import static java.lang.String.format;
public abstract class SpecBaseIntegrationTestCase extends JdbcIntegrationTestCase {
protected static final String PARAM_FORMATTNG = "%0$s.test%2$s";
private static boolean haveSetupTestData;
private static final boolean SETUP_DATA = Booleans.parseBoolean(System.getProperty("tests.sql.setup.data", "false"));
protected final String groupName;
protected final String testName;
@ -38,18 +38,12 @@ public abstract class SpecBaseIntegrationTestCase extends JdbcIntegrationTestCas
protected final Path source;
@BeforeClass
public static void clearSetupTestData() {
haveSetupTestData = false;
}
@Before
public void setupTestData() throws Exception {
if (haveSetupTestData) {
public static void setupTestData() throws Exception {
if (!SETUP_DATA) {
// We only need to load the test data once
return;
}
loadDatasetIntoEs();
haveSetupTestData = true;
}
@AfterClass

View File

@ -69,8 +69,6 @@ public class TransportSqlAction extends HandledTransportAction<SqlRequest, SqlRe
return;
}
// NOCOMMIT move session information somewhere - like into scroll or something. We should be able to reuse something.
// generate the plan and once it's done, generate the session id, store it and send back the response
planExecutor.sql(query, timeZone, chain(listener, c -> {
String id = generateId();
SESSIONS.put(id, c);