197
205
def test_cloning_metadir(self):
198
206
"""When there is a bzrdir present, the call succeeds."""
199
207
backing = self.get_transport()
200
dir = self.make_bzrdir('.')
208
dir = self.make_controldir('.')
201
209
local_result = dir.cloning_metadir()
202
210
request_class = smart_dir.SmartServerBzrDirRequestCloningMetaDir
203
211
request = request_class(backing)
204
212
expected = smart_req.SuccessfulSmartServerResponse(
205
213
(local_result.network_name(),
206
214
local_result.repository_format.network_name(),
207
('branch', local_result.get_branch_format().network_name())))
208
self.assertEqual(expected, request.execute('', 'False'))
215
(b'branch', local_result.get_branch_format().network_name())))
216
self.assertEqual(expected, request.execute(b'', b'False'))
210
218
def test_cloning_metadir_reference(self):
211
219
"""The request fails when bzrdir contains a branch reference."""
212
220
backing = self.get_transport()
213
221
referenced_branch = self.make_branch('referenced')
214
dir = self.make_bzrdir('.')
222
dir = self.make_controldir('.')
215
223
local_result = dir.cloning_metadir()
216
reference = _mod_branch.BranchReferenceFormat().initialize(
224
reference = _mod_bzrbranch.BranchReferenceFormat().initialize(
217
225
dir, target_branch=referenced_branch)
218
reference_url = _mod_branch.BranchReferenceFormat().get_reference(dir)
226
reference_url = _mod_bzrbranch.BranchReferenceFormat().get_reference(dir)
219
227
# The server shouldn't try to follow the branch reference, so it's fine
220
228
# if the referenced branch isn't reachable.
221
229
backing.rename('referenced', 'moved')
222
230
request_class = smart_dir.SmartServerBzrDirRequestCloningMetaDir
223
231
request = request_class(backing)
224
expected = smart_req.FailedSmartServerResponse(('BranchReference',))
225
self.assertEqual(expected, request.execute('', 'False'))
232
expected = smart_req.FailedSmartServerResponse((b'BranchReference',))
233
self.assertEqual(expected, request.execute(b'', b'False'))
236
class TestSmartServerBzrDirRequestCloningMetaDir(
237
tests.TestCaseWithMemoryTransport):
238
"""Tests for BzrDir.checkout_metadir."""
240
def test_checkout_metadir(self):
241
backing = self.get_transport()
242
request = smart_dir.SmartServerBzrDirRequestCheckoutMetaDir(
244
branch = self.make_branch('.', format='2a')
245
response = request.execute(b'')
247
smart_req.SmartServerResponse(
248
(b'Bazaar-NG meta directory, format 1\n',
249
b'Bazaar repository format 2a (needs bzr 1.16 or later)\n',
250
b'Bazaar Branch Format 7 (needs bzr 1.6)\n')),
254
class TestSmartServerBzrDirRequestDestroyBranch(
255
tests.TestCaseWithMemoryTransport):
256
"""Tests for BzrDir.destroy_branch."""
258
def test_destroy_branch_default(self):
259
"""The default branch can be removed."""
260
backing = self.get_transport()
261
dir = self.make_branch('.').controldir
262
request_class = smart_dir.SmartServerBzrDirRequestDestroyBranch
263
request = request_class(backing)
264
expected = smart_req.SuccessfulSmartServerResponse((b'ok',))
265
self.assertEqual(expected, request.execute(b'', None))
267
def test_destroy_branch_named(self):
268
"""A named branch can be removed."""
269
backing = self.get_transport()
270
dir = self.make_repository('.', format="development-colo").controldir
271
dir.create_branch(name="branchname")
272
request_class = smart_dir.SmartServerBzrDirRequestDestroyBranch
273
request = request_class(backing)
274
expected = smart_req.SuccessfulSmartServerResponse((b'ok',))
275
self.assertEqual(expected, request.execute(b'', "branchname"))
277
def test_destroy_branch_missing(self):
278
"""An error is raised if the branch didn't exist."""
279
backing = self.get_transport()
280
dir = self.make_controldir('.', format="development-colo")
281
request_class = smart_dir.SmartServerBzrDirRequestDestroyBranch
282
request = request_class(backing)
283
expected = smart_req.FailedSmartServerResponse((b'nobranch',), None)
284
self.assertEqual(expected, request.execute(b'', b"branchname"))
287
class TestSmartServerBzrDirRequestHasWorkingTree(
288
tests.TestCaseWithTransport):
289
"""Tests for BzrDir.has_workingtree."""
291
def test_has_workingtree_yes(self):
292
"""A working tree is present."""
293
backing = self.get_transport()
294
dir = self.make_branch_and_tree('.').controldir
295
request_class = smart_dir.SmartServerBzrDirRequestHasWorkingTree
296
request = request_class(backing)
297
expected = smart_req.SuccessfulSmartServerResponse((b'yes',))
298
self.assertEqual(expected, request.execute(b''))
300
def test_has_workingtree_no(self):
301
"""A working tree is missing."""
302
backing = self.get_transport()
303
dir = self.make_controldir('.')
304
request_class = smart_dir.SmartServerBzrDirRequestHasWorkingTree
305
request = request_class(backing)
306
expected = smart_req.SuccessfulSmartServerResponse((b'no',))
307
self.assertEqual(expected, request.execute(b''))
310
class TestSmartServerBzrDirRequestDestroyRepository(
311
tests.TestCaseWithMemoryTransport):
312
"""Tests for BzrDir.destroy_repository."""
314
def test_destroy_repository_default(self):
315
"""The repository can be removed."""
316
backing = self.get_transport()
317
dir = self.make_repository('.').controldir
318
request_class = smart_dir.SmartServerBzrDirRequestDestroyRepository
319
request = request_class(backing)
320
expected = smart_req.SuccessfulSmartServerResponse((b'ok',))
321
self.assertEqual(expected, request.execute(b''))
323
def test_destroy_repository_missing(self):
324
"""An error is raised if the repository didn't exist."""
325
backing = self.get_transport()
326
dir = self.make_controldir('.')
327
request_class = smart_dir.SmartServerBzrDirRequestDestroyRepository
328
request = request_class(backing)
329
expected = smart_req.FailedSmartServerResponse(
330
(b'norepository',), None)
331
self.assertEqual(expected, request.execute(b''))
228
334
class TestSmartServerRequestCreateRepository(tests.TestCaseWithMemoryTransport):
273
379
repo = self.make_repository('.', shared=shared, format=format)
274
380
if repo.supports_rich_root():
278
384
if repo._format.supports_tree_reference:
282
388
if repo._format.supports_external_lookups:
286
392
if (smart_dir.SmartServerRequestFindRepositoryV3 ==
287
393
self._request_class):
288
394
return smart_req.SuccessfulSmartServerResponse(
289
('ok', '', rich_root, subtrees, external,
395
(b'ok', b'', rich_root, subtrees, external,
290
396
repo._format.network_name()))
291
397
elif (smart_dir.SmartServerRequestFindRepositoryV2 ==
292
398
self._request_class):
293
399
# All tests so far are on formats, and for non-external
295
401
return smart_req.SuccessfulSmartServerResponse(
296
('ok', '', rich_root, subtrees, external))
402
(b'ok', b'', rich_root, subtrees, external))
298
404
return smart_req.SuccessfulSmartServerResponse(
299
('ok', '', rich_root, subtrees))
405
(b'ok', b'', rich_root, subtrees))
301
407
def test_shared_repository(self):
302
408
"""When there is a shared repository, we get 'ok', 'relpath-to-repo'."""
303
409
backing = self.get_transport()
304
410
request = self._request_class(backing)
305
411
result = self._make_repository_and_result(shared=True)
306
self.assertEqual(result, request.execute(''))
307
self.make_bzrdir('subdir')
412
self.assertEqual(result, request.execute(b''))
413
self.make_controldir('subdir')
308
414
result2 = smart_req.SmartServerResponse(
309
result.args[0:1] + ('..', ) + result.args[2:])
415
result.args[0:1] + (b'..', ) + result.args[2:])
310
416
self.assertEqual(result2,
311
request.execute('subdir'))
312
self.make_bzrdir('subdir/deeper')
417
request.execute(b'subdir'))
418
self.make_controldir('subdir/deeper')
313
419
result3 = smart_req.SmartServerResponse(
314
result.args[0:1] + ('../..', ) + result.args[2:])
420
result.args[0:1] + (b'../..', ) + result.args[2:])
315
421
self.assertEqual(result3,
316
request.execute('subdir/deeper'))
422
request.execute(b'subdir/deeper'))
318
424
def test_rich_root_and_subtree_encoding(self):
319
425
"""Test for the format attributes for rich root and subtree support."""
320
426
backing = self.get_transport()
321
427
request = self._request_class(backing)
322
428
result = self._make_repository_and_result(
323
format='dirstate-with-subtree')
429
format='development-subtree')
324
430
# check the test will be valid
325
self.assertEqual('yes', result.args[2])
326
self.assertEqual('yes', result.args[3])
327
self.assertEqual(result, request.execute(''))
431
self.assertEqual(b'yes', result.args[2])
432
self.assertEqual(b'yes', result.args[3])
433
self.assertEqual(result, request.execute(b''))
329
435
def test_supports_external_lookups_no_v2(self):
330
436
"""Test for the supports_external_lookups attribute."""
331
437
backing = self.get_transport()
332
438
request = self._request_class(backing)
333
439
result = self._make_repository_and_result(
334
format='dirstate-with-subtree')
440
format='development-subtree')
335
441
# check the test will be valid
336
self.assertEqual('no', result.args[4])
337
self.assertEqual(result, request.execute(''))
442
self.assertEqual(b'yes', result.args[4])
443
self.assertEqual(result, request.execute(b''))
340
446
class TestSmartServerBzrDirRequestGetConfigFile(
1507
1905
r1 = tree.commit('a commit', rev_id=rev_id_utf8)
1509
1907
self.assertTrue(tree.branch.repository.has_revision(rev_id_utf8))
1510
self.assertEqual(smart_req.SmartServerResponse(('yes', )),
1511
request.execute('', rev_id_utf8))
1908
self.assertEqual(smart_req.SmartServerResponse((b'yes', )),
1909
request.execute(b'', rev_id_utf8))
1912
class TestSmartServerRepositoryIterFilesBytes(tests.TestCaseWithTransport):
1914
def test_single(self):
1915
backing = self.get_transport()
1916
request = smart_repo.SmartServerRepositoryIterFilesBytes(backing)
1917
t = self.make_branch_and_tree('.')
1918
self.addCleanup(t.lock_write().unlock)
1919
self.build_tree_contents([("file", b"somecontents")])
1920
t.add(["file"], [b"thefileid"])
1921
t.commit(rev_id=b'somerev', message="add file")
1922
self.assertIs(None, request.execute(b''))
1923
response = request.do_body(b"thefileid\0somerev\n")
1924
self.assertTrue(response.is_successful())
1925
self.assertEqual(response.args, (b"ok", ))
1926
self.assertEqual(b"".join(response.body_stream),
1927
b"ok\x000\n" + zlib.compress(b"somecontents"))
1929
def test_missing(self):
1930
backing = self.get_transport()
1931
request = smart_repo.SmartServerRepositoryIterFilesBytes(backing)
1932
t = self.make_branch_and_tree('.')
1933
self.addCleanup(t.lock_write().unlock)
1934
self.assertIs(None, request.execute(b''))
1935
response = request.do_body(b"thefileid\0revision\n")
1936
self.assertTrue(response.is_successful())
1937
self.assertEqual(response.args, (b"ok", ))
1938
self.assertEqual(b"".join(response.body_stream),
1939
b"absent\x00thefileid\x00revision\x000\n")
1942
class TestSmartServerRequestHasSignatureForRevisionId(
1943
tests.TestCaseWithMemoryTransport):
1945
def test_missing_revision(self):
1946
"""For a missing revision, NoSuchRevision is returned."""
1947
backing = self.get_transport()
1948
request = smart_repo.SmartServerRequestHasSignatureForRevisionId(
1950
self.make_repository('.')
1952
smart_req.FailedSmartServerResponse(
1953
(b'nosuchrevision', b'revid'), None),
1954
request.execute(b'', b'revid'))
1956
def test_missing_signature(self):
1957
"""For a missing signature, ('no', ) is returned."""
1958
backing = self.get_transport()
1959
request = smart_repo.SmartServerRequestHasSignatureForRevisionId(
1961
tree = self.make_branch_and_memory_tree('.')
1964
r1 = tree.commit('a commit', rev_id=b'A')
1966
self.assertTrue(tree.branch.repository.has_revision(b'A'))
1967
self.assertEqual(smart_req.SmartServerResponse((b'no', )),
1968
request.execute(b'', b'A'))
1970
def test_present_signature(self):
1971
"""For a present signature, ('yes', ) is returned."""
1972
backing = self.get_transport()
1973
request = smart_repo.SmartServerRequestHasSignatureForRevisionId(
1975
strategy = gpg.LoopbackGPGStrategy(None)
1976
tree = self.make_branch_and_memory_tree('.')
1979
r1 = tree.commit('a commit', rev_id=b'A')
1980
tree.branch.repository.start_write_group()
1981
tree.branch.repository.sign_revision(b'A', strategy)
1982
tree.branch.repository.commit_write_group()
1984
self.assertTrue(tree.branch.repository.has_revision(b'A'))
1985
self.assertEqual(smart_req.SmartServerResponse((b'yes', )),
1986
request.execute(b'', b'A'))
1514
1989
class TestSmartServerRepositoryGatherStats(tests.TestCaseWithMemoryTransport):
1745
2317
repo.set_make_working_trees(False)
1746
2318
request_class = smart_repo.SmartServerRepositorySetMakeWorkingTrees
1747
2319
request = request_class(backing)
1748
self.assertEqual(smart_req.SuccessfulSmartServerResponse(('ok',)),
1749
request.execute('', 'True'))
1750
repo = repo.bzrdir.open_repository()
2320
self.assertEqual(smart_req.SuccessfulSmartServerResponse((b'ok',)),
2321
request.execute(b'', b'True'))
2322
repo = repo.controldir.open_repository()
1751
2323
self.assertTrue(repo.make_working_trees())
2326
class TestSmartServerRepositoryGetSerializerFormat(
2327
tests.TestCaseWithMemoryTransport):
2329
def test_get_serializer_format(self):
2330
backing = self.get_transport()
2331
repo = self.make_repository('.', format='2a')
2332
request_class = smart_repo.SmartServerRepositoryGetSerializerFormat
2333
request = request_class(backing)
2335
smart_req.SuccessfulSmartServerResponse((b'ok', b'10')),
2336
request.execute(b''))
2339
class TestSmartServerRepositoryWriteGroup(
2340
tests.TestCaseWithMemoryTransport):
2342
def test_start_write_group(self):
2343
backing = self.get_transport()
2344
repo = self.make_repository('.')
2345
lock_token = repo.lock_write().repository_token
2346
self.addCleanup(repo.unlock)
2347
request_class = smart_repo.SmartServerRepositoryStartWriteGroup
2348
request = request_class(backing)
2349
self.assertEqual(smart_req.SuccessfulSmartServerResponse((b'ok', [])),
2350
request.execute(b'', lock_token))
2352
def test_start_write_group_unsuspendable(self):
2353
backing = self.get_transport()
2354
repo = self.make_repository('.', format='knit')
2355
lock_token = repo.lock_write().repository_token
2356
self.addCleanup(repo.unlock)
2357
request_class = smart_repo.SmartServerRepositoryStartWriteGroup
2358
request = request_class(backing)
2360
smart_req.FailedSmartServerResponse((b'UnsuspendableWriteGroup',)),
2361
request.execute(b'', lock_token))
2363
def test_commit_write_group(self):
2364
backing = self.get_transport()
2365
repo = self.make_repository('.')
2366
lock_token = repo.lock_write().repository_token
2367
self.addCleanup(repo.unlock)
2368
repo.start_write_group()
2369
tokens = repo.suspend_write_group()
2370
request_class = smart_repo.SmartServerRepositoryCommitWriteGroup
2371
request = request_class(backing)
2372
self.assertEqual(smart_req.SuccessfulSmartServerResponse((b'ok',)),
2373
request.execute(b'', lock_token, tokens))
2375
def test_abort_write_group(self):
2376
backing = self.get_transport()
2377
repo = self.make_repository('.')
2378
lock_token = repo.lock_write().repository_token
2379
repo.start_write_group()
2380
tokens = repo.suspend_write_group()
2381
self.addCleanup(repo.unlock)
2382
request_class = smart_repo.SmartServerRepositoryAbortWriteGroup
2383
request = request_class(backing)
2384
self.assertEqual(smart_req.SuccessfulSmartServerResponse((b'ok',)),
2385
request.execute(b'', lock_token, tokens))
2387
def test_check_write_group(self):
2388
backing = self.get_transport()
2389
repo = self.make_repository('.')
2390
lock_token = repo.lock_write().repository_token
2391
repo.start_write_group()
2392
tokens = repo.suspend_write_group()
2393
self.addCleanup(repo.unlock)
2394
request_class = smart_repo.SmartServerRepositoryCheckWriteGroup
2395
request = request_class(backing)
2396
self.assertEqual(smart_req.SuccessfulSmartServerResponse((b'ok',)),
2397
request.execute(b'', lock_token, tokens))
2399
def test_check_write_group_invalid(self):
2400
backing = self.get_transport()
2401
repo = self.make_repository('.')
2402
lock_token = repo.lock_write().repository_token
2403
self.addCleanup(repo.unlock)
2404
request_class = smart_repo.SmartServerRepositoryCheckWriteGroup
2405
request = request_class(backing)
2406
self.assertEqual(smart_req.FailedSmartServerResponse(
2407
(b'UnresumableWriteGroup', [b'random'],
2408
b'Malformed write group token')),
2409
request.execute(b'', lock_token, [b"random"]))
1754
2412
class TestSmartServerPackRepositoryAutopack(tests.TestCaseWithTransport):
1756
2414
def make_repo_needing_autopacking(self, path='.'):
1822
2480
"""All registered request_handlers can be found."""
1823
2481
# If there's a typo in a register_lazy call, this loop will fail with
1824
2482
# an AttributeError.
1825
for key, item in smart_req.request_handlers.iteritems():
2483
for key in smart_req.request_handlers.keys():
2485
item = smart_req.request_handlers.get(key)
2486
except AttributeError as e:
2487
raise AttributeError('failed to get %s: %s' % (key, e))
1828
2489
def assertHandlerEqual(self, verb, handler):
1829
2490
self.assertEqual(smart_req.request_handlers.get(verb), handler)
1831
2492
def test_registered_methods(self):
1832
2493
"""Test that known methods are registered to the correct object."""
1833
self.assertHandlerEqual('Branch.get_config_file',
2494
self.assertHandlerEqual(b'Branch.break_lock',
2495
smart_branch.SmartServerBranchBreakLock)
2496
self.assertHandlerEqual(b'Branch.get_config_file',
1834
2497
smart_branch.SmartServerBranchGetConfigFile)
1835
self.assertHandlerEqual('Branch.get_parent',
2498
self.assertHandlerEqual(b'Branch.put_config_file',
2499
smart_branch.SmartServerBranchPutConfigFile)
2500
self.assertHandlerEqual(b'Branch.get_parent',
1836
2501
smart_branch.SmartServerBranchGetParent)
1837
self.assertHandlerEqual('Branch.get_tags_bytes',
2502
self.assertHandlerEqual(b'Branch.get_physical_lock_status',
2503
smart_branch.SmartServerBranchRequestGetPhysicalLockStatus)
2504
self.assertHandlerEqual(b'Branch.get_tags_bytes',
1838
2505
smart_branch.SmartServerBranchGetTagsBytes)
1839
self.assertHandlerEqual('Branch.lock_write',
2506
self.assertHandlerEqual(b'Branch.lock_write',
1840
2507
smart_branch.SmartServerBranchRequestLockWrite)
1841
self.assertHandlerEqual('Branch.last_revision_info',
2508
self.assertHandlerEqual(b'Branch.last_revision_info',
1842
2509
smart_branch.SmartServerBranchRequestLastRevisionInfo)
1843
self.assertHandlerEqual('Branch.revision_history',
2510
self.assertHandlerEqual(b'Branch.revision_history',
1844
2511
smart_branch.SmartServerRequestRevisionHistory)
1845
self.assertHandlerEqual('Branch.set_config_option',
2512
self.assertHandlerEqual(b'Branch.revision_id_to_revno',
2513
smart_branch.SmartServerBranchRequestRevisionIdToRevno)
2514
self.assertHandlerEqual(b'Branch.set_config_option',
1846
2515
smart_branch.SmartServerBranchRequestSetConfigOption)
1847
self.assertHandlerEqual('Branch.set_last_revision',
2516
self.assertHandlerEqual(b'Branch.set_last_revision',
1848
2517
smart_branch.SmartServerBranchRequestSetLastRevision)
1849
self.assertHandlerEqual('Branch.set_last_revision_info',
2518
self.assertHandlerEqual(b'Branch.set_last_revision_info',
1850
2519
smart_branch.SmartServerBranchRequestSetLastRevisionInfo)
1851
self.assertHandlerEqual('Branch.set_last_revision_ex',
2520
self.assertHandlerEqual(b'Branch.set_last_revision_ex',
1852
2521
smart_branch.SmartServerBranchRequestSetLastRevisionEx)
1853
self.assertHandlerEqual('Branch.set_parent_location',
2522
self.assertHandlerEqual(b'Branch.set_parent_location',
1854
2523
smart_branch.SmartServerBranchRequestSetParentLocation)
1855
self.assertHandlerEqual('Branch.unlock',
2524
self.assertHandlerEqual(b'Branch.unlock',
1856
2525
smart_branch.SmartServerBranchRequestUnlock)
1857
self.assertHandlerEqual('BzrDir.find_repository',
2526
self.assertHandlerEqual(b'BzrDir.destroy_branch',
2527
smart_dir.SmartServerBzrDirRequestDestroyBranch)
2528
self.assertHandlerEqual(b'BzrDir.find_repository',
1858
2529
smart_dir.SmartServerRequestFindRepositoryV1)
1859
self.assertHandlerEqual('BzrDir.find_repositoryV2',
2530
self.assertHandlerEqual(b'BzrDir.find_repositoryV2',
1860
2531
smart_dir.SmartServerRequestFindRepositoryV2)
1861
self.assertHandlerEqual('BzrDirFormat.initialize',
2532
self.assertHandlerEqual(b'BzrDirFormat.initialize',
1862
2533
smart_dir.SmartServerRequestInitializeBzrDir)
1863
self.assertHandlerEqual('BzrDirFormat.initialize_ex_1.16',
2534
self.assertHandlerEqual(b'BzrDirFormat.initialize_ex_1.16',
1864
2535
smart_dir.SmartServerRequestBzrDirInitializeEx)
1865
self.assertHandlerEqual('BzrDir.cloning_metadir',
2536
self.assertHandlerEqual(b'BzrDir.checkout_metadir',
2537
smart_dir.SmartServerBzrDirRequestCheckoutMetaDir)
2538
self.assertHandlerEqual(b'BzrDir.cloning_metadir',
1866
2539
smart_dir.SmartServerBzrDirRequestCloningMetaDir)
1867
self.assertHandlerEqual('BzrDir.get_config_file',
2540
self.assertHandlerEqual(b'BzrDir.get_branches',
2541
smart_dir.SmartServerBzrDirRequestGetBranches)
2542
self.assertHandlerEqual(b'BzrDir.get_config_file',
1868
2543
smart_dir.SmartServerBzrDirRequestConfigFile)
1869
self.assertHandlerEqual('BzrDir.open_branch',
2544
self.assertHandlerEqual(b'BzrDir.open_branch',
1870
2545
smart_dir.SmartServerRequestOpenBranch)
1871
self.assertHandlerEqual('BzrDir.open_branchV2',
2546
self.assertHandlerEqual(b'BzrDir.open_branchV2',
1872
2547
smart_dir.SmartServerRequestOpenBranchV2)
1873
self.assertHandlerEqual('BzrDir.open_branchV3',
2548
self.assertHandlerEqual(b'BzrDir.open_branchV3',
1874
2549
smart_dir.SmartServerRequestOpenBranchV3)
1875
self.assertHandlerEqual('PackRepository.autopack',
2550
self.assertHandlerEqual(b'PackRepository.autopack',
1876
2551
smart_packrepo.SmartServerPackRepositoryAutopack)
1877
self.assertHandlerEqual('Repository.gather_stats',
2552
self.assertHandlerEqual(b'Repository.add_signature_text',
2553
smart_repo.SmartServerRepositoryAddSignatureText)
2554
self.assertHandlerEqual(b'Repository.all_revision_ids',
2555
smart_repo.SmartServerRepositoryAllRevisionIds)
2556
self.assertHandlerEqual(b'Repository.break_lock',
2557
smart_repo.SmartServerRepositoryBreakLock)
2558
self.assertHandlerEqual(b'Repository.gather_stats',
1878
2559
smart_repo.SmartServerRepositoryGatherStats)
1879
self.assertHandlerEqual('Repository.get_parent_map',
2560
self.assertHandlerEqual(b'Repository.get_parent_map',
1880
2561
smart_repo.SmartServerRepositoryGetParentMap)
1881
self.assertHandlerEqual('Repository.get_rev_id_for_revno',
2562
self.assertHandlerEqual(b'Repository.get_physical_lock_status',
2563
smart_repo.SmartServerRepositoryGetPhysicalLockStatus)
2564
self.assertHandlerEqual(b'Repository.get_rev_id_for_revno',
1882
2565
smart_repo.SmartServerRepositoryGetRevIdForRevno)
1883
self.assertHandlerEqual('Repository.get_revision_graph',
2566
self.assertHandlerEqual(b'Repository.get_revision_graph',
1884
2567
smart_repo.SmartServerRepositoryGetRevisionGraph)
1885
self.assertHandlerEqual('Repository.get_stream',
2568
self.assertHandlerEqual(b'Repository.get_revision_signature_text',
2569
smart_repo.SmartServerRepositoryGetRevisionSignatureText)
2570
self.assertHandlerEqual(b'Repository.get_stream',
1886
2571
smart_repo.SmartServerRepositoryGetStream)
1887
self.assertHandlerEqual('Repository.has_revision',
2572
self.assertHandlerEqual(b'Repository.get_stream_1.19',
2573
smart_repo.SmartServerRepositoryGetStream_1_19)
2574
self.assertHandlerEqual(b'Repository.iter_revisions',
2575
smart_repo.SmartServerRepositoryIterRevisions)
2576
self.assertHandlerEqual(b'Repository.has_revision',
1888
2577
smart_repo.SmartServerRequestHasRevision)
1889
self.assertHandlerEqual('Repository.insert_stream',
2578
self.assertHandlerEqual(b'Repository.insert_stream',
1890
2579
smart_repo.SmartServerRepositoryInsertStream)
1891
self.assertHandlerEqual('Repository.insert_stream_locked',
2580
self.assertHandlerEqual(b'Repository.insert_stream_locked',
1892
2581
smart_repo.SmartServerRepositoryInsertStreamLocked)
1893
self.assertHandlerEqual('Repository.is_shared',
2582
self.assertHandlerEqual(b'Repository.is_shared',
1894
2583
smart_repo.SmartServerRepositoryIsShared)
1895
self.assertHandlerEqual('Repository.lock_write',
2584
self.assertHandlerEqual(b'Repository.iter_files_bytes',
2585
smart_repo.SmartServerRepositoryIterFilesBytes)
2586
self.assertHandlerEqual(b'Repository.lock_write',
1896
2587
smart_repo.SmartServerRepositoryLockWrite)
1897
self.assertHandlerEqual('Repository.tarball',
2588
self.assertHandlerEqual(b'Repository.make_working_trees',
2589
smart_repo.SmartServerRepositoryMakeWorkingTrees)
2590
self.assertHandlerEqual(b'Repository.pack',
2591
smart_repo.SmartServerRepositoryPack)
2592
self.assertHandlerEqual(b'Repository.reconcile',
2593
smart_repo.SmartServerRepositoryReconcile)
2594
self.assertHandlerEqual(b'Repository.tarball',
1898
2595
smart_repo.SmartServerRepositoryTarball)
1899
self.assertHandlerEqual('Repository.unlock',
2596
self.assertHandlerEqual(b'Repository.unlock',
1900
2597
smart_repo.SmartServerRepositoryUnlock)
1901
self.assertHandlerEqual('Transport.is_readonly',
2598
self.assertHandlerEqual(b'Repository.start_write_group',
2599
smart_repo.SmartServerRepositoryStartWriteGroup)
2600
self.assertHandlerEqual(b'Repository.check_write_group',
2601
smart_repo.SmartServerRepositoryCheckWriteGroup)
2602
self.assertHandlerEqual(b'Repository.commit_write_group',
2603
smart_repo.SmartServerRepositoryCommitWriteGroup)
2604
self.assertHandlerEqual(b'Repository.abort_write_group',
2605
smart_repo.SmartServerRepositoryAbortWriteGroup)
2606
self.assertHandlerEqual(b'VersionedFileRepository.get_serializer_format',
2607
smart_repo.SmartServerRepositoryGetSerializerFormat)
2608
self.assertHandlerEqual(b'VersionedFileRepository.get_inventories',
2609
smart_repo.SmartServerRepositoryGetInventories)
2610
self.assertHandlerEqual(b'Transport.is_readonly',
1902
2611
smart_req.SmartServerIsReadonly)
2614
class SmartTCPServerHookTests(tests.TestCaseWithMemoryTransport):
2615
"""Tests for SmartTCPServer hooks."""
2618
super(SmartTCPServerHookTests, self).setUp()
2619
self.server = server.SmartTCPServer(self.get_transport())
2621
def test_run_server_started_hooks(self):
2622
"""Test the server started hooks get fired properly."""
2624
server.SmartTCPServer.hooks.install_named_hook('server_started',
2625
lambda backing_urls, url: started_calls.append((backing_urls, url)),
2627
started_ex_calls = []
2628
server.SmartTCPServer.hooks.install_named_hook('server_started_ex',
2629
lambda backing_urls, url: started_ex_calls.append((backing_urls, url)),
2631
self.server._sockname = ('example.com', 42)
2632
self.server.run_server_started_hooks()
2633
self.assertEqual(started_calls,
2634
[([self.get_transport().base], 'bzr://example.com:42/')])
2635
self.assertEqual(started_ex_calls,
2636
[([self.get_transport().base], self.server)])
2638
def test_run_server_started_hooks_ipv6(self):
2639
"""Test that socknames can contain 4-tuples."""
2640
self.server._sockname = ('::', 42, 0, 0)
2642
server.SmartTCPServer.hooks.install_named_hook('server_started',
2643
lambda backing_urls, url: started_calls.append((backing_urls, url)),
2645
self.server.run_server_started_hooks()
2646
self.assertEqual(started_calls,
2647
[([self.get_transport().base], 'bzr://:::42/')])
2649
def test_run_server_stopped_hooks(self):
2650
"""Test the server stopped hooks."""
2651
self.server._sockname = ('example.com', 42)
2653
server.SmartTCPServer.hooks.install_named_hook('server_stopped',
2654
lambda backing_urls, url: stopped_calls.append((backing_urls, url)),
2656
self.server.run_server_stopped_hooks()
2657
self.assertEqual(stopped_calls,
2658
[([self.get_transport().base], 'bzr://example.com:42/')])
2661
class TestSmartServerRepositoryPack(tests.TestCaseWithMemoryTransport):
2663
def test_pack(self):
2664
backing = self.get_transport()
2665
request = smart_repo.SmartServerRepositoryPack(backing)
2666
tree = self.make_branch_and_memory_tree('.')
2667
repo_token = tree.branch.repository.lock_write().repository_token
2669
self.assertIs(None, request.execute(b'', repo_token, False))
2672
smart_req.SuccessfulSmartServerResponse((b'ok', ), ),
2673
request.do_body(b''))
2676
class TestSmartServerRepositoryGetInventories(tests.TestCaseWithTransport):
2678
def _get_serialized_inventory_delta(self, repository, base_revid, revid):
2679
base_inv = repository.revision_tree(base_revid).root_inventory
2680
inv = repository.revision_tree(revid).root_inventory
2681
inv_delta = inv._make_delta(base_inv)
2682
serializer = inventory_delta.InventoryDeltaSerializer(True, False)
2683
return b"".join(serializer.delta_to_lines(base_revid, revid, inv_delta))
2685
def test_single(self):
2686
backing = self.get_transport()
2687
request = smart_repo.SmartServerRepositoryGetInventories(backing)
2688
t = self.make_branch_and_tree('.', format='2a')
2689
self.addCleanup(t.lock_write().unlock)
2690
self.build_tree_contents([("file", b"somecontents")])
2691
t.add(["file"], [b"thefileid"])
2692
t.commit(rev_id=b'somerev', message="add file")
2693
self.assertIs(None, request.execute(b'', b'unordered'))
2694
response = request.do_body(b"somerev\n")
2695
self.assertTrue(response.is_successful())
2696
self.assertEqual(response.args, (b"ok", ))
2697
stream = [('inventory-deltas', [
2698
versionedfile.FulltextContentFactory(b'somerev', None, None,
2699
self._get_serialized_inventory_delta(
2700
t.branch.repository, b'null:', b'somerev'))])]
2701
fmt = controldir.format_registry.get('2a')().repository_format
2703
b"".join(response.body_stream),
2704
b"".join(smart_repo._stream_to_byte_stream(stream, fmt)))
2706
def test_empty(self):
2707
backing = self.get_transport()
2708
request = smart_repo.SmartServerRepositoryGetInventories(backing)
2709
t = self.make_branch_and_tree('.', format='2a')
2710
self.addCleanup(t.lock_write().unlock)
2711
self.build_tree_contents([("file", b"somecontents")])
2712
t.add(["file"], [b"thefileid"])
2713
t.commit(rev_id=b'somerev', message="add file")
2714
self.assertIs(None, request.execute(b'', b'unordered'))
2715
response = request.do_body(b"")
2716
self.assertTrue(response.is_successful())
2717
self.assertEqual(response.args, (b"ok", ))
2718
self.assertEqual(b"".join(response.body_stream),
2719
b"Bazaar pack format 1 (introduced in 0.18)\nB54\n\nBazaar repository format 2a (needs bzr 1.16 or later)\nE")
2722
class TestSmartServerRepositoryGetStreamForMissingKeys(GetStreamTestBase):
2724
def test_missing(self):
2725
"""The search argument may be a 'ancestry-of' some heads'."""
2726
backing = self.get_transport()
2727
request = smart_repo.SmartServerRepositoryGetStreamForMissingKeys(
2729
repo, r1, r2 = self.make_two_commit_repo()
2730
request.execute(b'', repo._format.network_name())
2731
lines = b'inventories\t' + r1
2732
response = request.do_body(lines)
2733
self.assertEqual((b'ok',), response.args)
2734
stream_bytes = b''.join(response.body_stream)
2735
self.assertStartsWith(stream_bytes, b'Bazaar pack format 1')
2737
def test_unknown_format(self):
2738
"""The format may not be known by the remote server."""
2739
backing = self.get_transport()
2740
request = smart_repo.SmartServerRepositoryGetStreamForMissingKeys(
2742
repo, r1, r2 = self.make_two_commit_repo()
2743
request.execute(b'', b'yada yada yada')
2744
expected = smart_req.FailedSmartServerResponse(
2745
(b'UnknownFormat', b'repository', b'yada yada yada'))
2748
class TestSmartServerRepositoryRevisionArchive(tests.TestCaseWithTransport):
2750
backing = self.get_transport()
2751
request = smart_repo.SmartServerRepositoryRevisionArchive(backing)
2752
t = self.make_branch_and_tree('.')
2753
self.addCleanup(t.lock_write().unlock)
2754
self.build_tree_contents([("file", b"somecontents")])
2755
t.add(["file"], [b"thefileid"])
2756
t.commit(rev_id=b'somerev', message="add file")
2757
response = request.execute(b'', b"somerev", b"tar", b"foo.tar", b"foo")
2758
self.assertTrue(response.is_successful())
2759
self.assertEqual(response.args, (b"ok", ))
2760
b = BytesIO(b"".join(response.body_stream))
2761
with tarfile.open(mode='r', fileobj=b) as tf:
2762
self.assertEqual(['foo/file'], tf.getnames())
2765
class TestSmartServerRepositoryAnnotateFileRevision(tests.TestCaseWithTransport):
2768
backing = self.get_transport()
2769
request = smart_repo.SmartServerRepositoryAnnotateFileRevision(backing)
2770
t = self.make_branch_and_tree('.')
2771
self.addCleanup(t.lock_write().unlock)
2772
self.build_tree_contents([("file", b"somecontents\nmorecontents\n")])
2773
t.add(["file"], [b"thefileid"])
2774
t.commit(rev_id=b'somerev', message="add file")
2775
response = request.execute(b'', b"somerev", b"file")
2776
self.assertTrue(response.is_successful())
2777
self.assertEqual(response.args, (b"ok", ))
2779
[['somerev', 'somecontents\n'], ['somerev', 'morecontents\n']],
2780
bencode.bdecode(response.body))