Skip to content

Commit

Permalink
Add a basic kvstore test
Browse files Browse the repository at this point in the history
This test is just meant to be a proof of concept that the kvstore
is acutall modularized. We should add a lot more tests and structure
the test cases better in the future.

Change-Id: Ia0b8bf19ff28953a36dd2711350d7d164fa8e23e
Reviewed-on: http://review.couchbase.org/48766
Reviewed-by: abhinav dangeti <abhinav@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
  • Loading branch information
mikewied authored and Michael Wiederhold committed Mar 26, 2015
1 parent ba3f6e8 commit aad03f6
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Expand Up @@ -197,6 +197,13 @@ ADD_EXECUTABLE(ep-engine_failover_table_test tests/module_tests/failover_table_t
${OBJECTREGISTRY_SOURCE} ${CONFIG_SOURCE})
TARGET_LINK_LIBRARIES(ep-engine_failover_table_test cJSON platform)

ADD_EXECUTABLE(ep-engine_kvstore_test
tests/module_tests/kvstore_test.cc
${OBJECTREGISTRY_SOURCE} ${KVSTORE_SOURCE} ${COUCH_KVSTORE_SOURCE}
${CONFIG_SOURCE} src/mutex.cc src/testlogger.cc)
TARGET_LINK_LIBRARIES(ep-engine_kvstore_test cJSON JSON_checker couchstore
dirutils platform)

ADD_TEST(ep-engine_atomic_ptr_test ep-engine_atomic_ptr_test)
ADD_TEST(ep-engine_atomic_test ep-engine_atomic_test)
ADD_TEST(ep-engine_checkpoint_test ep-engine_checkpoint_test)
Expand All @@ -209,6 +216,7 @@ ADD_TEST(ep-engine_misc_test ep-engine_misc_test)
ADD_TEST(ep-engine_mutex_test ep-engine_mutex_test)
ADD_TEST(ep-engine_priority_test ep-engine_priority_test)
ADD_TEST(ep-engine_ringbuffer_test ep-engine_ringbuffer_test)
ADD_TEST(ep-engine_kvstore_test ep-engine_kvstore_test)

ADD_LIBRARY(timing_tests SHARED tests/module_tests/timing_tests.cc)
SET_TARGET_PROPERTIES(timing_tests PROPERTIES PREFIX "")
Expand Down
102 changes: 102 additions & 0 deletions tests/module_tests/kvstore_test.cc
@@ -0,0 +1,102 @@
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* Copyright 2010 Couchbase, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "config.h"

#include <platform/dirutils.h>

#include "callbacks.h"
#include "common.h"
#include "kvstore.h"

extern "C" {
static rel_time_t basic_current_time(void) {
return 0;
}

rel_time_t (*ep_current_time)() = basic_current_time;

time_t ep_real_time() {
return time(NULL);
}
}

class WriteCallback : public Callback<mutation_result> {
public:
WriteCallback() {}

void callback(mutation_result &result) {

}

};

class StatsCallback : public Callback<kvstats_ctx> {
public:
StatsCallback() {}

void callback(kvstats_ctx &result) {

}

};

class GetCallback : public Callback<GetValue> {
public:
GetCallback() {}

void callback(GetValue &result) {
cb_assert(strncmp("value", result.getValue()->getData(), 5) == 0);
}

};

void basic_kvstore_test() {
std::string data_dir("/tmp/kvstore-test");
std::string backend("couchdb");

CouchbaseDirectoryUtilities::rmrf(data_dir.c_str());

KVStoreConfig config(1024, data_dir, backend);
KVStore* kvstore = KVStoreFactory::create(config);

StatsCallback sc;
std::string failoverLog("");
vbucket_state state(vbucket_state_active, 0, 0, 0, 0, 0, 0, 0, 0,
failoverLog);
kvstore->snapshotVBucket(0, state, &sc);

kvstore->begin();

Item item("key", 3, 0, 0, "value", 5);
WriteCallback wc;
kvstore->set(item, wc);

kvstore->commit(&sc, 1, 1, 1, 0);

GetCallback gc;
kvstore->get("key", 0, gc);

delete kvstore;
}


int main(int argc, char **argv) {
(void)argc; (void)argv;
putenv(strdup("ALLOW_NO_STATS_UPDATE=yeah"));
basic_kvstore_test();
}

0 comments on commit aad03f6

Please sign in to comment.