Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
2 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |