This document describes the comprehensive test suite for the MySQL protocol access layer, including cross-protocol data consistency tests.
File: test/mysql_api_memory_integration_test.go
Tests basic MySQL operations with memory storage engine:
- ✅ Insert and Select operations
- ✅ Update operations
- ✅ Delete operations
- ✅ SHOW DATABASES/TABLES commands
- ✅ Transaction support (BEGIN/COMMIT/ROLLBACK)
- ✅ Connection lifecycle
Run Command:
go test -v ./test -run TestMySQLMemorySingleNodeOperationsFile: test/mysql_api_rocksdb_integration_test.go
Tests MySQL operations with RocksDB persistent storage:
- ✅ All memory engine tests
- ✅ Large value handling (1KB, 10KB)
- ✅ Special characters in keys
- ✅ Data persistence
Run Command:
CGO_ENABLED=1 CGO_LDFLAGS="-lrocksdb -lpthread -lstdc++ -ldl -lm -lzstd -llz4 -lz -lsnappy -lbz2 -Wl,-U,_SecTrustCopyCertificateChain" \
go test -v ./test -run TestMySQLRocksDBFile: test/mysql_cross_protocol_test.go
Tests data consistency across HTTP, etcd, and MySQL protocols:
| Test | Description | Validates |
|---|---|---|
HTTP_Write_MySQL_Read |
Write via HTTP API, read via MySQL | Cross-protocol read consistency |
Etcd_Write_MySQL_Read |
Write via etcd gRPC, read via MySQL | Cross-protocol read consistency |
MySQL_Write_HTTP_Read |
Write via MySQL, read via HTTP API | Cross-protocol read consistency |
MySQL_Write_Etcd_Read |
Write via MySQL, read via etcd gRPC | Cross-protocol read consistency |
MySQL_Update_HTTP_Read |
Update via MySQL, verify via HTTP | Update propagation |
MySQL_Update_Etcd_Read |
Update via MySQL, verify via etcd | Update propagation |
MySQL_Delete_HTTP_Verify |
Delete via MySQL, verify via HTTP | Delete propagation |
MySQL_Delete_Etcd_Verify |
Delete via MySQL, verify via etcd | Delete propagation |
Batch_Interleaved_Operations |
Mixed protocol batch writes | Multi-protocol consistency |
Concurrent_Multi_Protocol_Writes |
Concurrent writes from all protocols | Concurrent consistency |
Run Command:
go test -v ./test -run TestMySQLCrossProtocolExpected Results:
- All data written via any protocol should be readable from all other protocols
- No data loss or corruption
- Consistent ordering and atomicity
File: test/mysql_cluster_integration_test.go
Tests MySQL in a multi-node Raft cluster:
| Test | Description | Validates |
|---|---|---|
Write_Node1_Read_All_MySQL |
Write to one node, read from all | Cluster replication |
HTTP_Write_Node2_MySQL_Read_All |
HTTP write on node 2, MySQL read all | Cross-protocol cluster consistency |
Etcd_Write_Node3_MySQL_Read_All |
etcd write on node 3, MySQL read all | Cross-protocol cluster consistency |
MySQL_Update_Different_Nodes |
Update from different nodes | Update replication |
MySQL_Delete_Verify_All |
Delete from one, verify on all | Delete replication |
Concurrent_MySQL_Writes |
Concurrent writes from all nodes | Concurrent cluster writes |
Mixed_Protocol_Cluster_Writes |
Mixed protocol writes in cluster | Full cluster consistency |
Run Command:
go test -v ./test -run TestMySQLCluster -timeout 5mNote: Cluster tests require more time and resources (3 nodes).
Tests MySQL-specific commands:
- ✅ SHOW DATABASES
- ✅ SHOW TABLES
- ✅ DESCRIBE/DESC table
- ✅ USE database
- ✅ SET variables
Run Command:
go test -v ./test -run TestMySQLProtocolShowCommandsgo test -v ./test -run TestMySQL.*Memory# Set CGO flags for RocksDB
export CGO_ENABLED=1
export CGO_LDFLAGS="-lrocksdb -lpthread -lstdc++ -ldl -lm -lzstd -llz4 -lz -lsnappy -lbz2 -Wl,-U,_SecTrustCopyCertificateChain"
# Run all MySQL tests
go test -v ./test -run TestMySQL -timeout 10mgo test -v ./test -run TestMySQLCrossProtocol -timeout 5mgo test -v ./test -run TestMySQLCluster -timeout 5m- Go 1.21+
- MySQL CLI client (for manual testing)
- RocksDB library (for RocksDB tests)
- Available ports: 13306-13311, 12379-12382, 19200-19300
- Memory: 2GB+ recommended
- Disk: 1GB+ free space for RocksDB
- Network: Localhost access
- Ports: Must be available (not in use)
- ✅ INSERT - Data insertion via SQL
- ✅ SELECT - Query operations with WHERE clause
- ✅ UPDATE - Data modification
- ✅ DELETE - Data removal
- ✅ BEGIN/COMMIT/ROLLBACK - Transaction control
- ✅ SHOW commands - Schema inspection
- ✅ Connection management
- ✅ HTTP → MySQL
- ✅ etcd → MySQL
- ✅ MySQL → HTTP
- ✅ MySQL → etcd
- ✅ Concurrent multi-protocol writes
- ✅ Batch operations
- ✅ Memory engine (in-memory with WAL)
- ✅ RocksDB engine (persistent storage)
- ✅ 3-node cluster replication
- ✅ Write to any node, read from all
- ✅ Cross-protocol in cluster
- ✅ Concurrent cluster operations
# Create config file
cat > config.yaml <<EOF
server:
cluster_id: 1
member_id: 1
listen_address: ":2379"
mysql:
enable: true
address: ":3306"
username: "root"
password: ""
EOF
# Start server
./metastore -config config.yaml -storage memory# Connect
mysql -h 127.0.0.1 -P 3306 -u root
# Test commands
USE metastore;
SHOW TABLES;
INSERT INTO kv (key, value) VALUES ('test', 'works');
SELECT * FROM kv WHERE key = 'test';
UPDATE kv SET value = 'updated' WHERE key = 'test';
DELETE FROM kv WHERE key = 'test';# Terminal 1: Start server
./metastore -config config.yaml -storage memory
# Terminal 2: Write via HTTP
curl -X PUT http://localhost:9121/mykey -d "myvalue"
# Terminal 3: Read via MySQL
mysql -h 127.0.0.1 -P 3306 -u root -e \
"SELECT * FROM metastore.kv WHERE key = 'mykey'"
# Terminal 4: Read via etcd
etcdctl --endpoints=localhost:2379 get mykeyError: bind: address already in use
Solution: Kill processes using the ports or change test ports
lsof -i :3306
kill <PID>Error: ld: library not found for -lrocksdb
Solution: Install RocksDB or skip RocksDB tests
# macOS
brew install rocksdb
# Or skip RocksDB tests
go test -v ./test -run TestMySQL.*MemoryError: Condition not met after waiting
Solution: Increase wait times or check Raft logs
- Increase
time.Sleep()durations in tests - Check data directory permissions
- Ensure no network issues
Error: dial tcp 127.0.0.1:3306: connect: connection refused
Solution: Wait longer for server startup
- Increase initial sleep time
- Add retry logic with longer timeout
- Check server logs for startup errors
Modify test config to enable debug logs:
cfg := NewTestConfig(1, 1, ":2379")
cfg.Server.Log.Level = "debug"
cfg.Server.Log.OutputPaths = []string{"test.log"}name: MySQL API Tests
on: [push, pull_request]
jobs:
test-memory:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Run Memory Tests
run: go test -v ./test -run TestMySQL.*Memory
test-rocksdb:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Install RocksDB
run: |
sudo apt-get update
sudo apt-get install -y librocksdb-dev
- name: Run RocksDB Tests
run: |
export CGO_ENABLED=1
go test -v ./test -run TestMySQLRocksDB
test-cross-protocol:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Run Cross-Protocol Tests
run: go test -v ./test -run TestMySQLCrossProtocol -timeout 5m# Run all benchmarks
go test -bench=. -benchmem ./test -run=^$
# Run specific benchmark
go test -bench=BenchmarkMySQLInsert -benchmem ./test| Operation | Throughput | Latency |
|---|---|---|
| INSERT | ~5,000 ops/sec | ~0.2ms |
| SELECT | ~10,000 ops/sec | ~0.1ms |
| UPDATE | ~4,000 ops/sec | ~0.25ms |
| DELETE | ~4,000 ops/sec | ~0.25ms |
Note: Performance depends on hardware and configuration
- Create test function in appropriate file
- Follow naming convention:
Test<Feature><Engine> - Add cleanup:
defer os.RemoveAll(dataDir) - Wait for Raft commits:
time.Sleep() - Use
requirefor critical checks,assertfor non-critical
func TestMySQLNewFeature(t *testing.T) {
t.Parallel()
// Setup
dataDir := "data/memory/test_feature"
os.RemoveAll(dataDir)
defer os.RemoveAll(dataDir)
// Create storage and server
// ... setup code ...
// Test logic
t.Run("SubTest1", func(t *testing.T) {
// ... test code ...
})
// Cleanup
// ... cleanup code ...
}The MySQL API test suite provides comprehensive coverage of:
- Basic MySQL protocol operations
- Cross-protocol data consistency
- Multi-node cluster replication
- Both storage engines (Memory and RocksDB)
All tests validate that the MySQL protocol layer maintains data consistency with HTTP and etcd APIs while providing standard MySQL compatibility.