def testDoesntSendStackedInfoNotStacked(self): # Mirroring a non-stacked branch sends '' as the stacked-on location # to the master. source_branch = self.make_branch('source-branch', format='1.9') protocol_output = StringIO() to_mirror = self.makePullerWorker( source_branch.base, self.get_url('destdir'), protocol=PullerWorkerProtocol(protocol_output)) to_mirror.mirror() stacked_on_url = self.getStackedOnUrlFromNetStringOutput( protocol_output.getvalue()) self.assertEqual('', stacked_on_url)
def testSendsStackedInfo(self): # When the puller worker stacks a branch, it reports the stacked on # URL to the master. base_branch = self.make_branch('base_branch', format='1.9') stacked_branch = self.make_branch('stacked-branch', format='1.9') protocol_output = StringIO() to_mirror = self.makePullerWorker( stacked_branch.base, self.get_url('destdir'), protocol=PullerWorkerProtocol(protocol_output), policy=PrearrangedStackedBranchPolicy(base_branch.base)) to_mirror.mirror() stacked_on_url = self.getStackedOnUrlFromNetStringOutput( protocol_output.getvalue()) self.assertEqual(base_branch.base, stacked_on_url)
def makePullerWorker(self, src_dir=None, dest_dir=None, branch_type=None, default_stacked_on_url=None, protocol=None, policy=None): """Anonymous creation method for PullerWorker.""" if protocol is None: protocol = PullerWorkerProtocol(StringIO()) if branch_type is None: if policy is None: policy = AcceptAnythingBranchMirrorerPolicy() opener = BranchMirrorer(policy, protocol) else: opener = None return PullerWorker(src_dir, dest_dir, branch_id=1, unique_name='foo/bar/baz', branch_type=branch_type, default_stacked_on_url=default_stacked_on_url, protocol=protocol, branch_mirrorer=opener)
def setUp(self): TestCaseInTempDir.setUp(self) self.output = StringIO() self.protocol = PullerWorkerProtocol(self.output) self.factory = ObjectFactory()
class TestWorkerProtocol(TestCaseInTempDir, PullerWorkerMixin): """Tests for the client-side implementation of the protocol used to communicate to the master process. """ def setUp(self): TestCaseInTempDir.setUp(self) self.output = StringIO() self.protocol = PullerWorkerProtocol(self.output) self.factory = ObjectFactory() def assertSentNetstrings(self, expected_netstrings): """Assert that the protocol sent the given netstrings (in order).""" observed_netstrings = get_netstrings(self.output.getvalue()) self.assertEqual(expected_netstrings, observed_netstrings) def resetBuffers(self): # Empty the test output and error buffers. self.output.truncate(0) self.assertEqual('', self.output.getvalue()) def test_nothingSentOnConstruction(self): # The protocol sends nothing until it receives an event. self.branch_to_mirror = self.makePullerWorker(protocol=self.protocol) self.assertSentNetstrings([]) def test_startMirror(self): # Calling startMirroring sends 'startMirroring' as a netstring. self.protocol.startMirroring() self.assertSentNetstrings(['startMirroring', '0']) def test_branchChanged(self): # Calling 'branchChanged' sends the arguments. arbitrary_args = [self.factory.getUniqueString() for x in range(6)] self.protocol.startMirroring() self.resetBuffers() self.protocol.branchChanged(*arbitrary_args) self.assertSentNetstrings(['branchChanged', '6'] + arbitrary_args) def test_mirrorFailed(self): # Calling 'mirrorFailed' sends the error message. self.protocol.startMirroring() self.resetBuffers() self.protocol.mirrorFailed('Error Message', 'OOPS') self.assertSentNetstrings( ['mirrorFailed', '2', 'Error Message', 'OOPS']) def test_progressMade(self): # Calling 'progressMade' sends an arbitrary string indicating # progress. self.protocol.progressMade('test') self.assertSentNetstrings(['progressMade', '0']) def test_log(self): # Calling 'log' sends 'log' as a netstring and its arguments, after # formatting as a string. self.protocol.log('logged %s', 'message') self.assertSentNetstrings(['log', '1', 'logged message'])
# There is no test for this (it would involve a great number of moving # parts) but it has been verified to work on production. Also see # https://bugs.launchpad.net/bzr/+bug/82086 from bzrlib.transport import register_lazy_transport register_lazy_transport('http://', 'bzrlib.transport.http._urllib', 'HttpTransport_urllib') register_lazy_transport('https://', 'bzrlib.transport.http._urllib', 'HttpTransport_urllib') if __name__ == '__main__': parser = OptionParser() (options, arguments) = parser.parse_args() (source_url, destination_url, branch_id, unique_name, branch_type_name, default_stacked_on_url) = arguments branch_type = BranchType.items[branch_type_name] if branch_type == BranchType.IMPORTED and 'http_proxy' in os.environ: del os.environ['http_proxy'] section_name = 'supermirror_%s_puller' % branch_type_map[branch_type] globalErrorUtility.configure(section_name) shut_up_deprecation_warning() force_bzr_to_use_urllib() resource.setrlimit(resource.RLIMIT_AS, (1500000000, 1500000000)) protocol = PullerWorkerProtocol(sys.stdout) install_worker_ui_factory(protocol) PullerWorker(source_url, destination_url, int(branch_id), unique_name, branch_type, default_stacked_on_url, protocol).mirror()
def setUp(self): TestCaseInTempDir.setUp(self) self.output = StringIO() self.protocol = PullerWorkerProtocol(self.output) self.factory = ObjectFactory()
class TestWorkerProtocol(TestCaseInTempDir, PullerWorkerMixin): """Tests for the client-side implementation of the protocol used to communicate to the master process. """ def setUp(self): TestCaseInTempDir.setUp(self) self.output = StringIO() self.protocol = PullerWorkerProtocol(self.output) self.factory = ObjectFactory() def assertSentNetstrings(self, expected_netstrings): """Assert that the protocol sent the given netstrings (in order).""" observed_netstrings = get_netstrings(self.output.getvalue()) self.assertEqual(expected_netstrings, observed_netstrings) def resetBuffers(self): # Empty the test output and error buffers. self.output.truncate(0) self.assertEqual('', self.output.getvalue()) def test_nothingSentOnConstruction(self): # The protocol sends nothing until it receives an event. self.branch_to_mirror = self.makePullerWorker(protocol=self.protocol) self.assertSentNetstrings([]) def test_startMirror(self): # Calling startMirroring sends 'startMirroring' as a netstring. self.protocol.startMirroring() self.assertSentNetstrings(['startMirroring', '0']) def test_branchChanged(self): # Calling 'branchChanged' sends the arguments. arbitrary_args = [self.factory.getUniqueString() for x in range(6)] self.protocol.startMirroring() self.resetBuffers() self.protocol.branchChanged(*arbitrary_args) self.assertSentNetstrings(['branchChanged', '6'] + arbitrary_args) def test_mirrorFailed(self): # Calling 'mirrorFailed' sends the error message. self.protocol.startMirroring() self.resetBuffers() self.protocol.mirrorFailed('Error Message', 'OOPS') self.assertSentNetstrings( ['mirrorFailed', '2', 'Error Message', 'OOPS']) def test_progressMade(self): # Calling 'progressMade' sends an arbitrary string indicating # progress. self.protocol.progressMade('test') self.assertSentNetstrings(['progressMade', '0']) def test_log(self): # Calling 'log' sends 'log' as a netstring and its arguments, after # formatting as a string. self.protocol.log('logged %s', 'message') self.assertSentNetstrings(['log', '1', 'logged message'])