]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | /* | |
4 | * Ceph - scalable distributed file system | |
5 | * | |
6 | * Copyright (C) 2016 Casey Bodley <cbodley@redhat.com> | |
7 | * | |
8 | * This is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU Lesser General Public | |
10 | * License version 2.1, as published by the Free Software | |
11 | * Foundation. See file COPYING. | |
12 | * | |
13 | */ | |
14 | ||
15 | #include "os/ObjectStore.h" | |
16 | #include <gtest/gtest.h> | |
17 | #include "common/Clock.h" | |
18 | #include "include/utime.h" | |
19 | #include <boost/tuple/tuple.hpp> | |
20 | ||
20effc67 TL |
21 | using namespace std; |
22 | ||
7c673cae FG |
23 | TEST(Transaction, MoveConstruct) |
24 | { | |
25 | auto a = ObjectStore::Transaction{}; | |
26 | a.nop(); | |
27 | ASSERT_FALSE(a.empty()); | |
28 | ||
29 | // move-construct in b | |
30 | auto b = std::move(a); | |
31 | ASSERT_TRUE(a.empty()); | |
32 | ASSERT_FALSE(b.empty()); | |
33 | } | |
34 | ||
35 | TEST(Transaction, MoveAssign) | |
36 | { | |
37 | auto a = ObjectStore::Transaction{}; | |
38 | a.nop(); | |
39 | ASSERT_FALSE(a.empty()); | |
40 | ||
41 | auto b = ObjectStore::Transaction{}; | |
42 | b = std::move(a); // move-assign to b | |
43 | ASSERT_TRUE(a.empty()); | |
44 | ASSERT_FALSE(b.empty()); | |
45 | } | |
46 | ||
47 | TEST(Transaction, CopyConstruct) | |
48 | { | |
49 | auto a = ObjectStore::Transaction{}; | |
50 | a.nop(); | |
51 | ASSERT_FALSE(a.empty()); | |
52 | ||
53 | auto b = a; // copy-construct in b | |
54 | ASSERT_FALSE(a.empty()); | |
55 | ASSERT_FALSE(b.empty()); | |
56 | } | |
57 | ||
58 | TEST(Transaction, CopyAssign) | |
59 | { | |
60 | auto a = ObjectStore::Transaction{}; | |
61 | a.nop(); | |
62 | ASSERT_FALSE(a.empty()); | |
63 | ||
64 | auto b = ObjectStore::Transaction{}; | |
65 | b = a; // copy-assign to b | |
66 | ASSERT_FALSE(a.empty()); | |
67 | ASSERT_FALSE(b.empty()); | |
68 | } | |
69 | ||
70 | TEST(Transaction, Swap) | |
71 | { | |
72 | auto a = ObjectStore::Transaction{}; | |
73 | a.nop(); | |
74 | ASSERT_FALSE(a.empty()); | |
75 | ||
76 | auto b = ObjectStore::Transaction{}; | |
77 | std::swap(a, b); // swap a and b | |
78 | ASSERT_TRUE(a.empty()); | |
79 | ASSERT_FALSE(b.empty()); | |
80 | } | |
81 | ||
82 | ObjectStore::Transaction generate_transaction() | |
83 | { | |
84 | auto a = ObjectStore::Transaction{}; | |
85 | a.nop(); | |
86 | ||
87 | coll_t cid; | |
88 | object_t obj("test_name"); | |
89 | snapid_t snap(0); | |
90 | hobject_t hoid(obj, "key", snap, 0, 0, "nspace"); | |
91 | ghobject_t oid(hoid); | |
92 | ||
93 | coll_t acid; | |
94 | object_t aobj("another_test_name"); | |
95 | snapid_t asnap(0); | |
96 | hobject_t ahoid(obj, "another_key", snap, 0, 0, "another_nspace"); | |
97 | ghobject_t aoid(hoid); | |
98 | std::set<string> keys; | |
99 | keys.insert("any_1"); | |
100 | keys.insert("any_2"); | |
101 | keys.insert("any_3"); | |
102 | ||
103 | bufferlist bl; | |
104 | bl.append_zero(4096); | |
105 | ||
106 | a.write(cid, oid, 1, 4096, bl, 0); | |
107 | ||
108 | a.omap_setkeys(acid, aoid, bl); | |
109 | ||
110 | a.omap_rmkeys(cid, aoid, keys); | |
111 | ||
112 | a.touch(acid, oid); | |
113 | ||
114 | return a; | |
115 | } | |
116 | ||
117 | TEST(Transaction, MoveRangesDelSrcObj) | |
118 | { | |
119 | auto t = ObjectStore::Transaction{}; | |
120 | t.nop(); | |
121 | ||
122 | coll_t c(spg_t(pg_t(1,2), shard_id_t::NO_SHARD)); | |
123 | ||
124 | ghobject_t o1(hobject_t("obj", "", 123, 456, -1, "")); | |
125 | ghobject_t o2(hobject_t("obj2", "", 123, 456, -1, "")); | |
126 | vector<std::pair<uint64_t, uint64_t>> move_info = { | |
127 | make_pair(1, 5), | |
128 | make_pair(10, 5) | |
129 | }; | |
130 | ||
131 | t.touch(c, o1); | |
132 | bufferlist bl; | |
133 | bl.append("some data"); | |
134 | t.write(c, o1, 1, bl.length(), bl); | |
135 | t.write(c, o1, 10, bl.length(), bl); | |
136 | ||
137 | t.clone(c, o1, o2); | |
138 | bl.append("some other data"); | |
139 | t.write(c, o2, 1, bl.length(), bl); | |
140 | } | |
141 | ||
142 | TEST(Transaction, GetNumBytes) | |
143 | { | |
144 | auto a = ObjectStore::Transaction{}; | |
145 | a.nop(); | |
146 | ASSERT_TRUE(a.get_encoded_bytes() == a.get_encoded_bytes_test()); | |
147 | ||
148 | coll_t cid; | |
149 | object_t obj("test_name"); | |
150 | snapid_t snap(0); | |
151 | hobject_t hoid(obj, "key", snap, 0, 0, "nspace"); | |
152 | ghobject_t oid(hoid); | |
153 | ||
154 | coll_t acid; | |
155 | object_t aobj("another_test_name"); | |
156 | snapid_t asnap(0); | |
157 | hobject_t ahoid(obj, "another_key", snap, 0, 0, "another_nspace"); | |
158 | ghobject_t aoid(hoid); | |
159 | std::set<string> keys; | |
160 | keys.insert("any_1"); | |
161 | keys.insert("any_2"); | |
162 | keys.insert("any_3"); | |
163 | ||
164 | bufferlist bl; | |
165 | bl.append_zero(4096); | |
166 | ||
167 | a.write(cid, oid, 1, 4096, bl, 0); | |
168 | ASSERT_TRUE(a.get_encoded_bytes() == a.get_encoded_bytes_test()); | |
169 | ||
170 | a.omap_setkeys(acid, aoid, bl); | |
171 | ASSERT_TRUE(a.get_encoded_bytes() == a.get_encoded_bytes_test()); | |
172 | ||
173 | a.omap_rmkeys(cid, aoid, keys); | |
174 | ASSERT_TRUE(a.get_encoded_bytes() == a.get_encoded_bytes_test()); | |
175 | ||
176 | a.touch(acid, oid); | |
177 | ASSERT_TRUE(a.get_encoded_bytes() == a.get_encoded_bytes_test()); | |
178 | } | |
179 | ||
180 | void bench_num_bytes(bool legacy) | |
181 | { | |
182 | const int max = 2500000; | |
183 | auto a = generate_transaction(); | |
184 | ||
185 | if (legacy) { | |
186 | cout << "get_encoded_bytes_test: "; | |
187 | } else { | |
188 | cout << "get_encoded_bytes: "; | |
189 | } | |
190 | ||
191 | utime_t start = ceph_clock_now(); | |
192 | if (legacy) { | |
193 | for (int i = 0; i < max; ++i) { | |
194 | a.get_encoded_bytes_test(); | |
195 | } | |
196 | } else { | |
197 | for (int i = 0; i < max; ++i) { | |
198 | a.get_encoded_bytes(); | |
199 | } | |
200 | } | |
201 | ||
202 | utime_t end = ceph_clock_now(); | |
203 | cout << max << " encodes in " << (end - start) << std::endl; | |
204 | ||
205 | } | |
206 | ||
207 | TEST(Transaction, GetNumBytesBenchLegacy) | |
208 | { | |
209 | bench_num_bytes(true); | |
210 | } | |
211 | ||
212 | TEST(Transaction, GetNumBytesBenchCurrent) | |
213 | { | |
214 | bench_num_bytes(false); | |
215 | } |