32
31
def has_revision(branch, revision_id):
33
return branch.repository.has_revision(revision_id)
33
branch.repository.get_revision_xml_file(revision_id)
35
except bzrlib.errors.NoSuchRevision:
35
39
def fetch_steps(self, br_a, br_b, writable_a):
36
40
"""A foreign test method for testing fetch locally and remotely."""
38
# TODO RBC 20060201 make this a repository test.
39
repo_b = br_b.repository
40
self.assertFalse(repo_b.has_revision(br_a.revision_history()[3]))
41
self.assertTrue(repo_b.has_revision(br_a.revision_history()[2]))
43
return WorkingTree.create_standalone(name).branch
45
self.assertFalse(has_revision(br_b, br_a.revision_history()[3]))
46
self.assert_(has_revision(br_b, br_a.revision_history()[2]))
42
47
self.assertEquals(len(br_b.revision_history()), 7)
43
48
self.assertEquals(greedy_fetch(br_b, br_a, br_a.revision_history()[2])[0], 0)
44
50
# greedy_fetch is not supposed to alter the revision history
45
51
self.assertEquals(len(br_b.revision_history()), 7)
46
self.assertFalse(repo_b.has_revision(br_a.revision_history()[3]))
52
self.assertFalse(has_revision(br_b, br_a.revision_history()[3]))
48
# fetching the next revision up in sample data copies one revision
54
self.assertEquals(len(br_b.revision_history()), 7)
49
55
self.assertEquals(greedy_fetch(br_b, br_a, br_a.revision_history()[3])[0], 1)
50
self.assertTrue(repo_b.has_revision(br_a.revision_history()[3]))
56
self.assert_(has_revision(br_b, br_a.revision_history()[3]))
51
57
self.assertFalse(has_revision(br_a, br_b.revision_history()[6]))
52
self.assertTrue(br_a.repository.has_revision(br_b.revision_history()[5]))
58
self.assert_(has_revision(br_a, br_b.revision_history()[5]))
54
60
# When a non-branch ancestor is missing, it should be unlisted...
55
61
# as its not reference from the inventory weave.
56
br_b4 = self.make_branch('br_4')
62
br_b4 = new_branch('br_4')
57
63
count, failures = greedy_fetch(br_b4, br_b)
58
64
self.assertEqual(count, 7)
59
65
self.assertEqual(failures, [])
61
67
self.assertEqual(greedy_fetch(writable_a, br_b)[0], 1)
62
self.assertTrue(has_revision(br_a, br_b.revision_history()[3]))
63
self.assertTrue(has_revision(br_a, br_b.revision_history()[4]))
68
self.assert_(has_revision(br_a, br_b.revision_history()[3]))
69
self.assert_(has_revision(br_a, br_b.revision_history()[4]))
65
br_b2 = self.make_branch('br_b2')
71
br_b2 = new_branch('br_b2')
66
72
self.assertEquals(greedy_fetch(br_b2, br_b)[0], 7)
67
self.assertTrue(has_revision(br_b2, br_b.revision_history()[4]))
68
self.assertTrue(has_revision(br_b2, br_a.revision_history()[2]))
73
self.assert_(has_revision(br_b2, br_b.revision_history()[4]))
74
self.assert_(has_revision(br_b2, br_a.revision_history()[2]))
69
75
self.assertFalse(has_revision(br_b2, br_a.revision_history()[3]))
71
br_a2 = self.make_branch('br_a2')
77
br_a2 = new_branch('br_a2')
72
78
self.assertEquals(greedy_fetch(br_a2, br_a)[0], 9)
73
self.assertTrue(has_revision(br_a2, br_b.revision_history()[4]))
74
self.assertTrue(has_revision(br_a2, br_a.revision_history()[3]))
75
self.assertTrue(has_revision(br_a2, br_a.revision_history()[2]))
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]))
77
br_a3 = self.make_branch('br_a3')
78
# pulling a branch with no revisions grabs nothing, regardless of
79
# whats in the inventory.
83
br_a3 = new_branch('br_a3')
80
84
self.assertEquals(greedy_fetch(br_a3, br_a2)[0], 0)
81
85
for revno in range(4):
83
br_a3.repository.has_revision(br_a.revision_history()[revno]))
86
self.assertFalse(has_revision(br_a3, br_a.revision_history()[revno]))
84
87
self.assertEqual(greedy_fetch(br_a3, br_a2, br_a.revision_history()[2])[0], 3)
85
# pull the 3 revisions introduced by a@u-0-3
86
88
fetched = greedy_fetch(br_a3, br_a2, br_a.revision_history()[3])[0]
87
self.assertEquals(fetched, 3, "fetched %d instead of 3" % fetched)
89
self.assertEquals(fetched, 6, "fetched %d instead of 6" % fetched)
88
90
# InstallFailed should be raised if the branch is missing the revision
89
91
# that was requested.
90
92
self.assertRaises(bzrlib.errors.InstallFailed, greedy_fetch, br_a3,
186
185
def test_fetch(self):
187
186
#highest indices a: 5, b: 7
187
print "TestHttpFetch.test_fetch disabled during transition."
188
189
br_a, br_b = make_branches(self)
189
br_rem_a = Branch.open(self.get_readonly_url('branch1'))
190
br_rem_a = Branch.open(self.get_remote_url(br_a.base))
190
191
fetch_steps(self, br_rem_a, br_b, br_a)
192
193
def test_weaves_are_retrieved_once(self):
193
194
self.build_tree(("source/", "source/file", "target/"))
194
wt = self.make_branch_and_tree('source')
195
wt = WorkingTree.create_standalone('source')
195
196
branch = wt.branch
196
197
wt.add(["file"], ["id"])
197
198
wt.commit("added file")
198
199
print >>open("source/file", 'w'), "blah"
199
200
wt.commit("changed file")
200
target = BzrDir.create_branch_and_repo("target/")
201
source = Branch.open(self.get_readonly_url("source/"))
201
target = Branch.create("target/")
202
source = Branch.open(self.get_remote_url("source/"))
202
203
self.assertEqual(greedy_fetch(target, source), (2, []))
203
204
# this is the path to the literal file. As format changes
204
205
# occur it needs to be updated. FIXME: ask the store for the
206
207
weave_suffix = 'weaves/ce/id.weave HTTP/1.1" 200 -'
207
208
self.assertEqual(1,
208
len([log for log in self.get_readonly_server().logs if log.endswith(weave_suffix)]))
209
len([log for log in self.server.logs if log.endswith(weave_suffix)]))
209
210
inventory_weave_suffix = 'inventory.weave HTTP/1.1" 200 -'
210
211
self.assertEqual(1,
211
len([log for log in self.get_readonly_server().logs if log.endswith(
212
len([log for log in self.server.logs if log.endswith(
212
213
inventory_weave_suffix)]))
213
214
# this r-h check test will prevent regressions, but it currently already
214
215
# passes, before the patch to cache-rh is applied :[
215
216
revision_history_suffix = 'revision-history HTTP/1.1" 200 -'
216
217
self.assertEqual(1,
217
len([log for log in self.get_readonly_server().logs if log.endswith(
218
len([log for log in self.server.logs if log.endswith(
218
219
revision_history_suffix)]))
219
220
# FIXME naughty poking in there.
220
self.get_readonly_server().logs = []
221
self.server.logs = []
221
222
# check there is nothing more to fetch
222
source = Branch.open(self.get_readonly_url("source/"))
223
source = Branch.open(self.get_remote_url("source/"))
223
224
self.assertEqual(greedy_fetch(target, source), (0, []))
224
self.failUnless(self.get_readonly_server().logs[0].endswith('branch-format HTTP/1.1" 200 -'))
225
self.failUnless(self.get_readonly_server().logs[1].endswith('revision-history HTTP/1.1" 200 -'))
226
self.assertEqual(2, len(self.get_readonly_server().logs))
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))