Add tests from develop
Added tests from develop. The test results need to be modified for 2.0.
This commit is contained in:
30
maxscale-system-test/maxscale/java/CMakeLists.txt
Normal file
30
maxscale-system-test/maxscale/java/CMakeLists.txt
Normal file
@ -0,0 +1,30 @@
|
||||
# Function for declaring java tests
|
||||
#
|
||||
# name Name of the test
|
||||
# src Test source files
|
||||
# entry_point The entry point of the JAR file
|
||||
# template The configuration template for this test
|
||||
#
|
||||
function(add_java_test name src entry_point template)
|
||||
add_jar(${name} SOURCES ${src} ${MXS_JAR}
|
||||
ENTRY_POINT ${entry_point} INCLUDE_JARS ${MXS_JAR} ${JDBC_JAR})
|
||||
add_test(NAME ${name} COMMAND java
|
||||
-cp ${TEST_JARPATH}:${CMAKE_CURRENT_BINARY_DIR}/${name}.jar
|
||||
${entry_point}
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||
add_template(${name} ${template})
|
||||
add_dependencies(${name} maxscale_java)
|
||||
set_property(TEST ${name} PROPERTY LABELS java)
|
||||
endfunction()
|
||||
|
||||
# Some constants that make changing the connector easier
|
||||
set(JDBC_JAR ${CMAKE_CURRENT_SOURCE_DIR}/mariadb-java-client-1.5.4.jar CACHE INTERNAL "")
|
||||
set(MXS_JAR ${CMAKE_CURRENT_BINARY_DIR}/maxscale_java.jar CACHE INTERNAL "")
|
||||
set(TEST_JARPATH "${MXS_JAR}:${JDBC_JAR}" CACHE INTERNAL "")
|
||||
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/MaxScaleConfiguration.java.in ${CMAKE_CURRENT_BINARY_DIR}/MaxScaleConfiguration.java @ONLY)
|
||||
add_jar(maxscale_java SOURCES MaxScaleConnection.java MaxScaleConfiguration.java
|
||||
INCLUDE_JARS mariadb-java-client-1.5.4.jar)
|
||||
add_subdirectory(test1)
|
||||
add_subdirectory(prep_stmt)
|
||||
add_subdirectory(batch)
|
@ -0,0 +1,39 @@
|
||||
package maxscale.java;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* MaxScale configuration class
|
||||
*
|
||||
* Configures MaxScale for testing
|
||||
*/
|
||||
public class MaxScaleConfiguration {
|
||||
|
||||
private static final String TEST_DIR = "@CMAKE_SOURCE_DIR@";
|
||||
private static final String CONFIG_COMMAND = TEST_DIR + "/non_native_setup";
|
||||
private static final String LOGS_COMMAND = TEST_DIR + "/copy_logs.sh";
|
||||
private String test = null;
|
||||
|
||||
public MaxScaleConfiguration(String test) throws Exception
|
||||
{
|
||||
this.test = test;
|
||||
ProcessBuilder pb = new ProcessBuilder(CONFIG_COMMAND, test);
|
||||
pb.inheritIO();
|
||||
pb.directory(new File(TEST_DIR));
|
||||
pb.environment().put("test_dir", TEST_DIR);
|
||||
Process process = pb.start();
|
||||
process.waitFor();
|
||||
}
|
||||
|
||||
public void close() {
|
||||
try {
|
||||
ProcessBuilder pb = new ProcessBuilder(LOGS_COMMAND, test);
|
||||
pb.inheritIO();
|
||||
pb.directory(new File(TEST_DIR));
|
||||
Process process = pb.start();
|
||||
process.waitFor();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
102
maxscale-system-test/maxscale/java/MaxScaleConnection.java
Normal file
102
maxscale-system-test/maxscale/java/MaxScaleConnection.java
Normal file
@ -0,0 +1,102 @@
|
||||
package maxscale.java;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
/**
|
||||
* Simple MaxScale connection class
|
||||
*
|
||||
* Allows execution of queries to one of the MaxScale services configured for
|
||||
* testing.
|
||||
*/
|
||||
public class MaxScaleConnection {
|
||||
|
||||
private static String ip = null;
|
||||
private static String user = null;
|
||||
private static String password = null;
|
||||
private static boolean smoke_test = false;
|
||||
private Connection conn_rw = null, conn_master = null, conn_slave = null;
|
||||
public static final int READWRITESPLIT_PORT = 4006;
|
||||
public static final int READCONNROUTE_MASTER_PORT = 4008;
|
||||
public static final int READCONNROUTE_SLAVE_PORT = 4009;
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public String getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public Connection getConnRw() {
|
||||
return conn_rw;
|
||||
}
|
||||
|
||||
public Connection getConnMaster() {
|
||||
return conn_master;
|
||||
}
|
||||
|
||||
public Connection getConnSlave() {
|
||||
return conn_slave;
|
||||
}
|
||||
|
||||
public void setConnRw(Connection conn) {
|
||||
conn_rw = conn;
|
||||
}
|
||||
|
||||
public void setConnMaster(Connection conn) {
|
||||
conn_master = conn;
|
||||
}
|
||||
|
||||
public void setConnSlave(Connection conn) {
|
||||
conn_slave = conn;
|
||||
}
|
||||
|
||||
public MaxScaleConnection(String options) throws SQLException, Exception {
|
||||
String s = System.getenv("smoke");
|
||||
smoke_test = (s != null && s.compareTo("yes") == 0);
|
||||
|
||||
if ((ip = System.getenv("maxscale_IP")) == null || ip.length() == 0) {
|
||||
throw new Exception("Missing environment variable 'maxscale_IP'.");
|
||||
}
|
||||
|
||||
if ((user = System.getenv("maxscale_user")) == null || user.length() == 0) {
|
||||
throw new Exception("Missing environment variable 'maxscale_user'.");
|
||||
}
|
||||
|
||||
if ((password = System.getenv("maxscale_password")) == null || password.length() == 0) {
|
||||
throw new Exception("Missing environment variable 'maxscale_password'.");
|
||||
}
|
||||
|
||||
System.out.println("IP: " + ip + " User: " + user + " Password: " + password);
|
||||
|
||||
Class.forName("org.mariadb.jdbc.Driver");
|
||||
conn_rw = DriverManager.getConnection(
|
||||
"jdbc:mariadb://" + ip + ":" + READWRITESPLIT_PORT + "/test?" + options, user, password);
|
||||
|
||||
conn_master = DriverManager.getConnection(
|
||||
"jdbc:mariadb://" + ip + ":" + READCONNROUTE_MASTER_PORT + "/test?" + options, user, password);
|
||||
|
||||
conn_slave = DriverManager.getConnection(
|
||||
"jdbc:mariadb://" + ip + ":" + READCONNROUTE_SLAVE_PORT + "/test?" + options, user, password);
|
||||
}
|
||||
|
||||
public MaxScaleConnection() throws SQLException, Exception {
|
||||
this("");
|
||||
}
|
||||
|
||||
public boolean isSmokeTest() {
|
||||
return smoke_test;
|
||||
}
|
||||
|
||||
public void query(Connection connection, String query) throws SQLException {
|
||||
Statement stmt = connection.createStatement();
|
||||
stmt.execute(query);
|
||||
}
|
||||
}
|
48
maxscale-system-test/maxscale/java/batch/BatchInsert.java
Normal file
48
maxscale-system-test/maxscale/java/batch/BatchInsert.java
Normal file
@ -0,0 +1,48 @@
|
||||
package maxscale.java.batch;
|
||||
|
||||
import maxscale.java.MaxScaleConfiguration;
|
||||
import maxscale.java.MaxScaleConnection;
|
||||
import java.sql.Connection;
|
||||
import java.sql.Statement;
|
||||
|
||||
public class BatchInsert {
|
||||
|
||||
public static void main(String[] args) {
|
||||
boolean error = false;
|
||||
try {
|
||||
MaxScaleConfiguration config = new MaxScaleConfiguration("batchinsert");
|
||||
MaxScaleConnection maxscale = new MaxScaleConnection("useBatchMultiSendNumber=500");
|
||||
|
||||
try {
|
||||
Connection connection = maxscale.getConnRw();
|
||||
Statement stmt = connection.createStatement();
|
||||
|
||||
stmt.execute("DROP TABLE IF EXISTS tt");
|
||||
stmt.execute("CREATE TABLE tt (d int)");
|
||||
|
||||
for (int i = 0; i < 150; i++) {
|
||||
stmt.addBatch("INSERT INTO tt(d) VALUES (1)");
|
||||
|
||||
if (i % 3 == 0) {
|
||||
stmt.addBatch("SET @test2='aaa'");
|
||||
}
|
||||
}
|
||||
|
||||
stmt.executeBatch();
|
||||
System.out.println("finished");
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error: " + e.getMessage());
|
||||
error = true;
|
||||
}
|
||||
config.close();
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error: " + e.getMessage());
|
||||
}
|
||||
|
||||
if (error) {
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
2
maxscale-system-test/maxscale/java/batch/CMakeLists.txt
Normal file
2
maxscale-system-test/maxscale/java/batch/CMakeLists.txt
Normal file
@ -0,0 +1,2 @@
|
||||
add_java_test(batchinsert BatchInsert.java maxscale.java.batch.BatchInsert batchinsert)
|
||||
set_tests_properties(batchinsert PROPERTIES TIMEOUT 300)
|
BIN
maxscale-system-test/maxscale/java/mariadb-java-client-1.5.4.jar
Normal file
BIN
maxscale-system-test/maxscale/java/mariadb-java-client-1.5.4.jar
Normal file
Binary file not shown.
@ -0,0 +1 @@
|
||||
add_java_test(java_prep_stmt PrepStmtTest.java maxscale.java.prep_stmt.PrepStmtTest java_prep_stmt)
|
128
maxscale-system-test/maxscale/java/prep_stmt/PrepStmtTest.java
Normal file
128
maxscale-system-test/maxscale/java/prep_stmt/PrepStmtTest.java
Normal file
@ -0,0 +1,128 @@
|
||||
package maxscale.java.prep_stmt;
|
||||
|
||||
import maxscale.java.MaxScaleConfiguration;
|
||||
import maxscale.java.MaxScaleConnection;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class PrepStmtTest {
|
||||
|
||||
public static final int RWSPLIT_PORT = 4006;
|
||||
public static final String DATABASE_NAME = "test";
|
||||
public static final String TABLE_NAME = "t1";
|
||||
|
||||
public static final int THREADS = 5;
|
||||
public static final int ITERATIONS_NORMAL = 100;
|
||||
public static final int ITERATIONS_SMOKE = 50;
|
||||
public static int test_iter = ITERATIONS_NORMAL;
|
||||
|
||||
public static final String INSERT_SQL = "INSERT INTO " + DATABASE_NAME + "." + TABLE_NAME + " VALUES (NULL, ?)";
|
||||
public static final String SELECT_SQL = "SELECT * FROM " + DATABASE_NAME + "." + TABLE_NAME + " WHERE id = ?";
|
||||
|
||||
public static String conn_str = null;
|
||||
public static String user = null;
|
||||
public static String password = null;
|
||||
|
||||
public static void main(String[] args) {
|
||||
boolean error = false;
|
||||
|
||||
try {
|
||||
MaxScaleConfiguration config = new MaxScaleConfiguration("java_prep_stmt");
|
||||
MaxScaleConnection maxscale = new MaxScaleConnection();
|
||||
|
||||
try {
|
||||
test_iter = ITERATIONS_SMOKE;
|
||||
|
||||
// Prepare test database
|
||||
System.out.println("Creating databases and tables..");
|
||||
maxscale.query(maxscale.getConnMaster(), "DROP DATABASE IF EXISTS " + DATABASE_NAME);
|
||||
maxscale.query(maxscale.getConnMaster(), "CREATE DATABASE " + DATABASE_NAME);
|
||||
maxscale.query(maxscale.getConnMaster(), "CREATE TABLE " + DATABASE_NAME
|
||||
+ "." + TABLE_NAME + "(id int primary key auto_increment, data varchar(128))");
|
||||
|
||||
|
||||
conn_str = "jdbc:mariadb://" + maxscale.getIp() + ":" +
|
||||
MaxScaleConnection.READWRITESPLIT_PORT + "/test?";
|
||||
user = maxscale.getUser();
|
||||
password = maxscale.getPassword();
|
||||
|
||||
ArrayList<Thread> threads = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < THREADS; i++) {
|
||||
threads.add(new Thread(){
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
Connection conn = DriverManager.getConnection(conn_str, user, password);
|
||||
conn.setAutoCommit(false);
|
||||
|
||||
for (int i = 0; i < test_iter; i++) {
|
||||
conn.isValid(1);
|
||||
|
||||
PreparedStatement ps_insert = conn.prepareStatement(PrepStmtTest.INSERT_SQL);
|
||||
|
||||
ps_insert.setString(1, String.valueOf(i));
|
||||
ps_insert.executeUpdate();
|
||||
conn.commit();
|
||||
|
||||
conn.isValid(1);
|
||||
|
||||
PreparedStatement ps_select = conn.prepareStatement(PrepStmtTest.SELECT_SQL);
|
||||
ps_select.setInt(1, i);
|
||||
ResultSet rset = ps_select.executeQuery();
|
||||
|
||||
conn.isValid(1);
|
||||
|
||||
while (rset.next()) {
|
||||
int r = rset.getInt(1);
|
||||
String s = rset.getString(2);
|
||||
if (i % 10 == 0) {
|
||||
System.out.println("Result: " + String.valueOf(r) + " " + s);
|
||||
}
|
||||
}
|
||||
}
|
||||
conn.close();
|
||||
} catch (Exception ex) {
|
||||
System.out.println("Error: " + ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
System.out.println("Starting " + String.valueOf(threads.size()) + " threads");
|
||||
|
||||
for (Thread a: threads) {
|
||||
a.start();
|
||||
}
|
||||
|
||||
for (Thread a: threads) {
|
||||
a.join();
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
error = true;
|
||||
System.out.println("Error: " + ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
config.close();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
error = true;
|
||||
System.out.println("Error: " + ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
if (error) {
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
1
maxscale-system-test/maxscale/java/test1/CMakeLists.txt
Normal file
1
maxscale-system-test/maxscale/java/test1/CMakeLists.txt
Normal file
@ -0,0 +1 @@
|
||||
add_java_test(simplejavatest SimpleConnectorJTest.java maxscale.java.test1.SimpleConnectorJTest simplejavatest)
|
@ -0,0 +1,69 @@
|
||||
package maxscale.java.test1;
|
||||
|
||||
import maxscale.java.MaxScaleConfiguration;
|
||||
import maxscale.java.MaxScaleConnection;
|
||||
|
||||
public class SimpleConnectorJTest {
|
||||
|
||||
public static final int RWSPLIT_PORT = 4006;
|
||||
public static final int READCONN_MASTER = 4008;
|
||||
public static final int READCONN_SLAVE = 4009;
|
||||
public static final String DATABASE_NAME = "mytestdb";
|
||||
public static final String TABLE_NAME = "t1";
|
||||
public static final int ITERATIONS_NORMAL = 1500;
|
||||
public static final int ITERATIONS_SMOKE = 150;
|
||||
public static int test_rows = ITERATIONS_NORMAL;
|
||||
|
||||
public static void main(String[] args) {
|
||||
boolean error = false;
|
||||
|
||||
try {
|
||||
MaxScaleConfiguration config = new MaxScaleConfiguration("simplejavatest");
|
||||
MaxScaleConnection maxscale = new MaxScaleConnection();
|
||||
try {
|
||||
|
||||
if (maxscale.isSmokeTest()) {
|
||||
test_rows = ITERATIONS_SMOKE;
|
||||
}
|
||||
|
||||
System.out.println("Creating databases and tables..");
|
||||
maxscale.query(maxscale.getConnMaster(), "DROP DATABASE IF EXISTS " + DATABASE_NAME);
|
||||
maxscale.query(maxscale.getConnMaster(), "CREATE DATABASE " + DATABASE_NAME);
|
||||
maxscale.query(maxscale.getConnMaster(), "CREATE TABLE " + DATABASE_NAME
|
||||
+ "." + TABLE_NAME + "(id int primary key auto_increment, data varchar(128))");
|
||||
|
||||
System.out.println("Inserting " + test_rows + " values");
|
||||
for (int i = 0; i < test_rows; i++) {
|
||||
maxscale.query(maxscale.getConnMaster(),
|
||||
"INSERT INTO " + DATABASE_NAME + "." + TABLE_NAME
|
||||
+ "(data) VALUES (" + String.valueOf(System.currentTimeMillis()) + ")");
|
||||
}
|
||||
|
||||
System.out.println("Querying " + test_rows / 10 + "rows " + test_rows + " times");
|
||||
for (int i = 0; i < test_rows; i++) {
|
||||
maxscale.query(maxscale.getConnMaster(),
|
||||
"SELECT * FROM " + DATABASE_NAME + "." + TABLE_NAME
|
||||
+ " LIMIT " + test_rows / 10);
|
||||
}
|
||||
|
||||
maxscale.query(maxscale.getConnMaster(), "DROP DATABASE IF EXISTS " + DATABASE_NAME);
|
||||
|
||||
} catch (Exception ex) {
|
||||
error = true;
|
||||
System.out.println("Error: " + ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
config.close();
|
||||
|
||||
} catch (Exception ex) {
|
||||
error = true;
|
||||
System.out.println("Error: " + ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
if (error) {
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user