2222
2222
# revision, then open it over hpss - we should be able to see that
2224
2224
base_transport = self.get_transport()
2225
base_builder = self.make_branch_builder('base', format='1.6')
2225
base_builder = self.make_branch_builder('base', format='1.9')
2226
2226
base_builder.start_series()
2227
2227
base_revid = base_builder.build_snapshot('rev-id', None,
2228
2228
[('add', ('', None, 'directory', None))],
2230
2230
base_builder.finish_series()
2231
stacked_branch = self.make_branch('stacked', format='1.6')
2231
stacked_branch = self.make_branch('stacked', format='1.9')
2232
2232
stacked_branch.set_stacked_on_url('../base')
2233
2233
# start a server looking at this
2234
2234
smart_server = server.SmartTCPServer_for_testing()
2255
2255
remote_repo.unlock()
2257
2257
def prepare_stacked_remote_branch(self):
2258
smart_server = server.SmartTCPServer_for_testing()
2259
smart_server.setUp()
2260
self.addCleanup(smart_server.tearDown)
2261
tree1 = self.make_branch_and_tree('tree1')
2258
"""Get stacked_upon and stacked branches with content in each."""
2259
self.setup_smart_server_with_call_log()
2260
tree1 = self.make_branch_and_tree('tree1', format='1.9')
2262
2261
tree1.commit('rev1', rev_id='rev1')
2263
tree2 = self.make_branch_and_tree('tree2', format='1.6')
2264
tree2.branch.set_stacked_on_url(tree1.branch.base)
2265
branch2 = Branch.open(smart_server.get_url() + '/tree2')
2262
tree2 = tree1.branch.bzrdir.sprout('tree2', stacked=True
2263
).open_workingtree()
2264
tree2.commit('local changes make me feel good.')
2265
branch2 = Branch.open(self.get_url('tree2'))
2266
2266
branch2.lock_read()
2267
2267
self.addCleanup(branch2.unlock)
2268
return tree1.branch, branch2
2270
2270
def test_stacked_get_parent_map(self):
2271
2271
# the public implementation of get_parent_map obeys stacking
2272
branch = self.prepare_stacked_remote_branch()
2272
_, branch = self.prepare_stacked_remote_branch()
2273
2273
repo = branch.repository
2274
2274
self.assertEqual(['rev1'], repo.get_parent_map(['rev1']).keys())
2276
2276
def test_unstacked_get_parent_map(self):
2277
2277
# _unstacked_provider.get_parent_map ignores stacking
2278
branch = self.prepare_stacked_remote_branch()
2278
_, branch = self.prepare_stacked_remote_branch()
2279
2279
provider = branch.repository._unstacked_provider
2280
2280
self.assertEqual([], provider.get_parent_map(['rev1']).keys())
2282
def fetch_stream_to_rev_order(self, stream):
2284
for kind, substream in stream:
2285
if not kind == 'revisions':
2288
for content in substream:
2289
result.append(content.key[-1])
2292
def get_ordered_revs(self, format, order):
2293
"""Get a list of the revisions in a stream to format format.
2295
:param format: The format of the target.
2296
:param order: the order that target should have requested.
2297
:result: The revision ids in the stream, in the order seen,
2298
the topological order of revisions in the source.
2300
unordered_format = bzrdir.format_registry.get(format)()
2301
target_repository_format = unordered_format.repository_format
2303
self.assertEqual(order, target_repository_format._fetch_order)
2304
trunk, stacked = self.prepare_stacked_remote_branch()
2305
source = stacked.repository._get_source(target_repository_format)
2306
tip = stacked.last_revision()
2307
revs = stacked.repository.get_ancestry(tip)
2308
search = graph.PendingAncestryResult([tip], stacked.repository)
2309
self.reset_smart_call_log()
2310
stream = source.get_stream(search)
2313
# We trust that if a revision is in the stream the rest of the new
2314
# content for it is too, as per our main fetch tests; here we are
2315
# checking that the revisions are actually included at all, and their
2317
return self.fetch_stream_to_rev_order(stream), revs
2319
def test_stacked_get_stream_unordered(self):
2320
# Repository._get_source.get_stream() from a stacked repository with
2321
# unordered yields the full data from both stacked and stacked upon
2323
rev_ord, expected_revs = self.get_ordered_revs('1.9', 'unordered')
2324
self.assertEqual(set(expected_revs), set(rev_ord))
2325
# Getting unordered results should have made a streaming data request
2326
# from the server, then one from the backing branch.
2327
self.assertLength(2, self.hpss_calls)
2329
def test_stacked_get_stream_topological(self):
2330
# Repository._get_source.get_stream() from a stacked repository with
2331
# topological sorting yields the full data from both stacked and
2332
# stacked upon sources in topological order.
2333
rev_ord, expected_revs = self.get_ordered_revs('knit', 'topological')
2334
self.assertEqual(expected_revs, rev_ord)
2335
# Getting topological sort requires VFS calls still
2336
self.assertLength(14, self.hpss_calls)
2338
def test_stacked_get_stream_groupcompress(self):
2339
# Repository._get_source.get_stream() from a stacked repository with
2340
# groupcompress sorting yields the full data from both stacked and
2341
# stacked upon sources in groupcompress order.
2342
raise tests.TestSkipped('No groupcompress ordered format available')
2343
rev_ord, expected_revs = self.get_ordered_revs('dev5', 'groupcompress')
2344
self.assertEqual(expected_revs, reversed(rev_ord))
2345
# Getting unordered results should have made a streaming data request
2346
# from the backing branch, and one from the stacked on branch.
2347
self.assertLength(2, self.hpss_calls)
2283
2350
class TestRemoteBranchEffort(tests.TestCaseWithTransport):