1 /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3  *     Copyright 2019 Couchbase, Inc
4  *
5  *   Licensed under the Apache License, Version 2.0 (the "License");
6  *   you may not use this file except in compliance with the License.
7  *   You may obtain a copy of the License at
8  *
9  *       http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *   Unless required by applicable law or agreed to in writing, software
12  *   distributed under the License is distributed on an "AS IS" BASIS,
13  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *   See the License for the specific language governing permissions and
15  *   limitations under the License.
16  */
17 
18 #include "mock_dcp_consumer.h"
19 #include "dcp/response.h"
20 #include "mock_stream.h"
21 
MockDcpConsumer(EventuallyPersistentEngine& theEngine, const void* cookie, const std::string& name, const std::string& consumerName)22 MockDcpConsumer::MockDcpConsumer(EventuallyPersistentEngine& theEngine,
23                                  const void* cookie,
24                                  const std::string& name,
25                                  const std::string& consumerName)
26     : DcpConsumer(theEngine, cookie, name, consumerName) {
27 }
28 
makePassiveStream( EventuallyPersistentEngine& e, std::shared_ptr<DcpConsumer> consumer, const std::string& name, uint32_t flags, uint32_t opaque, Vbid vb, uint64_t start_seqno, uint64_t end_seqno, uint64_t vb_uuid, uint64_t snap_start_seqno, uint64_t snap_end_seqno, uint64_t vb_high_seqno, const Collections::ManifestUid vb_manifest_uid)29 std::shared_ptr<PassiveStream> MockDcpConsumer::makePassiveStream(
30         EventuallyPersistentEngine& e,
31         std::shared_ptr<DcpConsumer> consumer,
32         const std::string& name,
33         uint32_t flags,
34         uint32_t opaque,
35         Vbid vb,
36         uint64_t start_seqno,
37         uint64_t end_seqno,
38         uint64_t vb_uuid,
39         uint64_t snap_start_seqno,
40         uint64_t snap_end_seqno,
41         uint64_t vb_high_seqno,
42         const Collections::ManifestUid vb_manifest_uid) {
43     return std::make_shared<MockPassiveStream>(e,
44                                                consumer,
45                                                name,
46                                                flags,
47                                                opaque,
48                                                vb,
49                                                start_seqno,
50                                                end_seqno,
51                                                vb_uuid,
52                                                snap_start_seqno,
53                                                snap_end_seqno,
54                                                vb_high_seqno,
55                                                vb_manifest_uid);
56 }
57 
getStreamOpaque(uint32_t opaque)58 boost::optional<uint32_t> MockDcpConsumer::getStreamOpaque(uint32_t opaque) {
59     for (const auto& pair : opaqueMap_) {
60         if (pair.second.first == opaque) {
61             return pair.first;
62         }
63     }
64     return {};
65 }
66