Skip to content

Commit

Permalink
Merge pull request #17 from rusher/master
Browse files Browse the repository at this point in the history
correction for travis initial +test correction
  • Loading branch information
rusher committed Jun 23, 2015
2 parents 431ee88 + a5fc025 commit 04452f2
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 152 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
@@ -1,6 +1,8 @@
sudo: required
language: java
before_install: .travis/before_install.sh
before_install:
- chmod +x .travis/before_test.sh
install: .travis/before_test.sh
jdk:
- oraclejdk8
- oraclejdk7
Expand Down
9 changes: 5 additions & 4 deletions .travis/before_install.sh → .travis/before_test.sh
Expand Up @@ -23,8 +23,8 @@ then
remove_mysql

sudo tee /etc/apt/sources.list.d/mysql.list << END
deb http://repo.mysql.com/apt/debian/ wheezy mysql-$MYSQL_VERSION
deb-src http://repo.mysql.com/apt/debian/ wheezy mysql-$MYSQL_VERSION
deb http://repo.mysql.com/apt/ubuntu/ precise mysql-$MYSQL_VERSION
deb-src http://repo.mysql.com/apt/ubuntu/ precise mysql-$MYSQL_VERSION
END

sudo apt-key adv --keyserver pool.sks-keyservers.net --recv-keys $MYSQ_GPG_KEY
Expand All @@ -40,7 +40,7 @@ else
sudo apt-get install python-software-properties

sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db
sudo add-apt-repository "deb http://ftp.igh.cnrs.fr/pub/mariadb/repo/${MARIA_VERSION}/debian wheezy main"
sudo add-apt-repository "deb http://ftp.igh.cnrs.fr/pub/mariadb/repo/${MARIA_VERSION}/ubuntu precise main"

sudo apt-get update

Expand All @@ -50,11 +50,12 @@ fi
sudo tee /etc/mysql/conf.d/map.cnf << END
[mysqld]
max_allowed_packet=$MAX_ALLOWED_PACKET
innodb_log_file_size=$[4*$MAX_ALLOWED_PACKET]
END

sudo service mysql restart


cat /etc/mysql/my.cnf

mysql -u root -e "create database test"
mysql -u root -e "create database test"
6 changes: 6 additions & 0 deletions src/test/java/org/mariadb/jdbc/BaseTest.java
Expand Up @@ -278,6 +278,12 @@ static void logInfo(String message)
{
log.info(message);
}

boolean isMariadbServer() throws SQLException {
DatabaseMetaData md = connection.getMetaData();
return md.getDatabaseProductVersion().indexOf("MariaDB") != -1;
}

}

