Mercurial > hg
comparison tests/test-bundle2.t @ 20876:ddd56f3eb786
bundle2: support for bundling and unbundling payload
We add the ability to bundle and unbundle a payload in parts. The payload is the
actual binary data of the part. It is used to convey all the applicative data.
For now we stick to very simple implementation with all the data fit in single
chunk. This open the door to some bundle2 testing usage. This will be improved before
bundle2 get used for real. We need to be able to stream the payload in multiple
part to exchange any changegroup efficiently. This simple version will do for
now.
Bundling and unbundling are done in the same changeset because the test for
parts is less modular. However, the result is not too complex.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Wed, 19 Mar 2014 23:36:15 -0700 |
parents | 9a75d2559cff |
children | 9e9e3a4e9261 |
comparison
equal
deleted
inserted
replaced
20875:cc62c9d6887a | 20876:ddd56f3eb786 |
---|---|
12 > from mercurial import cmdutil | 12 > from mercurial import cmdutil |
13 > from mercurial import util | 13 > from mercurial import util |
14 > from mercurial import bundle2 | 14 > from mercurial import bundle2 |
15 > cmdtable = {} | 15 > cmdtable = {} |
16 > command = cmdutil.command(cmdtable) | 16 > command = cmdutil.command(cmdtable) |
17 > | |
18 > ELEPHANTSSONG = """Patali Dirapata, Cromda Cromda Ripalo, Pata Pata, Ko Ko Ko | |
19 > Bokoro Dipoulito, Rondi Rondi Pepino, Pata Pata, Ko Ko Ko | |
20 > Emana Karassoli, Loucra Loucra Ponponto, Pata Pata, Ko Ko Ko.""" | |
21 > assert len(ELEPHANTSSONG) == 178 # future test say 178 bytes, trust it. | |
17 > | 22 > |
18 > @command('bundle2', | 23 > @command('bundle2', |
19 > [('', 'param', [], 'stream level parameter'), | 24 > [('', 'param', [], 'stream level parameter'), |
20 > ('', 'parts', False, 'include some arbitrary parts to the bundle'),], | 25 > ('', 'parts', False, 'include some arbitrary parts to the bundle'),], |
21 > '[OUTPUTFILE]') | 26 > '[OUTPUTFILE]') |
32 > if opts['parts']: | 37 > if opts['parts']: |
33 > part = bundle2.part('test:empty') | 38 > part = bundle2.part('test:empty') |
34 > bundler.addpart(part) | 39 > bundler.addpart(part) |
35 > # add a second one to make sure we handle multiple parts | 40 > # add a second one to make sure we handle multiple parts |
36 > part = bundle2.part('test:empty') | 41 > part = bundle2.part('test:empty') |
42 > bundler.addpart(part) | |
43 > part = bundle2.part('test:song', data=ELEPHANTSSONG) | |
37 > bundler.addpart(part) | 44 > bundler.addpart(part) |
38 > | 45 > |
39 > if path is None: | 46 > if path is None: |
40 > file = sys.stdout | 47 > file = sys.stdout |
41 > else: | 48 > else: |
60 > ui.write(' %s\n' % value) | 67 > ui.write(' %s\n' % value) |
61 > parts = list(unbundler) | 68 > parts = list(unbundler) |
62 > ui.write('parts count: %i\n' % len(parts)) | 69 > ui.write('parts count: %i\n' % len(parts)) |
63 > for p in parts: | 70 > for p in parts: |
64 > ui.write(' :%s:\n' % p.type) | 71 > ui.write(' :%s:\n' % p.type) |
72 > ui.write(' payload: %i bytes\n' % len(p.data)) | |
65 > EOF | 73 > EOF |
66 $ cat >> $HGRCPATH << EOF | 74 $ cat >> $HGRCPATH << EOF |
67 > [extensions] | 75 > [extensions] |
68 > bundle2=$TESTTMP/bundle2.py | 76 > bundle2=$TESTTMP/bundle2.py |
69 > EOF | 77 > EOF |
236 start emission of HG20 stream | 244 start emission of HG20 stream |
237 bundle parameter: | 245 bundle parameter: |
238 start of parts | 246 start of parts |
239 bundle part: "test:empty" | 247 bundle part: "test:empty" |
240 bundle part: "test:empty" | 248 bundle part: "test:empty" |
249 bundle part: "test:song" | |
241 end of bundle | 250 end of bundle |
242 | 251 |
243 $ cat ../parts.hg2 | 252 $ cat ../parts.hg2 |
244 HG20\x00\x00\x00\r (esc) | 253 HG20\x00\x00\x00\r (esc) |
245 test:empty\x00\x00\x00\x00\x00\x00\x00\r (esc) | 254 test:empty\x00\x00\x00\x00\x00\x00\x00\r (esc) |
246 test:empty\x00\x00\x00\x00\x00\x00\x00\x00 (no-eol) (esc) | 255 test:empty\x00\x00\x00\x00\x00\x00\x00\x0c test:song\x00\x00\x00\x00\x00\xb2Patali Dirapata, Cromda Cromda Ripalo, Pata Pata, Ko Ko Ko (esc) |
256 Bokoro Dipoulito, Rondi Rondi Pepino, Pata Pata, Ko Ko Ko | |
257 Emana Karassoli, Loucra Loucra Ponponto, Pata Pata, Ko Ko Ko.\x00\x00\x00\x00\x00\x00 (no-eol) (esc) | |
247 | 258 |
248 | 259 |
249 $ hg unbundle2 < ../parts.hg2 | 260 $ hg unbundle2 < ../parts.hg2 |
250 options count: 0 | 261 options count: 0 |
251 parts count: 2 | 262 parts count: 3 |
252 :test:empty: | 263 :test:empty: |
253 :test:empty: | 264 payload: 0 bytes |
265 :test:empty: | |
266 payload: 0 bytes | |
267 :test:song: | |
268 payload: 178 bytes | |
254 | 269 |
255 $ hg unbundle2 --debug < ../parts.hg2 | 270 $ hg unbundle2 --debug < ../parts.hg2 |
256 start processing of HG20 stream | 271 start processing of HG20 stream |
257 reading bundle2 stream parameters | 272 reading bundle2 stream parameters |
258 options count: 0 | 273 options count: 0 |
263 payload chunk size: 0 | 278 payload chunk size: 0 |
264 part header size: 13 | 279 part header size: 13 |
265 part type: "test:empty" | 280 part type: "test:empty" |
266 part parameters: 0 | 281 part parameters: 0 |
267 payload chunk size: 0 | 282 payload chunk size: 0 |
283 part header size: 12 | |
284 part type: "test:song" | |
285 part parameters: 0 | |
286 payload chunk size: 178 | |
287 payload chunk size: 0 | |
268 part header size: 0 | 288 part header size: 0 |
269 end of bundle2 stream | 289 end of bundle2 stream |
270 parts count: 2 | 290 parts count: 3 |
271 :test:empty: | 291 :test:empty: |
272 :test:empty: | 292 payload: 0 bytes |
293 :test:empty: | |
294 payload: 0 bytes | |
295 :test:song: | |
296 payload: 178 bytes |