/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_fetch.py

  • Committer: John Arbash Meinel
  • Date: 2008-07-08 14:55:19 UTC
  • mfrom: (3530 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3532.
  • Revision ID: john@arbash-meinel.com-20080708145519-paqg4kjwbpgs2xmq
Merge bzr.dev 3530

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
from bzrlib.branch import Branch
29
29
from bzrlib.bzrdir import BzrDir
30
30
from bzrlib.repofmt import knitrepo
31
 
from bzrlib.symbol_versioning import (
32
 
    zero_ninetyone,
33
 
    )
34
31
from bzrlib.tests import TestCaseWithTransport
35
32
from bzrlib.tests.http_utils import TestCaseWithWebserver
36
33
from bzrlib.tests.test_revision import make_branches
149
146
        branch = self.make_branch('branch', format=knit2_format)
150
147
        branch.pull(tree.branch, stop_revision='rev1')
151
148
        repo = branch.repository
152
 
        root_knit = repo.weave_store.get_weave('tree-root',
153
 
                                                repo.get_transaction())
154
 
        # Make sure fetch retrieved only what we requested
155
 
        self.assertTrue('rev1' in root_knit)
156
 
        self.assertTrue('rev2' not in root_knit)
 
149
        repo.lock_read()
 
150
        try:
 
151
            # Make sure fetch retrieved only what we requested
 
152
            self.assertEqual({('tree-root', 'rev1'):()},
 
153
                repo.texts.get_parent_map(
 
154
                    [('tree-root', 'rev1'), ('tree-root', 'rev2')]))
 
155
        finally:
 
156
            repo.unlock()
157
157
        branch.pull(tree.branch)
158
 
        root_knit = repo.weave_store.get_weave('tree-root',
159
 
                                                repo.get_transaction())
160
158
        # Make sure that the next revision in the root knit was retrieved,
161
159
        # even though the text, name, parent_id, etc., were unchanged.
162
 
        self.assertTrue('rev2' in root_knit)
 
160
        repo.lock_read()
 
161
        try:
 
162
            # Make sure fetch retrieved only what we requested
 
163
            self.assertEqual({('tree-root', 'rev2'):(('tree-root', 'rev1'),)},
 
164
                repo.texts.get_parent_map([('tree-root', 'rev2')]))
 
165
        finally:
 
166
            repo.unlock()
163
167
 
164
168
    def test_fetch_incompatible(self):
165
169
        knit_tree = self.make_branch_and_tree('knit', format='knit')
285
289
        # unfortunately this log entry is branch format specific. We could 
286
290
        # factor out the 'what files does this format use' to a method on the 
287
291
        # repository, which would let us to this generically. RBC 20060419
 
292
        # RBC 20080408: Or perhaps we can assert that no files are fully read
 
293
        # twice?
288
294
        self.assertEqual(1, self._count_log_matches('/ce/id.kndx', http_logs))
289
295
        self.assertEqual(1, self._count_log_matches('/ce/id.knit', http_logs))
290
296
        self.assertEqual(1, self._count_log_matches('inventory.kndx', http_logs))
296
302
                                                     http_logs))
297
303
        # FIXME naughty poking in there.
298
304
        self.get_readonly_server().logs = []
299
 
        # check there is nothing more to fetch
300
 
        source = Branch.open(self.get_readonly_url("source/"))
 
305
        # check there is nothing more to fetch.  We take care to re-use the
 
306
        # existing transport so that the request logs we're about to examine
 
307
        # aren't cluttered with redundant probes for a smart server.
 
308
        # XXX: Perhaps this further parameterisation: test http with smart
 
309
        # server, and test http without smart server?
 
310
        source = Branch.open(
 
311
            self.get_readonly_url("source/"),
 
312
            possible_transports=[source.bzrdir.root_transport])
301
313
        self.assertEqual(target.fetch(source), (0, []))
302
314
        # should make just two requests
303
315
        http_logs = self.get_readonly_server().logs
305
317
        self.log('\n'.join(http_logs))
306
318
        self.assertEqual(1, self._count_log_matches('branch-format', http_logs))
307
319
        self.assertEqual(1, self._count_log_matches('branch/format', http_logs))
308
 
        self.assertEqual(1, self._count_log_matches('repository/format', http_logs))
 
320
        self.assertEqual(1, self._count_log_matches('repository/format',
 
321
            http_logs))
