示例#1
0
print 'inserted %d records' % ROW_N
print

print 'Synchronize'
for server1 in cluster:
    for server2 in cluster:
        server1.wait_lsn(server2.id, server2.get_lsn(server2.id))
    print 'server', server1.id, 'done'
print 'done'
print

print 'Check data'
for server in cluster:
    cnt = yaml.safe_load(server.admin("box.space.test:len()", silent=True))[0]
    print 'server', server.id, 'is', cnt == ROW_N and 'ok' or 'not ok'
print 'Done'
print

print
print '----------------------------------------------------------------------'
print 'Cleanup'
print '----------------------------------------------------------------------'

for server in cluster:
    server.stop()
    print 'server', server.id, 'done'
print

master.cleanup()
master.deploy()
示例#2
0
print '-------------------------------------------------------------'
print 'Sync master with replica'
print '-------------------------------------------------------------'

# Sync master with replica
replication_source = yaml.load(replica.admin('box.cfg.listen', silent=True))[0]
sys.stdout.push_filter(replication_source, '<replication_source>')
master.admin("box.cfg{ replication_source = '%s' }" % replication_source)

master.wait_lsn(replica_id, replica.get_lsn(replica_id))
master.admin('box.info.vclock[%d] == 1' % replica_id)
master.admin('box.info.vclock[%d] == 0' % replica_id2)
master.admin('box.info.vclock[%d] == nil' % replica_id3)

master.admin("box.cfg{ replication_source = '' }")
replica.stop()
replica.cleanup(True)

print '-------------------------------------------------------------'
print 'Start a new replica and check that server_id, LSN is re-used'
print '-------------------------------------------------------------'

#
# gh-1219: Proper removal of servers with non-zero LSN from _cluster
#
# Snapshot is required. Otherwise a relay will skip records made by previous
# replica with the re-used id.
master.admin("box.snapshot()")
master.admin('box.info.vclock[%d] == 1' % replica_id)

replica = TarantoolServer(server.ini)
示例#3
0
print """
# Insert 10 tuples to hot_standby
"""
for i in range(id, id + 10):
    hot_standby_sql("insert into t0 values (%d, 'the tuple %d')" % (i, i))


print """
# Select 10 tuples from hot_standby
"""
for i in range(id, id + 10):
    hot_standby_sql("select * from t0 where k0 = %d" % i)


print """
# Select 10 tuples from replica
"""
replica.wait_lsn(21)
for i in range(id, id + 10):
    replica_sql("select * from t0 where k0 = %d" % i)


# Cleanup.
hot_standby.stop()
hot_standby.cleanup(True)
replica.stop()
replica.cleanup(True)
server.deploy(self.suite_ini["config"])

# vim: syntax=python
示例#4
0
master = server
master_id = master.get_param('server')['id']

master.admin("box.schema.user.grant('guest', 'replication')")

replica = TarantoolServer(server.ini)
replica.script = 'replication/replica.lua'
replica.vardir = server.vardir #os.path.join(server.vardir, 'replica')
replica.rpl_master = master
replica.deploy()
replica.wait_lsn(master_id, master.get_lsn(master_id))
replica_id = replica.get_param('server')['id']
replica.admin('box.info.server.id')
replica.admin('box.info.server.ro')
replica.admin('box.info.server.lsn')
replica.stop()

print '-------------------------------------------------------------'
print 'replica is read-only until receive self server_id in _cluster'
print '-------------------------------------------------------------'

# Remove xlog retrived by SUBSCRIBE
filename = str(0).zfill(20) + ".xlog"
wal = os.path.join(os.path.join(replica.vardir, replica.name), filename)
os.remove(wal)

# Start replica without master
server.stop()
replica.start()
replica.admin('box.cfg{replication_source = ""}')
示例#5
0
# White while hot_standby server not bind masters ports
time.sleep(0.2)

print """
# Insert 10 tuples to hot_standby
"""
for i in range(id, id + 10):
    hot_standby_sql("insert into t0 values (%d, 'the tuple %d')" % (i, i))

print """
# Select 10 tuples from hot_standby
"""
for i in range(id, id + 10):
    hot_standby_sql("select * from t0 where k0 = %d" % i)

print """
# Select 10 tuples from replica
"""
replica.wait_lsn(21)
for i in range(id, id + 10):
    replica_sql("select * from t0 where k0 = %d" % i)

# Cleanup.
hot_standby.stop()
hot_standby.cleanup(True)
replica.stop()
replica.cleanup(True)
server.deploy(self.suite_ini["config"])

# vim: syntax=python
示例#6
0
print 'inserted %d records' % ROW_N
print

print 'Synchronize'
for server1 in cluster:
    for server2 in cluster:
        server1.wait_lsn(server2.id, server2.get_lsn(server2.id))
    print 'server', server.id, 'done'
print 'done'
print

print 'Check data'
for server in cluster:
    cnt = yaml.load(server.admin("box.space.test:len()", silent = True))[0]
    print 'server', server.id, 'is', cnt == ROW_N and 'ok' or 'not ok'
print 'Done'
print

print
print '----------------------------------------------------------------------'
print 'Cleanup'
print '----------------------------------------------------------------------'

for server in cluster:
    server.stop()
    print 'server', server.id, 'done'
print

