|
| 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 | +} |
0 commit comments