48
47
def fetch_steps(self, br_a, br_b, writable_a):
49
48
"""A foreign test method for testing fetch locally and remotely."""
51
50
# TODO RBC 20060201 make this a repository test.
52
51
repo_b = br_b.repository
53
52
self.assertFalse(repo_b.has_revision(br_a.revision_history()[3]))
54
53
self.assertTrue(repo_b.has_revision(br_a.revision_history()[2]))
55
54
self.assertEquals(len(br_b.revision_history()), 7)
56
self.assertEquals(br_b.fetch(br_a, br_a.revision_history()[2])[0], 0)
55
br_b.fetch(br_a, br_a.revision_history()[2])
57
56
# branch.fetch is not supposed to alter the revision history
58
57
self.assertEquals(len(br_b.revision_history()), 7)
59
58
self.assertFalse(repo_b.has_revision(br_a.revision_history()[3]))
61
60
# fetching the next revision up in sample data copies one revision
62
self.assertEquals(br_b.fetch(br_a, br_a.revision_history()[3])[0], 1)
61
br_b.fetch(br_a, br_a.revision_history()[3])
63
62
self.assertTrue(repo_b.has_revision(br_a.revision_history()[3]))
64
63
self.assertFalse(has_revision(br_a, br_b.revision_history()[6]))
65
64
self.assertTrue(br_a.repository.has_revision(br_b.revision_history()[5]))
67
66
# When a non-branch ancestor is missing, it should be unlisted...
68
67
# as its not reference from the inventory weave.
69
68
br_b4 = self.make_branch('br_4')
70
count, failures = br_b4.fetch(br_b)
71
self.assertEqual(count, 7)
72
self.assertEqual(failures, [])
74
self.assertEqual(writable_a.fetch(br_b)[0], 1)
71
writable_a.fetch(br_b)
75
72
self.assertTrue(has_revision(br_a, br_b.revision_history()[3]))
76
73
self.assertTrue(has_revision(br_a, br_b.revision_history()[4]))
78
75
br_b2 = self.make_branch('br_b2')
79
self.assertEquals(br_b2.fetch(br_b)[0], 7)
80
77
self.assertTrue(has_revision(br_b2, br_b.revision_history()[4]))
81
78
self.assertTrue(has_revision(br_b2, br_a.revision_history()[2]))
82
79
self.assertFalse(has_revision(br_b2, br_a.revision_history()[3]))
84
81
br_a2 = self.make_branch('br_a2')
85
self.assertEquals(br_a2.fetch(br_a)[0], 9)
86
83
self.assertTrue(has_revision(br_a2, br_b.revision_history()[4]))
87
84
self.assertTrue(has_revision(br_a2, br_a.revision_history()[3]))
88
85
self.assertTrue(has_revision(br_a2, br_a.revision_history()[2]))
90
87
br_a3 = self.make_branch('br_a3')
91
# pulling a branch with no revisions grabs nothing, regardless of
88
# pulling a branch with no revisions grabs nothing, regardless of
92
89
# whats in the inventory.
93
self.assertEquals(br_a3.fetch(br_a2)[0], 0)
94
91
for revno in range(4):
96
93
br_a3.repository.has_revision(br_a.revision_history()[revno]))
97
self.assertEqual(br_a3.fetch(br_a2, br_a.revision_history()[2])[0], 3)
94
br_a3.fetch(br_a2, br_a.revision_history()[2])
98
95
# pull the 3 revisions introduced by a@u-0-3
99
fetched = br_a3.fetch(br_a2, br_a.revision_history()[3])[0]
100
self.assertEquals(fetched, 3, "fetched %d instead of 3" % fetched)
101
# InstallFailed should be raised if the branch is missing the revision
96
br_a3.fetch(br_a2, br_a.revision_history()[3])
97
# NoSuchRevision should be raised if the branch is missing the revision
102
98
# that was requested.
103
self.assertRaises(errors.InstallFailed, br_a3.fetch, br_a2, 'pizza')
99
self.assertRaises(errors.NoSuchRevision, br_a3.fetch, br_a2, 'pizza')
105
101
# TODO: Test trying to fetch from a branch that points to a revision not
106
102
# actually present in its repository. Not every branch format allows you
251
247
rev_id).get_file_text('this-file-id'), text)
254
class TestHttpFetch(TestCaseWithWebserver):
255
# FIXME RBC 20060124 this really isn't web specific, perhaps an
256
# instrumented readonly transport? Can we do an instrumented
257
# adapter and use self.get_readonly_url ?
259
def test_fetch(self):
260
#highest indices a: 5, b: 7
261
br_a, br_b = make_branches(self)
262
br_rem_a = Branch.open(self.get_readonly_url('branch1'))
263
fetch_steps(self, br_rem_a, br_b, br_a)
265
def _count_log_matches(self, target, logs):
266
"""Count the number of times the target file pattern was fetched in an http log"""
267
get_succeeds_re = re.compile(
268
'.*"GET .*%s HTTP/1.1" 20[06] - "-" "bzr/%s' %
269
( target, bzrlib.__version__))
272
if get_succeeds_re.match(line):
276
def test_weaves_are_retrieved_once(self):
277
self.build_tree(("source/", "source/file", "target/"))
278
# This test depends on knit dasta storage.
279
wt = self.make_branch_and_tree('source', format='dirstate-tags')
281
wt.add(["file"], ["id"])
282
wt.commit("added file")
283
open("source/file", 'w').write("blah\n")
284
wt.commit("changed file")
285
target = BzrDir.create_branch_and_repo("target/")
286
source = Branch.open(self.get_readonly_url("source/"))
287
self.assertEqual(target.fetch(source), (2, []))
288
# this is the path to the literal file. As format changes
289
# occur it needs to be updated. FIXME: ask the store for the
291
self.log("web server logs are:")
292
http_logs = self.get_readonly_server().logs
293
self.log('\n'.join(http_logs))
294
# unfortunately this log entry is branch format specific. We could
295
# factor out the 'what files does this format use' to a method on the
296
# repository, which would let us to this generically. RBC 20060419
297
# RBC 20080408: Or perhaps we can assert that no files are fully read
299
self.assertEqual(1, self._count_log_matches('/ce/id.kndx', http_logs))
300
self.assertEqual(1, self._count_log_matches('/ce/id.knit', http_logs))
301
self.assertEqual(1, self._count_log_matches('inventory.kndx', http_logs))
302
# this r-h check test will prevent regressions, but it currently already
303
# passes, before the patch to cache-rh is applied :[
304
self.assertTrue(1 >= self._count_log_matches('revision-history',
306
self.assertTrue(1 >= self._count_log_matches('last-revision',
308
# FIXME naughty poking in there.
309
self.get_readonly_server().logs = []
310
# check there is nothing more to fetch. We take care to re-use the
311
# existing transport so that the request logs we're about to examine
312
# aren't cluttered with redundant probes for a smart server.
313
# XXX: Perhaps this further parameterisation: test http with smart
314
# server, and test http without smart server?
315
source = Branch.open(
316
self.get_readonly_url("source/"),
317
possible_transports=[source.bzrdir.root_transport])
318
self.assertEqual(target.fetch(source), (0, []))
319
# should make just two requests
320
http_logs = self.get_readonly_server().logs
321
self.log("web server logs are:")
322
self.log('\n'.join(http_logs))
323
self.assertEqual(1, self._count_log_matches('branch-format', http_logs))
324
self.assertEqual(1, self._count_log_matches('branch/format', http_logs))
325
self.assertEqual(1, self._count_log_matches('repository/format',
327
self.assertTrue(1 >= self._count_log_matches('revision-history',
329
self.assertTrue(1 >= self._count_log_matches('last-revision',
331
self.assertEqual(4, len(http_logs))
334
250
class TestKnitToPackFetch(TestCaseWithTransport):
336
def find_get_record_stream(self, calls):
337
"""In a list of calls, find 'get_record_stream' calls.
252
def find_get_record_stream(self, calls, expected_count=1):
253
"""In a list of calls, find the last 'get_record_stream'.
339
This also ensures that there is only one get_record_stream call.
255
:param expected_count: The number of calls we should exepect to find.
256
If a different number is found, an assertion is raised.
341
258
get_record_call = None
342
260
for call in calls:
343
261
if call[0] == 'get_record_stream':
344
self.assertIs(None, get_record_call,
345
"there should only be one call to"
346
" get_record_stream")
347
263
get_record_call = call
348
self.assertIsNot(None, get_record_call,
349
"there should be exactly one call to "
350
" get_record_stream")
264
self.assertEqual(expected_count, call_count)
351
265
return get_record_call
353
267
def test_fetch_with_deltas_no_delta_closure(self):
367
281
source.inventories = versionedfile.RecordingVersionedFilesDecorator(
368
282
source.inventories)
370
self.assertTrue(target._fetch_uses_deltas)
284
self.assertTrue(target._format._fetch_uses_deltas)
371
285
target.fetch(source, revision_id='rev-one')
372
286
self.assertEqual(('get_record_stream', [('file-id', 'rev-one')],
373
target._fetch_order, False),
287
target._format._fetch_order, False),
374
288
self.find_get_record_stream(source.texts.calls))
375
289
self.assertEqual(('get_record_stream', [('rev-one',)],
376
target._fetch_order, False),
377
self.find_get_record_stream(source.inventories.calls))
290
target._format._fetch_order, False),
291
self.find_get_record_stream(source.inventories.calls, 2))
378
292
self.assertEqual(('get_record_stream', [('rev-one',)],
379
target._fetch_order, False),
293
target._format._fetch_order, False),
380
294
self.find_get_record_stream(source.revisions.calls))
381
295
# XXX: Signatures is special, and slightly broken. The
382
296
# standard item_keys_introduced_by actually does a lookup for every
406
320
source.revisions)
407
321
source.inventories = versionedfile.RecordingVersionedFilesDecorator(
408
322
source.inventories)
409
target._fetch_uses_deltas = False
323
# XXX: This won't work in general, but for the dirstate format it does.
324
self.overrideAttr(target._format, '_fetch_uses_deltas', False)
410
325
target.fetch(source, revision_id='rev-one')
411
326
self.assertEqual(('get_record_stream', [('file-id', 'rev-one')],
412
target._fetch_order, True),
327
target._format._fetch_order, True),
413
328
self.find_get_record_stream(source.texts.calls))
414
329
self.assertEqual(('get_record_stream', [('rev-one',)],
415
target._fetch_order, True),
416
self.find_get_record_stream(source.inventories.calls))
330
target._format._fetch_order, True),
331
self.find_get_record_stream(source.inventories.calls, 2))
417
332
self.assertEqual(('get_record_stream', [('rev-one',)],
418
target._fetch_order, True),
333
target._format._fetch_order, True),
419
334
self.find_get_record_stream(source.revisions.calls))
420
335
# XXX: Signatures is special, and slightly broken. The
421
336
# standard item_keys_introduced_by actually does a lookup for every