master.cleanup()
master.deploy()
class TestSuite_Schema(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        print " SCHEMA ".center(70, "=")
        print "-" * 70
        self.srv = TarantoolServer()
        self.srv.script = "tests/suites/box.lua"
        self.srv.start()
        self.con = tarantool.Connection("localhost", self.srv.args["primary"])
        self.sch = self.con.schema

    def test_00_authenticate(self):
        self.assertIsNone(self.srv.admin("box.schema.user.create('test', { password = '******' })"))
        self.assertIsNone(self.srv.admin("box.schema.user.grant('test', 'read,write', 'space', '_space')"))
        self.assertIsNone(self.srv.admin("box.schema.user.grant('test', 'read,write', 'space', '_index')"))
        self.assertEqual(self.con.authenticate("test", "test")._data, None)

    def test_01_space_bad(self):
        with self.assertRaisesRegexp(tarantool.SchemaError, "There's no space.*"):
            self.sch.get_space(0)
        with self.assertRaisesRegexp(tarantool.SchemaError, "There's no space.*"):
            self.sch.get_space(0)
        with self.assertRaisesRegexp(tarantool.SchemaError, "There's no space.*"):
            self.sch.get_space("bad_name")

    def test_02_index_bad(self):
        with self.assertRaisesRegexp(tarantool.SchemaError, "There's no space.*"):
            self.sch.get_index(0, "primary")
        with self.assertRaisesRegexp(tarantool.SchemaError, "There's no space.*"):
            self.sch.get_index("bad_space", "primary")
        with self.assertRaisesRegexp(tarantool.SchemaError, "There's no index.*"):
            self.sch.get_index(280, "bad_index")
        with self.assertRaisesRegexp(tarantool.SchemaError, "There's no index.*"):
            self.sch.get_index(280, "bad_index")
        with self.assertRaisesRegexp(tarantool.SchemaError, "There's no index.*"):
            self.sch.get_index(280, 3)

    def test_03_01_space_name__(self):
        self.con.flush_schema()
        space = self.sch.get_space("_schema")
        self.assertEqual(space.sid, 272)
        self.assertEqual(space.name, "_schema")
        self.assertEqual(space.arity, 1)
        space = self.sch.get_space("_space")
        self.assertEqual(space.sid, 280)
        self.assertEqual(space.name, "_space")
        self.assertEqual(space.arity, 1)
        space = self.sch.get_space("_index")
        self.assertEqual(space.sid, 288)
        self.assertEqual(space.name, "_index")
        self.assertEqual(space.arity, 1)

    def test_03_02_space_number(self):
        self.con.flush_schema()
        space = self.sch.get_space(272)
        self.assertEqual(space.sid, 272)
        self.assertEqual(space.name, "_schema")
        self.assertEqual(space.arity, 1)
        space = self.sch.get_space(280)
        self.assertEqual(space.sid, 280)
        self.assertEqual(space.name, "_space")
        self.assertEqual(space.arity, 1)
        space = self.sch.get_space(288)
        self.assertEqual(space.sid, 288)
        self.assertEqual(space.name, "_index")
        self.assertEqual(space.arity, 1)

    def test_04_space_cached(self):
        space = self.sch.get_space("_schema")
        self.assertEqual(space.sid, 272)
        self.assertEqual(space.name, "_schema")
        self.assertEqual(space.arity, 1)
        space = self.sch.get_space("_space")
        self.assertEqual(space.sid, 280)
        self.assertEqual(space.name, "_space")
        self.assertEqual(space.arity, 1)
        space = self.sch.get_space("_index")
        self.assertEqual(space.sid, 288)
        self.assertEqual(space.name, "_index")
        self.assertEqual(space.arity, 1)

    def test_05_01_index_name___name__(self):
        self.con.flush_schema()
        index = self.sch.get_index("_index", "primary")
        self.assertEqual(index.space.name, "_index")
        self.assertEqual(index.iid, 0)
        self.assertEqual(index.name, "primary")
        self.assertEqual(len(index.parts), 2)
        index = self.sch.get_index("_index", "name")
        self.assertEqual(index.space.name, "_index")
        self.assertEqual(index.iid, 2)
        self.assertEqual(index.name, "name")
        self.assertEqual(len(index.parts), 2)
        index = self.sch.get_index("_space", "primary")
        self.assertEqual(index.space.name, "_space")
        self.assertEqual(index.iid, 0)
        self.assertEqual(index.name, "primary")
        self.assertEqual(len(index.parts), 1)
        index = self.sch.get_index("_space", "name")
        self.assertEqual(index.space.name, "_space")
        self.assertEqual(index.iid, 2)
        self.assertEqual(index.name, "name")
        self.assertEqual(len(index.parts), 1)

    def test_05_02_index_name___number(self):
        self.con.flush_schema()
        index = self.sch.get_index("_index", 0)
        self.assertEqual(index.space.name, "_index")
        self.assertEqual(index.iid, 0)
        self.assertEqual(index.name, "primary")
        self.assertEqual(len(index.parts), 2)
        index = self.sch.get_index("_index", 2)
        self.assertEqual(index.space.name, "_index")
        self.assertEqual(index.iid, 2)
        self.assertEqual(index.name, "name")
        self.assertEqual(len(index.parts), 2)
        index = self.sch.get_index("_space", 0)
        self.assertEqual(index.space.name, "_space")
        self.assertEqual(index.iid, 0)
        self.assertEqual(index.name, "primary")
        self.assertEqual(len(index.parts), 1)
        index = self.sch.get_index("_space", 2)
        self.assertEqual(index.space.name, "_space")
        self.assertEqual(index.iid, 2)
        self.assertEqual(index.name, "name")
        self.assertEqual(len(index.parts), 1)

    def test_05_03_index_number_name__(self):
        self.con.flush_schema()
        index = self.sch.get_index(288, "primary")
        self.assertEqual(index.space.name, "_index")
        self.assertEqual(index.iid, 0)
        self.assertEqual(index.name, "primary")
        self.assertEqual(len(index.parts), 2)
        index = self.sch.get_index(288, "name")
        self.assertEqual(index.space.name, "_index")
        self.assertEqual(index.iid, 2)
        self.assertEqual(index.name, "name")
        self.assertEqual(len(index.parts), 2)
        index = self.sch.get_index(280, "primary")
        self.assertEqual(index.space.name, "_space")
        self.assertEqual(index.iid, 0)
        self.assertEqual(index.name, "primary")
        self.assertEqual(len(index.parts), 1)
        index = self.sch.get_index(280, "name")
        self.assertEqual(index.space.name, "_space")
        self.assertEqual(index.iid, 2)
        self.assertEqual(index.name, "name")
        self.assertEqual(len(index.parts), 1)

    def test_05_04_index_number_number(self):
        self.con.flush_schema()
        index = self.sch.get_index(288, 0)
        self.assertEqual(index.space.name, "_index")
        self.assertEqual(index.iid, 0)
        self.assertEqual(index.name, "primary")
        self.assertEqual(len(index.parts), 2)
        index = self.sch.get_index(288, 2)
        self.assertEqual(index.space.name, "_index")
        self.assertEqual(index.iid, 2)
        self.assertEqual(index.name, "name")
        self.assertEqual(len(index.parts), 2)
        index = self.sch.get_index(280, 0)
        self.assertEqual(index.space.name, "_space")
        self.assertEqual(index.iid, 0)
        self.assertEqual(index.name, "primary")
        self.assertEqual(len(index.parts), 1)
        index = self.sch.get_index(280, 2)
        self.assertEqual(index.space.name, "_space")
        self.assertEqual(index.iid, 2)
        self.assertEqual(index.name, "name")
        self.assertEqual(len(index.parts), 1)

    def test_06_index_cached(self):
        index = self.sch.get_index("_index", "primary")
        self.assertEqual(index.space.name, "_index")
        self.assertEqual(index.iid, 0)
        self.assertEqual(index.name, "primary")
        self.assertEqual(len(index.parts), 2)
        index = self.sch.get_index("_index", 2)
        self.assertEqual(index.space.name, "_index")
        self.assertEqual(index.iid, 2)
        self.assertEqual(index.name, "name")
        self.assertEqual(len(index.parts), 2)
        index = self.sch.get_index(280, "primary")
        self.assertEqual(index.space.name, "_space")
        self.assertEqual(index.iid, 0)
        self.assertEqual(index.name, "primary")
        self.assertEqual(len(index.parts), 1)
        index = self.sch.get_index(280, 2)
        self.assertEqual(index.space.name, "_space")
        self.assertEqual(index.iid, 2)
        self.assertEqual(index.name, "name")
        self.assertEqual(len(index.parts), 1)

    @classmethod
    def tearDownClass(self):
        self.srv.stop()
        self.srv.clean()
示例#8
0
class TestSuite_Schema(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        print(' SCHEMA '.center(70, '='))
        print('-' * 70)
        self.srv = TarantoolServer()
        self.srv.script = 'tests/suites/box.lua'
        self.srv.start()
        self.con = tarantool.Connection('localhost', self.srv.args['primary'])
        self.sch = self.con.schema

    def test_00_authenticate(self):
        self.assertIsNone(self.srv.admin("box.schema.user.create('test', { password = '******' })"))
        self.assertIsNone(self.srv.admin("box.schema.user.grant('test', 'read,write', 'space', '_space')"))
        self.assertIsNone(self.srv.admin("box.schema.user.grant('test', 'read,write', 'space', '_index')"))
        self.assertEqual(self.con.authenticate('test', 'test')._data, None)

    def test_01_space_bad(self):
        with self.assertRaisesRegexp(tarantool.SchemaError,
                'There\'s no space.*'):
            self.sch.get_space(0)
        with self.assertRaisesRegexp(tarantool.SchemaError,
                'There\'s no space.*'):
            self.sch.get_space(0)
        with self.assertRaisesRegexp(tarantool.SchemaError,
                'There\'s no space.*'):
            self.sch.get_space('bad_name')

    def test_02_index_bad(self):
        with self.assertRaisesRegexp(tarantool.SchemaError,
                'There\'s no space.*'):
            self.sch.get_index(0, 'primary')
        with self.assertRaisesRegexp(tarantool.SchemaError,
                'There\'s no space.*'):
            self.sch.get_index('bad_space', 'primary')
        with self.assertRaisesRegexp(tarantool.SchemaError,
                'There\'s no index.*'):
            self.sch.get_index(280, 'bad_index')
        with self.assertRaisesRegexp(tarantool.SchemaError,
                'There\'s no index.*'):
            self.sch.get_index(280, 'bad_index')
        with self.assertRaisesRegexp(tarantool.SchemaError,
                'There\'s no index.*'):
            self.sch.get_index(280, 3)

    def test_03_01_space_name__(self):
        self.con.flush_schema()
        space = self.sch.get_space('_schema')
        self.assertEqual(space.sid, 272)
        self.assertEqual(space.name, '_schema')
        self.assertEqual(space.arity, 1)
        space = self.sch.get_space('_space')
        self.assertEqual(space.sid, 280)
        self.assertEqual(space.name, '_space')
        self.assertEqual(space.arity, 1)
        space = self.sch.get_space('_index')
        self.assertEqual(space.sid, 288)
        self.assertEqual(space.name, '_index')
        self.assertEqual(space.arity, 1)

    def test_03_02_space_number(self):
        self.con.flush_schema()
        space = self.sch.get_space(272)
        self.assertEqual(space.sid, 272)
        self.assertEqual(space.name, '_schema')
        self.assertEqual(space.arity, 1)
        space = self.sch.get_space(280)
        self.assertEqual(space.sid, 280)
        self.assertEqual(space.name, '_space')
        self.assertEqual(space.arity, 1)
        space = self.sch.get_space(288)
        self.assertEqual(space.sid, 288)
        self.assertEqual(space.name, '_index')
        self.assertEqual(space.arity, 1)

    def test_04_space_cached(self):
        space = self.sch.get_space('_schema')
        self.assertEqual(space.sid, 272)
        self.assertEqual(space.name, '_schema')
        self.assertEqual(space.arity, 1)
        space = self.sch.get_space('_space')
        self.assertEqual(space.sid, 280)
        self.assertEqual(space.name, '_space')
        self.assertEqual(space.arity, 1)
        space = self.sch.get_space('_index')
        self.assertEqual(space.sid, 288)
        self.assertEqual(space.name, '_index')
        self.assertEqual(space.arity, 1)

    def test_05_01_index_name___name__(self):
        self.con.flush_schema()
        index = self.sch.get_index('_index', 'primary')
        self.assertEqual(index.space.name, '_index')
        self.assertEqual(index.iid, 0)
        self.assertEqual(index.name, 'primary')
        self.assertEqual(len(index.parts), 2)
        index = self.sch.get_index('_index', 'name')
        self.assertEqual(index.space.name, '_index')
        self.assertEqual(index.iid, 2)
        self.assertEqual(index.name, 'name')
        self.assertEqual(len(index.parts), 2)
        index = self.sch.get_index('_space', 'primary')
        self.assertEqual(index.space.name, '_space')
        self.assertEqual(index.iid, 0)
        self.assertEqual(index.name, 'primary')
        self.assertEqual(len(index.parts), 1)
        index = self.sch.get_index('_space', 'name')
        self.assertEqual(index.space.name, '_space')
        self.assertEqual(index.iid, 2)
        self.assertEqual(index.name, 'name')
        self.assertEqual(len(index.parts), 1)

    def test_05_02_index_name___number(self):
        self.con.flush_schema()
        index = self.sch.get_index('_index', 0)
        self.assertEqual(index.space.name, '_index')
        self.assertEqual(index.iid, 0)
        self.assertEqual(index.name, 'primary')
        self.assertEqual(len(index.parts), 2)
        index = self.sch.get_index('_index', 2)
        self.assertEqual(index.space.name, '_index')
        self.assertEqual(index.iid, 2)
        self.assertEqual(index.name, 'name')
        self.assertEqual(len(index.parts), 2)
        index = self.sch.get_index('_space', 0)
        self.assertEqual(index.space.name, '_space')
        self.assertEqual(index.iid, 0)
        self.assertEqual(index.name, 'primary')
        self.assertEqual(len(index.parts), 1)
        index = self.sch.get_index('_space', 2)
        self.assertEqual(index.space.name, '_space')
        self.assertEqual(index.iid, 2)
        self.assertEqual(index.name, 'name')
        self.assertEqual(len(index.parts), 1)

    def test_05_03_index_number_name__(self):
        self.con.flush_schema()
        index = self.sch.get_index(288, 'primary')
        self.assertEqual(index.space.name, '_index')
        self.assertEqual(index.iid, 0)
        self.assertEqual(index.name, 'primary')
        self.assertEqual(len(index.parts), 2)
        index = self.sch.get_index(288, 'name')
        self.assertEqual(index.space.name, '_index')
        self.assertEqual(index.iid, 2)
        self.assertEqual(index.name, 'name')
        self.assertEqual(len(index.parts), 2)
        index = self.sch.get_index(280, 'primary')
        self.assertEqual(index.space.name, '_space')
        self.assertEqual(index.iid, 0)
        self.assertEqual(index.name, 'primary')
        self.assertEqual(len(index.parts), 1)
        index = self.sch.get_index(280, 'name')
        self.assertEqual(index.space.name, '_space')
        self.assertEqual(index.iid, 2)
        self.assertEqual(index.name, 'name')
        self.assertEqual(len(index.parts), 1)

    def test_05_04_index_number_number(self):
        self.con.flush_schema()
        index = self.sch.get_index(288, 0)
        self.assertEqual(index.space.name, '_index')
        self.assertEqual(index.iid, 0)
        self.assertEqual(index.name, 'primary')
        self.assertEqual(len(index.parts), 2)
        index = self.sch.get_index(288, 2)
        self.assertEqual(index.space.name, '_index')
        self.assertEqual(index.iid, 2)
        self.assertEqual(index.name, 'name')
        self.assertEqual(len(index.parts), 2)
        index = self.sch.get_index(280, 0)
        self.assertEqual(index.space.name, '_space')
        self.assertEqual(index.iid, 0)
        self.assertEqual(index.name, 'primary')
        self.assertEqual(len(index.parts), 1)
        index = self.sch.get_index(280, 2)
        self.assertEqual(index.space.name, '_space')
        self.assertEqual(index.iid, 2)
        self.assertEqual(index.name, 'name')
        self.assertEqual(len(index.parts), 1)

    def test_06_index_cached(self):
        index = self.sch.get_index('_index', 'primary')
        self.assertEqual(index.space.name, '_index')
        self.assertEqual(index.iid, 0)
        self.assertEqual(index.name, 'primary')
        self.assertEqual(len(index.parts), 2)
        index = self.sch.get_index('_index', 2)
        self.assertEqual(index.space.name, '_index')
        self.assertEqual(index.iid, 2)
        self.assertEqual(index.name, 'name')
        self.assertEqual(len(index.parts), 2)
        index = self.sch.get_index(280, 'primary')
        self.assertEqual(index.space.name, '_space')
        self.assertEqual(index.iid, 0)
        self.assertEqual(index.name, 'primary')
        self.assertEqual(len(index.parts), 1)
        index = self.sch.get_index(280, 2)
        self.assertEqual(index.space.name, '_space')
        self.assertEqual(index.iid, 2)
        self.assertEqual(index.name, 'name')
        self.assertEqual(len(index.parts), 1)

    @classmethod
    def tearDownClass(self):
        self.srv.stop()
        self.srv.clean()
示例#9
0
class Request(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        print ' DML '.center(70, '=')
        print '-' * 70
        self.srv = TarantoolServer()
        self.srv.script = 'tests/suites/box.lua'
        self.srv.start()
        self.con = tarantool.Connection('localhost', self.srv.args['primary'])
        self.adm = self.srv.admin
        self.space_created = self.adm("box.schema.create_space('space_1')")
        self.adm("box.space['space_1']:create_index('primary', {type = 'tree', parts = {1, 'num'}, unique = true})")
        self.adm("box.space['space_1']:create_index('secondary', {type = 'tree', parts = {2, 'num', 3, 'str'}, unique = true})")
        self.adm("json = require('json')")
        self.adm("fiber = require('fiber')")
        self.adm("uuid = require('uuid')")

    def test_00_00_authenticate(self):
        self.assertIsNone(self.srv.admin("box.schema.user.create('test', { password = '******' })"))
        self.assertIsNone(self.srv.admin("box.schema.user.grant('test', 'execute,read,write', 'universe')"))
        self.assertEqual(self.con.authenticate('test', 'test')._data, None)

    def test_00_01_space_created(self):
        # Check that space is created in setUpClass
        self.assertEqual(self.space_created[1], 'created')

    def test_00_02_fill_space(self):
        # Fill space with values
        for i in xrange(1, 500):
            self.assertEqual(
                    self.con.insert('space_1', [i, i%5, 'tuple_'+str(i)])[0],
                    [i, i%5, 'tuple_'+str(i)]
            )
    def test_00_03_answer_repr(self):
        repr_str = \
'''- [1, 1, tuple_1]
'''
        self.assertEqual(repr(self.con.select('space_1', 1)), repr_str)

    def test_02_select(self):
        # Check that select with different keys are Ok. (With and without index names)
        self.assertEqual(self.con.select('space_1', 20), [[20, 0, 'tuple_20']])
        self.assertEqual(self.con.select('space_1', [21]), [[21, 1, 'tuple_21']])
        self.assertEqual(self.con.select('space_1', [22], index='primary'), [[22, 2, 'tuple_22']])
        self.assertEqual(self.con.select('space_1', [23], index='primary'), [[23, 3, 'tuple_23']])
        # Check that Offset and Limit args are working fine.
        self.assertEqual(self.con.select('space_1', [20], index='primary', limit=1), [[20, 0, 'tuple_20']])
        # With other indexes too
        self.assertEqual(
                sorted(
                    self.con.select('space_1', [0], index='secondary', offset=3, limit=0),
                    key = lambda x: x[0]),
                []
            )
        self.assertEqual(
                sorted(
                    self.con.select('space_1', [0], index='secondary', offset=3, limit=1),
                    key = lambda x: x[0]),
                [[110, 0, 'tuple_110']]
            )
        self.assertEqual(
                sorted(
                    self.con.select('space_1', [0], index='secondary', offset=3, limit=2),
                    key = lambda x: x[0]),
                [[110, 0, 'tuple_110'],\
                [115, 0, 'tuple_115']]
            )

        select_req = self.con.select('space_1', [0], index='secondary')
        self.assertEqual(len(select_req), 99)
        for i in select_req:
            self.assertTrue(not (i[0] % 5))
            self.assertTrue(not i[1])
            self.assertTrue(i[2] == 'tuple_' + str(i[0]))

        # Check limit again.
        self.assertEqual(len(self.con.select('space_1', [0, 'tuple_20'], index='secondary', limit=0)), 0)
        self.assertEqual(len(self.con.select('space_1', [0], index='secondary', limit=0)), 0)
        self.assertEqual(len(self.con.select('space_1', [0], index='secondary', limit=100)), 99)
        self.assertEqual(len(self.con.select('space_1', [0], index='secondary', limit=50)), 50)

        # TODO: Check iterator_types

    def test_03_delete(self):
        # Check that delete works fine
        self.assertEqual(self.con.delete('space_1', 20), [[20, 0, 'tuple_20']])
        self.assertEqual(self.con.delete('space_1', [20]), [])
        self.assertEqual(self.con.select('space_1', [20], index='primary'), [])
        # Check that <index_id> field has no meaning, yet.
        with self.assertRaisesRegexp(tarantool.DatabaseError,
                '(19, .*)'):
                self.con.delete('space_1', [1, 'tuple_21'])
        self.assertEqual(self.con.select('space_1', [21], index='primary'), [[21, 1, 'tuple_21']])

    def test_04_replace(self):
        # Check replace that is Ok.
        self.assertEqual(self.con.replace('space_1', [2, 2, 'tuple_3']), [[2, 2, 'tuple_3']])
        self.assertEqual(self.con.select('space_1', 2), [[2, 2, 'tuple_3']])
        # Check replace that isn't Ok.
        with self.assertRaisesRegexp(tarantool.DatabaseError,
                '(39, .*)'):
            self.assertEqual(self.con.replace('space_1', [2, 2]), [[2, 2, 'tuple_2']])

    def test_05_ping(self):
        # Simple ping test
        # * No exceptions are raised
        # * Ping time > 0
        self.assertTrue(self.con.ping() > 0)
        self.assertEqual(self.con.ping(notime=True), "Success")

    def test_06_update(self):
        self.assertEqual(self.con.update('space_1', (2,), [('+', 1, 3)]),
                [[2, 5, 'tuple_3']])
        self.assertEqual(self.con.update('space_1', (2,), [('-', 1, 3)]),
                [[2, 2, 'tuple_3']])
        self.assertEqual(self.con.update('space_1', (2,), [(':', 2, 3, 2, 'lalal')]),
                [[2, 2, 'tuplalal_3']])
        self.assertEqual(self.con.update('space_1', (2,), [('!', 2, '1')]),
                [[2, 2, '1', 'tuplalal_3']])
        self.assertEqual(self.con.update('space_1', (2,), [('!', 2, 'oingo, boingo')]),
                [[2, 2, 'oingo, boingo', '1', 'tuplalal_3']])
        self.assertEqual(self.con.update('space_1', (2,), [('#', 2, 2)]),
                [[2, 2, 'tuplalal_3']])

    def test_07_call(self):
        self.assertEqual(self.con.call('json.decode', '[123, 234, 345]'), [[123, 234, 345]])
        self.assertEqual(self.con.call('json.decode', ['[123, 234, 345]']), [[123, 234, 345]])
        self.assertEqual(self.con.call('json.decode', ('[123, 234, 345]',)), [[123, 234, 345]])
        with self.assertRaisesRegexp(tarantool.DatabaseError,
                '(32, .*)'):
            self.con.call('json.decode')
        with self.assertRaisesRegexp(tarantool.DatabaseError,
                '(22, .*)'):
            self.con.call('json.decode', '{"hello": "world"}')
        ans = self.con.call('fiber.time')
        self.assertEqual(len(ans), 1)
        self.assertEqual(len(ans[0]), 1)
        self.assertIsInstance(ans[0][0], float)
        ans = self.con.call('fiber.time64')
        self.assertEqual(len(ans), 1)
        self.assertEqual(len(ans[0]), 1)
        self.assertIsInstance(ans[0][0], (int, long))
        ans = self.con.call('uuid.str')
        self.assertEqual(len(ans), 1)
        self.assertEqual(len(ans[0]), 1)
        self.assertIsInstance(ans[0][0], str)
#        ans = self.con.call('uuid.hex')
#        self.assertEqual(len(ans), 1)
#        self.assertEqual(len(ans[0]), 1)
#        self.assertIsInstance(ans[0][0], str)
#        with self.assertRaisesRegexp(tarantool.DatabaseError,
#                '(12345, \'lol, error\')'):
#            self.con.call('box.error', [12345, 'lol, error'])

        self.assertEqual(self.con.call('box.tuple.new', [1, 2, 3, 'fld_1']), [[1, 2, 3, 'fld_1']])
        self.assertEqual(self.con.call('box.tuple.new', 'fld_1'), [['fld_1']])

    @classmethod
    def tearDownClass(self):
        self.srv.stop()
        self.srv.clean()
示例#10
0
replica.admin("box.info.lsn == 2")
replica.admin("box.info.vclock[{}] == 2".format(replica_id))

print("-------------------------------------------------------------")
print("Master must not crash then receives orphan rows from replica")
print("-------------------------------------------------------------")

replication_source = yaml.safe_load(replica.admin("box.cfg.listen", silent = True))[0]
sys.stdout.push_filter(replication_source, "<replication>")
master.admin("box.cfg{{ replication = '{}' }}".format(replication_source))

master.wait_lsn(replica_id, replica.get_lsn(replica_id))
master.admin("box.info.vclock[{}] == 2".format(replica_id))

master.admin("box.cfg{ replication = '' }")
replica.stop()
replica.cleanup()

print("-------------------------------------------------------------")
print("Start a new replica and check that server_id, LSN is re-used")
print("-------------------------------------------------------------")

#
# gh-1219: Proper removal of servers with non-zero LSN from _cluster
#
# Snapshot is required. Otherwise a relay will skip records made by previous
# replica with the re-used id.
master.admin("box.snapshot()")
master.admin("box.info.vclock[{}] == 2".format(replica_id))

replica = TarantoolServer(server.ini)
示例#11
0
class TestSuite_Schema(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        print ' SCHEMA '.center(70, '=')
        print '-' * 70
        self.srv = TarantoolServer()
        self.srv.script = 'tests/suites/box.lua'
        self.srv.start()
        self.con = tarantool.Connection('localhost', self.srv.args['primary'])
        self.sch = self.con.schema

    def test_00_authenticate(self):
        self.assertIsNone(
            self.srv.admin(
                "box.schema.user.create('test', { password = '******' })"))
        self.assertIsNone(
            self.srv.admin(
                "box.schema.user.grant('test', 'read,write', 'space', '_space')"
            ))
        self.assertIsNone(
            self.srv.admin(
                "box.schema.user.grant('test', 'read,write', 'space', '_index')"
            ))
        self.assertEqual(self.con.authenticate('test', 'test')._data, None)

    def test_01_space_bad(self):
        with self.assertRaisesRegexp(tarantool.SchemaError,
                                     'There\'s no space.*'):
            self.sch.get_space(0)
        with self.assertRaisesRegexp(tarantool.SchemaError,
                                     'There\'s no space.*'):
            self.sch.get_space(0)
        with self.assertRaisesRegexp(tarantool.SchemaError,
                                     'There\'s no space.*'):
            self.sch.get_space('bad_name')

    def test_02_index_bad(self):
        with self.assertRaisesRegexp(tarantool.SchemaError,
                                     'There\'s no space.*'):
            self.sch.get_index(0, 'primary')
        with self.assertRaisesRegexp(tarantool.SchemaError,
                                     'There\'s no space.*'):
            self.sch.get_index('bad_space', 'primary')
        with self.assertRaisesRegexp(tarantool.SchemaError,
                                     'There\'s no index.*'):
            self.sch.get_index(280, 'bad_index')
        with self.assertRaisesRegexp(tarantool.SchemaError,
                                     'There\'s no index.*'):
            self.sch.get_index(280, 'bad_index')
        with self.assertRaisesRegexp(tarantool.SchemaError,
                                     'There\'s no index.*'):
            self.sch.get_index(280, 3)

    def test_03_01_space_name__(self):
        self.con.flush_schema()
        space = self.sch.get_space('_schema')
        self.assertEqual(space.sid, 272)
        self.assertEqual(space.name, '_schema')
        self.assertEqual(space.arity, 1)
        space = self.sch.get_space('_space')
        self.assertEqual(space.sid, 280)
        self.assertEqual(space.name, '_space')
        self.assertEqual(space.arity, 1)
        space = self.sch.get_space('_index')
        self.assertEqual(space.sid, 288)
        self.assertEqual(space.name, '_index')
        self.assertEqual(space.arity, 1)

    def test_03_02_space_number(self):
        self.con.flush_schema()
        space = self.sch.get_space(272)
        self.assertEqual(space.sid, 272)
        self.assertEqual(space.name, '_schema')
        self.assertEqual(space.arity, 1)
        space = self.sch.get_space(280)
        self.assertEqual(space.sid, 280)
        self.assertEqual(space.name, '_space')
        self.assertEqual(space.arity, 1)
        space = self.sch.get_space(288)
        self.assertEqual(space.sid, 288)
        self.assertEqual(space.name, '_index')
        self.assertEqual(space.arity, 1)

    def test_04_space_cached(self):
        space = self.sch.get_space('_schema')
        self.assertEqual(space.sid, 272)
        self.assertEqual(space.name, '_schema')
        self.assertEqual(space.arity, 1)
        space = self.sch.get_space('_space')
        self.assertEqual(space.sid, 280)
        self.assertEqual(space.name, '_space')
        self.assertEqual(space.arity, 1)
        space = self.sch.get_space('_index')
        self.assertEqual(space.sid, 288)
        self.assertEqual(space.name, '_index')
        self.assertEqual(space.arity, 1)

    def test_05_01_index_name___name__(self):
        self.con.flush_schema()
        index = self.sch.get_index('_index', 'primary')
        self.assertEqual(index.space.name, '_index')
        self.assertEqual(index.iid, 0)
        self.assertEqual(index.name, 'primary')
        self.assertEqual(len(index.parts), 2)
        index = self.sch.get_index('_index', 'name')
        self.assertEqual(index.space.name, '_index')
        self.assertEqual(index.iid, 2)
        self.assertEqual(index.name, 'name')
        self.assertEqual(len(index.parts), 2)
        index = self.sch.get_index('_space', 'primary')
        self.assertEqual(index.space.name, '_space')
        self.assertEqual(index.iid, 0)
        self.assertEqual(index.name, 'primary')
        self.assertEqual(len(index.parts), 1)
        index = self.sch.get_index('_space', 'name')
        self.assertEqual(index.space.name, '_space')
        self.assertEqual(index.iid, 2)
        self.assertEqual(index.name, 'name')
        self.assertEqual(len(index.parts), 1)

    def test_05_02_index_name___number(self):
        self.con.flush_schema()
        index = self.sch.get_index('_index', 0)
        self.assertEqual(index.space.name, '_index')
        self.assertEqual(index.iid, 0)
        self.assertEqual(index.name, 'primary')
        self.assertEqual(len(index.parts), 2)
        index = self.sch.get_index('_index', 2)
        self.assertEqual(index.space.name, '_index')
        self.assertEqual(index.iid, 2)
        self.assertEqual(index.name, 'name')
        self.assertEqual(len(index.parts), 2)
        index = self.sch.get_index('_space', 0)
        self.assertEqual(index.space.name, '_space')
        self.assertEqual(index.iid, 0)
        self.assertEqual(index.name, 'primary')
        self.assertEqual(len(index.parts), 1)
        index = self.sch.get_index('_space', 2)
        self.assertEqual(index.space.name, '_space')
        self.assertEqual(index.iid, 2)
        self.assertEqual(index.name, 'name')
        self.assertEqual(len(index.parts), 1)

    def test_05_03_index_number_name__(self):
        self.con.flush_schema()
        index = self.sch.get_index(288, 'primary')
        self.assertEqual(index.space.name, '_index')
        self.assertEqual(index.iid, 0)
        self.assertEqual(index.name, 'primary')
        self.assertEqual(len(index.parts), 2)
        index = self.sch.get_index(288, 'name')
        self.assertEqual(index.space.name, '_index')
        self.assertEqual(index.iid, 2)
        self.assertEqual(index.name, 'name')
        self.assertEqual(len(index.parts), 2)
        index = self.sch.get_index(280, 'primary')
        self.assertEqual(index.space.name, '_space')
        self.assertEqual(index.iid, 0)
        self.assertEqual(index.name, 'primary')
        self.assertEqual(len(index.parts), 1)
        index = self.sch.get_index(280, 'name')
        self.assertEqual(index.space.name, '_space')
        self.assertEqual(index.iid, 2)
        self.assertEqual(index.name, 'name')
        self.assertEqual(len(index.parts), 1)

    def test_05_04_index_number_number(self):
        self.con.flush_schema()
        index = self.sch.get_index(288, 0)
        self.assertEqual(index.space.name, '_index')
        self.assertEqual(index.iid, 0)
        self.assertEqual(index.name, 'primary')
        self.assertEqual(len(index.parts), 2)
        index = self.sch.get_index(288, 2)
        self.assertEqual(index.space.name, '_index')
        self.assertEqual(index.iid, 2)
        self.assertEqual(index.name, 'name')
        self.assertEqual(len(index.parts), 2)
        index = self.sch.get_index(280, 0)
        self.assertEqual(index.space.name, '_space')
        self.assertEqual(index.iid, 0)
        self.assertEqual(index.name, 'primary')
        self.assertEqual(len(index.parts), 1)
        index = self.sch.get_index(280, 2)
        self.assertEqual(index.space.name, '_space')
        self.assertEqual(index.iid, 2)
        self.assertEqual(index.name, 'name')
        self.assertEqual(len(index.parts), 1)

    def test_06_index_cached(self):
        index = self.sch.get_index('_index', 'primary')
        self.assertEqual(index.space.name, '_index')
        self.assertEqual(index.iid, 0)
        self.assertEqual(index.name, 'primary')
        self.assertEqual(len(index.parts), 2)
        index = self.sch.get_index('_index', 2)
        self.assertEqual(index.space.name, '_index')
        self.assertEqual(index.iid, 2)
        self.assertEqual(index.name, 'name')
        self.assertEqual(len(index.parts), 2)
        index = self.sch.get_index(280, 'primary')
        self.assertEqual(index.space.name, '_space')
        self.assertEqual(index.iid, 0)
        self.assertEqual(index.name, 'primary')
        self.assertEqual(len(index.parts), 1)
        index = self.sch.get_index(280, 2)
        self.assertEqual(index.space.name, '_space')
        self.assertEqual(index.iid, 2)
        self.assertEqual(index.name, 'name')
        self.assertEqual(len(index.parts), 1)

    @classmethod
    def tearDownClass(self):
        self.srv.stop()
        self.srv.clean()
示例#12
0
class Supervisor(object):
    def __init__(self, suite_path, args):
        self.args = args
        self.tests = []
        self.suite_path = suite_path
        self.ini = {
            'core': 'tarantool',
            'script': os.path.join(suite_path, 'parallel.lua'),
        }

        # read suite config
        config = ConfigParser.ConfigParser()
        config.read(os.path.join(suite_path, "suite.ini"))
        self.ini.update(dict(config.items("default")))
        self.ini.update(self.args.__dict__)
        self.jobs = int(self.ini.get('jobs', 1))
        self.count = int(self.ini.get('count', 0))

        for i in ["script"]:
            self.ini[i] = os.path.join(suite_path,
                                       self.ini[i]) if i in self.ini else None
        self.server = TarantoolServer(self.ini)
        self.pool = None
        self.iterator = None

    def find_tests(self):
        self.tests += [Parallel_PythonTest(k) \
                for k in sorted(glob.glob(os.path.join(self.suite_path, "*.test.py" )))]

    def take_rand(self):
        if self.count != 0:
            for test in self.tests:
                sql = self.server.sql.clone()
                admin = self.server.admin.clone()
                yield [test, [sql, admin]]
        else:
            while True:
                sql = self.server.sql.clone()
                admin = self.server.admin.clone()
                yield [random.choice(self.tests), [sql, admin]]

    def run_all(self):
        self.find_tests()
        if self.count != 0:
            self.tests *= self.count
            random.shuffle(self.tests)
        self.pool = GopherPool(processes=self.jobs)
        self.iterator = self.pool.run()
        self.filler = self.pool.fill(self.take_rand())
        try:
            self.server.cleanup()
            logger.info("Tarantool.Instance > Server cleaned up")
            logger.info("Tarantool.Instance > Server's path: %s",
                        self.server.binary)
            self.server.deploy()
            logger.info("Tarantool.Instance > Server deployed")
            try:
                while True:
                    self.filler.next()
                    logger.debug("BigBrother.run > Jobs filled %d %d" %
                                 (self.pool.queuein.qsize(),
                                  self.pool.queueout.qsize()))
                    while True:
                        try:
                            logger.debug("BigBrother.run > waiting for task")
                            task = self.iterator.next(1)
                            logger.debug("BigBrother.run > took task")
                            if task is None:
                                logger.info('>>>> Test return NONE')
                                continue
                            stat = task.get_status()
                            if stat.status != 3:
                                logger.info('>>>> Test %s finished' %
                                            repr(task.name))
                            else:
                                logger.error(
                                    '>>>> Test %s failed with %s (%s)' % (repr(
                                        task.name), stat.message, stat.reject))
                        except (QueueEmpty, StopIteration):
                            break
            except StopIteration:
                pass
        finally:
            self.server.stop()
            logger.info("Tarantool.Instance > Server stopped")
示例#13
0
class Supervisor(object):
    def __init__(self, suite_path, args):
        self.args = args
        self.tests = []
        self.suite_path = suite_path
        self.ini = {
                'core': 'tarantool',
                'script': os.path.join(suite_path, 'parallel.lua'),
        }

        # read suite config
        config = ConfigParser.ConfigParser()
        config.read(os.path.join(suite_path, "suite.ini"))
        self.ini.update(dict(config.items("default")))
        self.ini.update(self.args.__dict__)
        self.jobs = int(self.ini.get('jobs', 1))
        self.count = int(self.ini.get('count', 0))

        for i in ["script"]:
            self.ini[i] = os.path.join(suite_path, self.ini[i]) if i in self.ini else None
        self.server = TarantoolServer(self.ini)
        self.pool = None
        self.iterator = None

    def find_tests(self):
        self.tests += [Parallel_PythonTest(k) \
                for k in sorted(glob.glob(os.path.join(self.suite_path, "*.test.py" )))]

    def take_rand(self):
        if self.count != 0:
            for test in self.tests:
                sql = self.server.sql.clone()
                admin = self.server.admin.clone()
                yield [test, [sql, admin]]
        else:
            while True:
                sql = self.server.sql.clone()
                admin = self.server.admin.clone()
                yield [random.choice(self.tests), [sql, admin]]

    def run_all(self):
        self.find_tests()
        if self.count != 0:
            self.tests *= self.count
            random.shuffle(self.tests)
        self.pool = GopherPool(processes = self.jobs)
        self.iterator = self.pool.run()
        self.filler = self.pool.fill(self.take_rand())
        try:
            self.server.cleanup()
            logger.info("Tarantool.Instance > Server cleaned up")
            logger.info("Tarantool.Instance > Server's path: %s", self.server.binary)
            self.server.deploy()
            logger.info("Tarantool.Instance > Server deployed")
            try:
                while True:
                    self.filler.next()
                    logger.debug("BigBrother.run > Jobs filled %d %d" %
                            (self.pool.queuein.qsize(), self.pool.queueout.qsize()))
                    while True:
                        try:
                            logger.debug("BigBrother.run > waiting for task")
                            task = self.iterator.next(1)
                            logger.debug("BigBrother.run > took task")
                            if task is None:
                                logger.info('>>>> Test return NONE')
                                continue
                            stat = task.get_status()
                            if stat.status != 3:
                                logger.info('>>>> Test %s finished' % repr(task.name))
                            else:
                                logger.error('>>>> Test %s failed with %s (%s)' %
                                        (repr(task.name), stat.message, stat.reject))
                        except (QueueEmpty, StopIteration):
                            break
            except StopIteration:
                pass
        finally:
            self.server.stop()
            logger.info("Tarantool.Instance > Server stopped")