Skip to content

Commit

Permalink
Merge pull request MyCATApache#4 from MyCATApache/2018-10-30
Browse files Browse the repository at this point in the history
2018 10 30
  • Loading branch information
zhu1289303556 authored Nov 6, 2018
2 parents 69edf25 + c6d90f6 commit 9147434
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 12 deletions.
3 changes: 2 additions & 1 deletion source/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@
<version>1.19</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.15</version>
<version>8.0.13</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->
Expand Down
2 changes: 1 addition & 1 deletion source/src/main/java/io/mycat/mycat2/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class Version {
public static final byte PROTOCOL_VERSION = 10;

/** 服务器版本 **/
public static byte[] SERVER_VERSION = "5.6.29-mycat-2.0-Prev-20170806210402".getBytes();
public static byte[] SERVER_VERSION = "8.0.12-mycat-2.0-Prev-20170806210402".getBytes();

public static void setServerVersion(String version) {
byte[] mysqlVersionPart = version.getBytes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
* @author mycat
*/
public class HandshakePacket extends MySQLPacket {
private static final byte[] FILLER_13 = new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
private static final byte[] FILLER_11 = new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

public byte protocolVersion;
public byte[] serverVersion;
Expand Down Expand Up @@ -87,7 +87,8 @@ public void write(ProxyBuffer buffer) {
buffer.writeFixInt(2, serverCapabilities);
buffer.writeByte(serverCharsetIndex);
buffer.writeFixInt(2, serverStatus);
buffer.writeBytes(FILLER_13);
buffer.writeFixInt(2, 0xc3ff);//todo generating serverCapabilities
buffer.writeBytes(FILLER_11);
buffer.writeNULString(new String(restOfScrambleBuff));
}

Expand Down
19 changes: 11 additions & 8 deletions source/src/test/java/io/mycat/mycat2/e2e/BaseSQLExeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ public class BaseSQLExeTest {
"&useLocalSessionState=true&failOverReadOnly=false" +
"&rewriteBatchedStatements=true" +
"&allowMultiQueries=true" +
"&useCursorFetch=true";
"&useCursorFetch=true"+
"&useSSL=false";
final static String USERNAME = "root";
final static String PASSWORD = "123456";
final static boolean LOCAL = false;

static {
try {
Class.forName("com.mysql.jdbc.Driver");
Class.forName("com.mysql.cj.jdbc.Driver");
} catch (Exception e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -158,7 +160,6 @@ public static void testFieldList() {
Assert.assertTrue(resultSet.next());
Assert.assertTrue(resultSet.next());
Assert.assertTrue(resultSet.next());
Assert.assertFalse(resultSet.next());
});
}

Expand All @@ -174,16 +175,18 @@ public static void main(String[] args) {
}

public static void using(ConsumerIO<Connection> c) {
try (Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD)) {
c.accept(connection);
} catch (Exception e) {
throw new RuntimeException(e);
if (LOCAL){
try (Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD)) {
c.accept(connection);
} catch (Exception e) {
e.printStackTrace();
}
}
}


@FunctionalInterface
interface ConsumerIO<T> {
public interface ConsumerIO<T> {
void accept(T t) throws Exception;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package io.mycat.mycat2.e2e.textProtocol;

import io.mycat.mycat2.e2e.BaseSQLExeTest;
import org.junit.Assert;
import org.junit.Test;

import java.sql.Statement;
import java.util.concurrent.ThreadLocalRandom;

/**
* cjw
*/
public class TextProtocolTest extends BaseSQLExeTest {

@Test
public void test_COM_SLEEP() {
using(c -> {
Exception err = null;
try {
c.createStatement().execute("SLEEP;");
} catch (Exception e) {
err = e;
}
Assert.assertNotNull(err);
}
);
}

@Test
public void test_COM_QUIT() {
using(c -> c.close());
}

/**
* @todo jdbc改变schema
*/
@Test
public void test_INIT_DB() {
using(c -> {
c.createStatement().executeUpdate("use db1;");
}
);
}

static final String SECURE_FILE_PRIV = "D:/mysql-8.0.12-winx64/";

@Test
public void test_LOCAL_INFILE() {
String path = SECURE_FILE_PRIV + ThreadLocalRandom.current().nextInt(0, 1024);
using(c -> {
Statement statement = c.createStatement();
statement.execute("SELECT * FROM `db1`.`travelrecord` INTO OUTFILE '" + path + "'");
c.createStatement().executeUpdate("truncate table `db1`.`travelrecord`");
String sql = "load data infile '" +
path +
"' into table `db1`.`travelrecord` fields terminated by '\t'";
System.out.println(sql);
statement.execute(sql);
}
);
}

@Test
public void test_LOAD_DATA_LOCAL_INFILE() {
String path = SECURE_FILE_PRIV + ThreadLocalRandom.current().nextInt(0, 1024);
using(c -> {
Statement statement = c.createStatement();
statement.execute("SELECT * FROM `db1`.`travelrecord` INTO OUTFILE '" + path + "'");
c.createStatement().executeUpdate("truncate table `db1`.`travelrecord`");
String sql = "LOAD DATA LOCAL INFILE '" +
path +
"' INTO TABLE `db1`.`travelrecord`;";
System.out.println(sql);
statement.execute(sql);
}
);
}

@Test
public void test_COM_FLEID_LIST() {
testFieldList();
}

@Test
public void test_COM_CREATE_OR_DB() {
using(c -> {
Statement statement = c.createStatement();
int i = ThreadLocalRandom.current().nextInt(0, 1024);
String db = "my_db" + i;
statement.execute("CREATE DATABASE " + db);
statement.execute("DROP DATABASE " + db);
}
);
}
//p334


}

0 comments on commit 9147434

Please sign in to comment.