309
322
        self.assertTrue(1 >= self._count_log_matches('revision-history',
310
323
                                                     http_logs))
311
324
        self.assertTrue(1 >= self._count_log_matches('last-revision',
312
325
                                                     http_logs))
313
326
        self.assertEqual(4, len(http_logs))
 
327
 
 
328
 
 
329
class Test1To2Fetch(TestCaseWithTransport):
 
330
    """Tests for Model1To2 failure modes"""
 
331
 
 
332
    def make_tree_and_repo(self):
 
333
        self.tree = self.make_branch_and_tree('tree', format='pack-0.92')
 
334
        self.repo = self.make_repository('rich-repo', format='rich-root-pack')
 
335
        self.repo.lock_write()
 
336
        self.addCleanup(self.repo.unlock)
 
337
 
 
338
    def do_fetch_order_test(self, first, second):
 
339
        """Test that fetch works no matter what the set order of revision is.
 
340
 
 
341
        This test depends on the order of items in a set, which is
 
342
        implementation-dependant, so we test A, B and then B, A.
 
343
        """
 
344
        self.make_tree_and_repo()
 
345
        self.tree.commit('Commit 1', rev_id=first)
 
346
        self.tree.commit('Commit 2', rev_id=second)
 
347
        self.repo.fetch(self.tree.branch.repository, second)
 
348
 
 
349
    def test_fetch_order_AB(self):
 
350
        """See do_fetch_order_test"""
 
351
        self.do_fetch_order_test('A', 'B')
 
352
 
 
353
    def test_fetch_order_BA(self):
 
354
        """See do_fetch_order_test"""
 
355
        self.do_fetch_order_test('B', 'A')
 
356
 
 
357
    def get_parents(self, file_id, revision_id):
 
358
        self.repo.lock_read()
 
359
        try:
 
360
            parent_map = self.repo.texts.get_parent_map([(file_id, revision_id)])
 
361
            return parent_map[(file_id, revision_id)]
 
362
        finally:
 
363
            self.repo.unlock()
 
364
 
 
365
    def test_fetch_ghosts(self):
 
366
        self.make_tree_and_repo()
 
367
        self.tree.commit('first commit', rev_id='left-parent')
 
368
        self.tree.add_parent_tree_id('ghost-parent')
 
369
        fork = self.tree.bzrdir.sprout('fork', 'null:').open_workingtree()
 
370
        fork.commit('not a ghost', rev_id='not-ghost-parent')
 
371
        self.tree.branch.repository.fetch(fork.branch.repository,
 
372
                                     'not-ghost-parent')
 
373
        self.tree.add_parent_tree_id('not-ghost-parent')
 
374
        self.tree.commit('second commit', rev_id='second-id')
 
375
        self.repo.fetch(self.tree.branch.repository, 'second-id')
 
376
        root_id = self.tree.get_root_id()
 
377
        self.assertEqual(
 
378
            ((root_id, 'left-parent'), (root_id, 'ghost-parent'),
 
379
             (root_id, 'not-ghost-parent')),
 
380
            self.get_parents(root_id, 'second-id'))
 
381
 
 
382
    def make_two_commits(self, change_root, fetch_twice):
 
383
        self.make_tree_and_repo()
 
384
        self.tree.commit('first commit', rev_id='first-id')
 
385
        if change_root:
 
386
            self.tree.set_root_id('unique-id')
 
387
        self.tree.commit('second commit', rev_id='second-id')
 
388
        if fetch_twice:
 
389
            self.repo.fetch(self.tree.branch.repository, 'first-id')
 
390
        self.repo.fetch(self.tree.branch.repository, 'second-id')
 
391
 
 
392
    def test_fetch_changed_root(self):
 
393
        self.make_two_commits(change_root=True, fetch_twice=False)
 
394
        self.assertEqual((), self.get_parents('unique-id', 'second-id'))
 
395
 
 
396
    def test_two_fetch_changed_root(self):
 
397
        self.make_two_commits(change_root=True, fetch_twice=True)
 
398
        self.assertEqual((), self.get_parents('unique-id', 'second-id'))
 
399
 
 
400
    def test_two_fetches(self):
 
401
        self.make_two_commits(change_root=False, fetch_twice=True)
 
402
        self.assertEqual((('TREE_ROOT', 'first-id'),),
 
403
            self.get_parents('TREE_ROOT', 'second-id'))