class CustomFormatter extends Formatter {
Expand Down
13 changes: 5 additions & 8 deletions src/test/java/org/mariadb/jdbc/CallableStatementTest.java
Expand Up @@ -63,18 +63,15 @@ public void useParameterName() throws Exception {
assertEquals(res, 1);
}

@Test
@Test(expected = SQLException.class)
public void useWrongParameterName() throws Exception {
createProcedure("useWrongParameterName", "(a int) begin select a; end");
CallableStatement stmt = connection.prepareCall("{call useParameterName(?)}");

try {
stmt.setInt("b",1);
fail("must fail");
} catch (SQLException sqle) {
assertTrue(sqle.getMessage().equals("there is no parameter with the name b"));
}
stmt.setInt("b", 1);
fail("must fail");
}


@Test
public void multiResultSets() throws Exception {
createProcedure("multiResultSets", "() BEGIN SELECT 1; SELECT 2; END");
Expand Down
112 changes: 1 addition & 111 deletions src/test/java/org/mariadb/jdbc/ConnectionPoolTest.java
Expand Up @@ -40,117 +40,7 @@ public void testConnectionWithApacheDBCP() throws SQLException {
connection.close();
dataSource.close();
}

/*
*
*/
@Test
public void testTimeoutsInPool() throws SQLException, InterruptedException {
org.apache.commons.dbcp.BasicDataSource dataSource;
dataSource = new org.apache.commons.dbcp.BasicDataSource();
dataSource.setUrl("jdbc:mysql://" + hostname + ":"+port+"/test?useCursorFetch=true&useTimezone=true&useLegacyDatetimeCode=false&serverTimezone=UTC");
dataSource.setUsername(username);
dataSource.setPassword(password);
// dataSource.setMaxActive(10);
// dataSource.setMinIdle(10); //keep 10 connections open
// dataSource.setValidationQuery("SELECT 1");
dataSource.setMaxActive(50);
dataSource.setLogAbandoned(true);
dataSource.setRemoveAbandoned(true);
dataSource.setRemoveAbandonedTimeout(300);
dataSource.setAccessToUnderlyingConnectionAllowed(true);
dataSource.setMinEvictableIdleTimeMillis(1800000);
dataSource.setTimeBetweenEvictionRunsMillis(-1);
dataSource.setNumTestsPerEvictionRun(3);

// adjust server wait timeout to 1 second
// Statement stmt1 = conn1.createStatement();
// stmt1.execute("set session wait_timeout=1");


try {
Connection conn = dataSource.getConnection();
log.fine("autocommit: " + conn.getAutoCommit());
Statement stmt = conn.createStatement();
stmt.executeUpdate("drop table if exists t3");
stmt.executeUpdate("create table t3(message text)");
conn.close();
} catch (SQLException e1) {
e1.printStackTrace();
}

InsertThread ins1 = new InsertThread(10000, dataSource);
Thread thread1 = new Thread(ins1);
thread1.start();
InsertThread ins2 = new InsertThread(10000, dataSource);
Thread thread2 = new Thread(ins2);
thread2.start();
InsertThread ins3 = new InsertThread(10000, dataSource);
Thread thread3 = new Thread(ins3);
thread3.start();
InsertThread ins4 = new InsertThread(10000, dataSource);
Thread thread4 = new Thread(ins4);
thread4.start();
InsertThread ins5 = new InsertThread(10000, dataSource);
Thread thread5 = new Thread(ins5);
thread5.start();
InsertThread ins6 = new InsertThread(10000, dataSource);
Thread thread6 = new Thread(ins6);
thread6.start();
InsertThread ins7 = new InsertThread(10000, dataSource);
Thread thread7 = new Thread(ins7);
thread7.start();
InsertThread ins8 = new InsertThread(10000, dataSource);
Thread thread8 = new Thread(ins8);
thread8.start();
InsertThread ins9 = new InsertThread(10000, dataSource);
Thread thread9 = new Thread(ins9);
thread9.start();
InsertThread ins10 = new InsertThread(10000, dataSource);
Thread thread10 = new Thread(ins10);
thread10.start();

// wait for threads to finish
while (thread1.isAlive() || thread2.isAlive() || thread3.isAlive() || thread4.isAlive() || thread5.isAlive() || thread6.isAlive() || thread7.isAlive() || thread8.isAlive() || thread9.isAlive() || thread10.isAlive())
{
//keep on waiting for threads to finish
}

// wait for 70 seconds so that the server times out the connections
Thread.sleep(70000); // Wait for the server to kill the connections

// do something
Statement stmt1 = dataSource.getConnection().createStatement();
stmt1.execute("SELECT COUNT(*) FROM t3");

// close data source
dataSource.close();

/*
Connection conn1 = null;
Statement stmt1 = null;
ResultSet rs;
for(int i = 1; i < 100000; i++)
{
conn1 = dataSource.getConnection();
stmt1 = conn1.createStatement();
rs = stmt1.executeQuery("SELECT 1");
rs.next();
conn1.close();
}
*/

// close all connections but conn1
/* conn1.close();
conn2.close();
conn3.close();
conn4.close();
conn5.close();
*/
// dataSource.close();
}


/**
* This test case simulates how the Apache DBCP connection pools works. It is written so it
* should compile without Apache DBCP but still show the problem.
Expand Down
4 changes: 4 additions & 0 deletions src/test/java/org/mariadb/jdbc/DatabaseMetadataTest.java
Expand Up @@ -259,6 +259,10 @@ else if (cat.equalsIgnoreCase("information_schema"))
public void testGetTables() throws SQLException {
DatabaseMetaData dbmd = connection.getMetaData();
ResultSet rs = dbmd.getTables(null,null,"prim_key",null);

//mysql 5.5 not compatible
if (!isMariadbServer()) requireMinimumVersion(5,5);

assertEquals(true,rs.next());
rs = dbmd.getTables("", null,"prim_key",null);
assertEquals(true,rs.next());
Expand Down
52 changes: 34 additions & 18 deletions src/test/java/org/mariadb/jdbc/DateTest.java
Expand Up @@ -239,7 +239,7 @@ public void serverTimezone() throws Exception {
java.sql.Timestamp ts = rs.getTimestamp(1);
long differenceToGMT = ts.getTime() - now.getTime();
long diff = Math.abs(differenceToGMT - offset);
assertTrue(diff < 1000); /* query take less than a second */
assertTrue(diff < 2000); /* query take less than a second */

ps = connection.prepareStatement("select utc_timestamp(), ?");
ps.setObject(1,now);
Expand All @@ -249,27 +249,43 @@ public void serverTimezone() throws Exception {
java.sql.Timestamp ts2 = rs.getTimestamp(2);
assertTrue(Math.abs(ts.getTime() - ts2.getTime()) < 1000); /* query take less than a second */
}

/**
* CONJ-107
* @throws SQLException
* @throws SQLException
*/
@Test
public void timestampMillisecondsTest() throws SQLException {
Statement statement = connection.createStatement();
statement.execute("DROP TABLE IF EXISTS tt");
statement.execute("CREATE TABLE tt (id decimal(10), create_time datetime(6) default 0)");
statement.execute("INSERT INTO tt (id, create_time) VALUES (1,'2013-07-18 13:44:22.123456')");
PreparedStatement ps = connection.prepareStatement("insert into tt (id, create_time) values (?,?)");
ps.setInt(1, 2);
Timestamp writeTs = new Timestamp(1273017612999L);
ps.setTimestamp(2, writeTs);
ps.execute();
ResultSet rs = statement.executeQuery("SELECT * FROM tt");
assertTrue(rs.next());
assertTrue("2013-07-18 13:44:22.123456".equals(rs.getString(2)));
assertTrue(rs.next());
Timestamp readTs = rs.getTimestamp(2);
assertEquals(writeTs, readTs);
Statement statement = connection.createStatement();
statement.execute("DROP TABLE IF EXISTS tt");

boolean isMariadbServer = isMariadbServer();
if (isMariadbServer) {
statement.execute("CREATE TABLE tt (id decimal(10), create_time datetime(6) default 0)");
statement.execute("INSERT INTO tt (id, create_time) VALUES (1,'2013-07-18 13:44:22.123456')");
} else {
statement.execute("CREATE TABLE tt (id decimal(10), create_time datetime default 0)");
statement.execute("INSERT INTO tt (id, create_time) VALUES (1,'2013-07-18 13:44:22')");
}
PreparedStatement ps = connection.prepareStatement("insert into tt (id, create_time) values (?,?)");
ps.setInt(1, 2);
Timestamp writeTs = new Timestamp(1273017612999L);
Timestamp writeTsWithoutMilliSec = new Timestamp(1273017612999L);
ps.setTimestamp(2, writeTs);
ps.execute();
ResultSet rs = statement.executeQuery("SELECT * FROM tt");
assertTrue(rs.next());
if (isMariadbServer) {
assertTrue("2013-07-18 13:44:22.123456".equals(rs.getString(2)));
} else {
assertTrue("2013-07-18 13:44:22".equals(rs.getString(2)));
}
assertTrue(rs.next());
Timestamp readTs = rs.getTimestamp(2);
if (isMariadbServer) {
assertEquals(writeTs, readTs);
} else {
assertEquals(writeTs, writeTsWithoutMilliSec);
}
}
}
22 changes: 16 additions & 6 deletions src/test/java/org/mariadb/jdbc/DriverTest.java
Expand Up @@ -1130,15 +1130,25 @@ public void testConnectWithDB() throws SQLException {
connection.createStatement().executeUpdate("drop database test_testdrop");
}

@Test
@Test
public void testError() throws SQLException {
// check that max_allowed_packet is big enough for the test
Assume.assumeTrue(checkMaxAllowedPacket("testError"));
Assume.assumeTrue(checkMaxAllowedPacket("testError"));

try {
char arr[] = new char[16*1024*1024-1];
Arrays.fill(arr,'a');
ResultSet rs = connection.createStatement().executeQuery("select '" + new String(arr) + "'");

ResultSet rs = connection.createStatement().executeQuery("select @@max_allowed_packet");
rs.next();
int max_allowed_packet = rs.getInt(1);

int selectSize = 9;
int packetHeader = 4;
char arr[] = new char[16 * 1024 * 1024 - selectSize - packetHeader];
Arrays.fill(arr, 'a');
String request = "select '" + new String(arr) + "'";
System.out.println("request size : " + (request.length()) + " / " + max_allowed_packet);

rs = connection.createStatement().executeQuery(request);
rs.next();
log.finest(String.valueOf(rs.getString(1).length()));
} finally {
Expand Down
10 changes: 6 additions & 4 deletions src/test/java/org/mariadb/jdbc/MySQLDriverTest.java
Expand Up @@ -233,9 +233,10 @@ public void largeQueryWrite() throws SQLException {
Arrays.fill(str, 'a');
String prefix= "select length('";
String suffix= "') as len";
int packetHeaderSize = 4 + 2 ; //packet head +2 escape for String parameter

for (int i=16*1024*1024 - prefix.length() -suffix.length() -5 ;
i < 16*1024*1024 - prefix.length() -suffix.length();
for (int i=16*1024*1024 - prefix.length() -suffix.length() -5 - packetHeaderSize ;
i < 16*1024*1024 - prefix.length() -suffix.length() - packetHeaderSize;
i++) {
String query = prefix;
String val = new String(str,0, i);
Expand Down Expand Up @@ -288,10 +289,11 @@ public void largePreparedQueryWriteCompress() throws SQLException {
char[] str= new char[16*1024*1024];
Arrays.fill(str, 'a');
String sql= "select ?";
int packetHeaderSize = 4 + 2 ; //packet head +2 escape for String parameter

PreparedStatement ps = connection.prepareStatement(sql);
for (int i=16*1024*1024 - sql.length() -5;
i < 16*1024*1024 - sql.length();
for (int i=16*1024*1024 - sql.length() -5 - packetHeaderSize ;
i < 16*1024*1024 - sql.length() - packetHeaderSize;
i++) {
String val = new String(str,0, i);
ps.setString(1,val);
Expand Down

0 comments on commit 04452f2

Please sign in to comment.