Skip to content

Commit 97b606f

Browse files
committed
Move Mock{Ep,Ephemeral}Bucket defns to .cc
Move the definitions of methods in classes Mock{Ep,Ephemeral}Bucket into new .cc files. This minimises the headers needed in the .h files; in turn reducing the number of other headers pulled in by users of the Mock classes. Also create a new Object Library to group the various mock_XXX.cc files, so we don't have to specify the individual source files multiple times when used by different programs. Change-Id: I6480c33606adf50268ac343950feb212806cb385 Reviewed-on: http://review.couchbase.org/113436 Tested-by: Build Bot <[email protected]> Reviewed-by: James Harrison <[email protected]>
1 parent 30317c7 commit 97b606f

22 files changed

+190
-93
lines changed

engines/ep/CMakeLists.txt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,20 @@ add_sanitizers(ep)
315315
if (NOT EP_BYPASS_TESTS)
316316
add_subdirectory(tests)
317317

318+
add_library(ep_mocks OBJECT
319+
tests/mock/mock_dcp_conn_map.cc
320+
tests/mock/mock_dcp_producer.cc
321+
tests/mock/mock_ep_bucket.cc
322+
tests/mock/mock_ephemeral_bucket.cc
323+
tests/mock/mock_ephemeral_vb.cc
324+
tests/mock/mock_executor_pool.cc
325+
tests/mock/mock_stream.cc
326+
tests/mock/mock_synchronous_ep_engine.cc
327+
${CMAKE_CURRENT_BINARY_DIR}/src/generated_configuration.h
328+
)
329+
set_property(TARGET ep_mocks PROPERTY POSITION_INDEPENDENT_CODE 1)
330+
add_sanitizers(ep_mocks)
331+
318332
# While ep_perfsuite is arguably a "test" and hence should live under
319333
# tests/, we *don't* want optimizations disabled for it hence keep in
320334
# this directory.
@@ -346,8 +360,8 @@ if (NOT EP_BYPASS_TESTS)
346360
benchmarks/mem_allocator_stats_bench.cc
347361
benchmarks/vbucket_bench.cc
348362
benchmarks/probabilistic_counter_bench.cc
349-
tests/mock/mock_synchronous_ep_engine.cc
350363
$<TARGET_OBJECTS:ep_objs>
364+
$<TARGET_OBJECTS:ep_mocks>
351365
$<TARGET_OBJECTS:memory_tracking>
352366
$<TARGET_OBJECTS:couchstore_test_fileops>
353367
${Memcached_SOURCE_DIR}/programs/engine_testapp/mock_server.cc

engines/ep/benchmarks/access_scanner_bench.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "benchmark_memory_tracker.h"
2828

2929
#include "engine_fixture.h"
30+
#include "item.h"
3031

