-
Notifications
You must be signed in to change notification settings - Fork 0
/
multisegment_test.cpp
70 lines (62 loc) · 1.89 KB
/
multisegment_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#define BOOST_TEST_MODULE multisegment
#include <boost/test/included/unit_test.hpp>
#include <iostream>
#include <random>
#include <algorithm>
#include "skiplist.h"
#include "keyvalue.h"
#include "memorysegment.h"
#include "multisegment.h"
#include "segment.h"
BOOST_AUTO_TEST_CASE( multisegment ) {
auto m1 = MemorySegment::newMemoryOnlySegment();
for (int i= 0; i < 1; i++) {
m1->put("mykey" + std::to_string(i), "myvalue" + std::to_string(i));
}
auto m2 = MemorySegment::newMemoryOnlySegment();
for (int i = 1; i < 2; i++) {
m2->put("mykey" + std::to_string(i), "myvalue" + std::to_string(i));
}
auto ms = MultiSegment::newMultiSegment({m1,m2});
auto itr = ms->lookup("","");
int count = 0;
while(true) {
auto kv = itr->next();
if(kv.key.empty()) {
break;
}
count++;
}
BOOST_TEST(count == 2);
}
BOOST_AUTO_TEST_CASE( multisegment_edit ) {
auto m1 = MemorySegment::newMemoryOnlySegment();
for (int i= 0; i < 1; i++) {
m1->put("mykey" + std::to_string(i), "myvalue" + std::to_string(i));
}
auto m2 = MemorySegment::newMemoryOnlySegment();
for (int i = 0; i < 1; i++) {
m2->put("mykey" + std::to_string(i), "myvaluex" + std::to_string(i));
}
auto ms = MultiSegment::newMultiSegment({m1,m2});
auto itr = ms->lookup("","");
auto kv = itr->next();
BOOST_TEST(kv.value=="myvaluex0");
auto kv2 = itr->next();
BOOST_TEST(kv2.key.empty());
}
BOOST_AUTO_TEST_CASE( multisegment_remove ) {
auto m1 = MemorySegment::newMemoryOnlySegment();
for (int i= 0; i < 1; i++) {
m1->put("mykey" + std::to_string(i), "myvalue" + std::to_string(i));
}
auto m2 = MemorySegment::newMemoryOnlySegment();
for (int i = 0; i < 1; i++) {
m2->put("mykey" + std::to_string(i), "");
}
auto ms = MultiSegment::newMultiSegment({m1,m2});
auto itr = ms->lookup("","");
int count = 0;
while(!(itr->next().value.empty())) count++;
BOOST_TEST(count==0);
}