Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
wangshaoyi committed Jul 12, 2024
1 parent d529a46 commit 1a269d4
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/storage/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ foreach(blackwindow_test_source ${BLACKWINDOW_TEST_SOURCE})
target_include_directories(${blackwindow_test_name}
PUBLIC ${PROJECT_SOURCE_DIR}/include
PUBLIC ${PROJECT_SOURCE_DIR}/..
PUBLIC ${PROJECT_SOURCE_DIR}/src
${ROCKSDB_INCLUDE_DIR}
${ROCKSDB_SOURCE_DIR}
)
Expand Down
84 changes: 84 additions & 0 deletions src/storage/tests/streams_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright (c) 2017-present, Qihoo, Inc. All rights reserved.
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree. An additional grant
// of patent rights can be found in the PATENTS file in the same directory.

#include <dirent.h>
#include <gtest/gtest.h>
#include <unistd.h>
#include <iostream>
#include <iterator>
#include <thread>

#include "storage/storage.h"
#include "storage/util.h"
#include "src/redis_streams.h"
//#include "db/db_impl/db_impl.h"

using namespace storage;

class StreamsTest : public ::testing::Test {
public:
StreamsTest() = default;
~StreamsTest() override = default;

void SetUp() override {
std::string path = "./db/streams";
if (access("./db", F_OK) != 0) {
mkdir("./db", 0755);
}
if (access(path.c_str(), F_OK) != 0) {
mkdir(path.c_str(), 0755);
}
db = new RedisStreams(nullptr, storage::kStreams);
storage_options.options.create_if_missing = true;
db->Open(storage_options, path);
}

void TearDown() override {
std::string path = "./db/streams";
DeleteFiles(path.c_str());
}

static void SetUpTestSuite() {}
static void TearDownTestSuite() {}

StorageOptions storage_options;
RedisStreams* db;
};

TEST_F(StreamsTest, DataFilter) {
int32_t ret = 0;
rocksdb::ReadOptions r_opts;
rocksdb::FlushOptions f_opts;
rocksdb::CompactRangeOptions c_opts;
storage::StreamAddTrimArgs args;

rocksdb::DB* rocks_db = db->GetDB();
auto handles = db->GetHandles();

auto s = db->XAdd("STREAM_KEY_0", "STREAM_MESSAGE_1", args);
ASSERT_TRUE(s.ok());

rocks_db->Flush(f_opts, handles);
auto iter = rocks_db->NewIterator(r_opts, handles[1]);
iter->SeekToFirst();
ASSERT_TRUE(iter->Valid());
delete iter;

s = db->Del("STREAM_KEY_0");
ASSERT_TRUE(s.ok());

rocks_db->Flush(f_opts, handles);
rocks_db->CompactRange(c_opts, handles[1], nullptr, nullptr);
iter = rocks_db->NewIterator(r_opts, handles[1]);
iter->SeekToFirst();
ASSERT_FALSE(iter->Valid());
delete iter;
}

int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

0 comments on commit 1a269d4

Please sign in to comment.