Skip to content

Commit

Permalink
[CONJ-477] make aurora run all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Jun 1, 2017
1 parent 4b81260 commit a145044
Show file tree
Hide file tree
Showing 16 changed files with 92 additions and 29 deletions.
8 changes: 7 additions & 1 deletion .travis/script.sh
Expand Up @@ -32,7 +32,13 @@ esac;

if [ -n "$AURORA" ]
then
testSingleHost=false
if [ -n "$AURORA_STRING_URL" ]
then
urlString=-DdbUrl=$AURORA_STRING_URL
testSingleHost=true
else
testSingleHost=false
fi
else
testSingleHost=true
fi
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/mariadb/jdbc/MariaDbDatabaseMetaData.java
Expand Up @@ -275,7 +275,7 @@ public static ResultSet getImportedKeys(String tableDef, String tableName, Strin
row[10] = Integer.toString(onDeleteReferenceAction);
row[11] = constraintName.name;
row[12] = null;
row[13] = Integer.toString(DatabaseMetaData.importedKeyInitiallyImmediate);
row[13] = Integer.toString(DatabaseMetaData.importedKeyNotDeferrable);
data.add(row);
}
}
Expand Down Expand Up @@ -768,7 +768,7 @@ public ResultSet getExportedKeys(String catalog, String schema, String table) th
+ " END DELETE_RULE,"
+ " RC.CONSTRAINT_NAME FK_NAME,"
+ " NULL PK_NAME,"
+ " 6 DEFERRABILITY"
+ importedKeyNotDeferrable + " DEFERRABILITY"
+ " FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE KCU"
+ " INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS RC"
+ " ON KCU.CONSTRAINT_SCHEMA = RC.CONSTRAINT_SCHEMA"
Expand Down Expand Up @@ -815,7 +815,7 @@ public ResultSet getImportedKeysUsingInformationSchema(String catalog, String sc
+ " END DELETE_RULE,"
+ " RC.CONSTRAINT_NAME FK_NAME,"
+ " NULL PK_NAME,"
+ " 6 DEFERRABILITY"
+ importedKeyNotDeferrable + " DEFERRABILITY"
+ " FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE KCU"
+ " INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS RC"
+ " ON KCU.CONSTRAINT_SCHEMA = RC.CONSTRAINT_SCHEMA"
Expand Down Expand Up @@ -2046,7 +2046,7 @@ public ResultSet getCrossReference(String parentCatalog, String parentSchema, St
+ " END DELETE_RULE,"
+ " RC.CONSTRAINT_NAME FK_NAME,"
+ " NULL PK_NAME,"
+ " 6 DEFERRABILITY"
+ importedKeyNotDeferrable + " DEFERRABILITY"
+ " FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE KCU"
+ " INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS RC"
+ " ON KCU.CONSTRAINT_SCHEMA = RC.CONSTRAINT_SCHEMA"
Expand Down
21 changes: 13 additions & 8 deletions src/main/java/org/mariadb/jdbc/UrlParser.java
Expand Up @@ -263,14 +263,7 @@ public UrlParser auroraPipelineQuirks() {

//Aurora has issue with pipelining, depending on network speed.
//Driver must rely on information provided by user : hostname if dns, and HA mode.</p>
boolean disablePipeline = haMode == HaMode.AURORA;
if (!disablePipeline && addresses != null) {
Pattern clusterPattern = Pattern.compile("(.+)\\.([a-z0-9\\-]+\\.rds\\.amazonaws\\.com)");
for (HostAddress hostAddress : addresses) {
Matcher matcher = clusterPattern.matcher(hostAddress.host);
if (matcher.find()) disablePipeline = true;
}
}
boolean disablePipeline = isAurora();

if (options.useBatchMultiSend == null) {
options.useBatchMultiSend = disablePipeline ? Boolean.FALSE : Boolean.TRUE;
Expand All @@ -282,6 +275,18 @@ public UrlParser auroraPipelineQuirks() {
return this;
}

public boolean isAurora() {
if (haMode == HaMode.AURORA) return true;
if (addresses != null) {
Pattern clusterPattern = Pattern.compile("(.+)\\.([a-z0-9\\-]+\\.rds\\.amazonaws\\.com)");
for (HostAddress hostAddress : addresses) {
Matcher matcher = clusterPattern.matcher(hostAddress.host);
if (matcher.find()) return true;
}
}
return false;
}

private static void setHaMode(UrlParser urlParser, String url, int separator) {
String[] baseTokens = url.substring(0, separator).split(":");

Expand Down
14 changes: 12 additions & 2 deletions src/test/java/org/mariadb/jdbc/BaseTest.java
Expand Up @@ -67,6 +67,8 @@
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.sql.*;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -99,12 +101,15 @@ public class BaseTest {
private static Deque<String> tempFunctionList = new ArrayDeque<>();
private static TcpProxy proxy = null;
private static UrlParser urlParser;
private static final NumberFormat numberFormat = DecimalFormat.getInstance();

@Rule
public TestRule watcher = new TestWatcher() {
private long ttime;
protected void starting(Description description) {
if (testSingleHost) {
System.out.println("start test : " + description.getClassName() + "." + description.getMethodName());
ttime = System.nanoTime();
}
}

Expand All @@ -126,13 +131,15 @@ protected void finished(Description description) {

protected void succeeded(Description description) {
if (testSingleHost) {
System.out.println("finished test success : " + description.getClassName() + "." + description.getMethodName());
System.out.println("finished test success : " + description.getClassName() + "." + description.getMethodName()
+ " after " + numberFormat.format(((double) System.nanoTime() - ttime) / 1000000) + " ms");
}
}

protected void failed(Throwable throwable, Description description) {
if (testSingleHost) {
System.out.println("finished test failed : " + description.getClassName() + "." + description.getMethodName());
System.out.println("finished test failed : " + description.getClassName() + "." + description.getMethodName()
+ " after " + numberFormat.format(((double) System.nanoTime() - ttime) / 1000000) + " ms");
}
}
};
Expand Down Expand Up @@ -807,4 +814,7 @@ public boolean sharedUseCompression() {
return urlParser.getOptions().useCompression;
}

public boolean sharedIsAurora() {
return urlParser.isAurora();
}
}
1 change: 0 additions & 1 deletion src/test/java/org/mariadb/jdbc/ConnectionPoolTest.java
Expand Up @@ -79,7 +79,6 @@ public static void initClass() throws SQLException {
}
}


@Test
public void testBasicPool() throws SQLException {

Expand Down
1 change: 1 addition & 0 deletions src/test/java/org/mariadb/jdbc/ConnectionTest.java
Expand Up @@ -304,6 +304,7 @@ public void isValidClosedConnection() throws SQLException {
*/
@Test
public void isValidConnectionThatTimesOutByServer() throws SQLException, InterruptedException {
Assume.assumeFalse(sharedIsAurora());
try (Connection connection = setConnection()) {
try (Statement statement = connection.createStatement()) {
statement.execute("set session wait_timeout=1");
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/mariadb/jdbc/DataSourceTest.java
Expand Up @@ -145,9 +145,9 @@ public void setServerNameTest() throws SQLException {
*
* @throws SQLException exception
*/
@Test // unless port 3307 can be used
@Test(timeout = 20000) // unless port 3307 can be used
public void setPortTest() throws SQLException {

Assume.assumeFalse("true".equals(System.getenv("AURORA")));
MariaDbDataSource ds = new MariaDbDataSource(hostname == null ? "localhost" : hostname, port, database);
try (Connection connection2 = ds.getConnection(username, password)) {
//delete blacklist, because can failover on 3306 is filled
Expand Down
34 changes: 26 additions & 8 deletions src/test/java/org/mariadb/jdbc/ErrorMessageTest.java
Expand Up @@ -52,6 +52,7 @@

package org.mariadb.jdbc;

import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.Test;

Expand Down Expand Up @@ -90,10 +91,16 @@ public void testSmallMultiBatchErrorMessage() throws SQLException {
executeBatchWithException(connection);
fail("Must Have thrown error");
} catch (SQLException sqle) {
assertTrue("message : " + sqle.getCause().getCause().getMessage(),
sqle.getCause().getCause().getMessage().contains(
"INSERT INTO testErrorMessage(test, test2) values "
+ "('more than 10 characters to provoc error', 10)"));
if (sharedIsAurora()) {
assertTrue(sqle.getCause().getCause().getMessage().contains(
"INSERT INTO testErrorMessage(test, test2) values (?, ?), "
+ "parameters ['more than 10 characters to provoc error',10]"));
} else {
assertTrue("message : " + sqle.getCause().getCause().getMessage(),
sqle.getCause().getCause().getMessage().contains(
"INSERT INTO testErrorMessage(test, test2) values "
+ "('more than 10 characters to provoc error', 10)"));
}
}
}

Expand All @@ -111,6 +118,7 @@ public void testSmallPrepareErrorMessage() throws SQLException {

@Test
public void testSmallBulkErrorMessage() throws SQLException {
Assume.assumeFalse(sharedIsAurora());
try (Connection connection = setBlankConnection("&useBatchMultiSend=true")) {
executeBatchWithException(connection);
fail("Must Have thrown error");
Expand All @@ -123,6 +131,7 @@ public void testSmallBulkErrorMessage() throws SQLException {

@Test
public void testSmallPrepareBulkErrorMessage() throws SQLException {
Assume.assumeFalse(sharedIsAurora());
try (Connection connection = setBlankConnection("&useBatchMultiSend=true&useServerPrepStmts=true")) {
executeBatchWithException(connection);
fail("Must Have thrown error");
Expand Down Expand Up @@ -150,10 +159,17 @@ public void testBigMultiErrorMessage() throws SQLException {
executeBigBatchWithException(connection);
fail("Must Have thrown error");
} catch (SQLException sqle) {
assertTrue("message : " + sqle.getCause().getCause().getMessage(),
sqle.getCause().getCause().getMessage().contains(
"INSERT INTO testErrorMessage(test, test2) values "
+ "('more than 10 characters to provoc error', 200)"));
if (!sharedIsAurora()) {
assertTrue("message : " + sqle.getCause().getCause().getMessage(),
sqle.getCause().getCause().getMessage().contains(
"INSERT INTO testErrorMessage(test, test2) values "
+ "('more than 10 characters to provoc error', 200)"));
} else {
assertTrue("message : " + sqle.getCause().getCause().getMessage(),
sqle.getCause().getCause().getMessage().contains(
"INSERT INTO testErrorMessage(test, test2) values (?, ?), parameters "
+ "['more than 10 characters to provoc error',200]"));
}
}
}

Expand All @@ -172,6 +188,7 @@ public void testBigPrepareErrorMessage() throws SQLException {

@Test
public void testBigBulkErrorMessage() throws SQLException {
Assume.assumeFalse(sharedIsAurora());
try (Connection connection = setBlankConnection("&useBatchMultiSend=true")) {
executeBigBatchWithException(connection);
fail("Must Have thrown error");
Expand All @@ -185,6 +202,7 @@ public void testBigBulkErrorMessage() throws SQLException {

@Test
public void testBigBulkErrorPrepareMessage() throws SQLException {
Assume.assumeFalse(sharedIsAurora());
try (Connection connection = setBlankConnection("&useBatchMultiSend=true&useServerPrepStmts=true")) {
executeBigBatchWithException(connection);
fail("Must Have thrown error");
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/org/mariadb/jdbc/ExecuteBatchTest.java
Expand Up @@ -167,6 +167,8 @@ public void run() {
public void serverBulk8mTest() throws SQLException {
Assume.assumeTrue(checkMaxAllowedPacketMore8m("serverBulk8mTest"));
Assume.assumeTrue(runLongTest);
Assume.assumeFalse(sharedIsAurora());

sharedConnection.createStatement().execute("TRUNCATE TABLE ExecuteBatchTest");

try (Connection connection = setConnection("&useComMulti=false&useBatchMultiSend=true&profileSql=" + profileSql)) {
Expand All @@ -180,6 +182,8 @@ public void serverBulk8mTest() throws SQLException {
public void serverBulk20mTest() throws SQLException {
Assume.assumeTrue(checkMaxAllowedPacketMore20m("serverBulk20mTest"));
Assume.assumeTrue(runLongTest);
Assume.assumeFalse(sharedIsAurora());

sharedConnection.createStatement().execute("TRUNCATE TABLE ExecuteBatchTest");

try (Connection connection = setConnection("&useComMulti=false&useBatchMultiSend=true&profileSql=" + profileSql)) {
Expand All @@ -206,6 +210,8 @@ public void serverStd8mTest() throws SQLException {
public void clientBulkTest() throws SQLException {
Assume.assumeTrue(checkMaxAllowedPacketMore8m("serverStd8mTest"));
Assume.assumeTrue(runLongTest);
Assume.assumeFalse(sharedIsAurora());

sharedConnection.createStatement().execute("TRUNCATE TABLE ExecuteBatchTest");

try (Connection connection = setConnection("&useComMulti=false&useBatchMultiSend=true&useServerPrepStmts=false&profileSql=" + profileSql)) {
Expand Down Expand Up @@ -293,6 +299,7 @@ private void addBatchData(PreparedStatement preparedStatement, int batchNumber,

@Test
public void useBatchMultiSend() throws Exception {
Assume.assumeFalse(sharedIsAurora());
try (Connection connection = setConnection("&useBatchMultiSend=true")) {
String sql = "insert into ExecuteBatchUseBatchMultiSend (test) values (?)";
try (PreparedStatement pstmt = connection.prepareStatement(sql)) {
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/org/mariadb/jdbc/MultiTest.java
Expand Up @@ -806,6 +806,8 @@ private void continueOnBatchError(boolean continueBatch, boolean serverPrepare,
+ " rewrite:" + rewrite
+ " batchMulti:" + batchMulti);
createTable("MultiTestt9", "id int not null primary key, test varchar(10)");
Assume.assumeTrue(!batchMulti || (batchMulti && !sharedIsAurora()));

try (Connection connection = setBlankConnection(
"&useServerPrepStmts=" + serverPrepare
+ "&useBatchMultiSend=" + batchMulti
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/mariadb/jdbc/PasswordEncodingTest.java
Expand Up @@ -64,7 +64,7 @@ public class PasswordEncodingTest extends BaseTest {

@Test
public void testPwdCharset() throws Exception {
cancelForVersion(5, 6, 36); //has password charset issue
cancelForVersion(5, 6); //has password charset issue

String[] charsets = new String[]{"UTF-8",
"windows-1252",
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/org/mariadb/jdbc/RePrepareTest.java
Expand Up @@ -52,6 +52,7 @@

package org.mariadb.jdbc;

import org.junit.Assume;
import org.junit.Test;

import java.sql.PreparedStatement;
Expand Down Expand Up @@ -88,6 +89,7 @@ public void rePrepareTestSelectError() throws SQLException {

@Test
public void rePrepareTestInsertError() throws SQLException {
Assume.assumeFalse(sharedIsAurora()); //Aurora has not "flush tables with read lock" right;
createTable("rePrepareTestInsertError", "test int");
try (Statement stmt = sharedConnection.createStatement()) {
try (PreparedStatement preparedStatement = sharedConnection.prepareStatement("INSERT INTO rePrepareTestInsertError(test) values (?)")) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/mariadb/jdbc/SslTest.java
Expand Up @@ -83,7 +83,7 @@ public class SslTest extends BaseTest {
*/
@BeforeClass
public static void enableCrypto() throws Exception {
Assume.assumeFalse("MAXSCALE".equals(System.getenv("TYPE")));
Assume.assumeFalse("MAXSCALE".equals(System.getenv("TYPE")) || "true".equals(System.getenv("AURORA")));
try {
Field field = Class.forName("javax.crypto.JceSecurity").getDeclaredField("isRestricted");
field.setAccessible(true);
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/org/mariadb/jdbc/StatementTest.java
Expand Up @@ -300,8 +300,9 @@ public void testLoadDataInvalidColumn() throws SQLException, UnsupportedEncoding
}
}

@Test
@Test(timeout = 10000)
public void statementClose() throws SQLException {
Assume.assumeTrue(sharedOptions().socketTimeout == null);
Properties infos = new Properties();
infos.put("socketTimeout", 1000);
try (Connection connection = createProxyConnection(infos)) {
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/org/mariadb/jdbc/StoredProcedureTest.java
Expand Up @@ -53,6 +53,7 @@
package org.mariadb.jdbc;


import org.junit.Assume;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
Expand Down Expand Up @@ -103,6 +104,9 @@ public static void initClass() throws SQLException {

@Test
public void testStoreProcedureStreaming() throws Exception {
// aurora doesn't send back output results parameter when having SELECT results, even with flag enabled
Assume.assumeFalse(sharedIsAurora());

//cancel for version 10.2 beta before fix https://jira.mariadb.org/browse/MDEV-11761
cancelForVersion(10, 2, 2);
cancelForVersion(10, 2, 3);
Expand Down Expand Up @@ -147,6 +151,9 @@ public void testStoreProcedureStreaming() throws Exception {

@Test
public void testStoreProcedureStreamingWithAnotherQuery() throws Exception {
// aurora doesn't send back output results parameter when having SELECT results, even with flag enabled
Assume.assumeFalse(sharedIsAurora());

//cancel for version 10.2 beta before fix https://jira.mariadb.org/browse/MDEV-11761
cancelForVersion(10, 2, 2);
cancelForVersion(10, 2, 3);
Expand Down

0 comments on commit a145044

Please sign in to comment.