示例#1
0
// validate block size control for 512 and max count of 1
void test_block_size_512_and_count_1() {
  // clean up from any previous run
  rm_hashdb_dir(temp_dir1);
  rm_hashdb_dir(temp_dir2);
  remove(temp_dfxml_file);

  // create new hashdb
  hashdb_settings_t settings;
  settings.hash_block_size = 512;
  settings.maximum_hash_duplicates  = 1;
  commands_t::create(settings, temp_dir1);
  commands_t::create(settings, temp_dir2);

  // import
  commands_t::import(temp_dir1, sample_dfxml512, "test_repository_name");
  commands_t::import(temp_dir1, sample_dfxml512, "test_repository_name2");
  BOOST_TEST_EQ(map_size(temp_dir1), 24);

  // export
  commands_t::do_export(temp_dir1, "temp_dfxml_out.xml");

  // import
  commands_t::import(temp_dir2, "temp_dfxml_out.xml", "test_repository_name");
  BOOST_TEST_EQ(map_size(temp_dir1), 24);
}
示例#2
0
// import/export: import1, export, import2 should retain size of 74
void test_import_export() {
  hashdb_settings_t settings;
  rm_hashdb_dir(temp_dir1);
  rm_hashdb_dir(temp_dir2);
  remove(temp_dfxml_file);

  // import
  commands_t::create(settings, temp_dir1);
  commands_t::import(temp_dir1, sample_dfxml4096, "repository1");
  commands_t::do_export(temp_dir1, "temp_dfxml_out.xml");
  commands_t::create(settings, temp_dir2);
  commands_t::import(temp_dir2, temp_dfxml_file, "repository2");
  BOOST_TEST_EQ(map_size(temp_dir2), 74);
}
示例#3
0
void run_setup() {
  rm_hashdb_dir(temp_dir);
  make_dir_if_not_there(temp_dir);

  source_lookup_store_t store(temp_store, RW_NEW);
  store.insert_value(std::pair<uint64_t,uint64_t>(2,3));
}
示例#4
0
// validate use of multiple repository names
void test_multiple_repository_names() {
  
  // clean up from any previous run
  rm_hashdb_dir(temp_dir);

  // create new hashdb
  hashdb_settings_t settings;
  commands_t::create(settings, temp_dir);

  // test ability to manage multiple repository names
  for (int i=0; i<12; i++) {
    // generate unique repository name
    std::ostringstream ss;
    ss << "test_repository_name_" << i;

    // import
    commands_t::import(temp_dir, sample_dfxml4096, ss.str());
  }

  // duplicate import should not add elements
  commands_t::import(temp_dir, sample_dfxml4096, "test_repository_name_0");

  // validate correct size
  BOOST_TEST_EQ(map_size(temp_dir), 74*12);
}
示例#5
0
void rw_new() {
  // clean up from any previous run
  rm_hashdb_dir(temp_dir);
  make_dir_if_not_there(temp_dir);

  // create each db
  lmdb_hash_store_t hash_store(temp_dir, RW_NEW, 512, 0);
  lmdb_name_store_t name_store(temp_dir, RW_NEW);
  lmdb_source_store_t source_store(temp_dir, RW_NEW);
}
示例#6
0
int cpp_main(int argc, char* argv[]) {

  rm_hashdb_dir(temp_dir);
  make_dir_if_not_there(temp_dir);

  run_setup();
  run_test();

  // done
  int status = boost::report_errors();
  return status;
}
示例#7
0
// tuning
void test_tuning() {

  // setup
  hashdb_settings_t settings;
  rm_hashdb_dir(temp_dir1);
  commands_t::create(settings, temp_dir1);
  commands_t::import(temp_dir1, sample_dfxml4096, "repository1");

  // rebuild_bloom
  settings.bloom1_M_hash_size = 20;
  commands_t::rebuild_bloom(settings, temp_dir1);
}
示例#8
0
void write_settings() {
  // clean up from any previous run
  rm_hashdb_dir(temp_dir);

  // create the hashdb directory
  hashdb_directory_manager_t::create_new_hashdb_dir(temp_dir);

  // create working settings
  hashdb_settings_t settings;
  settings.maximum_hash_duplicates = 4;
  hashdb_settings_store_t::write_settings(temp_dir, settings);
}
示例#9
0
// validate block size control for 4096
void test_block_size_4096() {
  // clean up from any previous run
  rm_hashdb_dir(temp_dir1);
  rm_hashdb_dir(temp_dir2);
  remove(temp_dfxml_file);

  // create new hashdb
  hashdb_settings_t settings;
  commands_t::create(settings, temp_dir1);
  commands_t::create(settings, temp_dir2);

  // import
  commands_t::import(temp_dir1, sample_dfxml4096, "test_repository_name");
  BOOST_TEST_EQ(map_size(temp_dir1), 74);

  // export
  commands_t::do_export(temp_dir1, "temp_dfxml_out.xml");

  // import
  commands_t::import(temp_dir2, "temp_dfxml_out.xml", "test_repository_name");
  BOOST_TEST_EQ(map_size(temp_dir2), 74);
}
示例#10
0
// scan services
void test_scan_services() {

  // setup
  hashdb_settings_t settings;
  rm_hashdb_dir(temp_dir1);
  commands_t::create(settings, temp_dir1);
  commands_t::import(temp_dir1, sample_dfxml4096, "repository1");

  // scan
  commands_t::scan(temp_dir1, sample_dfxml4096);
  hash_t k1;
  to_key(1, k1);
  commands_t::scan_hash(temp_dir1, k1.hexdigest());
}
示例#11
0
// test check for valid hash block size
void test_block_size_0() {
  // clean up from any previous run
  rm_hashdb_dir(temp_dir1);

  // create new hashdb
  hashdb_settings_t settings;
  settings.hash_block_size = 0;
  commands_t::create(settings, temp_dir1);

  // import
  commands_t::import(temp_dir1, sample_dfxml4096, "test_repository_name");

  // with hash_block_size=0, total should be every hash, including remainder
  BOOST_TEST_EQ(map_size(temp_dir1), 75);
}
示例#12
0
// performance analysis
void test_performance_analysis() {

  // setup
  hashdb_settings_t settings;
  rm_hashdb_dir(temp_dir1);
  commands_t::create(settings, temp_dir1);

  // add_random
  // not tested because it requires user input "q" to complete.
  // commands_t::add_random("repo_random", temp_dir1, "100000");

  // scan_random
  // not tested because it takes time to run
  // commands_t::scan_random(temp_dir1);
}
示例#13
0
// statistics
void test_statistics() {

  // setup
  hashdb_settings_t settings;
  rm_hashdb_dir(temp_dir1);
  commands_t::create(settings, temp_dir1);
  commands_t::import(temp_dir1, sample_dfxml4096, "repository1");

  // size
  commands_t::size(temp_dir1);

  // sources
  commands_t::sources(temp_dir1);

  // histogram
  commands_t::histogram(temp_dir1);

  // duplicates
  commands_t::duplicates(temp_dir1, "2");

  // hash_table
  commands_t::hash_table(temp_dir1, "repository1", sample_dfxml4096);
  commands_t::hash_table(temp_dir1, "invalid_repository", sample_dfxml4096);
}
示例#14
0
// database manipulation commands
void test_database_manipulation() {
  hashdb_settings_t settings;
  rm_hashdb_dir(temp_dir1);
  rm_hashdb_dir(temp_dir2);
  rm_hashdb_dir(temp_dir3);
  rm_hashdb_dir(temp_dir4);
  rm_hashdb_dir(temp_dir5);
  rm_hashdb_dir(temp_dir6);
  rm_hashdb_dir(temp_dir7);
  rm_hashdb_dir(temp_dir8);
  commands_t::create(settings, temp_dir1);
  commands_t::import(temp_dir1, sample_dfxml4096, "repository1");
  commands_t::create(settings, temp_dir2);
  commands_t::import(temp_dir2, sample_dfxml4096, "repository2");
  commands_t::add_multiple(temp_dir1, temp_dir2, temp_dir3);

  // add
  commands_t::add(temp_dir1, temp_dir4);
  BOOST_TEST_EQ(map_size(temp_dir4), 74);
  commands_t::add(temp_dir1, temp_dir4);
  BOOST_TEST_EQ(map_size(temp_dir4), 74);
  commands_t::add(temp_dir2, temp_dir4);
  BOOST_TEST_EQ(map_size(temp_dir4), 2*74);
  rm_hashdb_dir(temp_dir4);

  // add_multiple
  std::cout << "add_multiple\n";
  commands_t::add_multiple(temp_dir1, temp_dir2, temp_dir4);
  BOOST_TEST_EQ(map_size(temp_dir3), 2*74);
  commands_t::add_multiple(temp_dir1, temp_dir2, temp_dir4);
  BOOST_TEST_EQ(map_size(temp_dir3), 2*74);
  rm_hashdb_dir(temp_dir4);

  // add_repository
  std::cout << "add_repository\n";
  commands_t::add_repository(temp_dir1, temp_dir4, "invalid_repository");
  BOOST_TEST_EQ(map_size(temp_dir4), 0);
  commands_t::add_repository(temp_dir1, temp_dir4, "repository1");
  BOOST_TEST_EQ(map_size(temp_dir4), 74);
  commands_t::add_repository(temp_dir1, temp_dir4, "repository1");
  BOOST_TEST_EQ(map_size(temp_dir4), 74);
  commands_t::add_repository(temp_dir2, temp_dir4, "repository1");
  BOOST_TEST_EQ(map_size(temp_dir4), 74);
  commands_t::add_repository(temp_dir2, temp_dir4, "repository2");
  BOOST_TEST_EQ(map_size(temp_dir4), 2*74);
  rm_hashdb_dir(temp_dir4);

  // intersect
  std::cout << "intersect\n";
  commands_t::intersect(temp_dir1, temp_dir2, temp_dir4);
  BOOST_TEST_EQ(map_size(temp_dir4), 0);
  commands_t::intersect(temp_dir1, temp_dir3, temp_dir4);
  BOOST_TEST_EQ(map_size(temp_dir4), 74);
  rm_hashdb_dir(temp_dir4);

  // intersect hash
  std::cout << "intersect_hash\n";
  commands_t::intersect_hash(temp_dir1, temp_dir2, temp_dir4);
  BOOST_TEST_EQ(map_size(temp_dir4), 2*74);
  commands_t::intersect_hash(temp_dir1, temp_dir2, temp_dir4);
  BOOST_TEST_EQ(map_size(temp_dir4), 2*74);
  rm_hashdb_dir(temp_dir4);

  // subtract
  std::cout << "subtract\n";
  commands_t::subtract(temp_dir3, temp_dir1, temp_dir4);
  BOOST_TEST_EQ(map_size(temp_dir4), 74);
  commands_t::subtract(temp_dir3, temp_dir1, temp_dir4);
  BOOST_TEST_EQ(map_size(temp_dir4), 74);
  commands_t::add(temp_dir2, temp_dir4);
  BOOST_TEST_EQ(map_size(temp_dir4), 74);
  commands_t::add(temp_dir1, temp_dir4);
  BOOST_TEST_EQ(map_size(temp_dir4), 2*74);
  commands_t::subtract(temp_dir3, temp_dir2, temp_dir4);
  BOOST_TEST_EQ(map_size(temp_dir4), 2*74);
  commands_t::subtract(temp_dir3, temp_dir4, temp_dir5);
  BOOST_TEST_EQ(map_size(temp_dir5), 0);
  rm_hashdb_dir(temp_dir4);
  rm_hashdb_dir(temp_dir5);

  // subtract_hash
  std::cout << "subtract_hash\n";
  commands_t::subtract_hash(temp_dir3, temp_dir1, temp_dir4);
  BOOST_TEST_EQ(map_size(temp_dir4), 0);
  rm_hashdb_dir(temp_dir4);

  // deduplicate
  std::cout << "deduplicate1\n";
  commands_t::create(settings, temp_dir6);
  commands_t::import(temp_dir6, sample_dfxml4096, "repository1");
  commands_t::deduplicate(temp_dir6, temp_dir7);
  BOOST_TEST_EQ(map_size(temp_dir7), 74);
  std::cout << "deduplicate2\n";
  commands_t::import(temp_dir6, sample_dfxml4096, "repository2");
  commands_t::deduplicate(temp_dir6, temp_dir8);
  // check ability to open existing target
  commands_t::deduplicate(temp_dir6, temp_dir8);
  BOOST_TEST_EQ(map_size(temp_dir8), 0);
}