~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_fetch.py

  • Committer: John Arbash Meinel
  • Date: 2006-03-08 14:31:23 UTC
  • mfrom: (1598 +trunk)
  • mto: (1685.1.1 bzr-encoding)
  • mto: This revision was merged to the branch mainline in revision 1752.
  • Revision ID: john@arbash-meinel.com-20060308143123-448308b0db4de410
[merge] bzr.dev 1573, lots of updates

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
import sys
19
19
 
20
20
from bzrlib.branch import Branch
 
21
from bzrlib.bzrdir import BzrDir
21
22
from bzrlib.builtins import merge
22
23
import bzrlib.errors
23
 
from bzrlib.fetch import greedy_fetch
24
24
from bzrlib.tests import TestCaseWithTransport
25
25
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
26
26
from bzrlib.tests.test_revision import make_branches
29
29
 
30
30
 
31
31
def has_revision(branch, revision_id):
32
 
    try:
33
 
        branch.repository.get_revision_xml_file(revision_id)
34
 
        return True
35
 
    except bzrlib.errors.NoSuchRevision:
36
 
        return False
37
 
 
 
32
    return branch.repository.has_revision(revision_id)
38
33
 
39
34
def fetch_steps(self, br_a, br_b, writable_a):
40
35
    """A foreign test method for testing fetch locally and remotely."""
41
 
    def new_branch(name):
42
 
        os.mkdir(name)
43
 
        return WorkingTree.create_standalone(name).branch
44
 
            
45
 
    self.assertFalse(has_revision(br_b, br_a.revision_history()[3]))
46
 
    self.assert_(has_revision(br_b, br_a.revision_history()[2]))
47
 
    self.assertEquals(len(br_b.revision_history()), 7)
48
 
    self.assertEquals(greedy_fetch(br_b, br_a, br_a.revision_history()[2])[0], 0)
49
 
 
50
 
    # greedy_fetch is not supposed to alter the revision history
51
 
    self.assertEquals(len(br_b.revision_history()), 7)
52
 
    self.assertFalse(has_revision(br_b, br_a.revision_history()[3]))
53
 
 
54
 
    self.assertEquals(len(br_b.revision_history()), 7)
55
 
    self.assertEquals(greedy_fetch(br_b, br_a, br_a.revision_history()[3])[0], 1)
56
 
    self.assert_(has_revision(br_b, br_a.revision_history()[3]))
 
36
     
 
37
    # TODO RBC 20060201 make this a repository test.
 
38
    repo_b = br_b.repository
 
39
    self.assertFalse(repo_b.has_revision(br_a.revision_history()[3]))
 
40
    self.assertTrue(repo_b.has_revision(br_a.revision_history()[2]))
 
41
    self.assertEquals(len(br_b.revision_history()), 7)
 
42
    self.assertEquals(br_b.fetch(br_a, br_a.revision_history()[2])[0], 0)
 
43
    # branch.fetch is not supposed to alter the revision history
 
44
    self.assertEquals(len(br_b.revision_history()), 7)
 
45
    self.assertFalse(repo_b.has_revision(br_a.revision_history()[3]))
 
46
 
 
47
    # fetching the next revision up in sample data copies one revision
 
48
    self.assertEquals(br_b.fetch(br_a, br_a.revision_history()[3])[0], 1)
 
49
    self.assertTrue(repo_b.has_revision(br_a.revision_history()[3]))
57
50
    self.assertFalse(has_revision(br_a, br_b.revision_history()[6]))
58
 
    self.assert_(has_revision(br_a, br_b.revision_history()[5]))
 
51
    self.assertTrue(br_a.repository.has_revision(br_b.revision_history()[5]))
59
52
 
60
53
    # When a non-branch ancestor is missing, it should be unlisted...
61
54
    # as its not reference from the inventory weave.
62
 
    br_b4 = new_branch('br_4')
63
 
    count, failures = greedy_fetch(br_b4, br_b)
 
55
    br_b4 = self.make_branch('br_4')
 
56
    count, failures = br_b4.fetch(br_b)
64
57
    self.assertEqual(count, 7)
65
58
    self.assertEqual(failures, [])
66
59
 
67
 
    self.assertEqual(greedy_fetch(writable_a, br_b)[0], 1)
68
 
    self.assert_(has_revision(br_a, br_b.revision_history()[3]))
69
 
    self.assert_(has_revision(br_a, br_b.revision_history()[4]))
 
60
    self.assertEqual(writable_a.fetch(br_b)[0], 1)
 
61
    self.assertTrue(has_revision(br_a, br_b.revision_history()[3]))
 
62
    self.assertTrue(has_revision(br_a, br_b.revision_history()[4]))
70
63
        
71
 
    br_b2 = new_branch('br_b2')
72
 
    self.assertEquals(greedy_fetch(br_b2, br_b)[0], 7)
