@@ -97,6 +97,17 @@ class FossilDBSuite extends AnyFlatSpec with BeforeAndAfterEach with TestHelpers
9797 assert(reply.actualVersion == 0 )
9898 }
9999
100+ " PutMultipleKeysWithMultipleVersions" should " write all versions of all specified keys" in {
101+ client.putMultipleKeysWithMultipleVersions(PutMultipleKeysWithMultipleVersionsRequest (collectionA, Seq (VersionedKeyValuePairProto (aKey, 0 , testData1), VersionedKeyValuePairProto (aKey, 2 , testData2), VersionedKeyValuePairProto (aNotherKey, 5 , testData3))))
102+ val reply = client.get(GetRequest (collectionA, aKey))
103+ assert(reply.actualVersion == 2 )
104+ val reply2 = client.get(GetRequest (collectionA, aKey, version = Some (0 )))
105+ assert(reply2.actualVersion == 0 )
106+ val reply3 = client.get(GetRequest (collectionA, aNotherKey))
107+ assert(reply3.actualVersion == 5 )
108+ assert(reply3.value == testData3)
109+ }
110+
100111 " Get" should " return matching value after matching Put" in {
101112 client.put(PutRequest (collectionA, aKey, Some (0 ), testData1))
102113 val reply = client.get(GetRequest (collectionA, aKey, Some (0 )))
@@ -195,6 +206,37 @@ class FossilDBSuite extends AnyFlatSpec with BeforeAndAfterEach with TestHelpers
195206 assert(reply.keys.length == 3 )
196207 }
197208
209+ it should " respect prefix argument" in {
210+ client.put(PutRequest (collectionA, " 123456" , Some (1 ), testData1))
211+ client.put(PutRequest (collectionA, " 123457" , Some (123 ), testData2))
212+ client.put(PutRequest (collectionA, " 12345800" , Some (123 ), testData3))
213+ client.put(PutRequest (collectionA, " 12345801" , Some (123 ), testData3))
214+ client.put(PutRequest (collectionA, " 12345802" , Some (123 ), testData3))
215+ client.put(PutRequest (collectionA, " 123458" , Some (123 ), testData3))
216+ client.put(PutRequest (collectionA, " 123459" , Some (123 ), testData3))
217+
218+ val reply = client.listKeys(ListKeysRequest (collectionA, None , None , prefix = Some (" 123458" )))
219+ assert(reply.keys.length == 4 )
220+ assert(reply.keys(0 ) == " 12345800" )
221+ assert(reply.keys(1 ) == " 12345801" )
222+ }
223+
224+ it should " respect prefix argument and startAfterKey together" in {
225+ client.put(PutRequest (collectionA, " 123456" , Some (1 ), testData1))
226+ client.put(PutRequest (collectionA, " 123457" , Some (123 ), testData2))
227+ client.put(PutRequest (collectionA, " 12345800" , Some (123 ), testData3))
228+ client.put(PutRequest (collectionA, " 12345801" , Some (123 ), testData3))
229+ client.put(PutRequest (collectionA, " 12345802" , Some (123 ), testData3))
230+ client.put(PutRequest (collectionA, " 123458" , Some (123 ), testData3))
231+ client.put(PutRequest (collectionA, " 123459" , Some (123 ), testData3))
232+
233+ val reply = client.listKeys(ListKeysRequest (collectionA, None , startAfterKey = Some (" 12345800" ), prefix = Some (" 123458" )))
234+ assert(reply.keys.length == 3 )
235+ assert(reply.keys(0 ) == " 12345801" )
236+ assert(reply.keys(1 ) == " 12345802" )
237+ assert(reply.keys(2 ) == " 123458" )
238+ }
239+
198240 " GetMultipleVersions" should " return all versions in decending order if called without limits" in {
199241 client.put(PutRequest (collectionA, aKey, Some (0 ), testData1))
200242 client.put(PutRequest (collectionA, aKey, Some (1 ), testData2))
@@ -348,6 +390,46 @@ class FossilDBSuite extends AnyFlatSpec with BeforeAndAfterEach with TestHelpers
348390 assert(reply.keys.isEmpty)
349391 }
350392
393+ " GetMultipleKeysByListWithVersions" should " return selected keys with versions in descending order" in {
394+ client.put(PutRequest (collectionA, aKey, Some (0 ), testData1))
395+ client.put(PutRequest (collectionA, aNotherKey, Some (0 ), testData1))
396+ client.put(PutRequest (collectionA, aThirdKey, Some (0 ), testData1))
397+ client.put(PutRequest (collectionA, aKey, Some (1 ), testData2))
398+ client.put(PutRequest (collectionA, aNotherKey, Some (1 ), testData2))
399+ client.put(PutRequest (collectionA, aThirdKey, Some (1 ), testData2))
400+ client.put(PutRequest (collectionA, aKey, Some (2 ), testData3))
401+ client.put(PutRequest (collectionA, aNotherKey, Some (2 ), testData3))
402+ client.put(PutRequest (collectionA, aThirdKey, Some (2 ), testData3))
403+ val reply = client.getMultipleKeysByListWithMultipleVersions(GetMultipleKeysByListWithMultipleVersionsRequest (collectionA, keys = Seq (aNotherKey, aThirdKey)))
404+ assert(reply.keyVersionsValuesPairs.map(_.key) == Seq (aNotherKey, aThirdKey))
405+ assert(reply.keyVersionsValuesPairs(0 ).versionValuePairs.length == 3 )
406+ assert(reply.keyVersionsValuesPairs(1 ).versionValuePairs.length == 3 )
407+ assert(reply.keyVersionsValuesPairs(0 ).versionValuePairs(0 ) == VersionValuePairProto (2L , testData3))
408+ assert(reply.keyVersionsValuesPairs(0 ).versionValuePairs(1 ) == VersionValuePairProto (1L , testData2))
409+ assert(reply.keyVersionsValuesPairs(0 ).versionValuePairs(2 ) == VersionValuePairProto (0L , testData1))
410+ assert(reply.keyVersionsValuesPairs(1 ).versionValuePairs(0 ) == VersionValuePairProto (2L , testData3))
411+ assert(reply.keyVersionsValuesPairs(1 ).versionValuePairs(1 ) == VersionValuePairProto (1L , testData2))
412+ assert(reply.keyVersionsValuesPairs(1 ).versionValuePairs(2 ) == VersionValuePairProto (0L , testData1))
413+ }
414+
415+ it should " limit the versions if specified" in {
416+ client.put(PutRequest (collectionA, aKey, Some (0 ), testData1))
417+ client.put(PutRequest (collectionA, aNotherKey, Some (0 ), testData1))
418+ client.put(PutRequest (collectionA, aThirdKey, Some (0 ), testData1))
419+ client.put(PutRequest (collectionA, aKey, Some (1 ), testData2))
420+ client.put(PutRequest (collectionA, aNotherKey, Some (1 ), testData2))
421+ client.put(PutRequest (collectionA, aThirdKey, Some (1 ), testData2))
422+ client.put(PutRequest (collectionA, aKey, Some (2 ), testData3))
423+ client.put(PutRequest (collectionA, aNotherKey, Some (2 ), testData3))
424+ client.put(PutRequest (collectionA, aThirdKey, Some (2 ), testData3))
425+ val reply = client.getMultipleKeysByListWithMultipleVersions(GetMultipleKeysByListWithMultipleVersionsRequest (collectionA, keys = Seq (aNotherKey, aThirdKey), newestVersion = Some (1 ), oldestVersion = Some (1 )))
426+ assert(reply.keyVersionsValuesPairs.map(_.key) == Seq (aNotherKey, aThirdKey))
427+ assert(reply.keyVersionsValuesPairs(0 ).versionValuePairs.length == 1 )
428+ assert(reply.keyVersionsValuesPairs(1 ).versionValuePairs.length == 1 )
429+ assert(reply.keyVersionsValuesPairs(0 ).versionValuePairs(0 ) == VersionValuePairProto (1L , testData2))
430+ assert(reply.keyVersionsValuesPairs(1 ).versionValuePairs(0 ) == VersionValuePairProto (1L , testData2))
431+ }
432+
351433 " Backup" should " create non-empty backup directory" in {
352434 client.put(PutRequest (collectionA, aKey, Some (0 ), testData1))
353435 client.backup(BackupRequest ())
0 commit comments