зеркало из https://github.com/github/vitess-gh.git
Use pylint test-mode for fiels in test/.
Clean some obvious pylint errors in test dir.
This commit is contained in:
Родитель
77f72dbad7
Коммит
b6a7a01efe
|
@ -18,10 +18,16 @@ function msg() {
|
|||
PYLINT=/usr/bin/gpylint
|
||||
|
||||
function call_pylint {
|
||||
$PYLINT --mode style \
|
||||
local file=$1
|
||||
if echo "$file" | grep -q ^test/ ; then
|
||||
mode=style,test
|
||||
else
|
||||
mode=style
|
||||
fi
|
||||
$PYLINT --mode $mode \
|
||||
--disable g-bad-file-header,g-bad-import-order,g-unknown-interpreter \
|
||||
--module-header-template '' \
|
||||
--msg-template '{path}:{line}:{msg_id}{obj_prefix}{obj}: {msg}{sym_separator}[{symbol}]' "$@"
|
||||
--msg-template '{path}:{line}:{msg_id}{obj_prefix}{obj}: {msg}{sym_separator}[{symbol}]' $file
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -20,7 +20,9 @@ def tearDownModule():
|
|||
|
||||
|
||||
class TestAutomationHorizontalResharding(worker.TestBaseSplitClone):
|
||||
"""This test reuses worker.py because worker.py also covers the happy path
|
||||
"""End-to-end test for horizontal resharding automation.
|
||||
|
||||
This test reuses worker.py because worker.py also covers the happy path
|
||||
of the horizontal resharding code. Instead of running the different resharding
|
||||
steps "manually" as part of the test, they will be run by the automation
|
||||
cluster operation.
|
||||
|
@ -63,10 +65,11 @@ class TestAutomationHorizontalResharding(worker.TestBaseSplitClone):
|
|||
worker.shard_1_tablets.replica)
|
||||
|
||||
# Verify effect of MigrateServedTypes. Dest shards are serving now.
|
||||
utils.check_srv_keyspace('test_nj', self.KEYSPACE,
|
||||
'Partitions(master): -80 80-\n' +
|
||||
'Partitions(rdonly): -80 80-\n' +
|
||||
'Partitions(replica): -80 80-\n')
|
||||
utils.check_srv_keyspace(
|
||||
'test_nj', self.KEYSPACE,
|
||||
'Partitions(master): -80 80-\n'
|
||||
'Partitions(rdonly): -80 80-\n'
|
||||
'Partitions(replica): -80 80-\n')
|
||||
|
||||
# Check that query service is disabled (source shard) or enabled (dest).
|
||||
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import warnings
|
||||
# Dropping a table inexplicably produces a warning despite
|
||||
# the "IF EXISTS" clause. Squelch these warnings.
|
||||
warnings.simplefilter('ignore')
|
||||
|
||||
import logging
|
||||
import unittest
|
||||
|
@ -12,6 +9,10 @@ import environment
|
|||
import tablet
|
||||
import utils
|
||||
|
||||
# Dropping a table inexplicably produces a warning despite
|
||||
# the "IF EXISTS" clause. Squelch these warnings.
|
||||
warnings.simplefilter('ignore')
|
||||
|
||||
use_mysqlctld = True
|
||||
|
||||
tablet_master = tablet.Tablet(use_mysqlctld=use_mysqlctld)
|
||||
|
@ -168,9 +169,9 @@ class TestBackup(unittest.TestCase):
|
|||
auto_log=True, mode=utils.VTCTL_VTCTL)
|
||||
|
||||
# make sure the list of backups is empty now
|
||||
backups, err = utils.run_vtctl(tablet.get_backup_storage_flags() +
|
||||
['ListBackups', 'test_keyspace/0'],
|
||||
mode=utils.VTCTL_VTCTL, trap_output=True)
|
||||
backups, _ = utils.run_vtctl(tablet.get_backup_storage_flags() +
|
||||
['ListBackups', 'test_keyspace/0'],
|
||||
mode=utils.VTCTL_VTCTL, trap_output=True)
|
||||
backups = backups.splitlines()
|
||||
logging.debug('list of backups after remove: %s', backups)
|
||||
self.assertEqual(len(backups), 0)
|
||||
|
|
|
@ -12,13 +12,13 @@
|
|||
import logging
|
||||
import unittest
|
||||
|
||||
from mysql_flavor import mysql_flavor
|
||||
from vtdb import keyrange_constants
|
||||
from vtdb import update_stream
|
||||
|
||||
import environment
|
||||
import tablet
|
||||
import utils
|
||||
|
||||
from vtdb import keyrange_constants
|
||||
from vtdb import update_stream
|
||||
from mysql_flavor import mysql_flavor
|
||||
|
||||
src_master = tablet.Tablet()
|
||||
src_replica = tablet.Tablet()
|
||||
|
|
|
@ -8,8 +8,8 @@ import base64
|
|||
import unittest
|
||||
|
||||
import environment
|
||||
import utils
|
||||
import tablet
|
||||
import utils
|
||||
|
||||
# shards
|
||||
shard_0_master = tablet.Tablet()
|
||||
|
@ -60,7 +60,8 @@ def tearDownModule():
|
|||
|
||||
|
||||
class TestCustomSharding(unittest.TestCase):
|
||||
"""
|
||||
"""Test a custom-shared keyspace.
|
||||
|
||||
Warning: this test only works with BSON RPC, only area where the
|
||||
SplitQuery client is implemented.
|
||||
"""
|
||||
|
|
|
@ -14,15 +14,16 @@
|
|||
# - we remove the source tablets
|
||||
# - we remove the original shard
|
||||
|
||||
import logging
|
||||
import struct
|
||||
|
||||
import logging
|
||||
import unittest
|
||||
|
||||
from vtdb import keyrange_constants
|
||||
|
||||
import environment
|
||||
import utils
|
||||
import tablet
|
||||
import utils
|
||||
|
||||
keyspace_id_type = keyrange_constants.KIT_UINT64
|
||||
pack_keyspace_id = struct.Struct('!Q').pack
|
||||
|
@ -136,8 +137,8 @@ index by_msg (msg)
|
|||
|
||||
# _insert_startup_value inserts a value in the MySQL database before it
|
||||
# is sharded
|
||||
def _insert_startup_value(self, tablet, table, mid, msg):
|
||||
tablet.mquery('vt_test_keyspace', [
|
||||
def _insert_startup_value(self, tablet_obj, table, mid, msg):
|
||||
tablet_obj.mquery('vt_test_keyspace', [
|
||||
'begin',
|
||||
'insert into %s(id, msg) values(%d, "%s")' % (table, mid, msg),
|
||||
'commit'
|
||||
|
@ -148,8 +149,8 @@ index by_msg (msg)
|
|||
self._insert_startup_value(shard_master, 'resharding1', 2, 'msg2')
|
||||
self._insert_startup_value(shard_master, 'resharding1', 3, 'msg3')
|
||||
|
||||
def _backfill_keyspace_id(self, tablet):
|
||||
tablet.mquery('vt_test_keyspace', [
|
||||
def _backfill_keyspace_id(self, tablet_obj):
|
||||
tablet_obj.mquery('vt_test_keyspace', [
|
||||
'begin',
|
||||
'update resharding1 set keyspace_id=0x1000000000000000 where id=1',
|
||||
'update resharding1 set keyspace_id=0x9000000000000000 where id=2',
|
||||
|
@ -159,9 +160,9 @@ index by_msg (msg)
|
|||
|
||||
# _insert_value inserts a value in the MySQL database along with the comments
|
||||
# required for routing.
|
||||
def _insert_value(self, tablet, table, mid, msg, keyspace_id):
|
||||
def _insert_value(self, tablet_obj, table, mid, msg, keyspace_id):
|
||||
k = utils.uint64_to_hex(keyspace_id)
|
||||
tablet.mquery(
|
||||
tablet_obj.mquery(
|
||||
'vt_test_keyspace',
|
||||
['begin',
|
||||
'insert into %s(id, msg, keyspace_id) '
|
||||
|
@ -171,14 +172,14 @@ index by_msg (msg)
|
|||
'commit'],
|
||||
write=True)
|
||||
|
||||
def _get_value(self, tablet, table, mid):
|
||||
return tablet.mquery(
|
||||
def _get_value(self, tablet_obj, table, mid):
|
||||
return tablet_obj.mquery(
|
||||
'vt_test_keyspace',
|
||||
'select id, msg, keyspace_id from %s where id=%d' % (table, mid))
|
||||
|
||||
def _check_value(self, tablet, table, mid, msg, keyspace_id,
|
||||
def _check_value(self, tablet_obj, table, mid, msg, keyspace_id,
|
||||
should_be_here=True):
|
||||
result = self._get_value(tablet, table, mid)
|
||||
result = self._get_value(tablet_obj, table, mid)
|
||||
if keyspace_id_type == keyrange_constants.KIT_BYTES:
|
||||
fmt = '%s'
|
||||
keyspace_id = pack_keyspace_id(keyspace_id)
|
||||
|
@ -187,21 +188,23 @@ index by_msg (msg)
|
|||
if should_be_here:
|
||||
self.assertEqual(result, ((mid, msg, keyspace_id),),
|
||||
('Bad row in tablet %s for id=%d, keyspace_id=' +
|
||||
fmt + ', row=%s') % (tablet.tablet_alias, mid,
|
||||
fmt + ', row=%s') % (tablet_obj.tablet_alias, mid,
|
||||
keyspace_id, str(result)))
|
||||
else:
|
||||
self.assertEqual(len(result), 0,
|
||||
('Extra row in tablet %s for id=%d, keyspace_id=' +
|
||||
fmt + ': %s') % (tablet.tablet_alias, mid, keyspace_id,
|
||||
str(result)))
|
||||
self.assertEqual(
|
||||
len(result), 0,
|
||||
('Extra row in tablet %s for id=%d, keyspace_id=' +
|
||||
fmt + ': %s') % (tablet_obj.tablet_alias, mid, keyspace_id,
|
||||
str(result)))
|
||||
|
||||
# _is_value_present_and_correct tries to read a value.
|
||||
# if it is there, it will check it is correct and return True if it is.
|
||||
# if not correct, it will self.fail.
|
||||
# if not there, it will return False.
|
||||
def _is_value_present_and_correct(self, tablet, table, mid, msg, keyspace_id):
|
||||
result = self._get_value(tablet, table, mid)
|
||||
if len(result) == 0:
|
||||
def _is_value_present_and_correct(
|
||||
self, tablet_obj, table, mid, msg, keyspace_id):
|
||||
result = self._get_value(tablet_obj, table, mid)
|
||||
if not result:
|
||||
return False
|
||||
if keyspace_id_type == keyrange_constants.KIT_BYTES:
|
||||
fmt = '%s'
|
||||
|
@ -210,7 +213,7 @@ index by_msg (msg)
|
|||
fmt = '%x'
|
||||
self.assertEqual(result, ((mid, msg, keyspace_id),),
|
||||
('Bad row in tablet %s for id=%d, keyspace_id=' + fmt) % (
|
||||
tablet.tablet_alias, mid, keyspace_id))
|
||||
tablet_obj.tablet_alias, mid, keyspace_id))
|
||||
return True
|
||||
|
||||
def _check_startup_values(self):
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
# Use of this source code is governed by a BSD-style license that can
|
||||
# be found in the LICENSE file.
|
||||
|
||||
from vtdb import keyrange_constants
|
||||
|
||||
import initial_sharding
|
||||
import utils
|
||||
|
||||
from vtdb import keyrange_constants
|
||||
|
||||
# this test is just re-running an entire initial_sharding.py with a
|
||||
# varbinary keyspace_id
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#!/usr/bin/env python
|
||||
"""
|
||||
Script to set up a Vitess environment for Java client integration
|
||||
tests. Every shard gets a master instance. For extra instances,
|
||||
use the tablet-config option. Upon successful start up, the port for
|
||||
VtGate is written to stdout, and the program waits for a one line
|
||||
user input before shutting down.
|
||||
"""Set up a Vitess environment for Java client integration tests.
|
||||
|
||||
Every shard gets a master instance. For extra instances, use the
|
||||
tablet-config option. Upon successful start up, the port for VtGate is
|
||||
written to stdout, and the program waits for a one line user input
|
||||
before shutting down.
|
||||
|
||||
Start up steps include:
|
||||
- start MySQL instances
|
||||
|
@ -32,10 +32,10 @@ import tablet
|
|||
|
||||
class Tablet(tablet.Tablet):
|
||||
|
||||
def __init__(self, shard, type):
|
||||
def __init__(self, shard, tablet_type):
|
||||
super(Tablet, self).__init__()
|
||||
self.shard = shard
|
||||
self.type = type
|
||||
self.type = tablet_type
|
||||
|
||||
|
||||
class TestEnv(object):
|
||||
|
@ -93,7 +93,7 @@ class TestEnv(object):
|
|||
else:
|
||||
utils.run_vtctl(['ApplyVSchema', '-vschema_file', self.vschema])
|
||||
utils.VtGate(port=self.vtgate_port).start(
|
||||
cache_ttl='500s',
|
||||
cache_ttl='500s',
|
||||
)
|
||||
except:
|
||||
self.shutdown()
|
||||
|
|
|
@ -62,7 +62,7 @@ def tearDownModule():
|
|||
|
||||
|
||||
class TestPythonClientBase(unittest.TestCase):
|
||||
"""Base class for Python client tests"""
|
||||
"""Base class for Python client tests."""
|
||||
CONNECT_TIMEOUT = 10.0
|
||||
|
||||
# A packed keyspace_id from the middle of the full keyrange.
|
||||
|
@ -109,15 +109,16 @@ class TestPythonClientErrors(TestPythonClientBase):
|
|||
def test_execute_integrity_errors(self):
|
||||
"""Test we raise dbexceptions.IntegrityError for Execute calls."""
|
||||
# Special query that makes vtgateclienttest return an IntegrityError.
|
||||
self._verify_exception_for_execute('error://integrity error',
|
||||
dbexceptions.IntegrityError)
|
||||
self._verify_exception_for_execute(
|
||||
'error://integrity error',
|
||||
dbexceptions.IntegrityError)
|
||||
|
||||
def test_partial_integrity_errors(self):
|
||||
"""Test we raise dbexceptions.IntegrityError when Execute calls
|
||||
return a partial error."""
|
||||
"""Raise an IntegrityError when Execute returns a partial error."""
|
||||
# Special query that makes vtgateclienttest return a partial error.
|
||||
self._verify_exception_for_execute('partialerror://integrity error',
|
||||
dbexceptions.IntegrityError)
|
||||
self._verify_exception_for_execute(
|
||||
'partialerror://integrity error',
|
||||
dbexceptions.IntegrityError)
|
||||
|
||||
def _verify_exception_for_execute(self, query, exception):
|
||||
"""Verify that we raise a specific exception for all Execute calls.
|
||||
|
@ -201,7 +202,8 @@ class TestPythonClientErrors(TestPythonClientBase):
|
|||
# TODO(aaijazi): this test doesn't work for all clients yet.
|
||||
if protocols_flavor().vtgate_python_protocol() != 'gorpc':
|
||||
return
|
||||
self._verify_exception_for_stream_execute('error://integrity error',
|
||||
self._verify_exception_for_stream_execute(
|
||||
'error://integrity error',
|
||||
dbexceptions.IntegrityError)
|
||||
|
||||
def test_transient_error(self):
|
||||
|
@ -210,7 +212,8 @@ class TestPythonClientErrors(TestPythonClientBase):
|
|||
if protocols_flavor().vtgate_python_protocol() != 'gorpc':
|
||||
return
|
||||
# Special query that makes vtgateclienttest return a TransientError.
|
||||
self._verify_exception_for_execute('error://transient error',
|
||||
self._verify_exception_for_execute(
|
||||
'error://transient error',
|
||||
dbexceptions.TransientError)
|
||||
|
||||
def test_streaming_transient_error(self):
|
||||
|
@ -218,8 +221,9 @@ class TestPythonClientErrors(TestPythonClientBase):
|
|||
# TODO(aaijazi): this test doesn't work for all clients yet.
|
||||
if protocols_flavor().vtgate_python_protocol() != 'gorpc':
|
||||
return
|
||||
self._verify_exception_for_stream_execute('error://transient error',
|
||||
dbexceptions.TransientError)
|
||||
self._verify_exception_for_stream_execute(
|
||||
'error://transient error',
|
||||
dbexceptions.TransientError)
|
||||
|
||||
def test_error(self):
|
||||
"""Test a regular server error raises the right exception."""
|
||||
|
@ -227,19 +231,19 @@ class TestPythonClientErrors(TestPythonClientBase):
|
|||
error_caller_id = vtgate_client.CallerID(principal=error_request)
|
||||
|
||||
# Begin test
|
||||
with self.assertRaisesRegexp(dbexceptions.DatabaseError, "forced error"):
|
||||
with self.assertRaisesRegexp(dbexceptions.DatabaseError, 'forced error'):
|
||||
self.conn.begin(error_caller_id)
|
||||
|
||||
# Commit test
|
||||
with self.assertRaisesRegexp(dbexceptions.DatabaseError, "forced error"):
|
||||
with self.assertRaisesRegexp(dbexceptions.DatabaseError, 'forced error'):
|
||||
self.conn.begin(error_caller_id)
|
||||
|
||||
# Rollback test
|
||||
with self.assertRaisesRegexp(dbexceptions.DatabaseError, "forced error"):
|
||||
with self.assertRaisesRegexp(dbexceptions.DatabaseError, 'forced error'):
|
||||
self.conn.begin(error_caller_id)
|
||||
|
||||
# GetSrvKeyspace test
|
||||
with self.assertRaisesRegexp(dbexceptions.DatabaseError, "forced error"):
|
||||
with self.assertRaisesRegexp(dbexceptions.DatabaseError, 'forced error'):
|
||||
self.conn.get_srv_keyspace(error_request)
|
||||
|
||||
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import warnings
|
||||
# Dropping a table inexplicably produces a warning despite
|
||||
# the 'IF EXISTS' clause. Squelch these warnings.
|
||||
warnings.simplefilter('ignore')
|
||||
|
||||
import logging
|
||||
import time
|
||||
|
@ -17,6 +14,10 @@ import tablet
|
|||
from mysql_flavor import mysql_flavor
|
||||
from protocols_flavor import protocols_flavor
|
||||
|
||||
# Dropping a table inexplicably produces a warning despite
|
||||
# the 'IF EXISTS' clause. Squelch these warnings.
|
||||
warnings.simplefilter('ignore')
|
||||
|
||||
tablet_62344 = tablet.Tablet(62344)
|
||||
tablet_62044 = tablet.Tablet(62044)
|
||||
tablet_41983 = tablet.Tablet(41983)
|
||||
|
@ -84,17 +85,17 @@ class TestReparent(unittest.TestCase):
|
|||
(index, index))
|
||||
master_tablet.mquery('vt_test_keyspace', q, write=True)
|
||||
|
||||
def _check_vt_insert_test(self, tablet, index):
|
||||
def _check_vt_insert_test(self, tablet_obj, index):
|
||||
# wait until it gets the data
|
||||
timeout = 10.0
|
||||
while True:
|
||||
result = tablet.mquery('vt_test_keyspace',
|
||||
'select msg from vt_insert_test where id=%d' %
|
||||
index)
|
||||
result = tablet_obj.mquery(
|
||||
'vt_test_keyspace',
|
||||
'select msg from vt_insert_test where id=%d' % index)
|
||||
if len(result) == 1:
|
||||
break
|
||||
timeout = utils.wait_step('waiting for replication to catch up on %s' %
|
||||
tablet.tablet_alias,
|
||||
tablet_obj.tablet_alias,
|
||||
timeout, sleep_time=0.1)
|
||||
|
||||
def _check_db_addr(self, shard, db_type, expected_port, cell='test_nj'):
|
||||
|
@ -430,7 +431,9 @@ class TestReparent(unittest.TestCase):
|
|||
self._test_reparent_from_outside(brutal=True)
|
||||
|
||||
def _test_reparent_from_outside(self, brutal=False):
|
||||
"""This test will start a master and 3 slaves. Then:
|
||||
"""This test will start a master and 3 slaves.
|
||||
|
||||
Then:
|
||||
- one slave will be the new master
|
||||
- one slave will be reparented to that new master
|
||||
- one slave will be busted and dead in the water
|
||||
|
|
|
@ -4,10 +4,11 @@
|
|||
# Use of this source code is governed by a BSD-style license that can
|
||||
# be found in the LICENSE file.
|
||||
|
||||
import logging
|
||||
import struct
|
||||
import threading
|
||||
import time
|
||||
|
||||
import logging
|
||||
import unittest
|
||||
|
||||
from vtproto import topodata_pb2
|
||||
|
@ -15,8 +16,8 @@ from vtproto import topodata_pb2
|
|||
from vtdb import keyrange_constants
|
||||
|
||||
import environment
|
||||
import utils
|
||||
import tablet
|
||||
import utils
|
||||
|
||||
keyspace_id_type = keyrange_constants.KIT_UINT64
|
||||
pack_keyspace_id = struct.Struct('!Q').pack
|
||||
|
@ -117,9 +118,9 @@ def tearDownModule():
|
|||
# every 1/5s will update its value with the current timestamp
|
||||
class InsertThread(threading.Thread):
|
||||
|
||||
def __init__(self, tablet, object_name, user_id, keyspace_id):
|
||||
def __init__(self, tablet_obj, object_name, user_id, keyspace_id):
|
||||
threading.Thread.__init__(self)
|
||||
self.tablet = tablet
|
||||
self.tablet = tablet_obj
|
||||
self.object_name = object_name
|
||||
self.user_id = user_id
|
||||
self.keyspace_id = keyspace_id
|
||||
|
@ -130,7 +131,8 @@ class InsertThread(threading.Thread):
|
|||
'vt_test_keyspace',
|
||||
['begin',
|
||||
'insert into timestamps(name, time_milli, keyspace_id) '
|
||||
"values('%s', %d, 0x%x) /* vtgate:: keyspace_id:%s */ /* user_id:%d */" %
|
||||
"values('%s', %d, 0x%x) "
|
||||
'/* vtgate:: keyspace_id:%s */ /* user_id:%d */' %
|
||||
(self.object_name, long(time.time() * 1000), self.keyspace_id,
|
||||
self.str_keyspace_id, self.user_id),
|
||||
'commit'],
|
||||
|
@ -159,9 +161,9 @@ class InsertThread(threading.Thread):
|
|||
# the latency is pretty high (a few seconds).
|
||||
class MonitorLagThread(threading.Thread):
|
||||
|
||||
def __init__(self, tablet, object_name):
|
||||
def __init__(self, tablet_obj, object_name):
|
||||
threading.Thread.__init__(self)
|
||||
self.tablet = tablet
|
||||
self.tablet = tablet_obj
|
||||
self.object_name = object_name
|
||||
self.done = False
|
||||
self.max_lag = 0
|
||||
|
@ -172,7 +174,7 @@ class MonitorLagThread(threading.Thread):
|
|||
def run(self):
|
||||
try:
|
||||
while not self.done:
|
||||
result = self.tablet.mquery(
|
||||
result = self.tablet_obj.mquery(
|
||||
'vt_test_keyspace',
|
||||
'select time_milli from timestamps where name="%s"' %
|
||||
self.object_name)
|
||||
|
@ -204,7 +206,9 @@ keyspace_id ''' + t + ''' not null,
|
|||
primary key (id),
|
||||
index by_msg (msg)
|
||||
) Engine=InnoDB'''
|
||||
create_view_template = '''create view %s(id, msg, keyspace_id) as select id, msg, keyspace_id from %s'''
|
||||
create_view_template = (
|
||||
'create view %s(id, msg, keyspace_id) as select id, msg, keyspace_id '
|
||||
'from %s')
|
||||
create_timestamp_table = '''create table timestamps(
|
||||
name varchar(64),
|
||||
time_milli bigint(20) unsigned not null,
|
||||
|
@ -239,25 +243,26 @@ primary key (name)
|
|||
|
||||
# _insert_value inserts a value in the MySQL database along with the comments
|
||||
# required for routing.
|
||||
def _insert_value(self, tablet, table, id, msg, keyspace_id):
|
||||
def _insert_value(self, tablet_obj, table, id, msg, keyspace_id):
|
||||
k = utils.uint64_to_hex(keyspace_id)
|
||||
tablet.mquery(
|
||||
tablet_obj.mquery(
|
||||
'vt_test_keyspace',
|
||||
['begin',
|
||||
'insert into %s(id, msg, keyspace_id) '
|
||||
'values(%d, "%s", 0x%x) /* vtgate:: keyspace_id:%s */ /* user_id:%d */' %
|
||||
'values(%d, "%s", 0x%x) /* vtgate:: keyspace_id:%s */ '
|
||||
'/* user_id:%d */' %
|
||||
(table, id, msg, keyspace_id, k, id),
|
||||
'commit'],
|
||||
write=True)
|
||||
|
||||
def _get_value(self, tablet, table, id):
|
||||
return tablet.mquery(
|
||||
def _get_value(self, tablet_obj, table, id):
|
||||
return tablet_obj.mquery(
|
||||
'vt_test_keyspace',
|
||||
'select id, msg, keyspace_id from %s where id=%d' % (table, id))
|
||||
|
||||
def _check_value(self, tablet, table, id, msg, keyspace_id,
|
||||
def _check_value(self, tablet_obj, table, id, msg, keyspace_id,
|
||||
should_be_here=True):
|
||||
result = self._get_value(tablet, table, id)
|
||||
result = self._get_value(tablet_obj, table, id)
|
||||
if keyspace_id_type == keyrange_constants.KIT_BYTES:
|
||||
fmt = '%s'
|
||||
keyspace_id = pack_keyspace_id(keyspace_id)
|
||||
|
@ -266,21 +271,23 @@ primary key (name)
|
|||
if should_be_here:
|
||||
self.assertEqual(result, ((id, msg, keyspace_id),),
|
||||
('Bad row in tablet %s for id=%d, keyspace_id=' +
|
||||
fmt + ', row=%s') % (tablet.tablet_alias, id,
|
||||
fmt + ', row=%s') % (tablet_obj.tablet_alias, id,
|
||||
keyspace_id, str(result)))
|
||||
else:
|
||||
self.assertEqual(len(result), 0,
|
||||
('Extra row in tablet %s for id=%d, keyspace_id=' +
|
||||
fmt + ': %s') % (tablet.tablet_alias, id, keyspace_id,
|
||||
str(result)))
|
||||
self.assertEqual(
|
||||
len(result), 0,
|
||||
('Extra row in tablet %s for id=%d, keyspace_id=' +
|
||||
fmt + ': %s') % (tablet_obj.tablet_alias, id, keyspace_id,
|
||||
str(result)))
|
||||
|
||||
# _is_value_present_and_correct tries to read a value.
|
||||
# if it is there, it will check it is correct and return True if it is.
|
||||
# if not correct, it will self.fail.
|
||||
# if not there, it will return False.
|
||||
def _is_value_present_and_correct(self, tablet, table, id, msg, keyspace_id):
|
||||
result = self._get_value(tablet, table, id)
|
||||
if len(result) == 0:
|
||||
def _is_value_present_and_correct(
|
||||
self, tablet_obj, table, id, msg, keyspace_id):
|
||||
result = self._get_value(tablet_obj, table, id)
|
||||
if not result:
|
||||
return False
|
||||
if keyspace_id_type == keyrange_constants.KIT_BYTES:
|
||||
fmt = '%s'
|
||||
|
@ -289,7 +296,7 @@ primary key (name)
|
|||
fmt = '%x'
|
||||
self.assertEqual(result, ((id, msg, keyspace_id),),
|
||||
('Bad row in tablet %s for id=%d, keyspace_id=' + fmt) % (
|
||||
tablet.tablet_alias, id, keyspace_id))
|
||||
tablet_obj.tablet_alias, id, keyspace_id))
|
||||
return True
|
||||
|
||||
def _insert_startup_values(self):
|
||||
|
@ -373,13 +380,13 @@ primary key (name)
|
|||
'msg-range2-%d' % i, 0xE000000000000000 + base + i,
|
||||
should_be_here=False)
|
||||
|
||||
def _check_binlog_server_vars(self, tablet):
|
||||
v = utils.get_vars(tablet.port)
|
||||
def _check_binlog_server_vars(self, tablet_obj):
|
||||
v = utils.get_vars(tablet_obj.port)
|
||||
self.assertIn('UpdateStreamKeyRangeStatements', v)
|
||||
self.assertIn('UpdateStreamKeyRangeTransactions', v)
|
||||
|
||||
def _check_binlog_player_vars(self, tablet, seconds_behind_master_max=0):
|
||||
v = utils.get_vars(tablet.port)
|
||||
def _check_binlog_player_vars(self, tablet_obj, seconds_behind_master_max=0):
|
||||
v = utils.get_vars(tablet_obj.port)
|
||||
self.assertIn('BinlogPlayerMapSize', v)
|
||||
self.assertIn('BinlogPlayerSecondsBehindMaster', v)
|
||||
self.assertIn('BinlogPlayerSecondsBehindMasterMap', v)
|
||||
|
@ -403,14 +410,14 @@ primary key (name)
|
|||
v['BinlogPlayerSecondsBehindMasterMap']['0'],
|
||||
seconds_behind_master_max))
|
||||
|
||||
def _check_stream_health_equals_binlog_player_vars(self, tablet):
|
||||
blp_stats = utils.get_vars(tablet.port)
|
||||
def _check_stream_health_equals_binlog_player_vars(self, tablet_obj):
|
||||
blp_stats = utils.get_vars(tablet_obj.port)
|
||||
# Enforce health check because it's not running by default as
|
||||
# tablets are not started with it.
|
||||
utils.run_vtctl(['RunHealthCheck', tablet.tablet_alias, 'replica'])
|
||||
utils.run_vtctl(['RunHealthCheck', tablet_obj.tablet_alias, 'replica'])
|
||||
stream_health = utils.run_vtctl_json(['VtTabletStreamHealth',
|
||||
'-count', '1',
|
||||
tablet.tablet_alias])
|
||||
tablet_obj.tablet_alias])
|
||||
logging.debug('Got health: %s', str(stream_health))
|
||||
self.assertNotIn('serving', stream_health)
|
||||
self.assertIn('realtime_stats', stream_health)
|
||||
|
@ -531,11 +538,12 @@ primary key (name)
|
|||
|
||||
utils.run_vtctl(['RebuildKeyspaceGraph', 'test_keyspace'],
|
||||
auto_log=True)
|
||||
utils.check_srv_keyspace('test_nj', 'test_keyspace',
|
||||
'Partitions(master): -80 80-\n' +
|
||||
'Partitions(rdonly): -80 80-\n' +
|
||||
'Partitions(replica): -80 80-\n',
|
||||
keyspace_id_type=keyspace_id_type)
|
||||
utils.check_srv_keyspace(
|
||||
'test_nj', 'test_keyspace',
|
||||
'Partitions(master): -80 80-\n'
|
||||
'Partitions(rdonly): -80 80-\n'
|
||||
'Partitions(replica): -80 80-\n',
|
||||
keyspace_id_type=keyspace_id_type)
|
||||
|
||||
# the worker will do everything. We test with source_reader_count=10
|
||||
# (down from default=20) as connection pool is not big enough for 20.
|
||||
|
@ -612,7 +620,9 @@ primary key (name)
|
|||
# get status for a destination master tablet, make sure we have it all
|
||||
shard_2_master_status = shard_2_master.get_status()
|
||||
self.assertIn('Binlog player state: Running', shard_2_master_status)
|
||||
self.assertIn('<td><b>All</b>: 6000<br><b>Query</b>: 4000<br><b>Transaction</b>: 2000<br></td>', shard_2_master_status)
|
||||
self.assertIn(
|
||||
'<td><b>All</b>: 6000<br><b>Query</b>: 4000<br>'
|
||||
'<b>Transaction</b>: 2000<br></td>', shard_2_master_status)
|
||||
self.assertIn('</html>', shard_2_master_status)
|
||||
|
||||
# start a thread to insert data into shard_1 in the background
|
||||
|
@ -706,12 +716,15 @@ primary key (name)
|
|||
utils.check_tablet_query_service(self, shard_1_slave2, False, True)
|
||||
|
||||
# move replica back and forth
|
||||
utils.run_vtctl(['MigrateServedTypes', '-reverse', 'test_keyspace/80-', 'replica'],
|
||||
auto_log=True)
|
||||
# After a backwards migration, queryservice should be enabled on source and disabled on destinations
|
||||
utils.run_vtctl(
|
||||
['MigrateServedTypes', '-reverse', 'test_keyspace/80-', 'replica'],
|
||||
auto_log=True)
|
||||
# After a backwards migration, queryservice should be enabled on
|
||||
# source and disabled on destinations
|
||||
utils.check_tablet_query_service(self, shard_1_slave2, True, False)
|
||||
# Destination tablets would have query service disabled for other reasons than the migration,
|
||||
# so check the shard record instead of the tablets directly
|
||||
# Destination tablets would have query service disabled for other
|
||||
# reasons than the migration, so check the shard record instead of
|
||||
# the tablets directly.
|
||||
utils.check_shard_query_services(self, destination_shards,
|
||||
topodata_pb2.REPLICA, False)
|
||||
utils.check_srv_keyspace('test_nj', 'test_keyspace',
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
# Use of this source code is governed by a BSD-style license that can
|
||||
# be found in the LICENSE file.
|
||||
|
||||
from vtdb import keyrange_constants
|
||||
|
||||
import resharding
|
||||
import utils
|
||||
|
||||
from vtdb import keyrange_constants
|
||||
|
||||
# this test is just re-running an entire resharding.py with a
|
||||
# varbinary keyspace_id
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -1,20 +1,22 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import warnings
|
||||
# Dropping a table inexplicably produces a warning despite
|
||||
# the "IF EXISTS" clause. Squelch these warnings.
|
||||
warnings.simplefilter('ignore')
|
||||
|
||||
import json
|
||||
import logging
|
||||
import time
|
||||
import unittest
|
||||
import urllib2
|
||||
|
||||
import logging
|
||||
import unittest
|
||||
|
||||
import environment
|
||||
import tablet
|
||||
import utils
|
||||
|
||||
# Dropping a table inexplicably produces a warning despite
|
||||
# the "IF EXISTS" clause. Squelch these warnings.
|
||||
warnings.simplefilter('ignore')
|
||||
|
||||
master_tablet = tablet.Tablet()
|
||||
replica_tablet = tablet.Tablet()
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
|
||||
import logging
|
||||
import unittest
|
||||
import os
|
||||
|
||||
import environment
|
||||
import tablet
|
||||
|
@ -18,8 +19,9 @@ shard_1_replica1 = tablet.Tablet()
|
|||
shard_2_master = tablet.Tablet()
|
||||
shard_2_replica1 = tablet.Tablet()
|
||||
# shard_2 tablets are not used by all tests and not included by default.
|
||||
tablets = [shard_0_master, shard_0_replica1, shard_0_replica2, shard_0_rdonly,
|
||||
shard_0_backup, shard_1_master, shard_1_replica1]
|
||||
all_tablets = [
|
||||
shard_0_master, shard_0_replica1, shard_0_replica2, shard_0_rdonly,
|
||||
shard_0_backup, shard_1_master, shard_1_replica1]
|
||||
tablets_shard2 = [shard_2_master, shard_2_replica1]
|
||||
test_keyspace = 'test_keyspace'
|
||||
db_name = 'vt_' + test_keyspace
|
||||
|
@ -29,7 +31,7 @@ def setUpModule():
|
|||
try:
|
||||
environment.topo_server().setup()
|
||||
|
||||
_init_mysql(tablets)
|
||||
_init_mysql(all_tablets)
|
||||
|
||||
utils.run_vtctl(['CreateKeyspace', test_keyspace])
|
||||
|
||||
|
@ -47,7 +49,7 @@ def setUpModule():
|
|||
utils.Vtctld().start()
|
||||
|
||||
# create databases, start the tablets
|
||||
for t in tablets:
|
||||
for t in all_tablets:
|
||||
t.create_db(db_name)
|
||||
t.start_vttablet(wait_for_state=None)
|
||||
|
||||
|
@ -61,7 +63,7 @@ def setUpModule():
|
|||
shard_1_replica1.wait_for_vttablet_state('SERVING')
|
||||
|
||||
# make sure all replication is good
|
||||
for t in tablets:
|
||||
for t in all_tablets:
|
||||
t.reset_replication()
|
||||
|
||||
utils.run_vtctl(['InitShardMaster', test_keyspace+'/0',
|
||||
|
@ -91,10 +93,10 @@ def tearDownModule():
|
|||
if utils.options.skip_teardown:
|
||||
return
|
||||
|
||||
tablet.kill_tablets(tablets)
|
||||
tablet.kill_tablets(all_tablets)
|
||||
|
||||
teardown_procs = []
|
||||
for t in tablets:
|
||||
for t in all_tablets:
|
||||
teardown_procs.append(t.teardown_mysql())
|
||||
utils.wait_procs(teardown_procs, raise_on_error=False)
|
||||
|
||||
|
@ -102,44 +104,45 @@ def tearDownModule():
|
|||
utils.kill_sub_processes()
|
||||
utils.remove_tmp_files()
|
||||
|
||||
for t in tablets:
|
||||
for t in all_tablets:
|
||||
t.remove_tree()
|
||||
|
||||
|
||||
class TestSchema(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
for t in tablets:
|
||||
for t in all_tablets:
|
||||
t.create_db(db_name)
|
||||
|
||||
def tearDown(self):
|
||||
# This test assumes that it can reset the tablets by simply cleaning their
|
||||
# databases without restarting the tablets.
|
||||
for t in tablets:
|
||||
for t in all_tablets:
|
||||
t.clean_dbs()
|
||||
# Tablets from shard 2 are always started during the test. Shut
|
||||
# them down now.
|
||||
if shard_2_master in tablets:
|
||||
if shard_2_master in all_tablets:
|
||||
for t in tablets_shard2:
|
||||
t.kill_vttablet()
|
||||
utils.run_vtctl(['DeleteTablet', '-allow_master', t.tablet_alias],
|
||||
auto_log=True)
|
||||
tablets.remove(t)
|
||||
all_tablets.remove(t)
|
||||
utils.run_vtctl(['DeleteShard', 'test_keyspace/2'], auto_log=True)
|
||||
|
||||
def _check_tables(self, tablet, expected_count):
|
||||
tables = tablet.mquery(db_name, 'show tables')
|
||||
self.assertEqual(len(tables), expected_count,
|
||||
'Unexpected table count on %s (not %d): got tables: %s' %
|
||||
(tablet.tablet_alias, expected_count, str(tables)))
|
||||
def _check_tables(self, tablet_obj, expected_count):
|
||||
tables = tablet_obj.mquery(db_name, 'show tables')
|
||||
self.assertEqual(
|
||||
len(tables), expected_count,
|
||||
'Unexpected table count on %s (not %d): got tables: %s' %
|
||||
(tablet_obj.tablet_alias, expected_count, str(tables)))
|
||||
|
||||
def _check_db_not_created(self, tablet):
|
||||
def _check_db_not_created(self, tablet_obj):
|
||||
# Broadly catch all exceptions, since the exception being raised
|
||||
# is internal to MySQL. We're strictly checking the error message
|
||||
# though, so should be fine.
|
||||
with self.assertRaisesRegexp(
|
||||
Exception, '(1049, "Unknown database \'%s\'")' % db_name):
|
||||
tablet.mquery(db_name, 'show tables')
|
||||
tablet_obj.mquery(db_name, 'show tables')
|
||||
|
||||
def _apply_schema(self, keyspace, sql):
|
||||
utils.run_vtctl(['ApplySchema',
|
||||
|
@ -224,7 +227,7 @@ class TestSchema(unittest.TestCase):
|
|||
_init_mysql(tablets_shard2)
|
||||
finally:
|
||||
# Include shard2 tablets for tearDown.
|
||||
tablets.extend(tablets_shard2)
|
||||
all_tablets.extend(tablets_shard2)
|
||||
|
||||
shard_2_master.init_tablet('master', 'test_keyspace', '2')
|
||||
shard_2_replica1.init_tablet('replica', 'test_keyspace', '2')
|
||||
|
|
Загрузка…
Ссылка в новой задаче