1168
1168
def test_get_parent_map_reconnects_if_unknown_method(self):
1169
1169
transport_path = 'quack'
1170
1170
repo, client = self.setup_fake_client_and_repository(transport_path)
1171
client.add_unknown_method_response('Repository,get_parent_map')
1171
client.add_unknown_method_response('Repository.get_parent_map')
1172
1172
client.add_success_response_with_body('', 'ok')
1173
1173
self.assertFalse(client._medium._is_remote_before((1, 2)))
1174
1174
rev_id = 'revision-id'
1512
class TestVersionedFilesGetParentMap(tests.TestCaseWithTransport):
1514
def test_backwards_compat(self):
1515
"""If the server does not recognise the VersionedFiles.get_parent_map
1516
then the client will fallback to calling get_parent_map on the 'real'
1517
versioned files object.
1519
self.transport_server = server.SmartTCPServer_for_testing
1520
self.make_repository('branch')
1521
repo = repository.Repository.open(self.get_url('branch'))
1524
# Sabotage the real smart medium so that the test will fail if
1525
# something tries to use it after this point.
1526
repo._client._medium._socket = None
1527
# Replace the _real_repository with a test double so that we can
1528
# observe the fallback to using the 'real' object.
1529
class FakeRealVf(object):
1530
def get_parent_map(self, keys):
1531
client._calls.append(('real vf get_parent_map', keys))
1533
class FakeRealRepo(object):
1535
self.revisions = FakeRealVf()
1538
repo._real_repository = FakeRealRepo()
1539
# Inject a test double client.
1540
client = FakeClient(repo.bzrdir.root_transport.base)
1541
repo._client = client
1542
# Configure the fake client.
1543
client.add_unknown_method_response('VersionedFiles.get_parent_map')
1544
client.add_success_response_with_body('', 'ok')
1545
# Call get_parent_map.
1546
rev_id = 'revision-id'
1547
repo.revisions.get_parent_map([('rev-id',)])
1550
[('call_with_body_bytes_expecting_body',
1551
'VersionedFiles.get_parent_map',
1552
('extra/branch/', 'revisions', ('rev-id',)),
1554
('real vf get_parent_map', [('rev-id',)]),
1557
# The medium is now marked as being connected to an older server
1558
self.assertTrue(client._medium._is_remote_before((1, 8)))
1561
class TestVersionedFilesGetParentMapSerialisation(tests.TestCase):
1563
def test_serialise_search_recipe_empty(self):
1564
recipe = ([], [], 0)
1565
bytes = remote._serialise_search_tuple_key_recipe(recipe)
1566
self.assertEqual('\n\n0', bytes)
1568
def test_serialise_search_recipe(self):
1569
start = [('start', 'key', 'one'), ('start', 'key', 'two')]
1570
stop = [('stop', 'key', 'one'), ('stop', 'key', 'two')]
1571
recipe = (start, stop, 123)
1572
bytes = remote._serialise_search_tuple_key_recipe(recipe)
1574
'start key one\x00start key two\nstop key one\x00stop key two\n123',
1512
1578
class TestErrorTranslationBase(tests.TestCaseWithMemoryTransport):
1513
1579
"""Base class for unit tests for bzrlib.remote._translate_error."""