47
50
SuccessfulSmartServerResponse,
49
52
from bzrlib.tests import (
54
55
from bzrlib.transport import chroot, get_transport
55
from bzrlib.util import bencode
58
58
def load_tests(standard_tests, module, loader):
59
59
"""Multiply tests version and protocol consistency."""
60
60
# FindRepository tests.
61
61
bzrdir_mod = bzrlib.smart.bzrdir
62
applier = TestScenarioApplier()
64
63
("find_repository", {
65
64
"_request_class":bzrdir_mod.SmartServerRequestFindRepositoryV1}),
66
65
("find_repositoryV2", {
67
66
"_request_class":bzrdir_mod.SmartServerRequestFindRepositoryV2}),
67
("find_repositoryV3", {
68
"_request_class":bzrdir_mod.SmartServerRequestFindRepositoryV3}),
69
70
to_adapt, result = split_suite_by_re(standard_tests,
70
71
"TestSmartServerRequestFindRepository")
71
72
v2_only, v1_and_2 = split_suite_by_re(to_adapt,
73
for test in iter_suite_tests(v1_and_2):
74
result.addTests(applier.adapt(test))
75
del applier.scenarios[0]
76
for test in iter_suite_tests(v2_only):
77
result.addTests(applier.adapt(test))
74
tests.multiply_tests(v1_and_2, scenarios, result)
75
# The first scenario is only applicable to v1 protocols, it is deleted
77
tests.multiply_tests(v2_only, scenarios[1:], result)
114
114
return self.get_transport().get_smart_medium()
117
class TestByteStreamToStream(tests.TestCase):
119
def test_repeated_substreams_same_kind_are_one_stream(self):
120
# Make a stream - an iterable of bytestrings.
121
stream = [('text', [versionedfile.FulltextContentFactory(('k1',), None,
122
None, 'foo')]),('text', [
123
versionedfile.FulltextContentFactory(('k2',), None, None, 'bar')])]
124
fmt = bzrdir.format_registry.get('pack-0.92')().repository_format
125
bytes = smart.repository._stream_to_byte_stream(stream, fmt)
127
# Iterate the resulting iterable; checking that we get only one stream
129
fmt, stream = smart.repository._byte_stream_to_stream(bytes)
130
for kind, substream in stream:
131
streams.append((kind, list(substream)))
132
self.assertLength(1, streams)
133
self.assertLength(2, streams[0][1])
117
136
class TestSmartServerResponse(tests.TestCase):
119
138
def test__eq__(self):
160
179
request.transport_from_client_path('foo/').base)
182
class TestSmartServerBzrDirRequestCloningMetaDir(
183
tests.TestCaseWithMemoryTransport):
184
"""Tests for BzrDir.cloning_metadir."""
186
def test_cloning_metadir(self):
187
"""When there is a bzrdir present, the call succeeds."""
188
backing = self.get_transport()
189
dir = self.make_bzrdir('.')
190
local_result = dir.cloning_metadir()
191
request_class = smart_dir.SmartServerBzrDirRequestCloningMetaDir
192
request = request_class(backing)
193
expected = SuccessfulSmartServerResponse(
194
(local_result.network_name(),
195
local_result.repository_format.network_name(),
196
('branch', local_result.get_branch_format().network_name())))
197
self.assertEqual(expected, request.execute('', 'False'))
199
def test_cloning_metadir_reference(self):
200
"""The request fails when bzrdir contains a branch reference."""
201
backing = self.get_transport()
202
referenced_branch = self.make_branch('referenced')
203
dir = self.make_bzrdir('.')
204
local_result = dir.cloning_metadir()
205
reference = BranchReferenceFormat().initialize(dir, referenced_branch)
206
reference_url = BranchReferenceFormat().get_reference(dir)
207
# The server shouldn't try to follow the branch reference, so it's fine
208
# if the referenced branch isn't reachable.
209
backing.rename('referenced', 'moved')
210
request_class = smart_dir.SmartServerBzrDirRequestCloningMetaDir
211
request = request_class(backing)
212
expected = FailedSmartServerResponse(('BranchReference',))
213
self.assertEqual(expected, request.execute('', 'False'))
216
class TestSmartServerRequestCreateRepository(tests.TestCaseWithMemoryTransport):
217
"""Tests for BzrDir.create_repository."""
219
def test_makes_repository(self):
220
"""When there is a bzrdir present, the call succeeds."""
221
backing = self.get_transport()
222
self.make_bzrdir('.')
223
request_class = bzrlib.smart.bzrdir.SmartServerRequestCreateRepository
224
request = request_class(backing)
225
reference_bzrdir_format = bzrdir.format_registry.get('pack-0.92')()
226
reference_format = reference_bzrdir_format.repository_format
227
network_name = reference_format.network_name()
228
expected = SuccessfulSmartServerResponse(
229
('ok', 'no', 'no', 'no', network_name))
230
self.assertEqual(expected, request.execute('', network_name, 'True'))
163
233
class TestSmartServerRequestFindRepository(tests.TestCaseWithMemoryTransport):
164
234
"""Tests for BzrDir.find_repository."""
241
320
self.assertEqual(result, request.execute(''))
323
class TestSmartServerBzrDirRequestGetConfigFile(
324
tests.TestCaseWithMemoryTransport):
325
"""Tests for BzrDir.get_config_file."""
327
def test_present(self):
328
backing = self.get_transport()
329
dir = self.make_bzrdir('.')
330
dir.get_config().set_default_stack_on("/")
331
local_result = dir._get_config()._get_config_file().read()
332
request_class = smart_dir.SmartServerBzrDirRequestConfigFile
333
request = request_class(backing)
334
expected = SuccessfulSmartServerResponse((), local_result)
335
self.assertEqual(expected, request.execute(''))
337
def test_missing(self):
338
backing = self.get_transport()
339
dir = self.make_bzrdir('.')
340
request_class = smart_dir.SmartServerBzrDirRequestConfigFile
341
request = request_class(backing)
342
expected = SuccessfulSmartServerResponse((), '')
343
self.assertEqual(expected, request.execute(''))
244
346
class TestSmartServerRequestInitializeBzrDir(tests.TestCaseWithMemoryTransport):
246
348
def test_empty_dir(self):
272
374
request.execute, 'subdir')
377
class TestSmartServerRequestBzrDirInitializeEx(tests.TestCaseWithMemoryTransport):
378
"""Basic tests for BzrDir.initialize_ex_1.16 in the smart server.
380
The main unit tests in test_bzrdir exercise the API comprehensively.
383
def test_empty_dir(self):
384
"""Initializing an empty dir should succeed and do it."""
385
backing = self.get_transport()
386
name = self.make_bzrdir('reference')._format.network_name()
387
request = smart.bzrdir.SmartServerRequestBzrDirInitializeEx(backing)
388
self.assertEqual(SmartServerResponse(('', '', '', '', '', '', name,
389
'False', '', '', '')),
390
request.execute(name, '', 'True', 'False', 'False', '', '', '', '',
392
made_dir = bzrdir.BzrDir.open_from_transport(backing)
393
# no branch, tree or repository is expected with the current
395
self.assertRaises(errors.NoWorkingTree, made_dir.open_workingtree)
396
self.assertRaises(errors.NotBranchError, made_dir.open_branch)
397
self.assertRaises(errors.NoRepositoryPresent, made_dir.open_repository)
399
def test_missing_dir(self):
400
"""Initializing a missing directory should fail like the bzrdir api."""
401
backing = self.get_transport()
402
name = self.make_bzrdir('reference')._format.network_name()
403
request = smart.bzrdir.SmartServerRequestBzrDirInitializeEx(backing)
404
self.assertRaises(errors.NoSuchFile, request.execute, name,
405
'subdir/dir', 'False', 'False', 'False', '', '', '', '', 'False')
407
def test_initialized_dir(self):
408
"""Initializing an extant directory should fail like the bzrdir api."""
409
backing = self.get_transport()
410
name = self.make_bzrdir('reference')._format.network_name()
411
request = smart.bzrdir.SmartServerRequestBzrDirInitializeEx(backing)
412
self.make_bzrdir('subdir')
413
self.assertRaises(errors.FileExists, request.execute, name, 'subdir',
414
'False', 'False', 'False', '', '', '', '', 'False')
275
417
class TestSmartServerRequestOpenBranch(TestCaseWithChrootedTransport):
277
419
def test_no_branch(self):
302
444
request.execute('reference'))
447
class TestSmartServerRequestOpenBranchV2(TestCaseWithChrootedTransport):
449
def test_no_branch(self):
450
"""When there is no branch, ('nobranch', ) is returned."""
451
backing = self.get_transport()
452
self.make_bzrdir('.')
453
request = smart.bzrdir.SmartServerRequestOpenBranchV2(backing)
454
self.assertEqual(SmartServerResponse(('nobranch', )),
457
def test_branch(self):
458
"""When there is a branch, 'ok' is returned."""
459
backing = self.get_transport()
460
expected = self.make_branch('.')._format.network_name()
461
request = smart.bzrdir.SmartServerRequestOpenBranchV2(backing)
462
self.assertEqual(SuccessfulSmartServerResponse(('branch', expected)),
465
def test_branch_reference(self):
466
"""When there is a branch reference, the reference URL is returned."""
467
backing = self.get_transport()
468
request = smart.bzrdir.SmartServerRequestOpenBranchV2(backing)
469
branch = self.make_branch('branch')
470
checkout = branch.create_checkout('reference',lightweight=True)
471
reference_url = BranchReferenceFormat().get_reference(checkout.bzrdir)
472
self.assertFileEqual(reference_url, 'reference/.bzr/branch/location')
473
self.assertEqual(SuccessfulSmartServerResponse(('ref', reference_url)),
474
request.execute('reference'))
476
def test_stacked_branch(self):
477
"""Opening a stacked branch does not open the stacked-on branch."""
478
trunk = self.make_branch('trunk')
479
feature = self.make_branch('feature')
480
feature.set_stacked_on_url(trunk.base)
482
Branch.hooks.install_named_hook('open', opened_branches.append, None)
483
backing = self.get_transport()
484
request = smart.bzrdir.SmartServerRequestOpenBranchV2(backing)
487
response = request.execute('feature')
489
request.teardown_jail()
490
expected_format = feature._format.network_name()
492
SuccessfulSmartServerResponse(('branch', expected_format)),
494
self.assertLength(1, opened_branches)
305
497
class TestSmartServerRequestRevisionHistory(tests.TestCaseWithMemoryTransport):
307
499
def test_empty(self):
397
589
request.execute(''))
400
class SetLastRevisionTestBase(tests.TestCaseWithMemoryTransport):
592
class TestLockedBranch(tests.TestCaseWithMemoryTransport):
594
def get_lock_tokens(self, branch):
595
branch_token = branch.lock_write()
596
repo_token = branch.repository.lock_write()
597
branch.repository.unlock()
598
return branch_token, repo_token
601
class TestSmartServerBranchRequestSetConfigOption(TestLockedBranch):
603
def test_value_name(self):
604
branch = self.make_branch('.')
605
request = smart.branch.SmartServerBranchRequestSetConfigOption(
606
branch.bzrdir.root_transport)
607
branch_token, repo_token = self.get_lock_tokens(branch)
608
config = branch._get_config()
609
result = request.execute('', branch_token, repo_token, 'bar', 'foo',
611
self.assertEqual(SuccessfulSmartServerResponse(()), result)
612
self.assertEqual('bar', config.get_option('foo'))
616
def test_value_name_section(self):
617
branch = self.make_branch('.')
618
request = smart.branch.SmartServerBranchRequestSetConfigOption(
619
branch.bzrdir.root_transport)
620
branch_token, repo_token = self.get_lock_tokens(branch)
621
config = branch._get_config()
622
result = request.execute('', branch_token, repo_token, 'bar', 'foo',
624
self.assertEqual(SuccessfulSmartServerResponse(()), result)
625
self.assertEqual('bar', config.get_option('foo', 'gam'))
630
class TestSmartServerBranchRequestSetTagsBytes(TestLockedBranch):
631
# Only called when the branch format and tags match [yay factory
632
# methods] so only need to test straight forward cases.
634
def test_set_bytes(self):
635
base_branch = self.make_branch('base')
636
tag_bytes = base_branch._get_tags_bytes()
637
# get_lock_tokens takes out a lock.
638
branch_token, repo_token = self.get_lock_tokens(base_branch)
639
request = smart.branch.SmartServerBranchSetTagsBytes(
640
self.get_transport())
641
response = request.execute('base', branch_token, repo_token)
642
self.assertEqual(None, response)
643
response = request.do_chunk(tag_bytes)
644
self.assertEqual(None, response)
645
response = request.do_end()
647
SuccessfulSmartServerResponse(()), response)
650
def test_lock_failed(self):
651
base_branch = self.make_branch('base')
652
base_branch.lock_write()
653
tag_bytes = base_branch._get_tags_bytes()
654
request = smart.branch.SmartServerBranchSetTagsBytes(
655
self.get_transport())
656
self.assertRaises(errors.TokenMismatch, request.execute,
657
'base', 'wrong token', 'wrong token')
658
# The request handler will keep processing the message parts, so even
659
# if the request fails immediately do_chunk and do_end are still
661
request.do_chunk(tag_bytes)
667
class SetLastRevisionTestBase(TestLockedBranch):
401
668
"""Base test case for verbs that implement set_last_revision."""
601
878
self.assertEqual('child-1', self.tree.branch.last_revision())
881
class TestSmartServerBranchRequestGetParent(tests.TestCaseWithMemoryTransport):
883
def test_get_parent_none(self):
884
base_branch = self.make_branch('base')
885
request = smart.branch.SmartServerBranchGetParent(self.get_transport())
886
response = request.execute('base')
888
SuccessfulSmartServerResponse(('',)), response)
890
def test_get_parent_something(self):
891
base_branch = self.make_branch('base')
892
base_branch.set_parent(self.get_url('foo'))
893
request = smart.branch.SmartServerBranchGetParent(self.get_transport())
894
response = request.execute('base')
896
SuccessfulSmartServerResponse(("../foo",)),
900
class TestSmartServerBranchRequestSetParent(tests.TestCaseWithMemoryTransport):
902
def test_set_parent_none(self):
903
branch = self.make_branch('base', format="1.9")
905
branch._set_parent_location('foo')
907
request = smart.branch.SmartServerBranchRequestSetParentLocation(
908
self.get_transport())
909
branch_token = branch.lock_write()
910
repo_token = branch.repository.lock_write()
912
response = request.execute('base', branch_token, repo_token, '')
914
branch.repository.unlock()
916
self.assertEqual(SuccessfulSmartServerResponse(()), response)
917
self.assertEqual(None, branch.get_parent())
919
def test_set_parent_something(self):
920
branch = self.make_branch('base', format="1.9")
921
request = smart.branch.SmartServerBranchRequestSetParentLocation(
922
self.get_transport())
923
branch_token = branch.lock_write()
924
repo_token = branch.repository.lock_write()
926
response = request.execute('base', branch_token, repo_token,
929
branch.repository.unlock()
931
self.assertEqual(SuccessfulSmartServerResponse(()), response)
932
self.assertEqual('http://bar/', branch.get_parent())
935
class TestSmartServerBranchRequestGetTagsBytes(tests.TestCaseWithMemoryTransport):
936
# Only called when the branch format and tags match [yay factory
937
# methods] so only need to test straight forward cases.
939
def test_get_bytes(self):
940
base_branch = self.make_branch('base')
941
request = smart.branch.SmartServerBranchGetTagsBytes(
942
self.get_transport())
943
response = request.execute('base')
945
SuccessfulSmartServerResponse(('',)), response)
948
class TestSmartServerBranchRequestGetStackedOnURL(tests.TestCaseWithMemoryTransport):
950
def test_get_stacked_on_url(self):
951
base_branch = self.make_branch('base', format='1.6')
952
stacked_branch = self.make_branch('stacked', format='1.6')
953
# typically should be relative
954
stacked_branch.set_stacked_on_url('../base')
955
request = smart.branch.SmartServerBranchRequestGetStackedOnURL(
956
self.get_transport())
957
response = request.execute('stacked')
959
SmartServerResponse(('ok', '../base')),
604
963
class TestSmartServerBranchRequestLockWrite(tests.TestCaseWithMemoryTransport):
662
1035
branch_token+'xxx', repo_token)
663
1036
self.assertEqual(
664
1037
SmartServerResponse(('TokenMismatch',)), response)
1039
branch.repository.lock_write(repo_token)
1040
branch.repository.dont_leave_lock_in_place()
1041
branch.repository.unlock()
1042
branch.lock_write(branch_token)
1043
branch.dont_leave_lock_in_place()
666
1046
def test_lock_write_on_locked_repo(self):
667
1047
backing = self.get_transport()
668
1048
request = smart.branch.SmartServerBranchRequestLockWrite(backing)
669
1049
branch = self.make_branch('.', format='knit')
670
branch.repository.lock_write()
671
branch.repository.leave_lock_in_place()
672
branch.repository.unlock()
1050
repo = branch.repository
1051
repo_token = repo.lock_write()
1052
repo.leave_lock_in_place()
673
1054
response = request.execute('')
674
1055
self.assertEqual(
675
1056
SmartServerResponse(('LockContention',)), response)
1058
repo.lock_write(repo_token)
1059
repo.dont_leave_lock_in_place()
677
1062
def test_lock_write_on_readonly_transport(self):
678
1063
backing = self.get_readonly_transport()
821
1222
request.execute('', 'missingrevision'))
1225
class TestSmartServerRepositoryGetRevIdForRevno(tests.TestCaseWithMemoryTransport):
1227
def test_revno_found(self):
1228
backing = self.get_transport()
1229
request = smart.repository.SmartServerRepositoryGetRevIdForRevno(backing)
1230
tree = self.make_branch_and_memory_tree('.')
1233
rev1_id_utf8 = u'\xc8'.encode('utf-8')
1234
rev2_id_utf8 = u'\xc9'.encode('utf-8')
1235
tree.commit('1st commit', rev_id=rev1_id_utf8)
1236
tree.commit('2nd commit', rev_id=rev2_id_utf8)
1239
self.assertEqual(SmartServerResponse(('ok', rev1_id_utf8)),
1240
request.execute('', 1, (2, rev2_id_utf8)))
1242
def test_known_revid_missing(self):
1243
backing = self.get_transport()
1244
request = smart.repository.SmartServerRepositoryGetRevIdForRevno(backing)
1245
repo = self.make_repository('.')
1247
FailedSmartServerResponse(('nosuchrevision', 'ghost')),
1248
request.execute('', 1, (2, 'ghost')))
1250
def test_history_incomplete(self):
1251
backing = self.get_transport()
1252
request = smart.repository.SmartServerRepositoryGetRevIdForRevno(backing)
1253
parent = self.make_branch_and_memory_tree('parent', format='1.9')
1255
parent.add([''], ['TREE_ROOT'])
1256
r1 = parent.commit(message='first commit')
1257
r2 = parent.commit(message='second commit')
1259
local = self.make_branch_and_memory_tree('local', format='1.9')
1260
local.branch.pull(parent.branch)
1261
local.set_parent_ids([r2])
1262
r3 = local.commit(message='local commit')
1263
local.branch.create_clone_on_transport(
1264
self.get_transport('stacked'), stacked_on=self.get_url('parent'))
1266
SmartServerResponse(('history-incomplete', 2, r2)),
1267
request.execute('stacked', 1, (3, r3)))
1270
class TestSmartServerRepositoryGetStream(tests.TestCaseWithMemoryTransport):
1272
def make_two_commit_repo(self):
1273
tree = self.make_branch_and_memory_tree('.')
1276
r1 = tree.commit('1st commit')
1277
r2 = tree.commit('2nd commit', rev_id=u'\xc8'.encode('utf-8'))
1279
repo = tree.branch.repository
1282
def test_ancestry_of(self):
1283
"""The search argument may be a 'ancestry-of' some heads'."""
1284
backing = self.get_transport()
1285
request = smart.repository.SmartServerRepositoryGetStream(backing)
1286
repo, r1, r2 = self.make_two_commit_repo()
1287
fetch_spec = ['ancestry-of', r2]
1288
lines = '\n'.join(fetch_spec)
1289
request.execute('', repo._format.network_name())
1290
response = request.do_body(lines)
1291
self.assertEqual(('ok',), response.args)
1292
stream_bytes = ''.join(response.body_stream)
1293
self.assertStartsWith(stream_bytes, 'Bazaar pack format 1')
1295
def test_search(self):
1296
"""The search argument may be a 'search' of some explicit keys."""
1297
backing = self.get_transport()
1298
request = smart.repository.SmartServerRepositoryGetStream(backing)
1299
repo, r1, r2 = self.make_two_commit_repo()
1300
fetch_spec = ['search', '%s %s' % (r1, r2), 'null:', '2']
1301
lines = '\n'.join(fetch_spec)
1302
request.execute('', repo._format.network_name())
1303
response = request.do_body(lines)
1304
self.assertEqual(('ok',), response.args)
1305
stream_bytes = ''.join(response.body_stream)
1306
self.assertStartsWith(stream_bytes, 'Bazaar pack format 1')
824
1309
class TestSmartServerRequestHasRevision(tests.TestCaseWithMemoryTransport):
826
1311
def test_missing_revision(self):
961
1450
self.assertEqual('LockFailed', response.args[0])
1453
class TestInsertStreamBase(tests.TestCaseWithMemoryTransport):
1455
def make_empty_byte_stream(self, repo):
1456
byte_stream = smart.repository._stream_to_byte_stream([], repo._format)
1457
return ''.join(byte_stream)
1460
class TestSmartServerRepositoryInsertStream(TestInsertStreamBase):
1462
def test_insert_stream_empty(self):
1463
backing = self.get_transport()
1464
request = smart.repository.SmartServerRepositoryInsertStream(backing)
1465
repository = self.make_repository('.')
1466
response = request.execute('', '')
1467
self.assertEqual(None, response)
1468
response = request.do_chunk(self.make_empty_byte_stream(repository))
1469
self.assertEqual(None, response)
1470
response = request.do_end()
1471
self.assertEqual(SmartServerResponse(('ok', )), response)
1474
class TestSmartServerRepositoryInsertStreamLocked(TestInsertStreamBase):
1476
def test_insert_stream_empty(self):
1477
backing = self.get_transport()
1478
request = smart.repository.SmartServerRepositoryInsertStreamLocked(
1480
repository = self.make_repository('.', format='knit')
1481
lock_token = repository.lock_write()
1482
response = request.execute('', '', lock_token)
1483
self.assertEqual(None, response)
1484
response = request.do_chunk(self.make_empty_byte_stream(repository))
1485
self.assertEqual(None, response)
1486
response = request.do_end()
1487
self.assertEqual(SmartServerResponse(('ok', )), response)
1490
def test_insert_stream_with_wrong_lock_token(self):
1491
backing = self.get_transport()
1492
request = smart.repository.SmartServerRepositoryInsertStreamLocked(
1494
repository = self.make_repository('.', format='knit')
1495
lock_token = repository.lock_write()
1497
errors.TokenMismatch, request.execute, '', '', 'wrong-token')
964
1501
class TestSmartServerRepositoryUnlock(tests.TestCaseWithMemoryTransport):
966
1503
def setUp(self):
1008
1545
SmartServerResponse(('yes',)), response)
1548
class TestSmartServerRepositorySetMakeWorkingTrees(tests.TestCaseWithMemoryTransport):
1550
def test_set_false(self):
1551
backing = self.get_transport()
1552
repo = self.make_repository('.', shared=True)
1553
repo.set_make_working_trees(True)
1554
request_class = smart.repository.SmartServerRepositorySetMakeWorkingTrees
1555
request = request_class(backing)
1556
self.assertEqual(SuccessfulSmartServerResponse(('ok',)),
1557
request.execute('', 'False'))
1558
repo = repo.bzrdir.open_repository()
1559
self.assertFalse(repo.make_working_trees())
1561
def test_set_true(self):
1562
backing = self.get_transport()
1563
repo = self.make_repository('.', shared=True)
1564
repo.set_make_working_trees(False)
1565
request_class = smart.repository.SmartServerRepositorySetMakeWorkingTrees
1566
request = request_class(backing)
1567
self.assertEqual(SuccessfulSmartServerResponse(('ok',)),
1568
request.execute('', 'True'))
1569
repo = repo.bzrdir.open_repository()
1570
self.assertTrue(repo.make_working_trees())
1573
class TestSmartServerPackRepositoryAutopack(tests.TestCaseWithTransport):
1575
def make_repo_needing_autopacking(self, path='.'):
1576
# Make a repo in need of autopacking.
1577
tree = self.make_branch_and_tree('.', format='pack-0.92')
1578
repo = tree.branch.repository
1579
# monkey-patch the pack collection to disable autopacking
1580
repo._pack_collection._max_pack_count = lambda count: count
1582
tree.commit('commit %s' % x)
1583
self.assertEqual(10, len(repo._pack_collection.names()))
1584
del repo._pack_collection._max_pack_count
1587
def test_autopack_needed(self):
1588
repo = self.make_repo_needing_autopacking()
1590
self.addCleanup(repo.unlock)
1591
backing = self.get_transport()
1592
request = smart.packrepository.SmartServerPackRepositoryAutopack(
1594
response = request.execute('')
1595
self.assertEqual(SmartServerResponse(('ok',)), response)
1596
repo._pack_collection.reload_pack_names()
1597
self.assertEqual(1, len(repo._pack_collection.names()))
1599
def test_autopack_not_needed(self):
1600
tree = self.make_branch_and_tree('.', format='pack-0.92')
1601
repo = tree.branch.repository
1603
self.addCleanup(repo.unlock)
1605
tree.commit('commit %s' % x)
1606
backing = self.get_transport()
1607
request = smart.packrepository.SmartServerPackRepositoryAutopack(
1609
response = request.execute('')
1610
self.assertEqual(SmartServerResponse(('ok',)), response)
1611
repo._pack_collection.reload_pack_names()
1612
self.assertEqual(9, len(repo._pack_collection.names()))
1614
def test_autopack_on_nonpack_format(self):
1615
"""A request to autopack a non-pack repo is a no-op."""
1616
repo = self.make_repository('.', format='knit')
1617
backing = self.get_transport()
1618
request = smart.packrepository.SmartServerPackRepositoryAutopack(
1620
response = request.execute('')
1621
self.assertEqual(SmartServerResponse(('ok',)), response)
1011
1624
class TestHandlers(tests.TestCase):
1012
1625
"""Tests for the request.request_handlers object."""
1018
1631
for key, item in smart.request.request_handlers.iteritems():
1634
def assertHandlerEqual(self, verb, handler):
1635
self.assertEqual(smart.request.request_handlers.get(verb), handler)
1021
1637
def test_registered_methods(self):
1022
1638
"""Test that known methods are registered to the correct object."""
1024
smart.request.request_handlers.get('Branch.get_config_file'),
1639
self.assertHandlerEqual('Branch.get_config_file',
1025
1640
smart.branch.SmartServerBranchGetConfigFile)
1027
smart.request.request_handlers.get('Branch.lock_write'),
1641
self.assertHandlerEqual('Branch.get_parent',
1642
smart.branch.SmartServerBranchGetParent)
1643
self.assertHandlerEqual('Branch.get_tags_bytes',
1644
smart.branch.SmartServerBranchGetTagsBytes)
1645
self.assertHandlerEqual('Branch.lock_write',
1028
1646
smart.branch.SmartServerBranchRequestLockWrite)
1030
smart.request.request_handlers.get('Branch.last_revision_info'),
1647
self.assertHandlerEqual('Branch.last_revision_info',
1031
1648
smart.branch.SmartServerBranchRequestLastRevisionInfo)
1033
smart.request.request_handlers.get('Branch.revision_history'),
1649
self.assertHandlerEqual('Branch.revision_history',
1034
1650
smart.branch.SmartServerRequestRevisionHistory)
1036
smart.request.request_handlers.get('Branch.set_last_revision'),
1651
self.assertHandlerEqual('Branch.set_config_option',
1652
smart.branch.SmartServerBranchRequestSetConfigOption)
1653
self.assertHandlerEqual('Branch.set_last_revision',
1037
1654
smart.branch.SmartServerBranchRequestSetLastRevision)
1039
smart.request.request_handlers.get('Branch.set_last_revision_info'),
1655
self.assertHandlerEqual('Branch.set_last_revision_info',
1040
1656
smart.branch.SmartServerBranchRequestSetLastRevisionInfo)
1042
smart.request.request_handlers.get('Branch.unlock'),
1657
self.assertHandlerEqual('Branch.set_last_revision_ex',
1658
smart.branch.SmartServerBranchRequestSetLastRevisionEx)
1659
self.assertHandlerEqual('Branch.set_parent_location',
1660
smart.branch.SmartServerBranchRequestSetParentLocation)
1661
self.assertHandlerEqual('Branch.unlock',
1043
1662
smart.branch.SmartServerBranchRequestUnlock)
1045
smart.request.request_handlers.get('BzrDir.find_repository'),
1663
self.assertHandlerEqual('BzrDir.find_repository',
1046
1664
smart.bzrdir.SmartServerRequestFindRepositoryV1)
1048
smart.request.request_handlers.get('BzrDir.find_repositoryV2'),
1665
self.assertHandlerEqual('BzrDir.find_repositoryV2',
1049
1666
smart.bzrdir.SmartServerRequestFindRepositoryV2)
1051
smart.request.request_handlers.get('BzrDirFormat.initialize'),
1667
self.assertHandlerEqual('BzrDirFormat.initialize',
1052
1668
smart.bzrdir.SmartServerRequestInitializeBzrDir)
1054
smart.request.request_handlers.get('BzrDir.open_branch'),
1669
self.assertHandlerEqual('BzrDirFormat.initialize_ex_1.16',
1670
smart.bzrdir.SmartServerRequestBzrDirInitializeEx)
1671
self.assertHandlerEqual('BzrDir.cloning_metadir',
1672
smart.bzrdir.SmartServerBzrDirRequestCloningMetaDir)
1673
self.assertHandlerEqual('BzrDir.get_config_file',
1674
smart.bzrdir.SmartServerBzrDirRequestConfigFile)
1675
self.assertHandlerEqual('BzrDir.open_branch',
1055
1676
smart.bzrdir.SmartServerRequestOpenBranch)
1057
smart.request.request_handlers.get('Repository.gather_stats'),
1677
self.assertHandlerEqual('BzrDir.open_branchV2',
1678
smart.bzrdir.SmartServerRequestOpenBranchV2)
1679
self.assertHandlerEqual('PackRepository.autopack',
1680
smart.packrepository.SmartServerPackRepositoryAutopack)
1681
self.assertHandlerEqual('Repository.gather_stats',
1058
1682
smart.repository.SmartServerRepositoryGatherStats)
1060
smart.request.request_handlers.get('Repository.get_parent_map'),
1683
self.assertHandlerEqual('Repository.get_parent_map',
1061
1684
smart.repository.SmartServerRepositoryGetParentMap)
1063
smart.request.request_handlers.get(
1064
'Repository.get_revision_graph'),
1685
self.assertHandlerEqual('Repository.get_rev_id_for_revno',
1686
smart.repository.SmartServerRepositoryGetRevIdForRevno)
1687
self.assertHandlerEqual('Repository.get_revision_graph',
1065
1688
smart.repository.SmartServerRepositoryGetRevisionGraph)
1067
smart.request.request_handlers.get('Repository.has_revision'),
1689
self.assertHandlerEqual('Repository.get_stream',
1690
smart.repository.SmartServerRepositoryGetStream)
1691
self.assertHandlerEqual('Repository.has_revision',
1068
1692
smart.repository.SmartServerRequestHasRevision)
1070
smart.request.request_handlers.get('Repository.is_shared'),
1693
self.assertHandlerEqual('Repository.insert_stream',
1694
smart.repository.SmartServerRepositoryInsertStream)
1695
self.assertHandlerEqual('Repository.insert_stream_locked',
1696
smart.repository.SmartServerRepositoryInsertStreamLocked)
1697
self.assertHandlerEqual('Repository.is_shared',
1071
1698
smart.repository.SmartServerRepositoryIsShared)
1073
smart.request.request_handlers.get('Repository.lock_write'),
1699
self.assertHandlerEqual('Repository.lock_write',
1074
1700
smart.repository.SmartServerRepositoryLockWrite)
1076
smart.request.request_handlers.get('Repository.tarball'),
1701
self.assertHandlerEqual('Repository.tarball',
1077
1702
smart.repository.SmartServerRepositoryTarball)
1079
smart.request.request_handlers.get('Repository.unlock'),
1703
self.assertHandlerEqual('Repository.unlock',
1080
1704
smart.repository.SmartServerRepositoryUnlock)
1082
smart.request.request_handlers.get('Transport.is_readonly'),
1705
self.assertHandlerEqual('Transport.is_readonly',
1083
1706
smart.request.SmartServerIsReadonly)