comparison tests/test-batching.py @ 37615:f3dc8239e3a9

peer: scatter module to the wind (API) peer.py hardly contained any code. The code it did contain was generic to the version 1 peer interface or specific to the local repository peer. So code has been moved to wireprotov1peer and localrepo, as appropriate. Differential Revision: https://phab.mercurial-scm.org/D3260
author Gregory Szorc <gregory.szorc@gmail.com>
date Wed, 11 Apr 2018 12:51:09 -0700
parents a81d02ea65db
children 33a6eee08db2
comparison
equal deleted inserted replaced
37614:a81d02ea65db 37615:f3dc8239e3a9
7 7
8 from __future__ import absolute_import, print_function 8 from __future__ import absolute_import, print_function
9 9
10 from mercurial import ( 10 from mercurial import (
11 error, 11 error,
12 peer, 12 localrepo,
13 util, 13 util,
14 wireprotov1peer, 14 wireprotov1peer,
15
15 ) 16 )
16 17
17 # equivalent of repo.repository 18 # equivalent of repo.repository
18 class thing(object): 19 class thing(object):
19 def hello(self): 20 def hello(self):
29 return "%s und %s" % (b, a,) 30 return "%s und %s" % (b, a,)
30 def greet(self, name=None): 31 def greet(self, name=None):
31 return "Hello, %s" % name 32 return "Hello, %s" % name
32 def batchiter(self): 33 def batchiter(self):
33 '''Support for local batching.''' 34 '''Support for local batching.'''
34 return peer.localiterbatcher(self) 35 return localrepo.localiterbatcher(self)
35 36
36 # usage of "thing" interface 37 # usage of "thing" interface
37 def use(it): 38 def use(it):
38 39
39 # Direct call to base method shared between client and server. 40 # Direct call to base method shared between client and server.
49 foo = batch.foo(one="One", two="Two") 50 foo = batch.foo(one="One", two="Two")
50 bar = batch.bar("Eins", "Zwei") 51 bar = batch.bar("Eins", "Zwei")
51 bar2 = batch.bar(b="Uno", a="Due") 52 bar2 = batch.bar(b="Uno", a="Due")
52 53
53 # Future shouldn't be set until we submit(). 54 # Future shouldn't be set until we submit().
54 assert isinstance(foo, peer.future) 55 assert isinstance(foo, wireprotov1peer.future)
55 assert not util.safehasattr(foo, 'value') 56 assert not util.safehasattr(foo, 'value')
56 assert not util.safehasattr(bar, 'value') 57 assert not util.safehasattr(bar, 'value')
57 batch.submit() 58 batch.submit()
58 # Call results() to obtain results as a generator. 59 # Call results() to obtain results as a generator.
59 results = batch.results() 60 results = batch.results()
177 yield r 178 yield r
178 179
179 def batchiter(self): 180 def batchiter(self):
180 return wireprotov1peer.remoteiterbatcher(self) 181 return wireprotov1peer.remoteiterbatcher(self)
181 182
182 @peer.batchable 183 @wireprotov1peer.batchable
183 def foo(self, one, two=None): 184 def foo(self, one, two=None):
184 encargs = [('one', mangle(one),), ('two', mangle(two),)] 185 encargs = [('one', mangle(one),), ('two', mangle(two),)]
185 encresref = peer.future() 186 encresref = wireprotov1peer.future()
186 yield encargs, encresref 187 yield encargs, encresref
187 yield unmangle(encresref.value) 188 yield unmangle(encresref.value)
188 189
189 @peer.batchable 190 @wireprotov1peer.batchable
190 def bar(self, b, a): 191 def bar(self, b, a):
191 encresref = peer.future() 192 encresref = wireprotov1peer.future()
192 yield [('b', mangle(b),), ('a', mangle(a),)], encresref 193 yield [('b', mangle(b),), ('a', mangle(a),)], encresref
193 yield unmangle(encresref.value) 194 yield unmangle(encresref.value)
194 195
195 # greet is coded directly. It therefore does not support batching. If it 196 # greet is coded directly. It therefore does not support batching. If it
196 # does appear in a batch, the batch is split around greet, and the call to 197 # does appear in a batch, the batch is split around greet, and the call to