832
839
request = smart_branch.SmartServerBranchRequest(backing)
833
840
self.make_controldir('.')
834
841
self.assertRaises(errors.NotBranchError,
835
request.execute, b'')
842
request.execute, b'')
837
844
def test_branch_reference(self):
838
845
"""When there is a branch reference, NotBranchError is raised."""
839
846
backing = self.get_transport()
840
847
request = smart_branch.SmartServerBranchRequest(backing)
841
848
branch = self.make_branch('branch')
842
checkout = branch.create_checkout('reference', lightweight=True)
849
branch.create_checkout('reference', lightweight=True)
843
850
self.assertRaises(errors.NotBranchError,
844
request.execute, b'checkout')
851
request.execute, b'checkout')
847
854
class TestSmartServerBranchRequestLastRevisionInfo(
848
tests.TestCaseWithMemoryTransport):
855
tests.TestCaseWithMemoryTransport):
850
857
def test_empty(self):
851
858
"""For an empty branch, the result is ('ok', '0', b'null:')."""
852
859
backing = self.get_transport()
853
request = smart_branch.SmartServerBranchRequestLastRevisionInfo(backing)
860
request = smart_branch.SmartServerBranchRequestLastRevisionInfo(
854
862
self.make_branch('.')
855
self.assertEqual(smart_req.SmartServerResponse((b'ok', b'0', b'null:')),
864
smart_req.SmartServerResponse((b'ok', b'0', b'null:')),
856
865
request.execute(b''))
858
867
def test_ghost(self):
859
868
"""For an empty branch, the result is ('ok', '0', b'null:')."""
860
869
backing = self.get_transport()
861
request = smart_branch.SmartServerBranchRequestLastRevisionInfo(backing)
870
request = smart_branch.SmartServerBranchRequestLastRevisionInfo(
862
872
branch = self.make_branch('.')
863
874
def last_revision_info():
864
875
raise errors.GhostRevisionsHaveNoRevno(b'revid1', b'revid2')
865
876
self.overrideAttr(branch, 'last_revision_info', last_revision_info)
866
877
self.assertRaises(errors.GhostRevisionsHaveNoRevno,
867
request.do_with_branch, branch)
878
request.do_with_branch, branch)
869
880
def test_not_empty(self):
870
881
"""For a non-empty branch, the result is ('ok', 'revno', 'revid')."""
871
882
backing = self.get_transport()
872
request = smart_branch.SmartServerBranchRequestLastRevisionInfo(backing)
883
request = smart_branch.SmartServerBranchRequestLastRevisionInfo(
873
885
tree = self.make_branch_and_memory_tree('.')
874
886
tree.lock_write()
876
888
rev_id_utf8 = u'\xc8'.encode('utf-8')
877
r1 = tree.commit('1st commit')
878
r2 = tree.commit('2nd commit', rev_id=rev_id_utf8)
889
tree.commit('1st commit')
890
tree.commit('2nd commit', rev_id=rev_id_utf8)
880
892
self.assertEqual(
881
893
smart_req.SmartServerResponse((b'ok', b'2', rev_id_utf8)),
2492
2516
def test_registered_methods(self):
2493
2517
"""Test that known methods are registered to the correct object."""
2494
2518
self.assertHandlerEqual(b'Branch.break_lock',
2495
smart_branch.SmartServerBranchBreakLock)
2519
smart_branch.SmartServerBranchBreakLock)
2496
2520
self.assertHandlerEqual(b'Branch.get_config_file',
2497
smart_branch.SmartServerBranchGetConfigFile)
2521
smart_branch.SmartServerBranchGetConfigFile)
2498
2522
self.assertHandlerEqual(b'Branch.put_config_file',
2499
smart_branch.SmartServerBranchPutConfigFile)
2523
smart_branch.SmartServerBranchPutConfigFile)
2500
2524
self.assertHandlerEqual(b'Branch.get_parent',
2501
smart_branch.SmartServerBranchGetParent)
2525
smart_branch.SmartServerBranchGetParent)
2502
2526
self.assertHandlerEqual(b'Branch.get_physical_lock_status',
2503
smart_branch.SmartServerBranchRequestGetPhysicalLockStatus)
2527
smart_branch.SmartServerBranchRequestGetPhysicalLockStatus)
2504
2528
self.assertHandlerEqual(b'Branch.get_tags_bytes',
2505
smart_branch.SmartServerBranchGetTagsBytes)
2529
smart_branch.SmartServerBranchGetTagsBytes)
2506
2530
self.assertHandlerEqual(b'Branch.lock_write',
2507
smart_branch.SmartServerBranchRequestLockWrite)
2531
smart_branch.SmartServerBranchRequestLockWrite)
2508
2532
self.assertHandlerEqual(b'Branch.last_revision_info',
2509
smart_branch.SmartServerBranchRequestLastRevisionInfo)
2533
smart_branch.SmartServerBranchRequestLastRevisionInfo)
2510
2534
self.assertHandlerEqual(b'Branch.revision_history',
2511
smart_branch.SmartServerRequestRevisionHistory)
2535
smart_branch.SmartServerRequestRevisionHistory)
2512
2536
self.assertHandlerEqual(b'Branch.revision_id_to_revno',
2513
smart_branch.SmartServerBranchRequestRevisionIdToRevno)
2537
smart_branch.SmartServerBranchRequestRevisionIdToRevno)
2514
2538
self.assertHandlerEqual(b'Branch.set_config_option',
2515
smart_branch.SmartServerBranchRequestSetConfigOption)
2539
smart_branch.SmartServerBranchRequestSetConfigOption)
2516
2540
self.assertHandlerEqual(b'Branch.set_last_revision',
2517
smart_branch.SmartServerBranchRequestSetLastRevision)
2541
smart_branch.SmartServerBranchRequestSetLastRevision)
2518
2542
self.assertHandlerEqual(b'Branch.set_last_revision_info',
2519
smart_branch.SmartServerBranchRequestSetLastRevisionInfo)
2543
smart_branch.SmartServerBranchRequestSetLastRevisionInfo)
2520
2544
self.assertHandlerEqual(b'Branch.set_last_revision_ex',
2521
smart_branch.SmartServerBranchRequestSetLastRevisionEx)
2545
smart_branch.SmartServerBranchRequestSetLastRevisionEx)
2522
2546
self.assertHandlerEqual(b'Branch.set_parent_location',
2523
smart_branch.SmartServerBranchRequestSetParentLocation)
2547
smart_branch.SmartServerBranchRequestSetParentLocation)
2524
2548
self.assertHandlerEqual(b'Branch.unlock',
2525
smart_branch.SmartServerBranchRequestUnlock)
2549
smart_branch.SmartServerBranchRequestUnlock)
2526
2550
self.assertHandlerEqual(b'BzrDir.destroy_branch',
2527
smart_dir.SmartServerBzrDirRequestDestroyBranch)
2551
smart_dir.SmartServerBzrDirRequestDestroyBranch)
2528
2552
self.assertHandlerEqual(b'BzrDir.find_repository',
2529
smart_dir.SmartServerRequestFindRepositoryV1)
2553
smart_dir.SmartServerRequestFindRepositoryV1)
2530
2554
self.assertHandlerEqual(b'BzrDir.find_repositoryV2',
2531
smart_dir.SmartServerRequestFindRepositoryV2)
2555
smart_dir.SmartServerRequestFindRepositoryV2)
2532
2556
self.assertHandlerEqual(b'BzrDirFormat.initialize',
2533
smart_dir.SmartServerRequestInitializeBzrDir)
2557
smart_dir.SmartServerRequestInitializeBzrDir)
2534
2558
self.assertHandlerEqual(b'BzrDirFormat.initialize_ex_1.16',
2535
smart_dir.SmartServerRequestBzrDirInitializeEx)
2559
smart_dir.SmartServerRequestBzrDirInitializeEx)
2536
2560
self.assertHandlerEqual(b'BzrDir.checkout_metadir',
2537
smart_dir.SmartServerBzrDirRequestCheckoutMetaDir)
2561
smart_dir.SmartServerBzrDirRequestCheckoutMetaDir)
2538
2562
self.assertHandlerEqual(b'BzrDir.cloning_metadir',
2539
smart_dir.SmartServerBzrDirRequestCloningMetaDir)
2563
smart_dir.SmartServerBzrDirRequestCloningMetaDir)
2540
2564
self.assertHandlerEqual(b'BzrDir.get_branches',
2541
smart_dir.SmartServerBzrDirRequestGetBranches)
2565
smart_dir.SmartServerBzrDirRequestGetBranches)
2542
2566
self.assertHandlerEqual(b'BzrDir.get_config_file',
2543
smart_dir.SmartServerBzrDirRequestConfigFile)
2567
smart_dir.SmartServerBzrDirRequestConfigFile)
2544
2568
self.assertHandlerEqual(b'BzrDir.open_branch',
2545
smart_dir.SmartServerRequestOpenBranch)
2569
smart_dir.SmartServerRequestOpenBranch)
2546
2570
self.assertHandlerEqual(b'BzrDir.open_branchV2',
2547
smart_dir.SmartServerRequestOpenBranchV2)
2571
smart_dir.SmartServerRequestOpenBranchV2)
2548
2572
self.assertHandlerEqual(b'BzrDir.open_branchV3',
2549
smart_dir.SmartServerRequestOpenBranchV3)
2573
smart_dir.SmartServerRequestOpenBranchV3)
2550
2574
self.assertHandlerEqual(b'PackRepository.autopack',
2551
smart_packrepo.SmartServerPackRepositoryAutopack)
2575
smart_packrepo.SmartServerPackRepositoryAutopack)
2552
2576
self.assertHandlerEqual(b'Repository.add_signature_text',
2553
smart_repo.SmartServerRepositoryAddSignatureText)
2577
smart_repo.SmartServerRepositoryAddSignatureText)
2554
2578
self.assertHandlerEqual(b'Repository.all_revision_ids',
2555
smart_repo.SmartServerRepositoryAllRevisionIds)
2579
smart_repo.SmartServerRepositoryAllRevisionIds)
2556
2580
self.assertHandlerEqual(b'Repository.break_lock',
2557
smart_repo.SmartServerRepositoryBreakLock)
2581
smart_repo.SmartServerRepositoryBreakLock)
2558
2582
self.assertHandlerEqual(b'Repository.gather_stats',
2559
smart_repo.SmartServerRepositoryGatherStats)
2583
smart_repo.SmartServerRepositoryGatherStats)
2560
2584
self.assertHandlerEqual(b'Repository.get_parent_map',
2561
smart_repo.SmartServerRepositoryGetParentMap)
2585
smart_repo.SmartServerRepositoryGetParentMap)
2562
2586
self.assertHandlerEqual(b'Repository.get_physical_lock_status',
2563
smart_repo.SmartServerRepositoryGetPhysicalLockStatus)
2587
smart_repo.SmartServerRepositoryGetPhysicalLockStatus)
2564
2588
self.assertHandlerEqual(b'Repository.get_rev_id_for_revno',
2565
smart_repo.SmartServerRepositoryGetRevIdForRevno)
2589
smart_repo.SmartServerRepositoryGetRevIdForRevno)
2566
2590
self.assertHandlerEqual(b'Repository.get_revision_graph',
2567
smart_repo.SmartServerRepositoryGetRevisionGraph)
2591
smart_repo.SmartServerRepositoryGetRevisionGraph)
2568
2592
self.assertHandlerEqual(b'Repository.get_revision_signature_text',
2569
smart_repo.SmartServerRepositoryGetRevisionSignatureText)
2593
smart_repo.SmartServerRepositoryGetRevisionSignatureText)
2570
2594
self.assertHandlerEqual(b'Repository.get_stream',
2571
smart_repo.SmartServerRepositoryGetStream)
2595
smart_repo.SmartServerRepositoryGetStream)
2572
2596
self.assertHandlerEqual(b'Repository.get_stream_1.19',
2573
smart_repo.SmartServerRepositoryGetStream_1_19)
2597
smart_repo.SmartServerRepositoryGetStream_1_19)
2574
2598
self.assertHandlerEqual(b'Repository.iter_revisions',
2575
smart_repo.SmartServerRepositoryIterRevisions)
2599
smart_repo.SmartServerRepositoryIterRevisions)
2576
2600
self.assertHandlerEqual(b'Repository.has_revision',
2577
smart_repo.SmartServerRequestHasRevision)
2601
smart_repo.SmartServerRequestHasRevision)
2578
2602
self.assertHandlerEqual(b'Repository.insert_stream',
2579
smart_repo.SmartServerRepositoryInsertStream)
2603
smart_repo.SmartServerRepositoryInsertStream)
2580
2604
self.assertHandlerEqual(b'Repository.insert_stream_locked',
2581
smart_repo.SmartServerRepositoryInsertStreamLocked)
2605
smart_repo.SmartServerRepositoryInsertStreamLocked)
2582
2606
self.assertHandlerEqual(b'Repository.is_shared',
2583
smart_repo.SmartServerRepositoryIsShared)
2607
smart_repo.SmartServerRepositoryIsShared)
2584
2608
self.assertHandlerEqual(b'Repository.iter_files_bytes',
2585
smart_repo.SmartServerRepositoryIterFilesBytes)
2609
smart_repo.SmartServerRepositoryIterFilesBytes)
2586
2610
self.assertHandlerEqual(b'Repository.lock_write',
2587
smart_repo.SmartServerRepositoryLockWrite)
2611
smart_repo.SmartServerRepositoryLockWrite)
2588
2612
self.assertHandlerEqual(b'Repository.make_working_trees',
2589
smart_repo.SmartServerRepositoryMakeWorkingTrees)
2613
smart_repo.SmartServerRepositoryMakeWorkingTrees)
2590
2614
self.assertHandlerEqual(b'Repository.pack',
2591
smart_repo.SmartServerRepositoryPack)
2615
smart_repo.SmartServerRepositoryPack)
2592
2616
self.assertHandlerEqual(b'Repository.reconcile',
2593
smart_repo.SmartServerRepositoryReconcile)
2617
smart_repo.SmartServerRepositoryReconcile)
2594
2618
self.assertHandlerEqual(b'Repository.tarball',
2595
smart_repo.SmartServerRepositoryTarball)
2619
smart_repo.SmartServerRepositoryTarball)
2596
2620
self.assertHandlerEqual(b'Repository.unlock',
2597
smart_repo.SmartServerRepositoryUnlock)
2621
smart_repo.SmartServerRepositoryUnlock)
2598
2622
self.assertHandlerEqual(b'Repository.start_write_group',
2599
smart_repo.SmartServerRepositoryStartWriteGroup)
2623
smart_repo.SmartServerRepositoryStartWriteGroup)
2600
2624
self.assertHandlerEqual(b'Repository.check_write_group',
2601
smart_repo.SmartServerRepositoryCheckWriteGroup)
2625
smart_repo.SmartServerRepositoryCheckWriteGroup)
2602
2626
self.assertHandlerEqual(b'Repository.commit_write_group',
2603
smart_repo.SmartServerRepositoryCommitWriteGroup)
2627
smart_repo.SmartServerRepositoryCommitWriteGroup)
2604
2628
self.assertHandlerEqual(b'Repository.abort_write_group',
2605
smart_repo.SmartServerRepositoryAbortWriteGroup)
2629
smart_repo.SmartServerRepositoryAbortWriteGroup)
2606
2630
self.assertHandlerEqual(b'VersionedFileRepository.get_serializer_format',
2607
smart_repo.SmartServerRepositoryGetSerializerFormat)
2631
smart_repo.SmartServerRepositoryGetSerializerFormat)
2608
2632
self.assertHandlerEqual(b'VersionedFileRepository.get_inventories',
2609
smart_repo.SmartServerRepositoryGetInventories)
2633
smart_repo.SmartServerRepositoryGetInventories)
2610
2634
self.assertHandlerEqual(b'Transport.is_readonly',
2611
smart_req.SmartServerIsReadonly)
2635
smart_req.SmartServerIsReadonly)
2614
2638
class SmartTCPServerHookTests(tests.TestCaseWithMemoryTransport):
2622
2646
"""Test the server started hooks get fired properly."""
2623
2647
started_calls = []
2624
2648
server.SmartTCPServer.hooks.install_named_hook('server_started',
2625
lambda backing_urls, url: started_calls.append((backing_urls, url)),
2649
lambda backing_urls, url: started_calls.append(
2650
(backing_urls, url)),
2627
2652
started_ex_calls = []
2628
2653
server.SmartTCPServer.hooks.install_named_hook('server_started_ex',
2629
lambda backing_urls, url: started_ex_calls.append((backing_urls, url)),
2654
lambda backing_urls, url: started_ex_calls.append(
2655
(backing_urls, url)),
2631
2657
self.server._sockname = ('example.com', 42)
2632
2658
self.server.run_server_started_hooks()
2633
2659
self.assertEqual(started_calls,
2634
[([self.get_transport().base], 'bzr://example.com:42/')])
2660
[([self.get_transport().base], 'bzr://example.com:42/')])
2635
2661
self.assertEqual(started_ex_calls,
2636
[([self.get_transport().base], self.server)])
2662
[([self.get_transport().base], self.server)])
2638
2664
def test_run_server_started_hooks_ipv6(self):
2639
2665
"""Test that socknames can contain 4-tuples."""
2640
2666
self.server._sockname = ('::', 42, 0, 0)
2641
2667
started_calls = []
2642
2668
server.SmartTCPServer.hooks.install_named_hook('server_started',
2643
lambda backing_urls, url: started_calls.append((backing_urls, url)),
2669
lambda backing_urls, url: started_calls.append(
2670
(backing_urls, url)),
2645
2672
self.server.run_server_started_hooks()
2646
2673
self.assertEqual(started_calls,
2647
[([self.get_transport().base], 'bzr://:::42/')])
2674
[([self.get_transport().base], 'bzr://:::42/')])
2649
2676
def test_run_server_stopped_hooks(self):
2650
2677
"""Test the server stopped hooks."""
2651
2678
self.server._sockname = ('example.com', 42)
2652
2679
stopped_calls = []
2653
2680
server.SmartTCPServer.hooks.install_named_hook('server_stopped',
2654
lambda backing_urls, url: stopped_calls.append((backing_urls, url)),
2681
lambda backing_urls, url: stopped_calls.append(
2682
(backing_urls, url)),
2656
2684
self.server.run_server_stopped_hooks()
2657
2685
self.assertEqual(stopped_calls,
2658
[([self.get_transport().base], 'bzr://example.com:42/')])
2686
[([self.get_transport().base], 'bzr://example.com:42/')])
2661
2689
class TestSmartServerRepositoryPack(tests.TestCaseWithMemoryTransport):