Revision 86a0133d0527a1005ebd9b517fa973c1a4a0a1ae authored by sdong on 23 April 2014, 01:31:55 UTC, committed by sdong on 23 April 2014, 02:29:05 UTC
Summary:
This is a temp solution to expose index sizes to users from PlainTableReader before we persistent them to files.
In this patch, the memory consumption of indexes used by PlainTableReader will be reported as two user defined properties, so that users can monitor them.

Test Plan:
Add a unit test.
make all check`

Reviewers: haobo, ljin

Reviewed By: haobo

CC: nkg-, yhchiang, igor, ljin, dhruba, leveldb

Differential Revision: https://reviews.facebook.net/D18195
1 parent 1068d2f
Raw File
histogram_test.cc
//  Copyright (c) 2013, Facebook, 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 "util/histogram.h"

#include "util/testharness.h"

namespace rocksdb {

class HistogramTest { };

TEST(HistogramTest, BasicOperation) {

  HistogramImpl histogram;
  for (uint64_t i = 1; i <= 100; i++) {
    histogram.Add(i);
  }

  {
    double median = histogram.Median();
    // ASSERT_LE(median, 50);
    ASSERT_GT(median, 0);
  }

  {
    double percentile100 = histogram.Percentile(100.0);
    ASSERT_LE(percentile100, 100.0);
    ASSERT_GT(percentile100, 0.0);
    double percentile99 = histogram.Percentile(99.0);
    double percentile85 = histogram.Percentile(85.0);
    ASSERT_LE(percentile99, 99.0);
    ASSERT_TRUE(percentile99 >= percentile85);
  }

  ASSERT_EQ(histogram.Average(), 50.5); // avg is acurately caluclated.
}

TEST(HistogramTest, EmptyHistogram) {
  HistogramImpl histogram;
  ASSERT_EQ(histogram.Median(), 0.0);
  ASSERT_EQ(histogram.Percentile(85.0), 0.0);
  ASSERT_EQ(histogram.Average(), 0.0);
}

TEST(HistogramTest, ClearHistogram) {
  HistogramImpl histogram;
  for (uint64_t i = 1; i <= 100; i++) {
    histogram.Add(i);
  }
  histogram.Clear();
  ASSERT_EQ(histogram.Median(), 0);
  ASSERT_EQ(histogram.Percentile(85.0), 0);
  ASSERT_EQ(histogram.Average(), 0);
}

}  // namespace rocksdb

int main(int argc, char** argv) {
  return rocksdb::test::RunAllTests();
}
back to top