mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-16 10:26:05 -06:00
First pass at Java MySQL Connector test. This has a dependency on the mysql-connector-java jar file. We'll have to figure out classpath and dependency resolution once we start running these programmatically. The program also only checks the first row, column pair or rows updated of the output to see if it matched expected. This is a pretty big simplification to avoid defining too much configuration.
This commit is contained in:
74
mysql-client-tests/java/MySQLConnectorTest.java
Normal file
74
mysql-client-tests/java/MySQLConnectorTest.java
Normal file
@@ -0,0 +1,74 @@
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.sql.ResultSet;
|
||||
|
||||
public class MySQLConnectorTest {
|
||||
public static void main(String[] args) {
|
||||
Connection conn = null;
|
||||
|
||||
String user = args[0];
|
||||
String port = args[1];
|
||||
String db = args[2];
|
||||
|
||||
try {
|
||||
String url = "jdbc:mysql://127.0.0.1:" + port + "/" + db;
|
||||
|
||||
String password = "";
|
||||
|
||||
conn = DriverManager.getConnection(url, user, password);
|
||||
|
||||
Statement st = conn.createStatement();
|
||||
|
||||
String[] queries = {
|
||||
"create table test (pk int, value int, primary key(pk))",
|
||||
"describe test",
|
||||
"select * from test",
|
||||
"insert into test (pk, value) values (0,0)",
|
||||
"select * from test"
|
||||
};
|
||||
|
||||
// Only test the first row, column pair for now
|
||||
String[] results = {
|
||||
"0",
|
||||
"pk",
|
||||
null,
|
||||
"1",
|
||||
"0"
|
||||
};
|
||||
|
||||
for (int i = 0; i < queries.length; i++) {
|
||||
String query = queries[i];
|
||||
String expected = results[i];
|
||||
if ( st.execute(query) ) {
|
||||
ResultSet rs = st.getResultSet();
|
||||
if (rs.next()) {
|
||||
String result = rs.getString(1);
|
||||
if ( !expected.equals(result) ) {
|
||||
System.out.println("Query: \n" + query);
|
||||
System.out.println("Expected:\n" + expected);
|
||||
System.out.println("Result:\n" + result);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
String result = Integer.toString(st.getUpdateCount());
|
||||
if ( !expected.equals(result) ) {
|
||||
System.out.println("Query: \n" + query);
|
||||
System.out.println("Expected:\n" + expected);
|
||||
System.out.println("Rows Updated:\n" + result);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System.exit(0);
|
||||
|
||||
} catch (SQLException ex) {
|
||||
System.out.println("An error occurred.");
|
||||
ex.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user