73
 
    self.assert_(has_revision(br_b2, br_b.revision_history()[4]))
74
 
    self.assert_(has_revision(br_b2, br_a.revision_history()[2]))
 
64
    br_b2 = self.make_branch('br_b2')
 
65
    self.assertEquals(br_b2.fetch(br_b)[0], 7)
 
66
    self.assertTrue(has_revision(br_b2, br_b.revision_history()[4]))
 
67
    self.assertTrue(has_revision(br_b2, br_a.revision_history()[2]))
75
68
    self.assertFalse(has_revision(br_b2, br_a.revision_history()[3]))
76
69
 
77
 
    br_a2 = new_branch('br_a2')
78
 
    self.assertEquals(greedy_fetch(br_a2, br_a)[0], 9)
79
 
    self.assert_(has_revision(br_a2, br_b.revision_history()[4]))
80
 
    self.assert_(has_revision(br_a2, br_a.revision_history()[3]))
81
 
    self.assert_(has_revision(br_a2, br_a.revision_history()[2]))
 
70
    br_a2 = self.make_branch('br_a2')
 
71
    self.assertEquals(br_a2.fetch(br_a)[0], 9)
 
72
    self.assertTrue(has_revision(br_a2, br_b.revision_history()[4]))
 
73
    self.assertTrue(has_revision(br_a2, br_a.revision_history()[3]))
 
74
    self.assertTrue(has_revision(br_a2, br_a.revision_history()[2]))
82
75
 
83
 
    br_a3 = new_branch('br_a3')
84
 
    self.assertEquals(greedy_fetch(br_a3, br_a2)[0], 0)
 
76
    br_a3 = self.make_branch('br_a3')
 
77
    # pulling a branch with no revisions grabs nothing, regardless of 
 
78
    # whats in the inventory.
 
79
    self.assertEquals(br_a3.fetch(br_a2)[0], 0)
85
80
    for revno in range(4):
86
 
        self.assertFalse(has_revision(br_a3, br_a.revision_history()[revno]))
87
 
    self.assertEqual(greedy_fetch(br_a3, br_a2, br_a.revision_history()[2])[0], 3)
88
 
    fetched = greedy_fetch(br_a3, br_a2, br_a.revision_history()[3])[0]
89
 
    self.assertEquals(fetched, 6, "fetched %d instead of 6" % fetched)
 
81
        self.assertFalse(
 
82
            br_a3.repository.has_revision(br_a.revision_history()[revno]))
 
83
    self.assertEqual(br_a3.fetch(br_a2, br_a.revision_history()[2])[0], 3)
 
84
    # pull the 3 revisions introduced by a@u-0-3
 
85
    fetched = br_a3.fetch(br_a2, br_a.revision_history()[3])[0]
 
86
    self.assertEquals(fetched, 3, "fetched %d instead of 3" % fetched)
90
87
    # InstallFailed should be raised if the branch is missing the revision
91
88
    # that was requested.
92
 
    self.assertRaises(bzrlib.errors.InstallFailed, greedy_fetch, br_a3,
93
 
                      br_a2, 'pizza')
 
89
    self.assertRaises(bzrlib.errors.InstallFailed, br_a3.fetch, br_a2, 'pizza')
94
90
    # InstallFailed should be raised if the branch is missing a revision
95
91
    # from its own revision history
96
92
    br_a2.append_revision('a-b-c')
97
 
    self.assertRaises(bzrlib.errors.InstallFailed, greedy_fetch, br_a3,
98
 
                      br_a2)
99
 
 
100
 
 
 
93
    self.assertRaises(bzrlib.errors.InstallFailed, br_a3.fetch, br_a2)
101
94
    #TODO: test that fetch correctly does reweaving when needed. RBC 20051008
 
95
    # Note that this means - updating the weave when ghosts are filled in to 
 
96
    # add the right parents.
 
97
 
102
98
 
103
99
class TestFetch(TestCaseWithTransport):
104
100
 
128
124
        wt1 = self.make_branch_and_tree('br1')
129
125
        br1 = wt1.branch
130
126
        wt1.commit(message='rev 1-1', rev_id='1-1')
131
 
        br2 = br1.clone('br2')
 
127
        dir_2 = br1.bzrdir.sprout('br2')
 
128
        br2 = dir_2.open_branch()
132
129
        wt1.commit(message='rev 1-2', rev_id='1-2')
133
 
        WorkingTree('br2', br2).commit(message='rev 2-1', rev_id='2-1')
 
130
        dir_2.open_workingtree().commit(message='rev 2-1', rev_id='2-1')
134
131
        merge(other_revision=['br1', -1], base_revision=[None, None], 
135
132
              this_dir='br2')
136
133
        self._check_revs_present(br2)
152
149
        self.build_tree_contents([('br1/file', 'original contents\n')])
