leveldb
Public Member Functions | Private Attributes | List of all members
leveldb::Harness Class Reference
Collaboration diagram for leveldb::Harness:
Collaboration graph
[legend]

Public Member Functions

 Harness ()
 
void Init (const TestArgs &args)
 
 ~Harness ()
 
void Add (const std::string &key, const std::string &value)
 
void Test (Random *rnd)
 
void TestForwardScan (const std::vector< std::string > &keys, const KVMap &data)
 
void TestBackwardScan (const std::vector< std::string > &keys, const KVMap &data)
 
void TestRandomAccess (Random *rnd, const std::vector< std::string > &keys, const KVMap &data)
 
std::string ToString (const KVMap &data, const KVMap::const_iterator &it)
 
std::string ToString (const KVMap &data, const KVMap::const_reverse_iterator &it)
 
std::string ToString (const Iterator *it)
 
std::string PickRandomKey (Random *rnd, const std::vector< std::string > &keys)
 
DBdb () const
 

Private Attributes

Options options_
 
Constructorconstructor_
 

Detailed Description

Definition at line 437 of file table_test.cc.

Constructor & Destructor Documentation

§ Harness()

leveldb::Harness::Harness ( )
inline

Definition at line 439 of file table_test.cc.

439 : constructor_(NULL) { }
Constructor * constructor_
Definition: table_test.cc:644

§ ~Harness()

leveldb::Harness::~Harness ( )
inline

Definition at line 469 of file table_test.cc.

469  {
470  delete constructor_;
471  }
Constructor * constructor_
Definition: table_test.cc:644

Member Function Documentation

§ Add()

void leveldb::Harness::Add ( const std::string &  key,
const std::string &  value 
)
inline

Definition at line 473 of file table_test.cc.

473  {
474  constructor_->Add(key, value);
475  }
Constructor * constructor_
Definition: table_test.cc:644
void Add(const std::string &key, const Slice &value)
Definition: table_test.cc:146

§ db()

DB* leveldb::Harness::db ( ) const
inline

Definition at line 640 of file table_test.cc.

640 { return constructor_->db(); }
Constructor * constructor_
Definition: table_test.cc:644
virtual DB * db() const
Definition: table_test.cc:175

§ Init()

void leveldb::Harness::Init ( const TestArgs args)
inline

Definition at line 441 of file table_test.cc.

441  {
442  delete constructor_;
443  constructor_ = NULL;
444  options_ = Options();
445 
446  options_.block_restart_interval = args.restart_interval;
447  // Use shorter block size for tests to exercise block boundary
448  // conditions more.
449  options_.block_size = 256;
450  if (args.reverse_compare) {
452  }
453  switch (args.type) {
454  case TABLE_TEST:
455  constructor_ = new TableConstructor(options_.comparator);
456  break;
457  case BLOCK_TEST:
458  constructor_ = new BlockConstructor(options_.comparator);
459  break;
460  case MEMTABLE_TEST:
461  constructor_ = new MemTableConstructor(options_.comparator);
462  break;
463  case DB_TEST:
464  constructor_ = new DBConstructor(options_.comparator);
465  break;
466  }
467  }
static ReverseKeyComparator reverse_key_comparator
Definition: table_test.cc:64
Constructor * constructor_
Definition: table_test.cc:644
int block_restart_interval
Definition: options.h:113
const Comparator * comparator
Definition: options.h:41
size_t block_size
Definition: options.h:106

§ PickRandomKey()

std::string leveldb::Harness::PickRandomKey ( Random rnd,
const std::vector< std::string > &  keys 
)
inline

Definition at line 612 of file table_test.cc.

