1/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 *     Copyright 2017 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/*
19 * Mock of the BasicLinkedList class.  Wraps the real BasicLinkedList class
20 * and provides access to functions like getAllItemsForVerification().
21 */
22#pragma once
23
24#include "../mock/mock_basic_ll.h"
25#include "ephemeral_vb.h"
26
27#include <mutex>
28#include <vector>
29
30class MockEphemeralVBucket : public EphemeralVBucket {
31public:
32    MockEphemeralVBucket(Vbid i,
33                         vbucket_state_t newState,
34                         EPStats& st,
35                         CheckpointConfig& chkConfig,
36                         KVShard* kvshard,
37                         int64_t lastSeqno,
38                         uint64_t lastSnapStart,
39                         uint64_t lastSnapEnd,
40                         std::unique_ptr<FailoverTable> table,
41                         NewSeqnoCallback newSeqnoCb,
42                         SyncWriteResolvedCallback syncWriteResolvedCb,
43                         SyncWriteCompleteCallback syncWriteCb,
44                         SeqnoAckCallback seqnoAckCb,
45                         Configuration& config,
46                         EvictionPolicy evictionPolicy);
47
48    /* Register fake shared range lock for testing */
49    RangeGuard registerFakeSharedRangeLock(seqno_t start, seqno_t end) {
50        return mockLL->registerFakeSharedRangeLock(start, end);
51    }
52
53    /* Register fake exclusive range lock for testing */
54    RangeGuard registerFakeRangeLock(seqno_t start, seqno_t end) {
55        return mockLL->registerFakeRangeLock(start, end);
56    }
57
58    int public_getNumStaleItems() {
59        return mockLL->getNumStaleItems();
60    }
61
62    int public_getNumListItems() {
63        return mockLL->getNumItems();
64    }
65
66    int public_getNumListDeletedItems() {
67        return mockLL->getNumDeletedItems();
68    }
69
70    uint64_t public_getListHighSeqno() const {
71        return mockLL->getHighSeqno();
72    }
73
74    MockBasicLinkedList* getLL() {
75        return mockLL;
76    }
77
78    /**
79     * Convenience method to run the HT tombstone purger across the entire
80     * vBucket (this is normally done with a seperate task using the
81     * pause/resumevisitor).
82     * @return Count of items marked stale and moved to sequenceList.
83     */
84    size_t markOldTombstonesStale(rel_time_t purgeAge);
85
86    void public_doCollectionsStats(
87            const Collections::VB::Manifest::CachingReadHandle& cHandle,
88            const VBNotifyCtx& notifyCtx);
89
90private:
91    /* non owning ptr to the linkedlist in the ephemeral vbucket obj */
92    MockBasicLinkedList* mockLL;
93};
94