Skip to content

Commit

Permalink
#1314 add ut for trackable gc (#1318)
Browse files Browse the repository at this point in the history
  • Loading branch information
smwyzi authored and Yang Ce committed Sep 1, 2017
1 parent 12dec4c commit 5da3b40
Show file tree
Hide file tree
Showing 5 changed files with 612 additions and 34 deletions.
24 changes: 15 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ LDFLAGS += -rdynamic $(DEPS_LDPATH) $(DEPS_LDFLAGS) -lpthread -lrt -lz -ldl \
-lreadline -lncurses -fPIC
SO_LDFLAGS += -rdynamic $(DEPS_LDPATH) $(SO_DEPS_LDFLAGS) -lpthread -lrt -lz -ldl \
-shared -fPIC -Wl,--version-script,so-version-script # hide symbol of thirdparty libs
UTFLAGS += -Dprivate=public

PROTO_FILES := $(wildcard src/proto/*.proto)
PROTO_OUT_CC := $(PROTO_FILES:.proto=.pb.cc)
Expand Down Expand Up @@ -46,8 +47,9 @@ MONITOR_SRC := src/monitor/teramo_main.cc
MARK_SRC := src/benchmark/mark.cc src/benchmark/mark_main.cc
TEST_SRC := src/utils/test/prop_tree_test.cc src/utils/test/tprinter_test.cc \
src/io/test/tablet_io_test.cc src/io/test/tablet_scanner_test.cc \
src/master/test/master_impl_test.cc src/io/test/load_test.cc \
src/common/test/thread_pool_test.cc
src/io/test/load_test.cc src/master/test/master_test.cc \
src/master/test/master_impl_test.cc src/master/test/trackable_gc_test.cc \
src/common/test/thread_pool_test.cc

TEST_OUTPUT := test_output
UNITTEST_OUTPUT := $(TEST_OUTPUT)/unittest
Expand All @@ -71,7 +73,7 @@ HTTP_OBJ := $(HTTP_SRC:.cc=.o)
TEST_OBJ := $(TEST_SRC:.cc=.o)
ALL_OBJ := $(MASTER_OBJ) $(TABLETNODE_OBJ) $(IO_OBJ) $(SDK_OBJ) $(PROTO_OBJ) \
$(JNI_TERA_OBJ) $(OTHER_OBJ) $(COMMON_OBJ) $(SERVER_OBJ) $(CLIENT_OBJ) \
$(TEST_CLIENT_OBJ) $(TERA_C_OBJ) $(MONITOR_OBJ) $(MARK_OBJ) $(TEST_OBJ) \
$(TEST_CLIENT_OBJ) $(TERA_C_OBJ) $(MONITOR_OBJ) $(MARK_OBJ) \
$(SERVER_WRAPPER_OBJ)
LEVELDB_LIB := src/leveldb/libleveldb.a
LEVELDB_UTIL := src/leveldb/util/histogram.o src/leveldb/port/port_posix.o
Expand All @@ -83,8 +85,8 @@ TERA_C_SO = libtera_c.so
JNILIBRARY = libjni_tera.so
BENCHMARK = tera_bench tera_mark
TESTS = prop_tree_test tprinter_test string_util_test tablet_io_test \
tablet_scanner_test fragment_test progress_bar_test master_impl_test load_test \
thread_pool_test
tablet_scanner_test fragment_test progress_bar_test master_test load_test \
thread_pool_test

.PHONY: all clean cleanall test

Expand All @@ -100,7 +102,7 @@ all: $(PROGRAM) $(LIBRARY) $(SOLIBRARY) $(TERA_C_SO) $(JNILIBRARY) $(BENCHMARK)

test: $(TESTS)
mkdir -p $(UNITTEST_OUTPUT)
cp $(TESTS) $(UNITTEST_OUTPUT)
mv $(TESTS) $(UNITTEST_OUTPUT)
$(MAKE) test -C src/leveldb
cp src/leveldb/*_test $(UNITTEST_OUTPUT)

Expand All @@ -111,7 +113,7 @@ check: test
sh ./src/sdk/python/checker.sh

clean:
rm -rf $(ALL_OBJ) $(PROTO_OUT_CC) $(PROTO_OUT_H) $(TEST_OUTPUT)
rm -rf $(ALL_OBJ) $(TEST_OBJ) $(PROTO_OUT_CC) $(PROTO_OUT_H) $(TEST_OUTPUT)
$(MAKE) clean -C src/leveldb
rm -rf $(PROGRAM) $(LIBRARY) $(SOLIBRARY) $(TERA_C_SO) $(JNILIBRARY) $(BENCHMARK) $(TESTS) terahttp

Expand Down Expand Up @@ -193,13 +195,17 @@ tablet_scanner_test: src/sdk/tera.o src/io/test/tablet_scanner_test.o src/tablet
$(IO_OBJ) $(PROTO_OBJ) $(OTHER_OBJ) $(COMMON_OBJ) $(LEVELDB_LIB)
$(CXX) -o $@ $^ $(LDFLAGS)

master_impl_test: src/master/test/master_impl_test.o src/tera_entry.cc $(MASTER_OBJ) $(IO_OBJ) $(SDK_OBJ) \
$(PROTO_OBJ) $(OTHER_OBJ) $(COMMON_OBJ) $(LEVELDB_LIB)
master_test: src/master/test/master_test.o src/master/test/master_impl_test.o \
src/master/test/trackable_gc_test.o src/tera_entry.cc $(MASTER_OBJ) $(IO_OBJ) $(SDK_OBJ) \
$(PROTO_OBJ) $(OTHER_OBJ) $(COMMON_OBJ) $(LEVELDB_LIB)
$(CXX) -o $@ $^ $(LDFLAGS)

$(ALL_OBJ): %.o: %.cc $(PROTO_OUT_H)
$(CXX) $(CXXFLAGS) -c $< -o $@

$(TEST_OBJ): %.o: %.cc $(PROTO_OUT_H)
$(CXX) $(CXXFLAGS) $(UTFLAGS) -c $< -o $@

$(VERSION_SRC): FORCE
sh build_version.sh

Expand Down
1 change: 0 additions & 1 deletion src/master/master_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ class MasterImpl {
std::string ProfilingLog();

private:
friend class MasterImplTest;
typedef std::function<void (SnapshotRequest*, SnapshotResponse*, bool, int)> SnapshotClosure;
typedef std::function<void (SnapshotRollbackRequest*, SnapshotRollbackResponse*, bool, int)> RollbackClosure;
typedef std::function<void (ReleaseSnapshotRequest*, ReleaseSnapshotResponse*, bool, int)> DelSnapshotClosure;
Expand Down
32 changes: 8 additions & 24 deletions src/master/test/master_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,23 @@

#include <signal.h>

#include <gflags/gflags.h>
#include <glog/logging.h>
#include <gtest/gtest.h>
#include "gflags/gflags.h"
#include "glog/logging.h"
#include "gtest/gtest.h"

#include "common/base/scoped_ptr.h"
#include "master/master_impl.h"
#include "master/tablet_manager.h"
#include "utils/utils_cmd.h"
#include "version.h"

DECLARE_string(tera_master_port);
DECLARE_string(log_dir);
DECLARE_bool(tera_zk_enabled);
DECLARE_string(tera_leveldb_env_type);
DECLARE_string(tera_fake_zk_path_prefix);

namespace tera {
namespace master {

class MasterImplTest : public ::testing::Test, public MasterImpl {
public:
MasterImplTest() : merge_enter_phase2(false) {}
MasterImplTest() : merge_enter_phase2(false) {
}

void SplitTabletTest() {
SplitTabletRequest* request = NULL;
Expand Down Expand Up @@ -107,7 +102,7 @@ class MasterImplTest : public ::testing::Test, public MasterImpl {
LOG(ERROR) << "dummy UnloadTabletAsync...";
}

void MergeTabletBorkenTest() {
void MergeTabletBrokenTest() {
TablePtr table(new Table("mergetest"));
TabletPtr t1 = MakeTabletPtr("", "a", table);
t1->SetStatus(kTableReady);
Expand Down Expand Up @@ -150,21 +145,10 @@ TEST_F(MasterImplTest, MergeTest) {
MergeTabletTest();
}

TEST_F(MasterImplTest, MergeTabletBorkenTest) {
MergeTabletBorkenTest();
TEST_F(MasterImplTest, MergeTabletBrokenTest) {
MergeTabletBrokenTest();
}

} // master
} // tera

int main(int argc, char** argv) {
::google::ParseCommandLineFlags(&argc, &argv, true);
::google::InitGoogleLogging(argv[0]);
FLAGS_tera_zk_enabled = false;
FLAGS_tera_leveldb_env_type = "local";

tera::utils::SetupLog("master_test");
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

29 changes: 29 additions & 0 deletions src/master/test/master_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2015, Baidu.com, Inc. All Rights Reserved
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "gflags/gflags.h"
#include "glog/logging.h"
#include "gtest/gtest.h"

#include "utils/utils_cmd.h"

DECLARE_string(tera_master_port);
DECLARE_string(log_dir);
DECLARE_bool(tera_zk_enabled);
DECLARE_string(tera_leveldb_env_type);
DECLARE_string(tera_fake_zk_path_prefix);

int main(int argc, char** argv) {
::google::ParseCommandLineFlags(&argc, &argv, true);
::google::InitGoogleLogging(argv[0]);

FLAGS_tera_zk_enabled = false;
FLAGS_tera_leveldb_env_type = "local";

tera::utils::SetupLog("master_test");
::testing::InitGoogleTest(&argc, argv);

return RUN_ALL_TESTS();
}

Loading

0 comments on commit 5da3b40

Please sign in to comment.