Skip to content

Commit

Permalink
Using keyrange.py in unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
alainjobart committed Feb 11, 2014
1 parent 6b60ca7 commit 51dcd67
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
14 changes: 8 additions & 6 deletions test/initial_sharding.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
import time
import unittest

from vtdb import keyrange

import environment
import utils
import tablet

keyspace_id_type = "uint64"
keyspace_id_type = keyrange.KIT_UINT64
pack_keyspace_id = struct.Struct('!Q').pack

# initial shard, covers everything
Expand Down Expand Up @@ -100,10 +102,10 @@ class TestInitialSharding(unittest.TestCase):
# create_schema will create the same schema on the keyspace
# then insert some values
def _create_schema(self):
if keyspace_id_type == "uint64":
t = 'bigint(20) unsigned'
else:
if keyspace_id_type == 'bytes':
t = 'varbinary(64)'
else:
t = 'bigint(20) unsigned'
create_table_template = '''create table %s(
id bigint auto_increment,
msg varchar(64),
Expand Down Expand Up @@ -144,7 +146,7 @@ def _get_value(self, tablet, table, id):
def _check_value(self, tablet, table, id, msg, keyspace_id,
should_be_here=True):
result = self._get_value(tablet, table, id)
if keyspace_id_type == "bytes":
if keyspace_id_type == keyrange.KIT_BYTES:
fmt = "%s"
keyspace_id = pack_keyspace_id(keyspace_id)
else:
Expand All @@ -168,7 +170,7 @@ def _is_value_present_and_correct(self, tablet, table, id, msg, keyspace_id):
result = self._get_value(tablet, table, id)
if len(result) == 0:
return False
if keyspace_id_type == "bytes":
if keyspace_id_type == keyrange.KIT_BYTES:
fmt = "%s"
keyspace_id = pack_keyspace_id(keyspace_id)
else:
Expand Down
4 changes: 3 additions & 1 deletion test/initial_sharding_bytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import initial_sharding
import utils

from vtdb import keyrange

# this test is just re-running an entire initial_sharding.py with a
# varbinary keyspace_id
if __name__ == '__main__':
initial_sharding.keyspace_id_type = "bytes"
initial_sharding.keyspace_id_type = keyrange.KIT_BYTES
utils.main(initial_sharding)
14 changes: 8 additions & 6 deletions test/resharding.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
import time
import unittest

from vtdb import keyrange

import environment
import utils
import tablet

keyspace_id_type = "uint64"
keyspace_id_type = keyrange.KIT_UINT64
pack_keyspace_id = struct.Struct('!Q').pack

# initial shards
Expand Down Expand Up @@ -169,10 +171,10 @@ class TestResharding(unittest.TestCase):
# create_schema will create the same schema on the keyspace
# then insert some values
def _create_schema(self):
if keyspace_id_type == "uint64":
t = 'bigint(20) unsigned'
else:
if keyspace_id_type == keyrange.KIT_BYTES:
t = 'varbinary(64)'
else:
t = 'bigint(20) unsigned'
create_table_template = '''create table %s(
id bigint auto_increment,
msg varchar(64),
Expand Down Expand Up @@ -224,7 +226,7 @@ def _get_value(self, tablet, table, id):
def _check_value(self, tablet, table, id, msg, keyspace_id,
should_be_here=True):
result = self._get_value(tablet, table, id)
if keyspace_id_type == "bytes":
if keyspace_id_type == keyrange.KIT_BYTES:
fmt = "%s"
keyspace_id = pack_keyspace_id(keyspace_id)
else:
Expand All @@ -248,7 +250,7 @@ def _is_value_present_and_correct(self, tablet, table, id, msg, keyspace_id):
result = self._get_value(tablet, table, id)
if len(result) == 0:
return False
if keyspace_id_type == "bytes":
if keyspace_id_type == keyrange.KIT_BYTES:
fmt = "%s"
keyspace_id = pack_keyspace_id(keyspace_id)
else:
Expand Down
4 changes: 3 additions & 1 deletion test/resharding_bytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import resharding
import utils

from vtdb import keyrange

# this test is just re-running an entire resharding.py with a
# varbinary keyspace_id
if __name__ == '__main__':
resharding.keyspace_id_type = "bytes"
resharding.keyspace_id_type = keyrange.KIT_BYTES
utils.main(resharding)

0 comments on commit 51dcd67

Please sign in to comment.