Merge lp:~facundo/ubuntuone-client/configurable-two-values into lp:ubuntuone-client

Proposed by Facundo Batista
Status: Merged
Approved by: Guillermo Gonzalez
Approved revision: 965
Merged at revision: 964
Proposed branch: lp:~facundo/ubuntuone-client/configurable-two-values
Merge into: lp:ubuntuone-client
Diff against target: 272 lines (+117/-10)
6 files modified
data/syncdaemon.conf (+9/-0)
tests/platform/linux/eventlog/test_zg_listener.py (+5/-2)
tests/syncdaemon/test_action_queue.py (+22/-4)
tests/syncdaemon/test_config.py (+50/-0)
ubuntuone/syncdaemon/action_queue.py (+11/-4)
ubuntuone/syncdaemon/config.py (+20/-0)
To merge this branch: bzr merge lp:~facundo/ubuntuone-client/configurable-two-values
Reviewer Review Type Date Requested Status
Guillermo Gonzalez Approve
Lucio Torre (community) Approve
Review via email: mp+58573@code.launchpad.net

Commit message

Use "simultaneous transfers" and "maximum payload size" from configuration (LP: #767466).

Description of the change

Use "simultaneous transfers" and "maximum payload size" from configuration.

"simult_transfers" moved from a code constant to a value from configuration, and "max_payload_size" is set in the protocol also from the configuration.

Added configuration for these two values, with sensible defaults; also, methods added to get and set these values.

Tests included for everything.

To post a comment you must log in.
Revision history for this message
Lucio Torre (lucio.torre) wrote :

+1

review: Approve
965. By Facundo Batista

Fixes using new protocol.

Revision history for this message
Guillermo Gonzalez (verterok) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/syncdaemon.conf'
2--- data/syncdaemon.conf 2011-04-06 13:50:33 +0000
3+++ data/syncdaemon.conf 2011-04-20 21:52:54 +0000
4@@ -91,6 +91,15 @@
5 use_trash.help = Send the files and folders to Trash folder instead of
6 removing them permanently.
7
8+simult_transfers.default = 10
9+simult_transfers.parser = int
10+simult_transfers.help = Quantity of Uploads and Downloads that will be run
11+ in parallel.
12+
13+max_payload_size.default = 1400
14+max_payload_size.parser = int
15+max_payload_size.help = The maximum payload for messages sent to the server.
16+
17
18 [notifications]
19 show_all_notifications.default = True
20
21=== modified file 'tests/platform/linux/eventlog/test_zg_listener.py'
22--- tests/platform/linux/eventlog/test_zg_listener.py 2011-03-22 18:16:28 +0000
23+++ tests/platform/linux/eventlog/test_zg_listener.py 2011-04-20 21:52:54 +0000
24@@ -74,6 +74,7 @@
25 from tests.syncdaemon.test_action_queue import (
26 ConnectedBaseTestCase,
27 FakeSemaphore,
28+ TestingProtocol,
29 )
30
31 VOLUME = uuid.UUID('12345678-1234-1234-1234-123456789abc')
32@@ -606,7 +607,8 @@
33 cmd.handle_success(request)
34
35 # create a request and fill it with succesful information
36- request = client.PutContent(self.action_queue.client, self.share_id,
37+ aq_client = TestingProtocol()
38+ request = client.PutContent(aq_client, self.share_id,
39 'node', 'prvhash', 'newhash', 'crc32',
40 'size', 'deflated', 'fd')
41 request.new_generation = 13
42@@ -695,7 +697,8 @@
43 self.fsm.set_node_id(path, "a_node_id")
44
45 # create a request and fill it with succesful information
46- request = client.PutContent(self.action_queue.client, self.share_id,
47+ aq_client = TestingProtocol()
48+ request = client.PutContent(aq_client, self.share_id,
49 'node', 'prvhash', 'newhash', 'crc32',
50 'size', 'deflated', 'fd')
51 request.new_generation = 13
52
53=== modified file 'tests/syncdaemon/test_action_queue.py'
54--- tests/syncdaemon/test_action_queue.py 2011-04-12 19:46:23 +0000
55+++ tests/syncdaemon/test_action_queue.py 2011-04-20 21:52:54 +0000
56@@ -55,12 +55,12 @@
57 protocol_pb2,
58 request,
59 )
60-from ubuntuone.syncdaemon import states, interfaces
61+from ubuntuone.syncdaemon import states, interfaces, config
62 from ubuntuone.syncdaemon import action_queue
63 from ubuntuone.syncdaemon.action_queue import (
64 ActionQueue, ActionQueueCommand, ChangePublicAccess, CreateUDF,
65 DeleteVolume, Download, ListVolumes, ActionQueueProtocol, ListShares,
66- RequestQueue, UploadProgressWrapper, Upload, SIMULT_TRANSFERS,
67+ RequestQueue, UploadProgressWrapper, Upload,
68 CreateShare, DeleteShare, GetPublicFiles, GetDelta, GetDeltaFromScratch,
69 TRANSFER_PROGRESS_THRESHOLD, Unlink, Move, MakeFile, MakeDir, DeltaList,
70 ZipQueue, DeferredMap, ThrottlingStorageClient, PathLockingTree,
71@@ -199,6 +199,8 @@
72 class TestingProtocol(ActionQueue.protocol):
73 """Protocol for testing."""
74
75+ max_payload_size = 65536
76+
77 def connectionMade(self):
78 """connectionMade."""
79 ActionQueue.protocol.connectionMade(self)
80@@ -722,6 +724,13 @@
81 self.rq.unqueue(cmd2)
82 self.assertEqual(len(self.rq), 0)
83
84+ def test_init_simult_transfers(self):
85+ """Configure the transfers semaphore according to config."""
86+ user_config = config.get_user_config()
87+ user_config.set_simult_transfers(12345)
88+ rq = RequestQueue(action_queue=None)
89+ self.assertEqual(rq.transfers_semaphore.tokens, 12345)
90+
91
92 class TestDeferredMap(TwistedTestCase):
93 """Test the deferred map."""
94@@ -3239,7 +3248,8 @@
95 def test_handle_success_push_event(self):
96 """Test AQ_UPLOAD_FINISHED is pushed on success."""
97 # create a request and fill it with succesful information
98- request = client.PutContent(self.action_queue.client, VOLUME, 'node',
99+ aq_client = TestingProtocol()
100+ request = client.PutContent(aq_client, VOLUME, 'node',
101 'prvhash', 'newhash', 'crc32', 'size',
102 'deflated', 'fd')
103 request.new_generation = 13
104@@ -4940,6 +4950,13 @@
105 # check also the log
106 self.assertTrue(self.handler.check_debug('Ping! rtt: 1.123 segs'))
107
108+ def test_init_max_payload_size(self):
109+ """Configure max_payload_size on init according to config."""
110+ user_config = config.get_user_config()
111+ user_config.set_max_payload_size(12345)
112+ aqp = ActionQueueProtocol()
113+ self.assertEqual(aqp.max_payload_size, 12345)
114+
115
116 class CommandCycleTestCase(BasicTestCase):
117 """Test the command behaviour on run, retry, stop, etc.
118@@ -5363,7 +5380,8 @@
119 # transfer semaphore in _start
120 transfers_semaphore = self.queue.transfers_semaphore
121 semaphores = []
122- for i in xrange(SIMULT_TRANSFERS):
123+ user_config = config.get_user_config()
124+ for i in xrange(user_config.get_simult_transfers()):
125 s = transfers_semaphore.acquire()
126 s.addCallback(semaphores.append)
127
128
129=== modified file 'tests/syncdaemon/test_config.py'
130--- tests/syncdaemon/test_config.py 2011-04-13 19:23:22 +0000
131+++ tests/syncdaemon/test_config.py 2011-04-20 21:52:54 +0000
132@@ -428,6 +428,45 @@
133 branch_config = os.path.join(rootdir, "data", config.CONFIG_FILE)
134 self.assertIn(branch_config, config_files)
135
136+ def test_get_simult_transfers(self):
137+ """Get simult transfers."""
138+ conf_file = os.path.join(self.test_root, 'test_load_config.conf')
139+ with open(conf_file, 'w') as fh:
140+ fh.write('[__main__]\n')
141+ fh.write('simult_transfers = 12345\n')
142+ conf = config._Config(conf_file)
143+ self.assertEqual(conf.get_simult_transfers(), 12345)
144+
145+ def test_set_simult_transfers(self):
146+ """Set simult transfers."""
147+ conf_file = os.path.join(self.test_root, 'test_load_config.conf')
148+ with open(conf_file, 'w') as fh:
149+ fh.write('[__main__]\n')
150+ fh.write('simult_transfers = 12345\n')
151+ conf = config._Config(conf_file)
152+ conf.set_simult_transfers(666)
153+ self.assertEqual(conf.get_simult_transfers(), 666)
154+
155+ def test_get_max_payload_size(self):
156+ """Get the maximum payload size."""
157+ conf_file = os.path.join(self.test_root, 'test_load_config.conf')
158+ with open(conf_file, 'w') as fh:
159+ fh.write('[__main__]\n')
160+ fh.write('max_payload_size = 12345\n')
161+ conf = config._Config(conf_file)
162+ self.assertEqual(conf.get_max_payload_size(), 12345)
163+
164+ def test_set_max_payload_size(self):
165+ """Set the maximum payload size."""
166+ conf_file = os.path.join(self.test_root, 'test_load_config.conf')
167+ with open(conf_file, 'w') as fh:
168+ fh.write('[__main__]\n')
169+ fh.write('max_payload_size = 12345\n')
170+ conf = config._Config(conf_file)
171+ conf.set_max_payload_size(666)
172+ self.assertEqual(conf.get_max_payload_size(), 666)
173+
174+
175 class ConfigglueParsersTests(BaseTwistedTestCase):
176 """Tests for our custom configglue parsers"""
177
178@@ -603,3 +642,14 @@
179 self.cp.parse_all()
180 self.assertIn(r'\A\.~lock\..*#\Z',
181 self.cp.get('__main__', 'ignore').value)
182+
183+ def test_simult_transfers(self):
184+ """Test default configuration for simultaneous transfers."""
185+ self.cp.parse_all()
186+ self.assertEqual(self.cp.get('__main__', 'simult_transfers').value, 10)
187+
188+ def test_max_payload_size(self):
189+ """Test default configuration for maximum payload size."""
190+ self.cp.parse_all()
191+ configured = self.cp.get('__main__', 'max_payload_size').value
192+ self.assertEqual(configured, 1400)
193
194=== modified file 'ubuntuone/syncdaemon/action_queue.py'
195--- ubuntuone/syncdaemon/action_queue.py 2011-04-18 20:46:44 +0000
196+++ ubuntuone/syncdaemon/action_queue.py 2011-04-20 21:52:54 +0000
197@@ -57,6 +57,7 @@
198 from ubuntuone.storageprotocol.context import get_ssl_context
199 from ubuntuone.syncdaemon.interfaces import IActionQueue, IMarker
200 from ubuntuone.syncdaemon.logger import mklog, TRACE
201+from ubuntuone.syncdaemon import config
202
203 logger = logging.getLogger("ubuntuone.SyncDaemon.ActionQueue")
204
205@@ -69,9 +70,6 @@
206 # progress threshold to emit a download/upload progress event: 64Kb
207 TRANSFER_PROGRESS_THRESHOLD = 64*1024*1024
208
209-# no more than this uploads are executed simultaneously
210-SIMULT_TRANSFERS = 10
211-
212 def passit(func):
213 """Pass the value on for the next deferred, while calling func with it."""
214
215@@ -302,6 +300,11 @@
216 _looping_ping = None
217 _ping_delay = 600 # 10 minutes
218
219+ def __init__(self):
220+ LoggingStorageClient.__init__(self)
221+ user_config = config.get_user_config()
222+ self.max_payload_size = user_config.get_max_payload_size()
223+
224 def connectionMade(self):
225 """A new connection was made."""
226 self.log.info('Connection made.')
227@@ -458,9 +461,13 @@
228 self.waiting = []
229 self.hashed_waiting = {}
230 self.active = False
231- self.transfers_semaphore = defer.DeferredSemaphore(SIMULT_TRANSFERS)
232 self.active_deferred = defer.Deferred()
233
234+ # transfers semaphore
235+ user_config = config.get_user_config()
236+ simult_transfers = user_config.get_simult_transfers()
237+ self.transfers_semaphore = defer.DeferredSemaphore(simult_transfers)
238+
239 def __len__(self):
240 """Return the length of the waiting queue."""
241 return len(self.waiting)
242
243=== modified file 'ubuntuone/syncdaemon/config.py'
244--- ubuntuone/syncdaemon/config.py 2011-04-05 19:14:18 +0000
245+++ ubuntuone/syncdaemon/config.py 2011-04-20 21:52:54 +0000
246@@ -374,6 +374,26 @@
247 def set_use_trash(self, enabled):
248 self.set(MAIN, 'use_trash', str(enabled))
249
250+ @requires_section(MAIN)
251+ def get_simult_transfers(self):
252+ """Get the simultaneous transfers value."""
253+ return self.get_parsed(MAIN, 'simult_transfers')
254+
255+ @requires_section(MAIN)
256+ def set_simult_transfers(self, value):
257+ """Set the simultaneous transfers value."""
258+ self.set(MAIN, 'simult_transfers', str(value))
259+
260+ @requires_section(MAIN)
261+ def get_max_payload_size(self):
262+ """Get the maximum payload size."""
263+ return self.get_parsed(MAIN, 'max_payload_size')
264+
265+ @requires_section(MAIN)
266+ def set_max_payload_size(self, value):
267+ """Set the maximum payload size."""
268+ self.set(MAIN, 'max_payload_size', str(value))
269+
270 @requires_section(NOTIFICATIONS)
271 def set_show_all_notifications(self, enabled):
272 self.set(NOTIFICATIONS, 'show_all_notifications', str(enabled))

Subscribers

People subscribed via source and target branches