Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/test/java/org/drizzle/jdbc/BigQueryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
public class BigQueryTest {
@Test
public void sendBigQuery2() throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:drizzle://"+DriverTest.host+":3306/test_units_jdbc");
Connection conn=ConnectionCheck.Get_ConnectionDrizzle();
Statement stmt = conn.createStatement();
stmt.execute("drop table if exists bigblob");
stmt.execute("create table bigblob (id int not null primary key auto_increment, test longblob)");
Expand Down Expand Up @@ -47,7 +47,7 @@ public void sendBigQuery2() throws SQLException {
}
@Test
public void sendBigPreparedQuery() throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:drizzle://"+DriverTest.host+":3306/test_units_jdbc");
Connection conn=ConnectionCheck.Get_ConnectionDrizzle();
Statement stmt = conn.createStatement();
stmt.execute("drop table if exists bigblob2");
stmt.execute("create table bigblob2 (id int not null primary key auto_increment, test longblob, test2 longblob)");
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/drizzle/jdbc/BlobStreamingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class BlobStreamingTest {

public BlobStreamingTest() throws SQLException {
//connection = DriverManager.getConnection("jdbc:mysql:thin://10.100.100.50:3306/test_units_jdbc");
connection = DriverManager.getConnection("jdbc:drizzle://"+host+":3307/test_units_jdbc?enableBlobStreaming=true");
connection=ConnectionCheck.Get_ConnectionDrizzle("?enableBlobStreaming=truec");
//connection = DriverManager.getConnection("jdbc:mysql://10.100.100.50:3306/test_units_jdbc");
}
// @After
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/drizzle/jdbc/BlobTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void testBadStart2() throws SQLException {

@Test
public void testBug716378() throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:drizzle://" + DriverTest.host + ":3306/test_units_jdbc");
Connection conn=ConnectionCheck.Get_ConnectionDrizzle();
Statement stmt = conn.createStatement();
stmt.execute("drop table if exists bug716378");
stmt.execute("create table bug716378 (id int not null primary key auto_increment, test longblob, test2 blob, test3 text)");
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/drizzle/jdbc/BooleanTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
public class BooleanTest {
@Test
public void testBoolean() throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:drizzle://root@"+DriverTest.host+":4427/test_units_jdbc");
Connection conn=ConnectionCheck.Get_ConnectionDrizzle();
Statement stmt = conn.createStatement();
stmt.execute("drop table if exists booleantest");
stmt.execute("create table booleantest (id int not null primary key auto_increment, test boolean)");
Expand Down
22 changes: 11 additions & 11 deletions src/test/java/org/drizzle/jdbc/CancelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,18 @@
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLNonTransientException;
import java.sql.Statement;

import static org.junit.Assert.assertTrue;

public class CancelTest {
@Test(expected = SQLQueryCancelledException.class)
public void cancelQuery() throws SQLException, InterruptedException {
Connection conn = DriverManager.getConnection("jdbc:drizzle://"+DriverTest.host+":3306/test_units_jdbc");
Connection conn=ConnectionCheck.Get_ConnectionDrizzle();
Statement stmt = conn.createStatement();
new CancelThread(stmt).start();
stmt.execute("select * from information_schema.columns, information_schema.tables, information_schema.table_constraints");
stmt.execute("select * from information_schema.columns CROSS JOIN information_schema.tables CROSS JOIN information_schema.table_constraints");

}
private static class CancelThread extends Thread {
Expand All @@ -47,22 +45,24 @@ public void run() {

@Test(expected = SQLQueryTimedOutException.class)
public void timeoutQuery() throws SQLException, InterruptedException {
Connection conn = DriverManager.getConnection("jdbc:drizzle://"+DriverTest.host+":3306/test_units_jdbc");
Statement stmt = conn.createStatement();
stmt.setQueryTimeout(1);
stmt.executeQuery("select * from information_schema.columns, information_schema.tables, information_schema.table_constraints");
Connection conn=ConnectionCheck.Get_ConnectionDrizzle();

Statement stmt = conn.createStatement();
stmt.setQueryTimeout(1);
stmt.executeQuery("select * from information_schema.columns CROSS JOIN information_schema.tables CROSS JOIN information_schema.table_constraints");


}
@Test(expected = SQLQueryTimedOutException.class)
public void timeoutPrepQuery() throws SQLException, InterruptedException {
Connection conn = DriverManager.getConnection("jdbc:drizzle://"+DriverTest.host+":3306/test_units_jdbc");
PreparedStatement stmt = conn.prepareStatement("select * from information_schema.columns, information_schema.tables, information_schema.table_constraints");
Connection conn=ConnectionCheck.Get_ConnectionDrizzle();
PreparedStatement stmt = conn.prepareStatement("select * from information_schema.columns CROSS JOIN information_schema.tables CROSS JOIN information_schema.table_constraints");
stmt.setQueryTimeout(1);
stmt.execute();
}
@Test(expected = SQLNonTransientException.class)
public void connectionTimeout() throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:drizzle://www.google.com:1234/test_units_jdbc?connectTimeout=1");
Connection conn = DriverManager.getConnection("jdbc:drizzle://www.google.com:1234/test_units_jdbc?connectTimeout=1");
}


Expand Down
99 changes: 99 additions & 0 deletions src/test/java/org/drizzle/jdbc/ConnectionCheck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.drizzle.jdbc;

import org.junit.Test;
import static org.junit.Assert.assertEquals;

import java.sql.*;
import java.util.logging.Logger;
import java.util.logging.Level;

/**
*
* @author waqas
*/
public class ConnectionCheck {
public static String host="localhost";
public static String mysql_host="localhost";
public static Connection Get_ConnectionDrizzle() throws SQLException
{
Connection connection;
if (host.contains(":"))
{

connection = DriverManager.getConnection("jdbc:drizzle://root@" + host + "/test_units_jdbc");
}
else
{

connection = DriverManager.getConnection("jdbc:drizzle://root@" + host + ":4427/test_units_jdbc");
}
return connection;
}
public static Connection Get_ConnectionDrizzle(String Property) throws SQLException
{
Connection connection;
if (host.contains(":"))
{

connection = DriverManager.getConnection("jdbc:drizzle://root@" + host + "/test_units_jdbc"+Property);
}
else
{

connection = DriverManager.getConnection("jdbc:drizzle://root@" + host + ":4427/test_units_jdbc"+Property);
}
return connection;
}
public static Connection Get_ConnectionMySQL() throws SQLException
{
Connection connection;
if (mysql_host.contains(":"))
{

connection = DriverManager.getConnection("jdbc:mysql:thin://"+mysql_host+"/test_units_jdbc");
}
else
{

connection = DriverManager.getConnection("jdbc:mysql:thin://"+mysql_host+":3306/test_units_jdbc");
}
return connection;
}
public static Connection Get_ConnectionMySQL_WithUsername(String Username) throws SQLException
{
Connection connection;
if (mysql_host.contains(":"))
{

connection = DriverManager.getConnection("jdbc:mysql:thin://"+Username+"@"+mysql_host+"/test_units_jdbc");
}
else
{

connection = DriverManager.getConnection("jdbc:mysql:thin://"+Username+"@"+mysql_host+":3306/test_units_jdbc");
}
return connection;
}
public static Connection Get_ConnectionMySQL(String Property) throws SQLException
{
Connection connection;
if (mysql_host.contains(":"))
{

connection = DriverManager.getConnection("jdbc:mysql:thin://"+mysql_host+"/test_units_jdbc"+Property);
}
else
{

connection = DriverManager.getConnection("jdbc:mysql:thin://"+mysql_host+":3306/test_units_jdbc"+Property);
}

return connection;
}


}
27 changes: 24 additions & 3 deletions src/test/java/org/drizzle/jdbc/DataSourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,36 @@
* To change this template use File | Settings | File Templates.
*/
public class DataSourceTest {
@Test

DataSource ds;
public void testDrizzleDataSource() throws SQLException {
DataSource ds = new DrizzleDataSource(DriverTest.host,3307,"test_units_jdbc");
if (ConnectionCheck.host.contains(":"))
{
String copyhost_forsplit=ConnectionCheck.host;
String Brk[]=copyhost_forsplit.split(":");
int convert=Integer.parseInt(Brk[1]);
ds = new DrizzleDataSource(Brk[0],convert,"test_units_jdbc");
}
else
{
ds = new DrizzleDataSource(ConnectionCheck.host,3307,"test_units_jdbc");
}
Connection connection = ds.getConnection("root", null);
assertEquals(connection.isValid(0),true);
}
@Test
public void testDrizzleDataSource2() throws SQLException {
DataSource ds = new DrizzleDataSource(DriverTest.host,3307,"test_units_jdbc");
if (ConnectionCheck.host.contains(":"))
{
String copyhost_forsplit=ConnectionCheck.host;
String Brk[]=copyhost_forsplit.split(":");
int convert=Integer.parseInt(Brk[1]);
ds = new DrizzleDataSource(Brk[0],convert,"test_units_jdbc");
}
else
{
ds = new DrizzleDataSource(ConnectionCheck.host,3307,"test_units_jdbc");
}
Connection connection = ds.getConnection("root","");
assertEquals(connection.isValid(0),true);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/drizzle/jdbc/DatabaseMetadataTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class DatabaseMetadataTest {
static { Logger.getLogger("").setLevel(Level.OFF); }
private Connection connection;
public DatabaseMetadataTest() throws ClassNotFoundException, SQLException {
connection = DriverManager.getConnection("jdbc:drizzle://root@"+DriverTest.host+":3307/test_units_jdbc");
connection = ConnectionCheck.Get_ConnectionDrizzle();
//connection = DriverManager.getConnection("jdbc:mysql://a@localhost:3306/test_units_jdbc");
}
@Test
Expand Down
14 changes: 6 additions & 8 deletions src/test/java/org/drizzle/jdbc/DateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class DateTest {
static { Logger.getLogger("").setLevel(Level.OFF); }
@Test
public void dateTest() throws SQLException {
Connection connection = DriverManager.getConnection("jdbc:drizzle://root@"+DriverTest.host+":3307/test_units_jdbc");
Connection connection=ConnectionCheck.Get_ConnectionDrizzle();

Statement stmt = connection.createStatement();
stmt.executeUpdate("drop table if exists date_test");
Expand Down Expand Up @@ -51,8 +51,7 @@ public void dateTest() throws SQLException {
}
@Test(expected = SQLException.class)
public void dateTest2() throws SQLException {
Connection connection = DriverManager.getConnection("jdbc:drizzle://"+DriverTest.host+":4427/test_units_jdbc");

Connection connection = ConnectionCheck.Get_ConnectionDrizzle();
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("select 1");
rs.next();
Expand All @@ -61,7 +60,7 @@ public void dateTest2() throws SQLException {

@Test(expected = SQLException.class)
public void dateTest3() throws SQLException {
Connection connection = DriverManager.getConnection("jdbc:drizzle://"+DriverTest.host+":4427/test_units_jdbc");
Connection connection = ConnectionCheck.Get_ConnectionDrizzle();

Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("select 1 as a");
Expand All @@ -70,8 +69,7 @@ public void dateTest3() throws SQLException {
}
@Test(expected = SQLException.class)
public void timeTest3() throws SQLException {
Connection connection = DriverManager.getConnection("jdbc:drizzle://"+DriverTest.host+":4427/test_units_jdbc");

Connection connection= ConnectionCheck.Get_ConnectionDrizzle();
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("select 'aaa' as a");
rs.next();
Expand All @@ -95,7 +93,7 @@ public void timePackTest() {

@Test
public void yearTest() throws SQLException {
Connection connection = DriverManager.getConnection("jdbc:mysql:thin://"+DriverTest.host+":3306/test_units_jdbc");
Connection connection=ConnectionCheck.Get_ConnectionMySQL();
connection.createStatement().execute("drop table if exists yeartest");
connection.createStatement().execute("create table yeartest (y1 year, y2 year(2))");
connection.createStatement().execute("insert into yeartest values (null, null), (1901, 70), (0, 0), (2155, 69)");
Expand All @@ -111,7 +109,7 @@ public void yearTest() throws SQLException {
}
@Test
public void timeTest() throws SQLException {
Connection connection = DriverManager.getConnection("jdbc:mysql:thin://"+DriverTest.host+":3306/test_units_jdbc");
Connection connection=ConnectionCheck.Get_ConnectionMySQL();
connection.createStatement().execute("drop table if exists timetest");
connection.createStatement().execute("create table timetest (t time)");
connection.createStatement().execute("insert into timetest values (null), ('-838:59:59'), ('00:00:00'), ('838:59:59')");
Expand Down
31 changes: 23 additions & 8 deletions src/test/java/org/drizzle/jdbc/DriverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@
* Time: 7:58:11 AM
*/
public class DriverTest {
public static String host = "10.100.100.50";

private Connection connection;
static { Logger.getLogger("").setLevel(Level.OFF); }


public DriverTest() throws SQLException {
//connection = DriverManager.getConnection("jdbc:mysql:thin://10.100.100.50:3306/test_units_jdbc");
connection = DriverManager.getConnection("jdbc:drizzle://root@"+host+":3307/test_units_jdbc");
connection=ConnectionCheck.Get_ConnectionDrizzle();
//connection = DriverManager.getConnection("jdbc:mysql://10.100.100.50:3306/test_units_jdbc");
}
@After
Expand Down Expand Up @@ -836,8 +837,8 @@ public void testException1() throws SQLException {

@Test
public void testExceptionDivByZero() throws SQLException {


String dbname=getConnection().getMetaData().getDatabaseProductName();
System.out.println(dbname);
if(getConnection().getMetaData().getDatabaseProductName().toLowerCase().equals("drizzle")) {
boolean threwException = false;
try{
Expand All @@ -847,10 +848,12 @@ public void testExceptionDivByZero() throws SQLException {
}
assertEquals(true,threwException);
} else {
ResultSet rs = getConnection().createStatement().executeQuery("select 1/0");
ResultSet rs;
rs= getConnection().createStatement().executeQuery("select 1/0");
assertEquals(rs.next(),true);
assertEquals(null, rs.getString(1));
}
}

}
@Test(expected = SQLSyntaxErrorException.class)
public void testSyntaxError() throws SQLException {
Expand Down Expand Up @@ -1215,11 +1218,23 @@ public void testBit() throws SQLException {
@Test
public void testConnectWithDB() throws SQLException {

Connection conn = DriverManager.getConnection("jdbc:mysql:thin://"+host+":3306/");
Connection conn;
String AddPortToHost=ConnectionCheck.mysql_host;
if(!ConnectionCheck.mysql_host.contains(":"))
{
AddPortToHost=AddPortToHost+":3306/";
}
else
{
AddPortToHost=AddPortToHost+"/";
}

conn = DriverManager.getConnection("jdbc:mysql:thin://"+AddPortToHost);

try {
conn.createStatement().executeUpdate("drop database test_units_jdbc_testdrop");
} catch (Exception e) {}
conn = DriverManager.getConnection("jdbc:mysql:thin://"+host+":3306/test_units_jdbc_testdrop?createDB=true");
conn=ConnectionCheck.Get_ConnectionMySQL("_testdrop?createDB=true");
DatabaseMetaData dbmd = conn.getMetaData();
ResultSet rs = dbmd.getSchemas();
boolean foundDb = false;
Expand Down
Loading