612  {
613  if (keys.empty()) {
614  return "foo";
615  } else {
616  const int index = rnd->Uniform(keys.size());
617  std::string result = keys[index];
618  switch (rnd->Uniform(3)) {
619  case 0:
620  // Return an existing key
621  break;
622  case 1: {
623  // Attempt to return something smaller than an existing key
624  if (result.size() > 0 && result[result.size()-1] > '\0') {
625  result[result.size()-1]--;
626  }
627  break;
628  }
629  case 2: {
630  // Return something larger than an existing key
631  Increment(options_.comparator, &result);
632  break;
633  }
634  }
635  return result;
636  }
637  }
static void Increment(const Comparator *cmp, std::string *key)
Definition: table_test.cc:66
const Comparator * comparator
Definition: options.h:41
Here is the call graph for this function:

§ Test()

void leveldb::Harness::Test ( Random rnd)
inline

Definition at line 477 of file table_test.cc.

477  {
478  std::vector<std::string> keys;
479  KVMap data;
480  constructor_->Finish(options_, &keys, &data);
481 
482  TestForwardScan(keys, data);
483  TestBackwardScan(keys, data);
484  TestRandomAccess(rnd, keys, data);
485  }
Constructor * constructor_
Definition: table_test.cc:644
void TestRandomAccess(Random *rnd, const std::vector< std::string > &keys, const KVMap &data)
Definition: table_test.cc:517
std::map< std::string, std::string, STLLessThan > KVMap
Definition: table_test.cc:137
void TestBackwardScan(const std::vector< std::string > &keys, const KVMap &data)
Definition: table_test.cc:502
void Finish(const Options &options, std::vector< std::string > *keys, KVMap *kvmap)
Definition: table_test.cc:153
void TestForwardScan(const std::vector< std::string > &keys, const KVMap &data)
Definition: table_test.cc:487

§ TestBackwardScan()

void leveldb::Harness::TestBackwardScan ( const std::vector< std::string > &  keys,
const KVMap data 
)
inline

Definition at line 502 of file table_test.cc.

503  {
504  Iterator* iter = constructor_->NewIterator();
505  ASSERT_TRUE(!iter->Valid());
506  iter->SeekToLast();
507  for (KVMap::const_reverse_iterator model_iter = data.rbegin();
508  model_iter != data.rend();
509  ++model_iter) {
510  ASSERT_EQ(ToString(data, model_iter), ToString(iter));
511  iter->Prev();
512  }
513  ASSERT_TRUE(!iter->Valid());
514  delete iter;
515  }
virtual Iterator * NewIterator() const =0
std::string ToString(const KVMap &data, const KVMap::const_iterator &it)
Definition: table_test.cc:587
Constructor * constructor_
Definition: table_test.cc:644
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
#define ASSERT_TRUE(c)
Definition: testharness.h:105
Here is the call graph for this function:

§ TestForwardScan()

void leveldb::Harness::TestForwardScan ( const std::vector< std::string > &  keys,
const KVMap data 
)
inline

Definition at line 487 of file table_test.cc.

488  {
489  Iterator* iter = constructor_->NewIterator();
490  ASSERT_TRUE(!iter->Valid());
491  iter->SeekToFirst();
492  for (KVMap::const_iterator model_iter = data.begin();
493  model_iter != data.end();
494  ++model_iter) {
495  ASSERT_EQ(ToString(data, model_iter), ToString(iter));
496  iter->Next();
497  }
498  ASSERT_TRUE(!iter->Valid());
499  delete iter;
500  }
virtual Iterator * NewIterator() const =0
std::string ToString(const KVMap &data, const KVMap::const_iterator &it)
Definition: table_test.cc:587
Constructor * constructor_
Definition: table_test.cc:644
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
#define ASSERT_TRUE(c)
Definition: testharness.h:105
Here is the call graph for this function:

§ TestRandomAccess()

void leveldb::Harness::TestRandomAccess ( Random rnd,
const std::vector< std::string > &  keys,
const KVMap data 
)
inline

Definition at line 517 of file table_test.cc.