153
150
        wt1.add('file', 'this-file-id')
154
151
        wt1.commit(message='rev 1-1', rev_id='1-1')
155
 
        br2 = br1.clone('br2')
156
 
        wt2 = WorkingTree('br2', br2)
 
152
        dir_2 = br1.bzrdir.sprout('br2')
 
153
        br2 = dir_2.open_branch()
 
154
        wt2 = dir_2.open_workingtree()
157
155
        self.build_tree_contents([('br1/file', 'original from 1\n')])
158
156
        wt1.commit(message='rev 1-2', rev_id='1-2')
159
157
        self.build_tree_contents([('br1/file', 'agreement\n')])
184
182
 
185
183
    def test_fetch(self):
186
184
        #highest indices a: 5, b: 7
187
 
        print "TestHttpFetch.test_fetch disabled during transition."
188
 
        return
189
185
        br_a, br_b = make_branches(self)
190
 
        br_rem_a = Branch.open(self.get_remote_url(br_a.base))
 
186
        br_rem_a = Branch.open(self.get_readonly_url('branch1'))
191
187
        fetch_steps(self, br_rem_a, br_b, br_a)
192
188
 
193
189
    def test_weaves_are_retrieved_once(self):
194
190
        self.build_tree(("source/", "source/file", "target/"))
195
 
        wt = WorkingTree.create_standalone('source')
 
191
        wt = self.make_branch_and_tree('source')
196
192
        branch = wt.branch
197
193
        wt.add(["file"], ["id"])
198
194
        wt.commit("added file")
199
195
        print >>open("source/file", 'w'), "blah"
200
196
        wt.commit("changed file")
201
 
        target = Branch.create("target/")
202
 
        source = Branch.open(self.get_remote_url("source/"))
203
 
        self.assertEqual(greedy_fetch(target, source), (2, []))
 
197
        target = BzrDir.create_branch_and_repo("target/")
 
198
        source = Branch.open(self.get_readonly_url("source/"))
 
199
        self.assertEqual(target.fetch(source), (2, []))
 
200
        log_pattern = '%%s HTTP/1.1" 200 - "-" "bzr/%s"' % bzrlib.__version__
204
201
        # this is the path to the literal file. As format changes 
205
202
        # occur it needs to be updated. FIXME: ask the store for the
206
203
        # path.
207
 
        weave_suffix = 'weaves/ce/id.weave HTTP/1.1" 200 -'
208
 
        self.assertEqual(1,
209
 
            len([log for log in self.server.logs if log.endswith(weave_suffix)]))
210
 
        inventory_weave_suffix = 'inventory.weave HTTP/1.1" 200 -'
211
 
        self.assertEqual(1,
212
 
            len([log for log in self.server.logs if log.endswith(
 
204
        weave_suffix = log_pattern % 'weaves/ce/id.weave'
 
205
        self.assertEqual(1,
 
206
            len([log for log in self.get_readonly_server().logs if log.endswith(weave_suffix)]))
 
207
        inventory_weave_suffix = log_pattern % 'inventory.weave'
 
208
        self.assertEqual(1,
 
209
            len([log for log in self.get_readonly_server().logs if log.endswith(
213
210
                inventory_weave_suffix)]))
214
211
        # this r-h check test will prevent regressions, but it currently already 
215
212
        # passes, before the patch to cache-rh is applied :[
216
 
        revision_history_suffix = 'revision-history HTTP/1.1" 200 -'
 
213
        revision_history_suffix = log_pattern % 'revision-history'
217
214
        self.assertEqual(1,
218
 
            len([log for log in self.server.logs if log.endswith(
 
215
            len([log for log in self.get_readonly_server().logs if log.endswith(
219
216
                revision_history_suffix)]))
220
217
        # FIXME naughty poking in there.
221
 
        self.server.logs = []
 
218
        self.get_readonly_server().logs = []
222
219
        # check there is nothing more to fetch
223
 
        source = Branch.open(self.get_remote_url("source/"))
224
 
        self.assertEqual(greedy_fetch(target, source), (0, []))
225
 
        self.failUnless(self.server.logs[0].endswith('branch-format HTTP/1.1" 200 -'))
226
 
        self.failUnless(self.server.logs[1].endswith('revision-history HTTP/1.1" 200 -'))
227
 
        self.assertEqual(2, len(self.server.logs))
 
220
        source = Branch.open(self.get_readonly_url("source/"))
 
221
        self.assertEqual(target.fetch(source), (0, []))
 
222
        self.failUnless(self.get_readonly_server().logs[0].endswith(log_pattern % 'branch-format'))
 
223
        self.failUnless(self.get_readonly_server().logs[1].endswith(log_pattern % 'revision-history'))
 
224
        self.assertEqual(2, len(self.get_readonly_server().logs))