Skip to content

Commit 822c89d

Browse files
trondndaverigby
authored andcommitted
[cluster_test] move UpgradeTest class to its own files
Change-Id: Ibe141cfa615fddb989f4cf151e08031f68fced26 Reviewed-on: http://review.couchbase.org/c/kv_engine/+/135596 Tested-by: Trond Norbye <[email protected]> Reviewed-by: Dave Rigby <[email protected]>
1 parent 2db6ede commit 822c89d

File tree

7 files changed

+123
-79
lines changed

7 files changed

+123
-79
lines changed

tests/testapp_cluster/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ add_executable(cluster_test
88
main.cc
99
misc_tests.cc
1010
out_of_order_tests.cc
11-
rbac_tests.cc)
11+
rbac_tests.cc
12+
upgrade_test.cc
13+
upgrade_test.h)
1214
target_link_libraries(cluster_test cluster_framework)
1315
add_dependencies(cluster_test memcached ep default_engine)
1416
add_sanitizers(cluster_test)

tests/testapp_cluster/clustertest.cc

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424

2525
std::unique_ptr<cb::test::Cluster> cb::test::ClusterTest::cluster;
2626

27-
std::shared_ptr<cb::test::Bucket> cb::test::UpgradeTest::bucket;
28-
2927
void cb::test::ClusterTest::SetUpTestCase() {
3028
cluster = Cluster::create(4);
3129
if (!cluster) {
@@ -91,25 +89,3 @@ std::string cb::test::ClusterTest::createKey(CollectionID cid,
9189
ret.append(key);
9290
return ret;
9391
}
94-
95-
void cb::test::UpgradeTest::SetUpTestCase() {
96-
// Can't just use the ClusterTest::SetUp as we need to prevent it from
97-
// creating replication streams so that we can create them as we like to
98-
// mock upgrade scenarios.
99-
cluster = Cluster::create(3);
100-
if (!cluster) {
101-
std::cerr << "Failed to create the cluster" << std::endl;
102-
std::exit(EXIT_FAILURE);
103-
}
104-
105-
try {
106-
bucket = cluster->createBucket(
107-
"default",
108-
{{"replicas", 2}, {"max_vbuckets", 1}, {"max_num_shards", 1}},
109-
{},
110-
false /*No replication*/);
111-
} catch (const std::runtime_error& error) {
112-
std::cerr << error.what();
113-
std::exit(EXIT_FAILURE);
114-
}
115-
}

tests/testapp_cluster/clustertest.h

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222

2323
class MemcachedConnection;
2424

25-
namespace cb {
26-
namespace test {
25+
namespace cb::test {
2726

2827
class Bucket;
2928
class Cluster;
@@ -69,18 +68,4 @@ class ClusterTest : public ::testing::Test {
6968
static std::unique_ptr<Cluster> cluster;
7069
};
7170

72-
class UpgradeTest : public ClusterTest {
73-
public:
74-
static void SetUpTestCase();
75-
76-
static void TearDownTestCase() {
77-
bucket.reset();
78-
ClusterTest::TearDownTestCase();
79-
}
80-
81-
protected:
82-
static std::shared_ptr<Bucket> bucket;
83-
};
84-
85-
} // namespace test
86-
} // namespace cb
71+
} // namespace cb::test

tests/testapp_cluster/durability_upgrade_tests.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
#include "clustertest.h"
18+
#include "upgrade_test.h"
1819

1920
#include <cluster_framework/bucket.h>
2021
#include <cluster_framework/cluster.h>

tests/testapp_cluster/misc_tests.cc

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -155,40 +155,3 @@ TEST_F(BasicClusterTest, UsingExternalAuth) {
155155

156156
cluster->getAuthProviderService().removeUser("extuser");
157157
}
158-
159-
using UpgradeTest = cb::test::UpgradeTest;
160-
TEST_F(UpgradeTest, ExpiryOpcodeDoesntEnableDeleteV2) {
161-
// MB-38390: Check that DcpProducers respect the includeDeleteTime flag
162-
// sent at dcpOpen, and "enable_expiry_opcode" did not erroneously cause the
163-
// producer to send deletion times.
164-
165-
// Set up replication from node 0 to node 1 with flags==0, specifically so
166-
// includeDeleteTime is disabled.
167-
bucket->setupReplication({{0, 1, false, 0}, {0, 2, false, 0}});
168-
169-
// store and delete a document on the active
170-
auto conn = bucket->getConnection(Vbid(0));
171-
conn->authenticate("@admin", "password", "PLAIN");
172-
conn->selectBucket(bucket->getName());
173-
auto info = conn->store("foo", Vbid(0), "value");
174-
EXPECT_NE(0, info.cas);
175-
info = conn->remove("foo", Vbid(0));
176-
EXPECT_NE(0, info.cas);
177-
178-
// make sure that the delete is replicated to all replicas
179-
const auto nrep = bucket->getVbucketMap()[0].size() - 1;
180-
for (std::size_t rep = 0; rep < nrep; ++rep) {
181-
conn = bucket->getConnection(Vbid(0), vbucket_state_replica, rep);
182-
conn->authenticate("@admin", "password", "PLAIN");
183-
conn->selectBucket(bucket->getName());
184-
185-
// Wait for persistence of our item
186-
ObserveInfo observeInfo;
187-
do {
188-
observeInfo = conn->observeSeqno(Vbid(0), info.vbucketuuid);
189-
} while (observeInfo.lastPersistedSeqno != info.seqno);
190-
}
191-
192-
// Done! The consumer side dcp_deletion_validator would throw if
193-
// the producer sent a V2 deletion despite the flag being unset.
194-
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Copyright 2020 Couchbase, Inc
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "upgrade_test.h"
18+
#include <cluster_framework/bucket.h>
19+
#include <cluster_framework/cluster.h>
20+
#include <cluster_framework/dcp_replicator.h>
21+
#include <protocol/connection/client_connection.h>
22+
#include <protocol/connection/client_mcbp_commands.h>
23+
24+
std::shared_ptr<cb::test::Bucket> cb::test::UpgradeTest::bucket;
25+
26+
void cb::test::UpgradeTest::SetUpTestCase() {
27+
// Can't just use the ClusterTest::SetUp as we need to prevent it from
28+
// creating replication streams so that we can create them as we like to
29+
// mock upgrade scenarios.
30+
cluster = Cluster::create(3);
31+
if (!cluster) {
32+
std::cerr << "Failed to create the cluster" << std::endl;
33+
std::exit(EXIT_FAILURE);
34+
}
35+
36+
try {
37+
bucket = cluster->createBucket(
38+
"default",
39+
{{"replicas", 2}, {"max_vbuckets", 1}, {"max_num_shards", 1}},
40+
{},
41+
false /*No replication*/);
42+
} catch (const std::runtime_error& error) {
43+
std::cerr << error.what();
44+
std::exit(EXIT_FAILURE);
45+
}
46+
}
47+
using UpgradeTest = cb::test::UpgradeTest;
48+
TEST_F(UpgradeTest, ExpiryOpcodeDoesntEnableDeleteV2) {
49+
// MB-38390: Check that DcpProducers respect the includeDeleteTime flag
50+
// sent at dcpOpen, and "enable_expiry_opcode" did not erroneously cause the
51+
// producer to send deletion times.
52+
53+
// Set up replication from node 0 to node 1 with flags==0, specifically so
54+
// includeDeleteTime is disabled.
55+
bucket->setupReplication({{0, 1, false, 0}, {0, 2, false, 0}});
56+
57+
// store and delete a document on the active
58+
auto conn = bucket->getConnection(Vbid(0));
59+
conn->authenticate("@admin", "password", "PLAIN");
60+
conn->selectBucket(bucket->getName());
61+
auto info = conn->store("foo", Vbid(0), "value");
62+
EXPECT_NE(0, info.cas);
63+
info = conn->remove("foo", Vbid(0));
64+
EXPECT_NE(0, info.cas);
65+
66+
// make sure that the delete is replicated to all replicas
67+
const auto nrep = bucket->getVbucketMap()[0].size() - 1;
68+
for (std::size_t rep = 0; rep < nrep; ++rep) {
69+
conn = bucket->getConnection(Vbid(0), vbucket_state_replica, rep);
70+
conn->authenticate("@admin", "password", "PLAIN");
71+
conn->selectBucket(bucket->getName());
72+
73+
// Wait for persistence of our item
74+
ObserveInfo observeInfo;
75+
do {
76+
observeInfo = conn->observeSeqno(Vbid(0), info.vbucketuuid);
77+
} while (observeInfo.lastPersistedSeqno != info.seqno);
78+
}
79+
80+
// Done! The consumer side dcp_deletion_validator would throw if
81+
// the producer sent a V2 deletion despite the flag being unset.
82+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2020 Couchbase, Inc
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#pragma once
17+
18+
#include "clustertest.h"
19+
20+
namespace cb::test {
21+
/// The UpgradeTest class create a 3 node cluster and a bucket without
22+
/// replication set up to allow for mocking that
23+
class UpgradeTest : public ClusterTest {
24+
public:
25+
static void SetUpTestCase();
26+
27+
static void TearDownTestCase() {
28+
bucket.reset();
29+
ClusterTest::TearDownTestCase();
30+
}
31+
32+
protected:
33+
static std::shared_ptr<Bucket> bucket;
34+
};
35+
} // namespace cb::test

0 commit comments

Comments
 (0)