chore: import upstream snapshot with attribution
Fuzzer / Run Fuzzer (push) Has been cancelled
Race tests / Go race tests (ubuntu-22.04) (push) Has been cancelled

This commit is contained in:
wehub-resource-sync
2026-07-13 13:01:40 +08:00
commit 5357c39144
2379 changed files with 670828 additions and 0 deletions
@@ -0,0 +1,117 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dolthub</groupId>
<artifactId>j</artifactId>
<version>1.0.0</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>8.2.0</version>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>3.5.3</version>
</dependency>
<dependency>
<groupId>org.mariadb</groupId>
<artifactId>r2dbc-mariadb</artifactId>
<version>1.2.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.1</version>
<executions>
<execution>
<id>mysql-connector-test</id>
<phase>package</phase>
<goals><goal>shade</goal></goals>
<configuration>
<finalName>mysql-connector-test</finalName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>MySQLConnectorTest</mainClass>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformers>
</configuration>
</execution>
<execution>
<id>mysql-connector-test-collation</id>
<phase>package</phase>
<goals><goal>shade</goal></goals>
<configuration>
<finalName>mysql-connector-test-collation</finalName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>MySQLConnectorTest_Collation</mainClass>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformers>
</configuration>
</execution>
<execution>
<id>mariadb-connector-test</id>
<phase>package</phase>
<goals><goal>shade</goal></goals>
<configuration>
<finalName>mariadb-connector-test</finalName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>MariaDBConnectorTest</mainClass>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformers>
</configuration>
</execution>
<execution>
<id>mariadb-R2DBC-test</id>
<phase>package</phase>
<goals><goal>shade</goal></goals>
<configuration>
<finalName>mariadb-R2DBC-test</finalName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>MariaDBR2DBCTest</mainClass>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,179 @@
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;
import java.util.Objects;
public class MariaDBConnectorTest {
// TestCase represents a single query test case
static class TestCase {
public String query;
public String expectedResult;
public Object fieldAccessor; // String (column name) or Integer (field position)
public TestCase(String query, String expectedResult, Object fieldAccessor) {
this.query = query;
this.expectedResult = expectedResult;
this.fieldAccessor = fieldAccessor;
}
}
// test queries to be run against Dolt
private static final TestCase[] testCases = {
new TestCase("create table test (pk int, `value` int, primary key(pk))", "0", 1),
new TestCase("describe test", "pk", 1),
new TestCase("select * from test", null, "pk"),
new TestCase("insert into test (pk, `value`) values (0,0)", "1", 1),
new TestCase("select * from test", "0", "test.pk"),
new TestCase("call dolt_add('-A')", "0", 1),
new TestCase("call dolt_commit('-m', 'my commit')", "0", 1),
new TestCase("select COUNT(*) FROM dolt_log", "2", 1),
new TestCase("call dolt_checkout('-b', 'mybranch')", "0", 1),
new TestCase("insert into test (pk, `value`) values (1,1)", "1", 1),
new TestCase("call dolt_commit('-a', '-m', 'my commit2')", "1", 1),
new TestCase("call dolt_checkout('main')", "0", 1),
new TestCase("call dolt_merge('mybranch')", "", 1),
new TestCase("select COUNT(*) FROM dolt_log", "3", "COUNT(*)"),
};
public static void main(String[] args) {
testStatements(args);
testServerSideCursors(args);
testCollation(args);
System.exit(0);
}
// testServerSideCursors does a simple smoke test with server-side cursors to make sure
// results can be read. Note that we don't test results here; this is just a high level
// smoke test that we can execute server-side cursors logic without the server erroring out.
// This test was added for a regression where server-side cursor logic was getting
// corrupted result set memory and sending invalid data to the client, which caused the
// server to error out and crash the connection. If any errors are encountered, a stack trace
// is printed and this function exits with a non-zero code.
// For more details, see: https://github.com/dolthub/dolt/issues/9125
private static void testServerSideCursors(String[] args) {
String user = args[0];
String port = args[1];
String db = args[2];
try {
// MariaDB JDBC URL format
String url = "jdbc:mariadb://127.0.0.1:" + port + "/" + db +
"?useCursorFetch=true";
Connection conn = DriverManager.getConnection(url, user, "");
executePreparedQuery(conn, "SELECT 1;");
executePreparedQuery(conn, "SELECT database();");
executePreparedQuery(conn, "SHOW COLLATION;");
executePreparedQuery(conn, "SHOW COLLATION;");
executePreparedQuery(conn, "SHOW COLLATION;");
} catch (SQLException ex) {
System.out.println("An error occurred.");
ex.printStackTrace();
System.exit(1);
}
}
// executePreparedQuery executes the specified |query| using |conn| as a prepared statement,
// and uses server-side cursor to fetch results. This method does not do any validation of
// results from the query. It is simply a smoke test to ensure the connection doesn't crash.
private static void executePreparedQuery(Connection conn, String query) throws SQLException {
PreparedStatement stmt = conn.prepareStatement(query, ResultSet.TYPE_FORWARD_ONLY);
stmt.setFetchSize(25); // needed to ensure a server-side cursor is used
ResultSet rs = stmt.executeQuery();
while (rs.next()) {}
rs.close();
stmt.close();
}
// testStatements executes the queries from |queries| and asserts their results from
// |expectedResults|. If any errors are encountered, a stack trace is printed and this
// function exits with a non-zero code.
private static void testStatements(String[] args) {
Connection conn = null;
String user = args[0];
String port = args[1];
String db = args[2];
try {
// MariaDB JDBC URL format
String url = "jdbc:mariadb://127.0.0.1:" + port + "/" + db;
String password = "";
conn = DriverManager.getConnection(url, user, password);
Statement st = conn.createStatement();
for (TestCase test : testCases) {
if ( st.execute(test.query) ) {
ResultSet rs = st.getResultSet();
if (rs.next()) {
String result = "";
if (test.fieldAccessor instanceof String) {
result = rs.getString((String)test.fieldAccessor);
} else if (test.fieldAccessor instanceof Integer) {
result = rs.getString((Integer)test.fieldAccessor);
} else {
System.out.println("Unsupported field accessor value: " + test.fieldAccessor);
System.exit(1);
}
if (!Objects.equals(test.expectedResult, result) &&
!(test.query.contains("dolt_commit")) &&
!(test.query.contains("dolt_merge"))) {
System.out.println("Query: \n" + test.query);
System.out.println("Expected:\n" + test.expectedResult);
System.out.println("Result:\n" + result);
System.exit(1);
}
}
} else {
String result = Integer.toString(st.getUpdateCount());
if ( !Objects.equals(test.expectedResult, result) ) {
System.out.println("Query: \n" + test.query);
System.out.println("Expected:\n" + test.expectedResult);
System.out.println("Rows Updated:\n" + result);
System.exit(1);
}
}
}
} catch (SQLException ex) {
System.out.println("An error occurred.");
ex.printStackTrace();
System.exit(1);
}
}
// testCollation tests that metadata queries work properly with collations.
// This is a regression test for https://github.com/dolthub/dolt/issues/9890
private static void testCollation(String[] args) {
String user = args[0];
String port = args[1];
String db = args[2];
try {
// MariaDB JDBC URL format
String url = "jdbc:mariadb://127.0.0.1:" + port + "/" + db;
Connection conn = DriverManager.getConnection(url, user, "");
// This should not throw an exception
ResultSet result = conn.getMetaData().getColumns(null, null, null, null);
// Close the result set
if (result != null) {
result.close();
}
conn.close();
} catch (SQLException ex) {
System.out.println("Collation test failed.");
ex.printStackTrace();
System.exit(1);
}
}
}
@@ -0,0 +1,107 @@
import io.r2dbc.spi.Connection;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.Result;
import org.mariadb.r2dbc.MariadbConnectionConfiguration;
import org.mariadb.r2dbc.MariadbConnectionFactory;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import java.time.Duration;
public class MariaDBR2DBCTest {
// TestCase represents a single query test case
static class TestCase {
public String query;
public boolean isUpdate;
public TestCase(String query, boolean isUpdate) {
this.query = query;
this.isUpdate = isUpdate;
}
}
// test queries to be run against Dolt
private static final TestCase[] testCases = {
new TestCase("create table test (pk int, `value` int, primary key(pk))", true),
new TestCase("insert into test (pk, `value`) values (0,0)", true),
new TestCase("select * from test", false),
new TestCase("call dolt_add('-A')", false),
new TestCase("call dolt_commit('-m', 'my commit')", false),
new TestCase("select COUNT(*) FROM dolt_log", false),
new TestCase("call dolt_checkout('-b', 'mybranch')", false),
new TestCase("insert into test (pk, `value`) values (1,1)", true),
new TestCase("call dolt_commit('-a', '-m', 'my commit2')", false),
new TestCase("call dolt_checkout('main')", false),
new TestCase("call dolt_merge('mybranch')", false),
new TestCase("select COUNT(*) FROM dolt_log", false),
};
public static void main(String[] args) {
if (args.length < 3) {
System.err.println("Usage: MariaDBR2DBCTest <user> <port> <database>");
System.exit(1);
}
String user = args[0];
int port = Integer.parseInt(args[1]);
String database = args[2];
try {
runTests(user, port, database);
System.out.println("All R2DBC tests passed!");
} catch (Exception e) {
System.err.println("R2DBC test failed: " + e.getMessage());
e.printStackTrace();
System.exit(1);
}
}
private static void runTests(String user, int port, String database) {
// Create connection configuration
MariadbConnectionConfiguration config = MariadbConnectionConfiguration.builder()
.host("127.0.0.1")
.port(port)
.username(user)
.password("")
.database(database)
.build();
ConnectionFactory connectionFactory = new MariadbConnectionFactory(config);
// Run tests reactively - block at the end for the test
Mono.from(connectionFactory.create())
.flatMapMany(connection ->
Flux.fromArray(testCases)
.concatMap(testCase -> executeTest(connection, testCase))
.doFinally(signalType ->
Mono.from(connection.close()).subscribe()
)
)
.blockLast(Duration.ofSeconds(30));
}
private static Mono<Void> executeTest(Connection connection, TestCase testCase) {
System.out.println("Executing: " + testCase.query);
return Mono.from(connection.createStatement(testCase.query).execute())
.flatMap(result -> {
if (testCase.isUpdate) {
// For updates, just get the rows affected
return Mono.from(result.getRowsUpdated()).then();
} else {
// For selects, consume all rows
return Flux.from(result.map((row, metadata) -> row))
.then();
}
})
.onErrorResume(e -> {
System.err.println("Error executing query: " + testCase.query);
System.err.println("Error: " + e.getMessage());
return Mono.error(e);
});
}
}
@@ -0,0 +1,173 @@
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
public class MySQLConnectorTest {
// test queries to be run against Dolt
private static final 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",
"call dolt_add('-A')",
"call dolt_commit('-m', 'my commit')",
"select COUNT(*) FROM dolt_log",
"call dolt_checkout('-b', 'mybranch')",
"insert into test (pk, `value`) values (1,1)",
"call dolt_commit('-a', '-m', 'my commit2')",
"call dolt_checkout('main')",
"call dolt_merge('mybranch')",
"select COUNT(*) FROM dolt_log",
};
// We currently only test a single field value in the first row
private static final String[] expectedResults = {
"0",
"pk",
null,
"1",
"0",
"0",
"0",
"2",
"0",
"1",
"1",
"0",
"",
"3"
};
// fieldAccessors are the value used to access a field in a row in a result set. Currently, only
// String (i.e column name) and Integer (i.e. field position) values are supported.
private static final Object[] fieldAccessors = {
1,
1,
"pk",
1,
"test.pk",
1,
1,
1,
1,
1,
1,
1,
1,
"COUNT(*)",
};
public static void main(String[] args) {
testStatements(args);
testServerSideCursors(args);
System.exit(0);
}
// testServerSideCursors does a simple smoke test with server-side cursors to make sure
// results can be read. Note that we don't test results here; this is just a high level
// smoke test that we can execute server-side cursors logic without the server erroring out.
// This test was added for a regression where server-side cursor logic was getting
// corrupted result set memory and sending invalid data to the client, which caused the
// server to error out and crash the connection. If any errors are encountered, a stack trace
// is printed and this function exits with a non-zero code.
// For more details, see: https://github.com/dolthub/dolt/issues/9125
private static void testServerSideCursors(String[] args) {
String user = args[0];
String port = args[1];
String db = args[2];
try {
String url = "jdbc:mysql://127.0.0.1:" + port + "/" + db +
"?useServerPrepStmts=true&useCursorFetch=true";
Connection conn = DriverManager.getConnection(url, user, "");
executePreparedQuery(conn, "SELECT 1;");
executePreparedQuery(conn, "SELECT database();");
executePreparedQuery(conn, "SHOW COLLATION;");
executePreparedQuery(conn, "SHOW COLLATION;");
executePreparedQuery(conn, "SHOW COLLATION;");
} catch (SQLException ex) {
System.out.println("An error occurred.");
ex.printStackTrace();
System.exit(1);
}
}
// executePreparedQuery executes the specified |query| using |conn| as a prepared statement,
// and uses server-side cursor to fetch results. This method does not do any validation of
// results from the query. It is simply a smoke test to ensure the connection doesn't crash.
private static void executePreparedQuery(Connection conn, String query) throws SQLException {
PreparedStatement stmt = conn.prepareStatement(query, ResultSet.TYPE_FORWARD_ONLY);
stmt.setFetchSize(25); // needed to ensure a server-side cursor is used
ResultSet rs = stmt.executeQuery();
while (rs.next()) {}
rs.close();
stmt.close();
}
// testStatements executes the queries from |queries| and asserts their results from
// |expectedResults|. If any errors are encountered, a stack trace is printed and this
// function exits with a non-zero code.
private static void testStatements(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();
for (int i = 0; i < queries.length; i++) {
String query = queries[i];
String expected = expectedResults[i];
if ( st.execute(query) ) {
ResultSet rs = st.getResultSet();
if (rs.next()) {
String result = "";
Object fieldAccessor = fieldAccessors[i];
if (fieldAccessor instanceof String) {
result = rs.getString((String)fieldAccessor);
} else if (fieldAccessor instanceof Integer) {
result = rs.getString((Integer)fieldAccessor);
} else {
System.out.println("Unsupported field accessor value: " + fieldAccessor);
System.exit(1);
}
if (!expected.equals(result) && !(query.contains("dolt_commit")) && !(query.contains("dolt_merge"))) {
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);
}
}
}
} catch (SQLException ex) {
System.out.println("An error occurred.");
ex.printStackTrace();
System.exit(1);
}
}
}
@@ -0,0 +1,22 @@
import java.sql.*;
// https://github.com/dolthub/dolt/issues/9890
public class MySQLConnectorTest_Collation {
public static void main(String[] args) {
String user = args[0];
String port = args[1];
String db = args[2];
try {
String url = "jdbc:mysql://127.0.0.1:" + port + "/" + db;
Connection conn = DriverManager.getConnection(url, user, "");
var result = conn.getMetaData().getColumns(null, null, null, null);
} catch (SQLException ex) {
System.out.println("An error occurred.");
ex.printStackTrace();
System.exit(1);
}
System.exit(0);
}
}