Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1)

Side by Side Diff: src/RamCloudTest.cc

Issue 35001: Implementation of multiRead
Patch Set: Created 13 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /* Copyright (c) 2010 Stanford University
2 *
3 * Permission to use, copy, modify, and distribute this software for any
4 * purpose with or without fee is hereby granted, provided that the above
5 * copyright notice and this permission notice appear in all copies.
6 *
7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR(S) DISCLAIM ALL WARRANTIES
8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL AUTHORS BE LIABLE FOR
10 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14 */
15
16 #include "TestUtil.h"
17 #include "BackupManager.h"
18 #include "CoordinatorClient.h"
19 #include "CoordinatorServer.h"
20 #include "MasterServer.h"
21 #include "MockTransport.h"
22 #include "TransportManager.h"
23 #include "BindTransport.h"
24 #include "Recovery.h"
25 #include "RamCloud.h"
26
27 namespace RAMCloud {
john.ousterhout 2011/05/22 22:33:16 I'm a little confused about this file: from the na
28
29 class RamCloudTest : public CppUnit::TestFixture {
30 CPPUNIT_TEST_SUITE(RamCloudTest);
31 CPPUNIT_TEST(test_multiRead);
32 CPPUNIT_TEST(test_multiRead_badTable);
33 CPPUNIT_TEST(test_multiRead_noSuchObject);
34 CPPUNIT_TEST_SUITE_END();
35
36 BindTransport* transport;
37 CoordinatorServer* coordinatorServer;
38 CoordinatorClient* coordinatorClient1;
39 CoordinatorClient* coordinatorClient2;
40 ServerConfig masterConfig1;
41 ServerConfig masterConfig2;
42 MasterServer* master1;
43 MasterServer* master2;
44 RamCloud* ramcloud;
45
46 public:
47 RamCloudTest()
48 : transport(NULL)
49 , coordinatorServer(NULL)
50 , coordinatorClient1(NULL)
51 , coordinatorClient2(NULL)
52 , masterConfig1()
53 , masterConfig2()
54 , master1(NULL)
55 , master2(NULL)
56 , ramcloud(NULL)
57 {
58 masterConfig1.coordinatorLocator = "mock:host=coordinatorServer";
59 masterConfig1.localLocator = "mock:host=master1";
60 MasterServer::sizeLogAndHashTable("64", "8", &masterConfig1);
61 masterConfig2.coordinatorLocator = "mock:host=coordinatorServer";
62 masterConfig2.localLocator = "mock:host=master2";
63 MasterServer::sizeLogAndHashTable("64", "8", &masterConfig2);
64 }
65
66 void setUp() {
67 transport = new BindTransport();
68 transportManager.registerMock(transport);
69 coordinatorServer = new CoordinatorServer();
70 transport->addServer(*coordinatorServer, "mock:host=coordinatorServer");
71
72 coordinatorClient1 = new CoordinatorClient(
73 "mock:host=coordinatorServer");
74 master1 = new MasterServer(masterConfig1, coordinatorClient1, 0);
75 transport->addServer(*master1, "mock:host=master1");
76 master1->serverId.construct(
77 coordinatorClient1->enlistServer(MASTER,
78 masterConfig1.localLocator));
79
80 coordinatorClient2 = new CoordinatorClient(
81 "mock:host=coordinatorServer");
82 master2 = new MasterServer(masterConfig2, coordinatorClient2, 0);
83 transport->addServer(*master2, "mock:host=master2");
84 master2->serverId.construct(
85 coordinatorClient2->enlistServer(MASTER,
86 masterConfig2.localLocator));
87
88 ramcloud = new RamCloud("mock:host=coordinatorServer");
89 ramcloud->createTable("table1");
90 ramcloud->createTable("table2");
91 TestLog::enable();
92 }
93
94 void tearDown() {
95 TestLog::disable();
96 delete ramcloud;
97 delete master1;
98 delete master2;
99 delete coordinatorClient1;
100 delete coordinatorClient2;
101 delete coordinatorServer;
102 transportManager.unregisterMock();
103 delete transport;
104 }
105
106 /*
107 * Testing multiRead such that multiple Objects are read from
108 * multiple masters.
109 */
110 void test_multiRead() {
111 // Create objects to be read later
112 uint32_t tableId1 = ramcloud->openTable("table1");
113 uint64_t version1;
114 ramcloud->create(tableId1, "firstVal", 8, &version1, false);
115
116 uint32_t tableId2 = ramcloud->openTable("table2");
117 uint64_t version2;
118 ramcloud->create(tableId2, "secondVal", 9, &version2, false);
119 uint64_t version3;
120 ramcloud->create(tableId2, "thirdVal", 8, &version3, false);
121 uint64_t version4;
122 ramcloud->create(tableId2, "forthVal", 8, &version4, false);
123
124 // Create requests and read
125 MasterClient::ReadObject requests[4];
126
Ankita 2011/05/23 21:32:26 status initializations not to 0.
127 Tub<Buffer> readValue1;
128 uint64_t readVersion1;
129 Status readStatus1;
130 MasterClient::ReadObject request1(tableId1, 0, &readValue1,
131 &readVersion1, &readStatus1);
132 Tub<Buffer> readValue2;
133 uint64_t readVersion2;
134 Status readStatus2;
135 MasterClient::ReadObject request2(tableId2, 0, &readValue2,
136 &readVersion2, &readStatus2);
137 Tub<Buffer> readValue3;
138 uint64_t readVersion3;
139 Status readStatus3;
140 MasterClient::ReadObject request3(tableId2, 1, &readValue3,
141 &readVersion3, &readStatus3);
142 Tub<Buffer> readValue4;
143 uint64_t readVersion4;
144 Status readStatus4;
145 MasterClient::ReadObject request4(tableId2, 2, &readValue4,
146 &readVersion4, &readStatus4);
147
148 requests[0] = request1;
149 requests[1] = request2;
150 requests[2] = request3;
151 requests[3] = request4;
152
153 ramcloud->multiRead(requests, 4);
154
155 CPPUNIT_ASSERT_EQUAL(0, readStatus1);
156 if (readValue1) {
157 CPPUNIT_ASSERT_EQUAL(1, readVersion1);
158 CPPUNIT_ASSERT_EQUAL("firstVal", toString(readValue1.get()));
159 }
160 CPPUNIT_ASSERT_EQUAL(0, readStatus2);
161 if (readValue2){
162 CPPUNIT_ASSERT_EQUAL(1, readVersion2);
163 CPPUNIT_ASSERT_EQUAL("secondVal", toString(readValue2.get()));
164 }
165 CPPUNIT_ASSERT_EQUAL(0, readStatus3);
166 if (readValue3){
167 CPPUNIT_ASSERT_EQUAL(2, readVersion3);
168 CPPUNIT_ASSERT_EQUAL("thirdVal", toString(readValue3.get()));
169 }
170 CPPUNIT_ASSERT_EQUAL(0, readStatus4);
171 if (readValue4){
172 CPPUNIT_ASSERT_EQUAL(3, readVersion4);
173 CPPUNIT_ASSERT_EQUAL("forthVal", toString(readValue4.get()));
174 }
175 }
176
177 void test_multiRead_badTable() {
john.ousterhout 2011/05/22 22:33:16 This test and the following one appear to be testi
178 // Create one table and one value, for control of multiRead
179 uint32_t tableId1 = ramcloud->openTable("table1");
180 uint64_t version1;
181 ramcloud->create(tableId1, "firstVal", 8, &version1, false);
182
183 // Create requests and read
184 MasterClient::ReadObject requests[2];
185
186 Tub<Buffer> readValue1;
187 uint64_t readVersion1;
188 Status readStatus1;
189 MasterClient::ReadObject request1(tableId1, 0, &readValue1,
190 &readVersion1, &readStatus1);
191
192 // Ensure this tableId is not the same as that created earlier
193 uint32_t tableId2 = tableId1 + 10;
194 Tub<Buffer> readValue2;
195 uint64_t readVersion2;
196 Status readStatus2;
197 MasterClient::ReadObject request2(tableId2, 0, &readValue2,
198 &readVersion2, &readStatus2);
199
200 requests[0] = request1;
201 requests[1] = request2;
202
203 ramcloud->multiRead(requests, 2);
204
205 CPPUNIT_ASSERT_EQUAL(0, readStatus1);
206 if (readValue1) {
207 CPPUNIT_ASSERT_EQUAL(1, readVersion1);
208 CPPUNIT_ASSERT_EQUAL("firstVal", toString(readValue1.get()));
209 }
210 // Status 1 corresponds to STATUS_TABLE_DOESNT_EXIST
211 CPPUNIT_ASSERT_EQUAL(1, readStatus2);
212
213 }
214
215
216 void test_multiRead_noSuchObject() {
217 // Create one table and two values, for control of multiRead
218 uint32_t tableId1 = ramcloud->openTable("table1");
219 uint64_t version1;
220 ramcloud->create(tableId1, "firstVal", 8, &version1, false);
221 uint64_t version2;
222 ramcloud->create(tableId1, "secondVal", 9, &version2, false);
223
224 // Create requests and read
225 MasterClient::ReadObject requests[3];
226
227 Tub<Buffer> readValue1;
228 uint64_t readVersion1;
229 Status readStatus1;
230 MasterClient::ReadObject request1(tableId1, 0, &readValue1,
231 &readVersion1, &readStatus1);
232
233 Tub<Buffer> readValue2;
234 uint64_t readVersion2;
235 Status readStatus2;
236 MasterClient::ReadObject request2(tableId1, 1, &readValue2,
237 &readVersion2, &readStatus2);
238
239 Tub<Buffer> readValueError;
240 uint64_t readVersionError;
241 Status readStatusError;
242 MasterClient::ReadObject requestError(tableId1, 20, &readValueError,
243 &readVersionError, &readStatusError);
244
245 requests[0] = request1;
246 requests[1] = requestError;
247 requests[2] = request2;
248
249 ramcloud->multiRead(requests, 3);
250
251 CPPUNIT_ASSERT_EQUAL(0, readStatus1);
252 if (readValue1) {
253 CPPUNIT_ASSERT_EQUAL(1, readVersion1);
254 CPPUNIT_ASSERT_EQUAL("firstVal", toString(readValue1.get()));
255 }
256 // Status 2 corresponds to STATUS_OBJECT_DOESNT_EXIST
257 CPPUNIT_ASSERT_EQUAL(2, readStatusError);
258 CPPUNIT_ASSERT_EQUAL(0, readStatus2);
259 if (readValue2) {
260 CPPUNIT_ASSERT_EQUAL(2, readVersion2);
261 CPPUNIT_ASSERT_EQUAL("secondVal", toString(readValue2.get()));
262 }
263 }
264
265 DISALLOW_COPY_AND_ASSIGN(RamCloudTest);
266 };
267 CPPUNIT_TEST_SUITE_REGISTRATION(RamCloudTest);
268
269 } // namespace RAMCloud
OLDNEW

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld aab5469