3132
class AccessLogBenchEngine : public EngineFixture {
3233
protected:

engines/ep/benchmarks/vbucket_bench.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "checkpoint_manager.h"
2424
#include "engine_fixture.h"
2525
#include "fakes/fake_executorpool.h"
26+
#include "item.h"
2627
#include "stored_value_factories.h"
2728

2829
#include "../tests/module_tests/thread_gate.h"

engines/ep/tests/CMakeLists.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ add_sanitizers(ep_testsuite_objs)
1717
# (We end up compiling most of the src/ files of ep-engine for these unit tests,
1818
# so simpler / quicker just to link them into a single executable).
1919
ADD_EXECUTABLE(ep-engine_ep_unit_tests
20-
mock/mock_dcp_conn_map.cc
21-
mock/mock_dcp_producer.cc
22-
mock/mock_ephemeral_vb.cc
23-
mock/mock_executor_pool.cc
24-
mock/mock_stream.cc
25-
mock/mock_synchronous_ep_engine.cc
2620
module_tests/atomic_unordered_map_test.cc
2721
module_tests/basic_ll_test.cc
2822
module_tests/bloomfilter_test.cc
@@ -100,6 +94,7 @@ ADD_EXECUTABLE(ep-engine_ep_unit_tests
10094
module_tests/warmup_test.cc
10195
$<TARGET_OBJECTS:mock_dcp>
10296
$<TARGET_OBJECTS:ep_objs>
97+
$<TARGET_OBJECTS:ep_mocks>
10398
$<TARGET_OBJECTS:memory_tracking>
10499
$<TARGET_OBJECTS:couchstore_test_fileops>
105100
$<TARGET_OBJECTS:couchfile_upgrade_objects>
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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_ep_bucket.h"
19+
#include "ep_engine.h"
20+
#include "executorpool.h"
21+
#include "failover-table.h"
22+
#include "mock_checkpoint_manager.h"
23+
#include "mock_item_freq_decayer.h"
24+
25+
void MockEPBucket::createItemFreqDecayerTask() {
26+
Configuration& config = engine.getConfiguration();
27+
itemFreqDecayerTask = std::make_shared<MockItemFreqDecayerTask>(
28+
&engine, config.getItemFreqDecayerPercent());
29+
}
30+
31+
void MockEPBucket::disableItemFreqDecayerTask() {
32+
ExecutorPool::get()->cancel(itemFreqDecayerTask->getId());
33+
}
34+
35+
MockItemFreqDecayerTask* MockEPBucket::getMockItemFreqDecayerTask() {
36+
return dynamic_cast<MockItemFreqDecayerTask*>(itemFreqDecayerTask.get());
37+
}
38+
39+
VBucketPtr MockEPBucket::makeVBucket(
40+
Vbid id,
41+
vbucket_state_t state,
42+
KVShard* shard,
43+
std::unique_ptr<FailoverTable> table,
44+
NewSeqnoCallback newSeqnoCb,
45+
std::unique_ptr<Collections::VB::Manifest> manifest,
46+
vbucket_state_t initState,
47+
int64_t lastSeqno,
48+
uint64_t lastSnapStart,
49+
uint64_t lastSnapEnd,
50+
uint64_t purgeSeqno,
51+
uint64_t maxCas,
52+
int64_t hlcEpochSeqno,
53+
bool mightContainXattrs,
54+
const nlohmann::json& replicationTopology) {
55+
auto vptr = EPBucket::makeVBucket(id,
56+
state,
57+
shard,
58+
std::move(table),
59+
std::move(newSeqnoCb),
60+
std::move(manifest),
61+
initState,
62+
lastSeqno,
63+
lastSnapStart,
64+
lastSnapEnd,
65+
purgeSeqno,
66+
maxCas,
67+
hlcEpochSeqno,
68+
mightContainXattrs,
69+
replicationTopology);
70+
// Create a MockCheckpointManager.
71+
vptr->checkpointManager = std::make_unique<MockCheckpointManager>(
72+
stats,
73+
id,
74+
engine.getCheckpointConfig(),
75+
lastSeqno,
76+
lastSnapStart,
77+
lastSnapEnd,
78+
/*flusher callback*/ nullptr);
79+
return vptr;
80+
}

engines/ep/tests/mock/mock_ep_bucket.h

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,9 @@
1717

1818
#pragma once
1919

20-
#include "../mock/mock_checkpoint_manager.h"
21-
#include "../mock/mock_item_freq_decayer.h"
2220
#include "ep_bucket.h"
23-
#include "ep_engine.h"
24-
#include "executorpool.h"
25-
#include "failover-table.h" // For the std::move(table) in makeVBucket
21+
22+
class MockItemFreqDecayerTask;
2623

2724
/*
2825
* Mock of the EPBucket class.
@@ -32,20 +29,11 @@ class MockEPBucket : public EPBucket {
3229
MockEPBucket(EventuallyPersistentEngine& theEngine) : EPBucket(theEngine) {
3330
}
3431

35-
void createItemFreqDecayerTask() {
36-
Configuration& config = engine.getConfiguration();
37-
itemFreqDecayerTask = std::make_shared<MockItemFreqDecayerTask>(
38-
&engine, config.getItemFreqDecayerPercent());
39-
}
32+
void createItemFreqDecayerTask();
4033

41-
void disableItemFreqDecayerTask() {
42-
ExecutorPool::get()->cancel(itemFreqDecayerTask->getId());
43-
}
34+
void disableItemFreqDecayerTask();
4435

45-
MockItemFreqDecayerTask* getMockItemFreqDecayerTask() {
46-
return dynamic_cast<MockItemFreqDecayerTask*>(
47-
itemFreqDecayerTask.get());
48-
}
36+
MockItemFreqDecayerTask* getMockItemFreqDecayerTask();
4937

5038
VBucketPtr makeVBucket(Vbid id,
5139
vbucket_state_t state,
@@ -61,31 +49,5 @@ class MockEPBucket : public EPBucket {
6149
uint64_t maxCas,
6250
int64_t hlcEpochSeqno,
6351
bool mightContainXattrs,
64-
const nlohmann::json& replicationTopology) override {
65-
auto vptr = EPBucket::makeVBucket(id,
66-
state,
67-
shard,
68-
std::move(table),
69-
std::move(newSeqnoCb),
70-
std::move(manifest),
71-
initState,
72-
lastSeqno,
73-
lastSnapStart,
74-
lastSnapEnd,
75-
purgeSeqno,
76-
maxCas,
77-
hlcEpochSeqno,
78-
mightContainXattrs,
79-
replicationTopology);
80-
// Create a MockCheckpointManager.
81-
vptr->checkpointManager = std::make_unique<MockCheckpointManager>(
82-
stats,
83-
id,
84-
engine.getCheckpointConfig(),
85-
lastSeqno,
86-
lastSnapStart,
87-
lastSnapEnd,
88-
/*flusher callback*/ nullptr);
89-
return vptr;
90-
}
52+
const nlohmann::json& replicationTopology) override;
9153
};
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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_ephemeral_bucket.h"
19+
#include "ep_engine.h"
20+
#include "executorpool.h"
21+
#include "failover-table.h"
22+
#include "mock_checkpoint_manager.h"
23+
24+
VBucketPtr MockEphemeralBucket::makeVBucket(
25+
Vbid id,
26+
vbucket_state_t state,
27+
KVShard* shard,
28+
std::unique_ptr<FailoverTable> table,
29+
NewSeqnoCallback newSeqnoCb,
30+
std::unique_ptr<Collections::VB::Manifest> manifest,
31+
vbucket_state_t initState,
32+
int64_t lastSeqno,
33+
uint64_t lastSnapStart,
34+
uint64_t lastSnapEnd,
35+
uint64_t purgeSeqno,
36+
uint64_t maxCas,
37+
int64_t hlcEpochSeqno,
38+
bool mightContainXattrs,
39+
const nlohmann::json& replicationTopology) {
40+
auto vptr = EphemeralBucket::makeVBucket(id,
41+
state,
42+
shard,
43+
std::move(table),
44+
std::move(newSeqnoCb),
45+
std::move(manifest),
46+
initState,
47+
lastSeqno,
48+
lastSnapStart,
49+
lastSnapEnd,
50+
purgeSeqno,
51+
maxCas,
52+
hlcEpochSeqno,
53+
mightContainXattrs,
54+
replicationTopology);
55+
56+
vptr->checkpointManager = std::make_unique<MockCheckpointManager>(
57+
stats,
58+
id,
59+
engine.getCheckpointConfig(),
60+
lastSeqno,
61+
lastSnapStart,
62+
lastSnapEnd,
63+
/*flusher callback*/ nullptr);
64+
return vptr;
65+
}

