Skip to content

Commit fab7de9

Browse files
committed
MB-29287: Move SynchronousEPEngine building to seperate method
Refactor the construction and setup of SynchronousEPEngine from EventuallyPersistentStoreTest::SetUp() to a seperate builder function - SynchronousEPEngine::build(). This allows tests which want to instantiate more than one ep-engine instance to do so. Change-Id: I647d32a28a2c3a1e1bfbca563c2a1ebe5130ad56 Reviewed-on: http://review.couchbase.org/93043 Well-Formed: Build Bot <[email protected]> Tested-by: Build Bot <[email protected]> Reviewed-by: Trond Norbye <[email protected]>
1 parent ca86e99 commit fab7de9

File tree

4 files changed

+43
-19
lines changed

4 files changed

+43
-19
lines changed

src/ep_engine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,7 @@ class EventuallyPersistentEngine : public ENGINE_HANDLE_V1 {
10251025
int& keyOffset);
10261026

10271027
SERVER_HANDLE_V1 *serverApi;
1028+
// epstore is an owning pointer.
10281029
EventuallyPersistentStore *epstore;
10291030
WorkLoadPolicy *workload;
10301031
bucket_priority_t workloadPriority;

tests/module_tests/evp_store_single_threaded_test.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class SingleThreadedEPStoreTest : public EventuallyPersistentStoreTest {
6363
}
6464

6565
void TearDown() {
66-
shutdownAndPurgeTasks();
66+
shutdownAndPurgeTasks(engine.get());
6767
EventuallyPersistentStoreTest::TearDown();
6868
}
6969

@@ -83,10 +83,11 @@ class SingleThreadedEPStoreTest : public EventuallyPersistentStoreTest {
8383
}
8484

8585
/*
86-
* Set the stats isShutdown and attempt to drive all tasks to cancel
86+
* Set the stats isShutdown and attempt to drive all tasks to cancel for
87+
* the specified engine.
8788
*/
88-
void shutdownAndPurgeTasks() {
89-
engine->getEpStats().isShutdown = true;
89+
void shutdownAndPurgeTasks(EventuallyPersistentEngine* ep) {
90+
ep->getEpStats().isShutdown = true;
9091
task_executor->cancelAll();
9192

9293
for (task_type_t t :
@@ -102,8 +103,9 @@ class SingleThreadedEPStoreTest : public EventuallyPersistentStoreTest {
102103
}
103104
};
104105
runTasks(*task_executor->getLpTaskQ()[t]);
105-
task_executor->stopTaskGroup(engine->getTaskable().getGID(), t,
106-
engine->getEpStats().forceShutdown);
106+
task_executor->stopTaskGroup(ep->getTaskable().getGID(),
107+
t,
108+
ep->getEpStats().forceShutdown);
107109
}
108110
}
109111

tests/module_tests/evp_store_test.cc

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,27 @@ void SynchronousEPEngine::setEPStore(EventuallyPersistentStore* store) {
8181
epstore = store;
8282
}
8383

84+
std::unique_ptr<SynchronousEPEngine> SynchronousEPEngine::build(
85+
const std::string& config) {
86+
std::unique_ptr<SynchronousEPEngine> engine(
87+
new SynchronousEPEngine(config));
88+
89+
// switch current thread to this new engine, so all sub-created objects
90+
// are accounted in it's mem_used.
91+
ObjectRegistry::onSwitchThread(engine.get());
92+
93+
engine->setEPStore(new MockEPStore(*engine));
94+
95+
// Ensure that EPEngine is told about necessary server callbacks
96+
// (client disconnect, bucket delete).
97+
engine->public_initializeEngineCallbacks();
98+
99+
// Swtich current thread off this engine.
100+
ObjectRegistry::onSwitchThread(nullptr);
101+
102+
return engine;
103+
}
104+
84105
MockEPStore::MockEPStore(EventuallyPersistentEngine &theEngine)
85106
: EventuallyPersistentStore(theEngine) {
86107
// Perform a limited set of setup (normally done by EPStore::initialize) -
@@ -114,31 +135,26 @@ void EventuallyPersistentStoreTest::SetUp() {
114135
// from a previous run.
115136
CouchbaseDirectoryUtilities::rmrf(test_dbname);
116137

138+
// Need to initialize ep_real_time and friends.
139+
initialize_time_functions(get_mock_server_api()->core);
140+
117141
// Add dbname to config string.
118142
std::string config = config_string;
119143
if (config.size() > 0) {
120144
config += ";";
121145
}
122146
config += "dbname=" + std::string(test_dbname);
123147

124-
engine.reset(new SynchronousEPEngine(config));
125-
ObjectRegistry::onSwitchThread(engine.get());
126-
127-
store = new MockEPStore(*engine);
128-
engine->setEPStore(store);
129-
130-
// Ensure that EPEngine is hold about necessary server callbacks
131-
// (client disconnect, bucket delete).
132-
engine->public_initializeEngineCallbacks();
133-
134-
// Need to initialize ep_real_time and friends.
135-
initialize_time_functions(get_mock_server_api()->core);
148+
engine = SynchronousEPEngine::build(config);
149+
store = reinterpret_cast<MockEPStore*>(engine->getEpStore());
136150

137151
cookie = create_mock_cookie();
138152
}
139153

140154
void EventuallyPersistentStoreTest::TearDown() {
141-
destroy_mock_cookie(cookie);
155+
if (cookie) {
156+
destroy_mock_cookie(cookie);
157+
}
142158
destroy_mock_event_callbacks();
143159
engine->getDcpConnMap().manageConnections();
144160
engine.reset();

tests/module_tests/evp_store_test.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ class SynchronousEPEngine : public EventuallyPersistentEngine {
4949

5050
void setEPStore(EventuallyPersistentStore* store);
5151

52+
/// Constructs a SynchronousEPEngine instance, along with the necessary
53+
/// sub-components.
54+
static std::unique_ptr<SynchronousEPEngine> build(
55+
const std::string& config);
56+
5257
/* Allow us to call normally protected methods */
5358

5459
ENGINE_ERROR_CODE public_doTapVbTakeoverStats(const void *cookie,

0 commit comments

Comments
 (0)