mon/PGMap: add unit test for min_last_epoch_clean

Signed-off-by: Sage Weil <sage@inktank.com>
This commit is contained in:
Sage Weil 2014-02-22 09:17:44 -08:00
parent bcc18d4877
commit df3ba724d5
2 changed files with 101 additions and 0 deletions

View File

@ -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}

96
src/test/mon/PGMap.cc Normal file
View File

@ -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 <info@inktank.com>
*
* 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<const char*> args;
argv_to_vec(argc, (const char **)argv, args);
env_to_vec(args);
vector<const char*> 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();
}