engines/ep/tests/mock/mock_ephemeral_bucket.h

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@
1616
*/
1717

1818
#pragma once
19-
#include "../mock/mock_checkpoint_manager.h"
20-
#include "ep_engine.h"
19+
2120
#include "ephemeral_bucket.h"
22-
#include "failover-table.h" // For the std::move(table) in makeVBucket
2321

2422
/*
2523
* Mock of the EphemeralBucket class.
@@ -30,16 +28,6 @@ class MockEphemeralBucket : public EphemeralBucket {
3028
: EphemeralBucket(theEngine) {
3129
}
3230

33-
void createItemFreqDecayerTask() {
34-
Configuration& config = engine.getConfiguration();
35-
itemFreqDecayerTask = std::make_shared<ItemFreqDecayerTask>(
36-
&engine, config.getItemFreqDecayerPercent());
37-
}
38-
39-
void disableItemFreqDecayerTask() {
40-
ExecutorPool::get()->cancel(itemFreqDecayerTask->getId());
41-
}
42-
4331
VBucketPtr makeVBucket(Vbid id,
4432
vbucket_state_t state,
4533
KVShard* shard,
@@ -54,31 +42,5 @@ class MockEphemeralBucket : public EphemeralBucket {
5442
uint64_t maxCas,
5543
int64_t hlcEpochSeqno,
5644
bool mightContainXattrs,
57-
const nlohmann::json& replicationTopology) override {
58-
auto vptr = EphemeralBucket::makeVBucket(id,
59-
state,
60-
shard,
61-
std::move(table),
62-
std::move(newSeqnoCb),
63-
std::move(manifest),
64-
initState,
65-
lastSeqno,
66-
lastSnapStart,
67-
lastSnapEnd,
68-
purgeSeqno,
69-
maxCas,
70-
hlcEpochSeqno,
71-
mightContainXattrs,
72-
replicationTopology);
73-
74-
vptr->checkpointManager = std::make_unique<MockCheckpointManager>(
75-
stats,
76-
id,
77-
engine.getCheckpointConfig(),
78-
lastSeqno,
79-
lastSnapStart,
80-
lastSnapEnd,
81-
/*flusher callback*/ nullptr);
82-
return vptr;
83-
}
45+
const nlohmann::json& replicationTopology) override;
8446
};

engines/ep/tests/mock/mock_synchronous_ep_engine.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717

1818
#include "mock_synchronous_ep_engine.h"
1919

20-
#include <checkpoint_remover.h>
21-
#include <programs/engine_testapp/mock_server.h>
20+
#include "checkpoint_config.h"
21+
#include "checkpoint_remover.h"
2222
#include "dcp/dcpconnmap.h"
2323
#include "dcp/flow-control-manager.h"
2424
#include "replicationthrottle.h"
25+
#include <programs/engine_testapp/mock_server.h>
2526

2627
#include <platform/cbassert.h>
2728
#include <string>

engines/ep/tests/module_tests/collections/evp_store_collections_eraser_test.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "ephemeral_tombstone_purger.h"
1919
#include "ephemeral_vb.h"
20+
#include "item.h"
2021
#include "tests/mock/mock_synchronous_ep_engine.h"
2122
#include "tests/module_tests/collections/test_manifest.h"
2223
#include "tests/module_tests/evp_store_single_threaded_test.h"

0 commit comments

Comments
 (0)