From df3ba724d53b589095225d8309a340a06fbc3ed0 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Sat, 22 Feb 2014 09:17:44 -0800 Subject: [PATCH] mon/PGMap: add unit test for min_last_epoch_clean Signed-off-by: Sage Weil --- src/test/Makefile.am | 5 +++ src/test/mon/PGMap.cc | 96 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 src/test/mon/PGMap.cc diff --git a/src/test/Makefile.am b/src/test/Makefile.am index 4126d5b82a029..fd7a3fe4e15d3 100644 --- a/src/test/Makefile.am +++ b/src/test/Makefile.am @@ -536,6 +536,11 @@ unittest_mon_moncap_LDADD = $(LIBMON) $(UNITTEST_LDADD) $(CEPH_GLOBAL) unittest_mon_moncap_CXXFLAGS = $(UNITTEST_CXXFLAGS) check_PROGRAMS += unittest_mon_moncap +unittest_mon_pgmap_SOURCES = test/mon/PGMap.cc +unittest_mon_pgmap_LDADD = $(LIBMON) $(UNITTEST_LDADD) $(CEPH_GLOBAL) +unittest_mon_pgmap_CXXFLAGS = $(UNITTEST_CXXFLAGS) +check_PROGRAMS += unittest_mon_pgmap + #if WITH_RADOSGW #unittest_librgw_SOURCES = test/librgw.cc #unittest_librgw_LDFLAGS = -lrt $(PTHREAD_CFLAGS) -lcurl ${AM_LDFLAGS} diff --git a/src/test/mon/PGMap.cc b/src/test/mon/PGMap.cc new file mode 100644 index 0000000000000..20dc27f39caa5 --- /dev/null +++ b/src/test/mon/PGMap.cc @@ -0,0 +1,96 @@ +// -*- mode:C; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2014 Inktank + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License version 2, as published by the Free Software + * Foundation. See file COPYING. + */ + +#include "mon/PGMap.h" +#include "gtest/gtest.h" + +#include "common/ceph_argparse.h" +#include "global/global_init.h" +#include "global/global_context.h" + +TEST(pgmap, min_last_epoch_clean) +{ + PGMap pg_map; + PGMap::Incremental inc; + osd_stat_t os; + pg_stat_t ps; + + ps.last_epoch_clean = 999; + inc.pg_stat_updates[pg_t(9,9)] = ps; + inc.version = 1; + inc.update_stat(0, 123, os); + pg_map.apply_incremental(g_ceph_context, inc); + ASSERT_EQ(123, pg_map.calc_min_last_epoch_clean()); + + inc = PGMap::Incremental(); + inc.version = 2; + inc.update_stat(1, 222, os); + pg_map.apply_incremental(g_ceph_context, inc); + ASSERT_EQ(123, pg_map.calc_min_last_epoch_clean()); + + inc = PGMap::Incremental(); + inc.version = 3; + inc.update_stat(0, 222, os); + pg_map.apply_incremental(g_ceph_context, inc); + ASSERT_EQ(222, pg_map.calc_min_last_epoch_clean()); + + inc = PGMap::Incremental(); + inc.version = 4; + inc.update_stat(0, 333, os); + inc.update_stat(1, 333, os); + pg_map.apply_incremental(g_ceph_context, inc); + ASSERT_EQ(333, pg_map.calc_min_last_epoch_clean()); + + ps.last_epoch_clean = 222; + inc = PGMap::Incremental(); + inc.version = 5; + inc.pg_stat_updates[pg_t(1,1)] = ps; + pg_map.apply_incremental(g_ceph_context, inc); + ASSERT_EQ(222, pg_map.calc_min_last_epoch_clean()); + + ps.last_epoch_clean = 223; + inc = PGMap::Incremental(); + inc.version = 6; + inc.pg_stat_updates[pg_t(1,1)] = ps; + pg_map.apply_incremental(g_ceph_context, inc); + ASSERT_EQ(223, pg_map.calc_min_last_epoch_clean()); + + ps.last_epoch_clean = 224; + inc = PGMap::Incremental(); + inc.version = 7; + inc.pg_stat_updates[pg_t(2,2)] = ps; + pg_map.apply_incremental(g_ceph_context, inc); + ASSERT_EQ(223, pg_map.calc_min_last_epoch_clean()); + + ps.last_epoch_clean = 225; + inc = PGMap::Incremental(); + inc.version = 8; + inc.pg_stat_updates[pg_t(1,1)] = ps; + pg_map.apply_incremental(g_ceph_context, inc); + ASSERT_EQ(224, pg_map.calc_min_last_epoch_clean()); + +} + + + +int main(int argc, char **argv) { + vector args; + argv_to_vec(argc, (const char **)argv, args); + env_to_vec(args); + + vector def_args; + global_init(&def_args, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0); + common_init_finish(g_ceph_context); + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} -- 2.39.5