Merge lp:~facundo/ubuntuone-storage-protocol/stable-1-6--use-tuneable-maxsize into lp:ubuntuone-storage-protocol/stable-1-6

Proposed by Facundo Batista on 2011-04-25
Status: Merged
Approved by: Facundo Batista on 2011-04-27
Approved revision: 133
Merged at revision: 133
Proposed branch: lp:~facundo/ubuntuone-storage-protocol/stable-1-6--use-tuneable-maxsize
Merge into: lp:ubuntuone-storage-protocol/stable-1-6
Diff against target: 176 lines (+59/-12)
4 files modified
tests/test_bytesproducer.py (+2/-4)
tests/test_client.py (+50/-2)
tests/test_putcontent.py (+4/-5)
ubuntuone/storageprotocol/client.py (+3/-1)
To merge this branch: bzr merge lp:~facundo/ubuntuone-storage-protocol/stable-1-6--use-tuneable-maxsize
Reviewer Review Type Date Requested Status
dobey (community) 2011-04-26 Approve on 2011-04-27
Lucio Torre (community) 2011-04-25 Approve on 2011-04-26
Review via email: mp+58994@code.launchpad.net

Commit message

Change the way the producer decides how much BYTES to send (LP: #767466).

Description of the change

Change the way the producer decides how much BYTES to send.

This way, not being more a constant, StorageClient or any Request can change it easily.

Tests included.

To post a comment you must log in.
Lucio Torre (lucio.torre) :
review: Approve
dobey (dobey) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/test_bytesproducer.py'
2--- tests/test_bytesproducer.py 2011-02-22 15:04:43 +0000
3+++ tests/test_bytesproducer.py 2011-04-25 21:06:32 +0000
4@@ -26,10 +26,7 @@
5 from twisted.internet import task
6 from twisted.trial.unittest import TestCase as TwistedTestCase
7
8-from ubuntuone.storageprotocol import client, request, protocol_pb2
9-
10-# puts a lower limit, easier for testing
11-request.MAX_PAYLOAD_SIZE = 3
12+from ubuntuone.storageprotocol import client, protocol_pb2
13
14
15 class FakeRequest(object):
16@@ -38,6 +35,7 @@
17 def __init__(self):
18 self.messages = []
19 self.cancelled = False
20+ self.max_payload_size = 3 # lower limit, easier for testing
21
22 def sendMessage(self, message):
23 """Store the message in own list."""
24
25=== modified file 'tests/test_client.py'
26--- tests/test_client.py 2010-11-05 14:54:42 +0000
27+++ tests/test_client.py 2011-04-25 21:06:32 +0000
28@@ -17,15 +17,19 @@
29 # along with this program. If not, see <http://www.gnu.org/licenses/>.
30 """Tests for the protocol client."""
31
32+import StringIO
33+import os
34 import unittest
35 import uuid
36
37 from twisted.internet.defer import Deferred
38+from twisted.trial.unittest import TestCase as TwistedTestCase
39
40 from ubuntuone.storageprotocol import protocol_pb2, sharersp, delta, request
41 from ubuntuone.storageprotocol.client import (
42- StorageClient, CreateUDF, ListVolumes, DeleteVolume, GetDelta,
43- Authenticate, MakeFile, MakeDir, PutContent, Move, Unlink)
44+ StorageClient, CreateUDF, ListVolumes, DeleteVolume, GetDelta, Unlink,
45+ Authenticate, MakeFile, MakeDir, PutContent, Move, BytesMessageProducer,
46+)
47 from ubuntuone.storageprotocol import volumes
48 from tests import test_delta_info
49
50@@ -168,6 +172,11 @@
51 """Clean up."""
52 self.client = None
53
54+ def test_init_maxpayloadsize(self):
55+ """Get the value from the constant at init time."""
56+ self.assertEqual(self.client.max_payload_size,
57+ request.MAX_PAYLOAD_SIZE)
58+
59 # client to server
60 def test_client_get_delta(self):
61 """Get a delta."""
62@@ -805,5 +814,44 @@
63 return Move(FakedProtocol(), None, None, None, None)
64
65
66+class PutContentTestCase(TwistedTestCase):
67+ """Test cases for PutContent op."""
68+
69+ def test_max_payload_size(self):
70+ """Get the value from the protocol."""
71+ self.protocol = FakedProtocol()
72+ assert 12345 != self.protocol.max_payload_size
73+ self.protocol.max_payload_size = 12345
74+ pc = PutContent(self.protocol, None, None, None, None,
75+ None, None, None, None)
76+ self.assertEqual(pc.max_payload_size, 12345)
77+
78+ def test_bytesmessageproducer_maxpayloadsize(self):
79+ """The producer uses the payload size from the request."""
80+ # set up the PutContent
81+ pc = PutContent(FakedProtocol(), None, None, None, None,
82+ None, None, None, None)
83+ assert 12345 != pc.max_payload_size
84+ pc.max_payload_size = 12345
85+
86+ # set up the producer
87+ fake_file = StringIO.StringIO(os.urandom(100000))
88+ producer = BytesMessageProducer(pc, fake_file, 0)
89+ producer.producing = True
90+
91+ # set up a function to check and go!
92+ d = Deferred()
93+
94+ def check(message):
95+ """Check."""
96+ self.assertEqual(len(message.bytes.bytes), 12345)
97+ producer.producing = False
98+ d.callback(True)
99+
100+ pc.sendMessage = check
101+ producer.go()
102+ return d
103+
104+
105 if __name__ == '__main__':
106 unittest.main()
107
108=== modified file 'tests/test_putcontent.py'
109--- tests/test_putcontent.py 2011-02-10 19:06:13 +0000
110+++ tests/test_putcontent.py 2011-04-25 21:06:32 +0000
111@@ -25,8 +25,7 @@
112
113 from twisted.test.proto_helpers import StringTransport
114
115-from ubuntuone.storageprotocol.request import RequestHandler
116-from ubuntuone.storageprotocol.client import PutContent
117+from ubuntuone.storageprotocol.client import PutContent, StorageClient
118 from ubuntuone.storageprotocol import protocol_pb2
119 from mocker import Mocker, ANY
120
121@@ -52,7 +51,7 @@
122 mocker.result('')
123 mocker.replay()
124
125- protocol = RequestHandler()
126+ protocol = StorageClient()
127 protocol.transport = transport
128 pc = PutContent(protocol, 'share', 'node', '', '', 0, 0, 0, fd)
129 message = protocol_pb2.Message()
130@@ -77,7 +76,7 @@
131 mocker.result('')
132 mocker.replay()
133
134- protocol = RequestHandler()
135+ protocol = StorageClient()
136 protocol.transport = transport
137 pc = PutContent(protocol, 'share', 'node', '', '', 0, 0, 0, fd)
138 message = protocol_pb2.Message()
139@@ -92,7 +91,7 @@
140 def setUp(self):
141 unittest.TestCase.setUp(self)
142 transport = StringTransport()
143- self.protocol = RequestHandler()
144+ self.protocol = StorageClient()
145 self.protocol.transport = transport
146
147 def test_server_upload_id(self):
148
149=== modified file 'ubuntuone/storageprotocol/client.py'
150--- ubuntuone/storageprotocol/client.py 2011-02-23 19:48:51 +0000
151+++ ubuntuone/storageprotocol/client.py 2011-04-25 21:06:32 +0000
152@@ -60,6 +60,7 @@
153 self._volume_new_generation_callback = None
154
155 self.line_mode = True
156+ self.max_payload_size = request.MAX_PAYLOAD_SIZE
157
158 def protocol_version(self):
159 """Ask for the protocol version
160@@ -1119,7 +1120,7 @@
161
162 if self.offset:
163 self.fh.seek(self.offset)
164- data = self.fh.read(request.MAX_PAYLOAD_SIZE)
165+ data = self.fh.read(self.request.max_payload_size)
166 if data:
167 if self.offset:
168 self.offset += len(data)
169@@ -1174,6 +1175,7 @@
170 self.upload_id = upload_id
171 self.new_generation = None
172 self.magic_hash = magic_hash
173+ self.max_payload_size = protocol.max_payload_size
174
175 def _start(self):
176 """Send PUT_CONTENT."""

Subscribers

People subscribed via source and target branches