]>
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 Red Hat | |
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 <gtest/gtest.h> | |
16 | #include "osd/PGTransaction.h" | |
17 | ||
20effc67 TL |
18 | using namespace std; |
19 | ||
7c673cae FG |
20 | TEST(pgtransaction, simple) |
21 | { | |
22 | hobject_t h; | |
23 | PGTransaction t; | |
24 | ASSERT_TRUE(t.empty()); | |
25 | t.nop(h); | |
26 | ASSERT_FALSE(t.empty()); | |
27 | unsigned num = 0; | |
28 | t.safe_create_traverse( | |
29 | [&](const pair<const hobject_t, PGTransaction::ObjectOperation> &p) { | |
30 | ASSERT_EQ(p.first, h); | |
31 | using T = PGTransaction::ObjectOperation::Init; | |
32 | ASSERT_TRUE(boost::get<T::None>(&p.second.init_type)); | |
33 | ++num; | |
34 | }); | |
35 | ASSERT_EQ(num, 1u); | |
36 | } | |
37 | ||
38 | TEST(pgtransaction, clone_safe_create_traverse) | |
39 | { | |
40 | hobject_t h, h2; | |
41 | h2.snap = 1; | |
42 | PGTransaction t; | |
43 | ASSERT_TRUE(t.empty()); | |
44 | t.nop(h2); | |
45 | ASSERT_FALSE(t.empty()); | |
46 | t.clone(h, h2); | |
47 | unsigned num = 0; | |
48 | t.safe_create_traverse( | |
49 | [&](const pair<const hobject_t, PGTransaction::ObjectOperation> &p) { | |
50 | using T = PGTransaction::ObjectOperation::Init; | |
51 | if (num == 0) { | |
52 | ASSERT_EQ(p.first, h); | |
53 | ASSERT_TRUE(boost::get<T::Clone>(&p.second.init_type)); | |
54 | ASSERT_EQ( | |
55 | boost::get<T::Clone>(&p.second.init_type)->source, | |
56 | h2); | |
57 | } else if (num == 1) { | |
58 | ASSERT_EQ(p.first, h2); | |
59 | ASSERT_TRUE(boost::get<T::None>(&p.second.init_type)); | |
60 | } else { | |
61 | ASSERT_LT(num, 2u); | |
62 | } | |
63 | ++num; | |
64 | }); | |
65 | } | |
66 | ||
67 | TEST(pgtransaction, clone_safe_create_traverse2) | |
68 | { | |
69 | hobject_t h, h2, h3; | |
70 | h.snap = 10; | |
71 | h2.snap = 5; | |
72 | h3.snap = 3; | |
73 | PGTransaction t; | |
74 | ASSERT_TRUE(t.empty()); | |
75 | t.nop(h3); | |
76 | ASSERT_FALSE(t.empty()); | |
77 | t.clone(h, h2); | |
78 | t.remove(h2); | |
79 | t.clone(h2, h3); | |
80 | unsigned num = 0; | |
81 | t.safe_create_traverse( | |
82 | [&](const pair<const hobject_t, PGTransaction::ObjectOperation> &p) { | |
83 | using T = PGTransaction::ObjectOperation::Init; | |
84 | if (num == 0) { | |
85 | ASSERT_EQ(p.first, h); | |
86 | ASSERT_TRUE(boost::get<T::Clone>(&p.second.init_type)); | |
87 | ASSERT_EQ( | |
88 | boost::get<T::Clone>(&p.second.init_type)->source, | |
89 | h2); | |
90 | } else if (num == 1) { | |
91 | ASSERT_EQ(p.first, h2); | |
92 | ASSERT_TRUE(boost::get<T::Clone>(&p.second.init_type)); | |
93 | ASSERT_EQ( | |
94 | boost::get<T::Clone>(&p.second.init_type)->source, | |
95 | h3); | |
96 | } else if (num == 2) { | |
97 | ASSERT_EQ(p.first, h3); | |
98 | ASSERT_TRUE(boost::get<T::None>(&p.second.init_type)); | |
99 | } else { | |
100 | ASSERT_LT(num, 3u); | |
101 | } | |
102 | ++num; | |
103 | }); | |
104 | } | |
105 | ||
106 | TEST(pgtransaction, clone_safe_create_traverse3) | |
107 | { | |
108 | hobject_t h, h2, h3; | |
109 | h.snap = 10; | |
110 | h2.snap = 5; | |
111 | h3.snap = 3; | |
112 | PGTransaction t; | |
113 | t.remove(h); | |
114 | t.remove(h2); | |
115 | t.clone(h2, h3); | |
116 | unsigned num = 0; | |
117 | t.safe_create_traverse( | |
118 | [&](const pair<const hobject_t, PGTransaction::ObjectOperation> &p) { | |
119 | using T = PGTransaction::ObjectOperation::Init; | |
120 | if (p.first == h) { | |
121 | ASSERT_TRUE(p.second.is_delete()); | |
122 | } else if (p.first == h2) { | |
123 | ASSERT_TRUE(boost::get<T::Clone>(&p.second.init_type)); | |
124 | ASSERT_EQ( | |
125 | boost::get<T::Clone>(&p.second.init_type)->source, | |
126 | h3); | |
127 | } | |
128 | ASSERT_LT(num, 2u); | |
129 | ++num; | |
130 | }); | |
131 | } |