tests/test-bundle2.t
changeset 20997 d7df4b7378ae
parent 20995 e995d104c87f
child 20998 93a3c5b58635
equal deleted inserted replaced
20996:ed3c5e18a047 20997:d7df4b7378ae
    30   >     verses = 0
    30   >     verses = 0
    31   >     for line in part.data.split('\n'):
    31   >     for line in part.data.split('\n'):
    32   >         op.ui.write('    %s\n' % line)
    32   >         op.ui.write('    %s\n' % line)
    33   >         verses += 1
    33   >         verses += 1
    34   >     op.records.add('song', {'verses': verses})
    34   >     op.records.add('song', {'verses': verses})
       
    35   > 
       
    36   > @bundle2.parthandler('test:ping')
       
    37   > def pinghandler(op, part):
       
    38   >     op.ui.write('received ping request (id %i)\n' % part.id)
       
    39   >     if op.reply is not None:
       
    40   >         op.reply.addpart(bundle2.part('test:pong',
       
    41   >                                       [('in-reply-to', str(part.id))]))
    35   > 
    42   > 
    36   > @command('bundle2',
    43   > @command('bundle2',
    37   >          [('', 'param', [], 'stream level parameter'),
    44   >          [('', 'param', [], 'stream level parameter'),
    38   >           ('', 'unknown', False, 'include an unknown mandatory part in the bundle'),
    45   >           ('', 'unknown', False, 'include an unknown mandatory part in the bundle'),
    39   >           ('', 'parts', False, 'include some arbitrary parts to the bundle'),
    46   >           ('', 'parts', False, 'include some arbitrary parts to the bundle'),
    81   >        bundler.addpart(part)
    88   >        bundler.addpart(part)
    82   >     if opts['unknown']:
    89   >     if opts['unknown']:
    83   >        part = bundle2.part('test:UNKNOWN',
    90   >        part = bundle2.part('test:UNKNOWN',
    84   >                            data='some random content')
    91   >                            data='some random content')
    85   >        bundler.addpart(part)
    92   >        bundler.addpart(part)
       
    93   >     if opts['parts']:
       
    94   >        part = bundle2.part('test:ping')
       
    95   >        bundler.addpart(part)
    86   > 
    96   > 
    87   >     if path is None:
    97   >     if path is None:
    88   >        file = sys.stdout
    98   >        file = sys.stdout
    89   >     else:
    99   >     else:
    90   >         file = open(path, 'w')
   100   >         file = open(path, 'w')
    91   > 
   101   > 
    92   >     for chunk in bundler.getchunks():
   102   >     for chunk in bundler.getchunks():
    93   >         file.write(chunk)
   103   >         file.write(chunk)
    94   > 
   104   > 
    95   > @command('unbundle2', [], '')
   105   > @command('unbundle2', [], '')
    96   > def cmdunbundle2(ui, repo):
   106   > def cmdunbundle2(ui, repo, replypath=None):
    97   >     """process a bundle2 stream from stdin on the current repo"""
   107   >     """process a bundle2 stream from stdin on the current repo"""
    98   >     try:
   108   >     try:
    99   >         tr = None
   109   >         tr = None
   100   >         lock = repo.lock()
   110   >         lock = repo.lock()
   101   >         tr = repo.transaction('processbundle')
   111   >         tr = repo.transaction('processbundle')
   114   >     if op.records['song']:
   124   >     if op.records['song']:
   115   >         totalverses = sum(r['verses'] for r in op.records['song'])
   125   >         totalverses = sum(r['verses'] for r in op.records['song'])
   116   >         ui.write('%i total verses sung\n' % totalverses)
   126   >         ui.write('%i total verses sung\n' % totalverses)
   117   >     for rec in op.records['changegroup']:
   127   >     for rec in op.records['changegroup']:
   118   >         ui.write('addchangegroup return: %i\n' % rec['return'])
   128   >         ui.write('addchangegroup return: %i\n' % rec['return'])
       
   129   >     if op.reply is not None and replypath is not None:
       
   130   >         file = open(replypath, 'w')
       
   131   >         for chunk in op.reply.getchunks():
       
   132   >             file.write(chunk)
   119   > 
   133   > 
   120   > @command('statbundle2', [], '')
   134   > @command('statbundle2', [], '')
   121   > def cmdstatbundle2(ui, repo):
   135   > def cmdstatbundle2(ui, repo):
   122   >     """print statistic on the bundle2 container read from stdin"""
   136   >     """print statistic on the bundle2 container read from stdin"""
   123   >     unbundler = bundle2.unbundle20(ui, sys.stdin)
   137   >     unbundler = bundle2.unbundle20(ui, sys.stdin)
   316   start of parts
   330   start of parts
   317   bundle part: "test:empty"
   331   bundle part: "test:empty"
   318   bundle part: "test:empty"
   332   bundle part: "test:empty"
   319   bundle part: "test:song"
   333   bundle part: "test:song"
   320   bundle part: "test:math"
   334   bundle part: "test:math"
       
   335   bundle part: "test:ping"
   321   end of bundle
   336   end of bundle
   322 
   337 
   323   $ cat ../parts.hg2
   338   $ cat ../parts.hg2
   324   HG20\x00\x00\x00\x11 (esc)
   339   HG20\x00\x00\x00\x11 (esc)
   325   test:empty\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x11 (esc)
   340   test:empty\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x11 (esc)
   326   test:empty\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x10	test:song\x00\x00\x00\x02\x00\x00\x00\x00\x00\xb2Patali Dirapata, Cromda Cromda Ripalo, Pata Pata, Ko Ko Ko (esc)
   341   test:empty\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x10	test:song\x00\x00\x00\x02\x00\x00\x00\x00\x00\xb2Patali Dirapata, Cromda Cromda Ripalo, Pata Pata, Ko Ko Ko (esc)
   327   Bokoro Dipoulito, Rondi Rondi Pepino, Pata Pata, Ko Ko Ko
   342   Bokoro Dipoulito, Rondi Rondi Pepino, Pata Pata, Ko Ko Ko
   328   Emana Karassoli, Loucra Loucra Ponponto, Pata Pata, Ko Ko Ko.\x00\x00\x00\x00\x00+	test:math\x00\x00\x00\x03\x02\x01\x02\x04\x01\x04\x07\x03pi3.14e2.72cookingraw\x00\x00\x00\x0242\x00\x00\x00\x00\x00\x00 (no-eol) (esc)
   343   Emana Karassoli, Loucra Loucra Ponponto, Pata Pata, Ko Ko Ko.\x00\x00\x00\x00\x00+	test:math\x00\x00\x00\x03\x02\x01\x02\x04\x01\x04\x07\x03pi3.14e2.72cookingraw\x00\x00\x00\x0242\x00\x00\x00\x00\x00\x10	test:ping\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00 (no-eol) (esc)
   329 
   344 
   330 
   345 
   331   $ hg statbundle2 < ../parts.hg2
   346   $ hg statbundle2 < ../parts.hg2
   332   options count: 0
   347   options count: 0
   333   parts count:   4
   348   parts count:   5
   334     :test:empty:
   349     :test:empty:
   335       mandatory: 0
   350       mandatory: 0
   336       advisory: 0
   351       advisory: 0
   337       payload: 0 bytes
   352       payload: 0 bytes
   338     :test:empty:
   353     :test:empty:
   345       payload: 178 bytes
   360       payload: 178 bytes
   346     :test:math:
   361     :test:math:
   347       mandatory: 2
   362       mandatory: 2
   348       advisory: 1
   363       advisory: 1
   349       payload: 2 bytes
   364       payload: 2 bytes
       
   365     :test:ping:
       
   366       mandatory: 0
       
   367       advisory: 0
       
   368       payload: 0 bytes
   350 
   369 
   351   $ hg statbundle2 --debug < ../parts.hg2
   370   $ hg statbundle2 --debug < ../parts.hg2
   352   start processing of HG20 stream
   371   start processing of HG20 stream
   353   reading bundle2 stream parameters
   372   reading bundle2 stream parameters
   354   options count: 0
   373   options count: 0
   373   part type: "test:math"
   392   part type: "test:math"
   374   part id: "3"
   393   part id: "3"
   375   part parameters: 3
   394   part parameters: 3
   376   payload chunk size: 2
   395   payload chunk size: 2
   377   payload chunk size: 0
   396   payload chunk size: 0
       
   397   part header size: 16
       
   398   part type: "test:ping"
       
   399   part id: "4"
       
   400   part parameters: 0
       
   401   payload chunk size: 0
   378   part header size: 0
   402   part header size: 0
   379   end of bundle2 stream
   403   end of bundle2 stream
   380   parts count:   4
   404   parts count:   5
   381     :test:empty:
   405     :test:empty:
   382       mandatory: 0
   406       mandatory: 0
   383       advisory: 0
   407       advisory: 0
   384       payload: 0 bytes
   408       payload: 0 bytes
   385     :test:empty:
   409     :test:empty:
   392       payload: 178 bytes
   416       payload: 178 bytes
   393     :test:math:
   417     :test:math:
   394       mandatory: 2
   418       mandatory: 2
   395       advisory: 1
   419       advisory: 1
   396       payload: 2 bytes
   420       payload: 2 bytes
       
   421     :test:ping:
       
   422       mandatory: 0
       
   423       advisory: 0
       
   424       payload: 0 bytes
   397 
   425 
   398 Test actual unbundling of test part
   426 Test actual unbundling of test part
   399 =======================================
   427 =======================================
   400 
   428 
   401 Process the bundle
   429 Process the bundle
   432   part id: "3"
   460   part id: "3"
   433   part parameters: 3
   461   part parameters: 3
   434   payload chunk size: 2
   462   payload chunk size: 2
   435   payload chunk size: 0
   463   payload chunk size: 0
   436   ignoring unknown advisory part 'test:math'
   464   ignoring unknown advisory part 'test:math'
       
   465   part header size: 16
       
   466   part type: "test:ping"
       
   467   part id: "4"
       
   468   part parameters: 0
       
   469   payload chunk size: 0
       
   470   found a handler for part 'test:ping'
       
   471   received ping request (id 4)
   437   part header size: 0
   472   part header size: 0
   438   end of bundle2 stream
   473   end of bundle2 stream
   439   0 unread bytes
   474   0 unread bytes
   440   3 total verses sung
   475   3 total verses sung
   441 
   476 
       
   477 Unbundle with an unknown mandatory part
       
   478 (should abort)
   442 
   479 
   443   $ hg bundle2 --parts --unknown ../unknown.hg2
   480   $ hg bundle2 --parts --unknown ../unknown.hg2
   444 
   481 
   445   $ hg unbundle2 < ../unknown.hg2
   482   $ hg unbundle2 < ../unknown.hg2
   446   The choir starts singing:
   483   The choir starts singing:
   448       Bokoro Dipoulito, Rondi Rondi Pepino, Pata Pata, Ko Ko Ko
   485       Bokoro Dipoulito, Rondi Rondi Pepino, Pata Pata, Ko Ko Ko
   449       Emana Karassoli, Loucra Loucra Ponponto, Pata Pata, Ko Ko Ko.
   486       Emana Karassoli, Loucra Loucra Ponponto, Pata Pata, Ko Ko Ko.
   450   0 unread bytes
   487   0 unread bytes
   451   abort: missing support for 'test:unknown'
   488   abort: missing support for 'test:unknown'
   452   [255]
   489   [255]
       
   490 
       
   491 unbundle with a reply
       
   492 
       
   493   $ hg unbundle2 ../reply.hg2 < ../parts.hg2
       
   494   The choir starts singing:
       
   495       Patali Dirapata, Cromda Cromda Ripalo, Pata Pata, Ko Ko Ko
       
   496       Bokoro Dipoulito, Rondi Rondi Pepino, Pata Pata, Ko Ko Ko
       
   497       Emana Karassoli, Loucra Loucra Ponponto, Pata Pata, Ko Ko Ko.
       
   498   received ping request (id 4)
       
   499   0 unread bytes
       
   500   3 total verses sung
       
   501 
       
   502 The reply is a bundle
       
   503 
       
   504   $ cat ../reply.hg2
       
   505   HG20\x00\x00\x00\x1e	test:pong\x00\x00\x00\x00\x01\x00\x0b\x01in-reply-to4\x00\x00\x00\x00\x00\x00 (no-eol) (esc)
       
   506 
       
   507 The reply is valid
       
   508 
       
   509   $ hg statbundle2 < ../reply.hg2
       
   510   options count: 0
       
   511   parts count:   1
       
   512     :test:pong:
       
   513       mandatory: 1
       
   514       advisory: 0
       
   515       payload: 0 bytes
   453 
   516 
   454 Support for changegroup
   517 Support for changegroup
   455 ===================================
   518 ===================================
   456 
   519 
   457   $ hg unbundle $TESTDIR/bundles/rebase.hg
   520   $ hg unbundle $TESTDIR/bundles/rebase.hg