519  {
520  static const bool kVerbose = false;
521  Iterator* iter = constructor_->NewIterator();
522  ASSERT_TRUE(!iter->Valid());
523  KVMap::const_iterator model_iter = data.begin();
524  if (kVerbose) fprintf(stderr, "---\n");
525  for (int i = 0; i < 200; i++) {
526  const int toss = rnd->Uniform(5);
527  switch (toss) {
528  case 0: {
529  if (iter->Valid()) {
530  if (kVerbose) fprintf(stderr, "Next\n");
531  iter->Next();
532  ++model_iter;
533  ASSERT_EQ(ToString(data, model_iter), ToString(iter));
534  }
535  break;
536  }
537 
538  case 1: {
539  if (kVerbose) fprintf(stderr, "SeekToFirst\n");
540  iter->SeekToFirst();
541  model_iter = data.begin();
542  ASSERT_EQ(ToString(data, model_iter), ToString(iter));
543  break;
544  }
545 
546  case 2: {
547  std::string key = PickRandomKey(rnd, keys);
548  model_iter = data.lower_bound(key);
549  if (kVerbose) fprintf(stderr, "Seek '%s'\n",
550  EscapeString(key).c_str());
551  iter->Seek(Slice(key));
552  ASSERT_EQ(ToString(data, model_iter), ToString(iter));
553  break;
554  }
555 
556  case 3: {
557  if (iter->Valid()) {
558  if (kVerbose) fprintf(stderr, "Prev\n");
559  iter->Prev();
560  if (model_iter == data.begin()) {
561  model_iter = data.end(); // Wrap around to invalid value
562  } else {
563  --model_iter;
564  }
565  ASSERT_EQ(ToString(data, model_iter), ToString(iter));
566  }
567  break;
568  }
569 
570  case 4: {
571  if (kVerbose) fprintf(stderr, "SeekToLast\n");
572  iter->SeekToLast();
573  if (keys.empty()) {
574  model_iter = data.end();
575  } else {
576  std::string last = data.rbegin()->first;
577  model_iter = data.lower_bound(last);
578  }
579  ASSERT_EQ(ToString(data, model_iter), ToString(iter));
580  break;
581  }
582  }
583  }
584  delete iter;
585  }
std::string PickRandomKey(Random *rnd, const std::vector< std::string > &keys)
Definition: table_test.cc:612
virtual Iterator * NewIterator() const =0
std::string ToString(const KVMap &data, const KVMap::const_iterator &it)
Definition: table_test.cc:587
Constructor * constructor_
Definition: table_test.cc:644
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
std::string EscapeString(const Slice &value)
Definition: logging.cc:42
#define ASSERT_TRUE(c)
Definition: testharness.h:105
static const int kVerbose
Definition: bloom_test.cc:14
Here is the call graph for this function:

§ ToString() [1/3]

std::string leveldb::Harness::ToString ( const KVMap data,
const KVMap::const_iterator &  it 
)
inline

Definition at line 587 of file table_test.cc.

587  {
588  if (it == data.end()) {
589  return "END";
590  } else {
591  return "'" + it->first + "->" + it->second + "'";
592  }
593  }

§ ToString() [2/3]

std::string leveldb::Harness::ToString ( const KVMap data,
const KVMap::const_reverse_iterator &  it 
)
inline

Definition at line 595 of file table_test.cc.

596  {
597  if (it == data.rend()) {
598  return "END";
599  } else {
600  return "'" + it->first + "->" + it->second + "'";
601  }
602  }

§ ToString() [3/3]

std::string leveldb::Harness::ToString ( const Iterator it)
inline

Definition at line 604 of file table_test.cc.

604  {
605  if (!it->Valid()) {
606  return "END";
607  } else {
608  return "'" + it->key().ToString() + "->" + it->value().ToString() + "'";
609  }
610  }
Here is the call graph for this function:

Member Data Documentation

§ constructor_

Constructor* leveldb::Harness::constructor_
private

Definition at line 644 of file table_test.cc.

§ options_

Options leveldb::Harness::options_
private

Definition at line 643 of file table_test.cc.


The documentation for this class was generated from the following file: