def test_source_shards_serving(self): """Nominal case where the source shard is serving all types.""" shards = collections.OrderedDict([('-80', {}), ('80-', {}), ('0', _ALL_TYPES)]) expected_result = [['SetShardServedTypes', 'foo/0', 'replica'], ['SetShardServedTypes', 'foo/0', 'rdonly'], ['SetShardServedTypes', 'foo/0', 'master']] self.assertEquals(fix_served_types.get_vtctl_commands('foo', shards), expected_result)
def test_source_shards_serving(self): """Nominal case where the source shard is serving all types.""" shards = collections.OrderedDict( [('-80', {}), ('80-', {}), ('0', _ALL_TYPES)]) expected_result = [ ['SetShardServedTypes', 'foo/0', 'replica'], ['SetShardServedTypes', 'foo/0', 'rdonly'], ['SetShardServedTypes', 'foo/0', 'master']] self.assertEquals( fix_served_types.get_vtctl_commands('foo', shards), expected_result)
def test_partial_serving_overlap_shard_2(self): """Source shard and destination shard 2 are serving all types.""" shards = collections.OrderedDict( [('-80', {}), ('80-', _ALL_TYPES), ('0', _ALL_TYPES)]) expected_result = [ ['SetShardServedTypes', '--remove', 'foo/80-', 'replica'], ['SetShardServedTypes', '--remove', 'foo/80-', 'rdonly'], ['SetShardServedTypes', '--remove', 'foo/80-', 'master'], ['SetShardServedTypes', 'foo/0', 'replica'], ['SetShardServedTypes', 'foo/0', 'rdonly'], ['SetShardServedTypes', 'foo/0', 'master']] self.assertEquals( fix_served_types.get_vtctl_commands('foo', shards), expected_result)
def test_mixed_serving_types(self): """Source shard serves some types, destination shards serve other types.""" shards = collections.OrderedDict( [('-80', _NO_MASTER), ('80-', _NO_MASTER), ('0', _JUST_MASTER)]) expected_result = [ ['SetShardServedTypes', '--remove', 'foo/-80', 'replica'], ['SetShardServedTypes', '--remove', 'foo/-80', 'rdonly'], ['SetShardServedTypes', '--remove', 'foo/80-', 'replica'], ['SetShardServedTypes', '--remove', 'foo/80-', 'rdonly'], ['SetShardServedTypes', 'foo/0', 'replica'], ['SetShardServedTypes', 'foo/0', 'rdonly'], ['SetShardServedTypes', 'foo/0', 'master']] self.assertEquals( fix_served_types.get_vtctl_commands('foo', shards), expected_result)
def test_partial_serving_overlap_shard_2(self): """Source shard and destination shard 2 are serving all types.""" shards = collections.OrderedDict([('-80', {}), ('80-', _ALL_TYPES), ('0', _ALL_TYPES)]) expected_result = [ ['SetShardServedTypes', '--remove', 'foo/80-', 'replica'], ['SetShardServedTypes', '--remove', 'foo/80-', 'rdonly'], ['SetShardServedTypes', '--remove', 'foo/80-', 'master'], ['SetShardServedTypes', 'foo/0', 'replica'], ['SetShardServedTypes', 'foo/0', 'rdonly'], ['SetShardServedTypes', 'foo/0', 'master'] ] self.assertEquals(fix_served_types.get_vtctl_commands('foo', shards), expected_result)
def test_mixed_serving_types(self): """Source shard serves some types, destination shards serve other types.""" shards = collections.OrderedDict([('-80', _NO_MASTER), ('80-', _NO_MASTER), ('0', _JUST_MASTER)]) expected_result = [ ['SetShardServedTypes', '--remove', 'foo/-80', 'replica'], ['SetShardServedTypes', '--remove', 'foo/-80', 'rdonly'], ['SetShardServedTypes', '--remove', 'foo/80-', 'replica'], ['SetShardServedTypes', '--remove', 'foo/80-', 'rdonly'], ['SetShardServedTypes', 'foo/0', 'replica'], ['SetShardServedTypes', 'foo/0', 'rdonly'], ['SetShardServedTypes', 'foo/0', 'master'] ] self.assertEquals(fix_served_types.get_vtctl_commands('foo', shards), expected_result)