Skip to content

Commit 1f82f98

Browse files
authored
Add charset/snapshot_file to vttest. (vitessio#2611)
This helps for testing efforts that require restoring from a snapshot. Also, setting charset is already allowed via start_vt_processes, so this PR just exposes it through run_local_database.
1 parent f740814 commit 1f82f98

File tree

5 files changed

+32
-17
lines changed

5 files changed

+32
-17
lines changed

java/client/src/test/java/com/youtube/vitess/client/TestUtil.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ public static void setupTestEnv(TestEnv testEnv) throws Exception {
4747
continue;
4848
}
4949
try {
50-
Type mapType = new TypeToken<Map<String, Integer>>() {}.getType();
51-
Map<String, Integer> map = new Gson().fromJson(line, mapType);
50+
Type mapType = new TypeToken<Map<String, Object>>() {}.getType();
51+
Map<String, Object> map = new Gson().fromJson(line, mapType);
5252
testEnv.setPythonScriptProcess(p);
53-
testEnv.setPort(map.get(System.getProperty(PROPERTY_KEY_CLIENT_TEST_PORT)));
53+
testEnv.setPort(((Double)map.get(System.getProperty(PROPERTY_KEY_CLIENT_TEST_PORT))).intValue());
5454
return;
5555
} catch (JsonSyntaxException e) {
5656
logger.error("JsonSyntaxException parsing setup command output: " + line, e);

py/vttest/local_database.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ def __init__(self,
2121
web_dir=None,
2222
default_schema_dir=None,
2323
extra_my_cnf=None,
24-
web_dir2=None):
24+
web_dir2=None,
25+
snapshot_file=None,
26+
charset='utf8'):
2527
"""Initializes an object of this class.
2628
2729
Args:
@@ -41,6 +43,8 @@ def __init__(self,
4143
extra_my_cnf: additional cnf file to use for the EXTRA_MY_CNF var.
4244
web_dir2: see the documentation for the corresponding command line
4345
flag in run_local_database.py
46+
snapshot_file: A MySQL DB snapshot file.
47+
charset: MySQL charset.
4448
"""
4549

4650
self.topology = topology
@@ -51,17 +55,20 @@ def __init__(self,
5155
self.default_schema_dir = default_schema_dir
5256
self.extra_my_cnf = extra_my_cnf
5357
self.web_dir2 = web_dir2
58+
self.snapshot_file = snapshot_file
59+
self.charset = charset
5460

5561
def setup(self):
5662
"""Create a MySQL instance and all Vitess processes."""
5763
mysql_port = environment.get_port('mysql')
5864
self.directory = environment.get_test_directory()
5965
self.mysql_db = environment.mysql_db_class(
60-
self.directory, mysql_port, self.extra_my_cnf)
66+
self.directory, mysql_port, self.extra_my_cnf, self.snapshot_file)
6167

6268
self.mysql_db.setup()
63-
self.create_databases()
64-
self.load_schema()
69+
if not self.snapshot_file:
70+
self.create_databases()
71+
self.load_schema()
6572
if self.init_data_options is not None:
6673
self.rng = random.Random(self.init_data_options.rng_seed)
6774
self.populate_with_random_data()
@@ -70,7 +77,7 @@ def setup(self):
7077

7178
vt_processes.start_vt_processes(self.directory, self.topology,
7279
self.mysql_db, self.schema_dir,
73-
web_dir=self.web_dir,
80+
charset=self.charset, web_dir=self.web_dir,
7481
web_dir2=self.web_dir2)
7582

7683
def teardown(self):
@@ -105,7 +112,9 @@ def config(self):
105112

106113
result = {
107114
'port': vt_processes.vtcombo_process.port,
108-
}
115+
'socket': self.mysql_db.unix_socket(),
116+
}
117+
109118
if environment.get_protocol() == 'grpc':
110119
result['grpc_port'] = vt_processes.vtcombo_process.grpc_port
111120
return result

py/vttest/mysql_db.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
class MySqlDB(object):
1010
"""A MySqlDB contains basic info about a MySQL instance."""
1111

12-
def __init__(self, directory, port, extra_my_cnf=None):
12+
def __init__(self, directory, port, extra_my_cnf=None, snapshot_file=None):
1313
self._directory = directory
1414
self._port = port
1515
self._extra_my_cnf = extra_my_cnf
16+
self._snapshot_file = snapshot_file
1617

1718
def setup(self, port):
1819
"""Starts the MySQL database."""

py/vttest/mysql_db_mysqlctl.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
class MySqlDBMysqlctl(mysql_db.MySqlDB):
1919
"""Contains data and methods to manage a MySQL instance using mysqlctl."""
2020

21-
def __init__(self, directory, port, extra_my_cnf):
22-
super(MySqlDBMysqlctl, self).__init__(directory, port, extra_my_cnf)
21+
def __init__(self, directory, port, extra_my_cnf, snapshot_file=None):
22+
super(MySqlDBMysqlctl, self).__init__(
23+
directory, port, extra_my_cnf, snapshot_file)
2324

2425
def setup(self):
2526
cmd = [

py/vttest/run_local_database.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,17 @@
3434
import os
3535
import sys
3636

37-
from vtdb import prefer_vtroot_imports # pylint: disable=unused-import
3837

3938
from google.protobuf import text_format
4039

40+
from vtproto import vttest_pb2
41+
from vtdb import prefer_vtroot_imports # pylint: disable=unused-import
4142
from vttest import environment
43+
from vttest import init_data_options
4244
from vttest import local_database
4345
from vttest import mysql_flavor
44-
from vttest import init_data_options
4546
from vttest import sharding_utils
4647

47-
from vtproto import vttest_pb2
48-
4948

5049
def main(cmdline_options):
5150
topology = vttest_pb2.VTTestTopology()
@@ -96,7 +95,9 @@ def main(cmdline_options):
9695
web_dir=cmdline_options.web_dir,
9796
web_dir2=cmdline_options.web_dir2,
9897
default_schema_dir=cmdline_options.default_schema_dir,
99-
extra_my_cnf=extra_my_cnf) as local_db:
98+
extra_my_cnf=extra_my_cnf,
99+
charset=cmdline_options.charset,
100+
snapshot_file=cmdline_options.snapshot_file) as local_db:
100101
print json.dumps(local_db.config())
101102
sys.stdout.flush()
102103
try:
@@ -186,6 +187,9 @@ def main(cmdline_options):
186187
help='Replica tablets per shard (includes master)')
187188
parser.add_option('--rdonly_count', type='int', default=1,
188189
help='Rdonly tablets per shard')
190+
parser.add_option('--charset', default='utf8', help='MySQL charset')
191+
parser.add_option(
192+
'--snapshot_file', default=None, help='A MySQL DB snapshot file')
189193
(options, args) = parser.parse_args()
190194
if options.verbose:
191195
logging.getLogger().setLevel(logging.DEBUG)

0 commit comments

Comments
 (0)