@@ -30,7 +30,7 @@ class FossilDBSuite extends FlatSpec with BeforeAndAfterEach with TestHelpers wi
3030 private val testData3 = ByteString .copyFromUtf8(" testData3" )
3131
3232 private val aKey = " aKey"
33- private val anotherKey = " anotherKey "
33+ private val aNotherKey = " aNotherKey "
3434 private val aThirdKey = " aThirdKey"
3535
3636 override def beforeEach : Unit = {
@@ -114,7 +114,7 @@ class FossilDBSuite extends FlatSpec with BeforeAndAfterEach with TestHelpers wi
114114 }
115115
116116 it should " fail after Put with other key" in {
117- client.put(PutRequest (collectionA, anotherKey , Some (0 ), testData1))
117+ client.put(PutRequest (collectionA, aNotherKey , Some (0 ), testData1))
118118 val reply = client.get(GetRequest (collectionA, aKey))
119119 assert(! reply.success)
120120 }
@@ -136,24 +136,24 @@ class FossilDBSuite extends FlatSpec with BeforeAndAfterEach with TestHelpers wi
136136 " ListKeys" should " list all keys of a collection" in {
137137 client.put(PutRequest (collectionA, aKey, Some (0 ), testData1))
138138 client.put(PutRequest (collectionA, aKey, Some (1 ), testData2))
139- client.put(PutRequest (collectionA, anotherKey , Some (4 ), testData2))
139+ client.put(PutRequest (collectionA, aNotherKey , Some (4 ), testData2))
140140 client.put(PutRequest (collectionB, aThirdKey, Some (1 ), testData1))
141141 val reply = client.listKeys(ListKeysRequest (collectionA))
142142 assert(reply.keys.contains(aKey))
143- assert(reply.keys.contains(anotherKey ))
143+ assert(reply.keys.contains(aNotherKey ))
144144 assert(reply.keys.length == 2 )
145145 }
146146
147147 it should " support pagination with startAfterKey" in {
148148 client.put(PutRequest (collectionA, aKey, Some (0 ), testData1))
149149 client.put(PutRequest (collectionA, aKey, Some (1 ), testData2))
150- client.put(PutRequest (collectionA, anotherKey , Some (4 ), testData2))
150+ client.put(PutRequest (collectionA, aNotherKey , Some (4 ), testData2))
151151 client.put(PutRequest (collectionB, aThirdKey, Some (1 ), testData1))
152152 val reply = client.listKeys(ListKeysRequest (collectionA, Some (1 )))
153153 assert(reply.keys.length == 1 )
154154 assert(reply.keys.contains(aKey))
155155 val reply2 = client.listKeys(ListKeysRequest (collectionA, Some (1 ), Some (reply.keys.last)))
156- assert(reply2.keys.contains(anotherKey ))
156+ assert(reply2.keys.contains(aNotherKey ))
157157 assert(reply2.keys.length == 1 )
158158 }
159159
@@ -173,7 +173,7 @@ class FossilDBSuite extends FlatSpec with BeforeAndAfterEach with TestHelpers wi
173173 client.put(PutRequest (collectionA, aKey, Some (0 ), testData1))
174174 client.put(PutRequest (collectionA, aKey, Some (1 ), testData2))
175175 client.put(PutRequest (collectionA, aKey, Some (2 ), testData3))
176- client.put(PutRequest (collectionA, anotherKey , Some (0 ), testData1))
176+ client.put(PutRequest (collectionA, aNotherKey , Some (0 ), testData1))
177177 val reply = client.getMultipleVersions(GetMultipleVersionsRequest (collectionA, aKey))
178178 assert(reply.versions(0 ) == 2 )
179179 assert(reply.versions(1 ) == 1 )
@@ -191,7 +191,7 @@ class FossilDBSuite extends FlatSpec with BeforeAndAfterEach with TestHelpers wi
191191 client.put(PutRequest (collectionA, aKey, Some (3 ), testData3))
192192 client.put(PutRequest (collectionA, aKey, Some (4 ), testData1))
193193 client.put(PutRequest (collectionA, aKey, Some (5 ), testData1))
194- client.put(PutRequest (collectionA, anotherKey , Some (0 ), testData1))
194+ client.put(PutRequest (collectionA, aNotherKey , Some (0 ), testData1))
195195
196196 val reply = client.getMultipleVersions(GetMultipleVersionsRequest (collectionA, aKey, Some (4 ), Some (2 )))
197197 assert(reply.versions(0 ) == 4 )
@@ -202,68 +202,126 @@ class FossilDBSuite extends FlatSpec with BeforeAndAfterEach with TestHelpers wi
202202 assert(reply.values.length == 2 )
203203 }
204204
205- " GetMultipleKeys" should " return keys starting with initial one (no prefix) " in {
205+ " GetMultipleKeys" should " return all keys " in {
206206 client.put(PutRequest (collectionA, aKey, Some (0 ), testData1))
207- client.put(PutRequest (collectionA, anotherKey , Some (0 ), testData2))
207+ client.put(PutRequest (collectionA, aNotherKey , Some (0 ), testData2))
208208 client.put(PutRequest (collectionA, aThirdKey, Some (0 ), testData3))
209- val reply = client.getMultipleKeys(GetMultipleKeysRequest (collectionA, aThirdKey ))
210- assert(reply.keys.length == 2 )
211- assert(reply.keys.contains(anotherKey ))
209+ val reply = client.getMultipleKeys(GetMultipleKeysRequest (collectionA))
210+ assert(reply.keys.length == 3 )
211+ assert(reply.keys.contains(aNotherKey ))
212212 assert(reply.keys.contains(aThirdKey))
213- assert(reply.values.length == 2 )
213+ assert(reply.values.length == 3 )
214214 assert(reply.values.contains(testData2))
215215 assert(reply.values.contains(testData3))
216- assert(reply.actualVersions.length == 2 )
216+ assert(reply.actualVersions.length == 3 )
217217 assert(reply.actualVersions.contains(0 ))
218218 }
219219
220- it should " return keys of matching version (sorted alphabetically) " in {
220+ it should " return keys of matching version" in {
221221 client.put(PutRequest (collectionA, aKey, Some (0 ), testData1))
222- client.put(PutRequest (collectionA, anotherKey , Some (0 ), testData1))
222+ client.put(PutRequest (collectionA, aNotherKey , Some (0 ), testData1))
223223 client.put(PutRequest (collectionA, aThirdKey, Some (0 ), testData1))
224224 client.put(PutRequest (collectionA, aKey, Some (1 ), testData2))
225- client.put(PutRequest (collectionA, anotherKey , Some (1 ), testData2))
225+ client.put(PutRequest (collectionA, aNotherKey , Some (1 ), testData2))
226226 client.put(PutRequest (collectionA, aThirdKey, Some (1 ), testData2))
227227 client.put(PutRequest (collectionA, aKey, Some (2 ), testData3))
228- client.put(PutRequest (collectionA, anotherKey , Some (2 ), testData3))
228+ client.put(PutRequest (collectionA, aNotherKey , Some (2 ), testData3))
229229 client.put(PutRequest (collectionA, aThirdKey, Some (2 ), testData3))
230- val reply = client.getMultipleKeys(GetMultipleKeysRequest (collectionA, aKey , None , Some (1 )))
230+ val reply = client.getMultipleKeys(GetMultipleKeysRequest (collectionA, None , None , Some (1 )))
231231 assert(reply.keys.length == 3 )
232232 assert(reply.values.contains(testData2))
233233 }
234234
235- it should " return keys of matching version, matching prefix (sorted alphabetically) " in {
235+ it should " return keys of matching version, matching prefix" in {
236236 client.put(PutRequest (collectionA, aKey, Some (0 ), testData1))
237- client.put(PutRequest (collectionA, anotherKey , Some (0 ), testData1))
237+ client.put(PutRequest (collectionA, aNotherKey , Some (0 ), testData1))
238238 client.put(PutRequest (collectionA, aThirdKey, Some (0 ), testData1))
239239 client.put(PutRequest (collectionA, aKey, Some (1 ), testData2))
240- client.put(PutRequest (collectionA, anotherKey , Some (1 ), testData2))
240+ client.put(PutRequest (collectionA, aNotherKey , Some (1 ), testData2))
241241 client.put(PutRequest (collectionA, aThirdKey, Some (1 ), testData2))
242242 client.put(PutRequest (collectionA, aKey, Some (2 ), testData3))
243- client.put(PutRequest (collectionA, anotherKey , Some (2 ), testData3))
243+ client.put(PutRequest (collectionA, aNotherKey , Some (2 ), testData3))
244244 client.put(PutRequest (collectionA, aThirdKey, Some (2 ), testData3))
245- val reply = client.getMultipleKeys(GetMultipleKeysRequest (collectionA, aKey , Some (" aK " ), Some (1 )))
245+ val reply = client.getMultipleKeys(GetMultipleKeysRequest (collectionA, None , Some (" aN " ), Some (1 )))
246246 assert(reply.keys.length == 1 )
247+ assert(reply.keys.contains(aNotherKey))
248+ assert(reply.values.contains(testData2))
249+ assert(reply.actualVersions.contains(1 ))
250+ }
251+
252+ it should " return keys of matching version, matching prefix even if it is exact match" in {
253+ client.put(PutRequest (collectionA, aKey, Some (0 ), testData1))
254+ client.put(PutRequest (collectionA, aNotherKey, Some (0 ), testData1))
255+ client.put(PutRequest (collectionA, aThirdKey, Some (0 ), testData1))
256+ client.put(PutRequest (collectionA, aKey, Some (1 ), testData2))
257+ client.put(PutRequest (collectionA, aNotherKey, Some (1 ), testData2))
258+ client.put(PutRequest (collectionA, aThirdKey, Some (1 ), testData2))
259+ client.put(PutRequest (collectionA, aKey, Some (2 ), testData3))
260+ client.put(PutRequest (collectionA, aNotherKey, Some (2 ), testData3))
261+ client.put(PutRequest (collectionA, aThirdKey, Some (2 ), testData3))
262+ val reply = client.getMultipleKeys(GetMultipleKeysRequest (collectionA, None , Some (aNotherKey), Some (1 )))
263+ assert(reply.keys.length == 1 )
264+ assert(reply.keys.contains(aNotherKey))
247265 assert(reply.values.contains(testData2))
248266 assert(reply.actualVersions.contains(1 ))
249267 }
250268
251269 it should " with limit return only the first n keys of matching version " in {
252270 client.put(PutRequest (collectionA, aKey, Some (0 ), testData1))
253- client.put(PutRequest (collectionA, anotherKey , Some (0 ), testData1))
271+ client.put(PutRequest (collectionA, aNotherKey , Some (0 ), testData1))
254272 client.put(PutRequest (collectionA, aThirdKey, Some (0 ), testData1))
255273 client.put(PutRequest (collectionA, aKey, Some (1 ), testData2))
256- client.put(PutRequest (collectionA, anotherKey , Some (1 ), testData2))
274+ client.put(PutRequest (collectionA, aNotherKey , Some (1 ), testData2))
257275 client.put(PutRequest (collectionA, aThirdKey, Some (1 ), testData2))
258276 client.put(PutRequest (collectionA, aKey, Some (2 ), testData3))
259- client.put(PutRequest (collectionA, anotherKey , Some (2 ), testData3))
277+ client.put(PutRequest (collectionA, aNotherKey , Some (2 ), testData3))
260278 client.put(PutRequest (collectionA, aThirdKey, Some (2 ), testData3))
261- val reply = client.getMultipleKeys(GetMultipleKeysRequest (collectionA, aKey , None , Some (1 ), Some (2 )))
279+ val reply = client.getMultipleKeys(GetMultipleKeysRequest (collectionA, None , None , Some (1 ), Some (2 )))
262280 assert(reply.keys.length == 2 )
263281 assert(reply.values.contains(testData2))
264282 assert(reply.actualVersions.contains(1 ))
265283 }
266284
285+ it should " support pagination with startAfterKey" in {
286+ client.put(PutRequest (collectionA, aKey, Some (0 ), testData1))
287+ client.put(PutRequest (collectionA, aNotherKey, Some (0 ), testData1))
288+ client.put(PutRequest (collectionA, aThirdKey, Some (0 ), testData1))
289+ val reply = client.getMultipleKeys(GetMultipleKeysRequest (collectionA, Some (aKey), None , None , Some (2 )))
290+ assert(reply.keys.length == 2 )
291+ assert(reply.values.contains(testData1))
292+ assert(reply.actualVersions.contains(0 ))
293+ }
294+
295+ it should " support pagination with startAfterKey, with prefix and version" in {
296+ client.put(PutRequest (collectionA, aKey, Some (0 ), testData1))
297+ client.put(PutRequest (collectionA, aNotherKey, Some (0 ), testData1))
298+ client.put(PutRequest (collectionA, aThirdKey, Some (0 ), testData1))
299+ client.put(PutRequest (collectionA, aKey, Some (1 ), testData2))
300+ client.put(PutRequest (collectionA, aNotherKey, Some (1 ), testData2))
301+ client.put(PutRequest (collectionA, aThirdKey, Some (1 ), testData2))
302+ client.put(PutRequest (collectionA, aKey, Some (2 ), testData3))
303+ client.put(PutRequest (collectionA, aNotherKey, Some (2 ), testData3))
304+ client.put(PutRequest (collectionA, aThirdKey, Some (2 ), testData3))
305+ val reply = client.getMultipleKeys(GetMultipleKeysRequest (collectionA, Some (aKey), Some (" a" ), Some (1 ), Some (1 )))
306+ assert(reply.keys.length == 1 )
307+ assert(reply.values.contains(testData2))
308+ assert(reply.actualVersions.contains(1 ))
309+ }
310+
311+ it should " support pagination with startAfterKey, with prefix and version where no keys match the prefix" in {
312+ client.put(PutRequest (collectionA, aKey, Some (0 ), testData1))
313+ client.put(PutRequest (collectionA, aNotherKey, Some (0 ), testData1))
314+ client.put(PutRequest (collectionA, aThirdKey, Some (0 ), testData1))
315+ client.put(PutRequest (collectionA, aKey, Some (1 ), testData2))
316+ client.put(PutRequest (collectionA, aNotherKey, Some (1 ), testData2))
317+ client.put(PutRequest (collectionA, aThirdKey, Some (1 ), testData2))
318+ client.put(PutRequest (collectionA, aKey, Some (2 ), testData3))
319+ client.put(PutRequest (collectionA, aNotherKey, Some (2 ), testData3))
320+ client.put(PutRequest (collectionA, aThirdKey, Some (2 ), testData3))
321+ val reply = client.getMultipleKeys(GetMultipleKeysRequest (collectionA, Some (aKey), Some (" BogusPrefix" ), Some (1 ), Some (2 )))
322+ assert(reply.keys.isEmpty)
323+ }
324+
267325 " Backup" should " create non-empty backup directory" in {
268326 client.put(PutRequest (collectionA, aKey, Some (0 ), testData1))
269327 client.backup(BackupRequest ())
0 commit comments