/* * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ #include "../unit_test.h" #include #include #include "qpid/legacystore/jrnl/jcntl.h" using namespace boost::unit_test; using namespace mrg::journal; using namespace std; QPID_AUTO_TEST_SUITE(jinf_suite) const string test_filename("_ut_jinf"); #include "_st_helper_fns.h" timespec ts; QPID_AUTO_TEST_CASE(write_constructor) { string test_name = get_test_name(test_filename, "write_constructor"); const string jid = test_name + "_jid"; const string base_filename = test_name + "_bfn"; jdir::create_dir(test_dir); // Check test dir exists; create it if not ::clock_gettime(CLOCK_REALTIME, &ts); jinf ji(jid, test_dir, base_filename, NUM_JFILES, false, 0, JFSIZE_SBLKS, JRNL_WMGR_DEF_PAGE_SIZE, JRNL_WMGR_DEF_PAGES, ts); BOOST_CHECK_EQUAL(ji.jver(), RHM_JDAT_VERSION); BOOST_CHECK(ji.jid().compare(jid) == 0); BOOST_CHECK(ji.jdir().compare(test_dir) == 0); BOOST_CHECK(ji.base_filename().compare(base_filename) == 0); const timespec this_ts = ji.ts(); BOOST_CHECK_EQUAL(this_ts.tv_sec, ts.tv_sec); BOOST_CHECK_EQUAL(this_ts.tv_nsec, ts.tv_nsec); BOOST_CHECK_EQUAL(ji.num_jfiles(), u_int16_t(NUM_JFILES)); BOOST_CHECK_EQUAL(ji.is_ae(), false); BOOST_CHECK_EQUAL(ji.ae_max_jfiles(), u_int16_t(0)); BOOST_CHECK_EQUAL(ji.jfsize_sblks(), u_int32_t(JFSIZE_SBLKS)); BOOST_CHECK_EQUAL(ji.sblk_size_dblks(), u_int16_t(JRNL_SBLK_SIZE)); BOOST_CHECK_EQUAL(ji.dblk_size(), u_int32_t(JRNL_DBLK_SIZE)); BOOST_CHECK_EQUAL(ji.wcache_pgsize_sblks(), u_int32_t(JRNL_WMGR_DEF_PAGE_SIZE)); BOOST_CHECK_EQUAL(ji.wcache_num_pages(), u_int16_t(JRNL_WMGR_DEF_PAGES)); BOOST_CHECK_EQUAL(ji.rcache_pgsize_sblks(), u_int32_t(JRNL_RMGR_PAGE_SIZE)); BOOST_CHECK_EQUAL(ji.rcache_num_pages(), u_int16_t(JRNL_RMGR_PAGES)); ji.write(); cout << "done" << endl; } QPID_AUTO_TEST_CASE(read_constructor) { string test_name = get_test_name(test_filename, "read_constructor"); const string jid = test_name + "_jid"; const string base_filename = test_name + "_bfn"; lfid_pfid_map::create_new_jinf(jid, base_filename, false); stringstream fn; fn << test_dir << "/" < sblk_buffer(expand_size, 0); of.write(&sblk_buffer[0], expand_size); of.close(); stringstream fn; fn << test_dir << "/" << base_filename << "." << JRNL_INFO_EXTENSION; jinf ji(fn.str(), false); try { ji.analyze(); BOOST_FAIL("Failed to detect irregular journal file size in file \"" << filename << "\""); } catch (const jexception& e) {} // ignore - expected m.destroy_journal(); } cout << "done" << endl; } QPID_AUTO_TEST_CASE(analyze_owi_in_non_ae_journal) { string test_name = get_test_name(test_filename, "analyze_owi_in_non_ae_journal"); const string jid = test_name + "_jid"; const string base_filename = test_name + "_bfn"; lfid_pfid_map m(jid, base_filename); for (u_int16_t oldest_file = 1; oldest_file < NUM_DEFAULT_JFILES-1; oldest_file++) { for (u_int16_t bad_owi_file = oldest_file + 1; bad_owi_file < NUM_DEFAULT_JFILES; bad_owi_file++) { m.journal_create(NUM_DEFAULT_JFILES, NUM_DEFAULT_JFILES, oldest_file, bad_owi_file); m.write_journal(false, 0); stringstream fn; fn << test_dir << "/" << base_filename << "." << JRNL_INFO_EXTENSION; jinf ji(fn.str(), false); try { ji.analyze(); BOOST_FAIL("Failed to detect irregular OWI flag in non-ae journal file \"" << fn.str() << "\""); } catch (const jexception& e) {} // ignore - expected m.destroy_journal(); } } cout << "done" << endl; } QPID_AUTO_TEST_CASE(analyze_owi_in_ae_min_size_journal) { string test_name = get_test_name(test_filename, "analyze_owi_in_ae_min_size_journal"); const string jid = test_name + "_jid"; const string base_filename = test_name + "_bfn"; lfid_pfid_map m(jid, base_filename); for (u_int16_t oldest_file = 1; oldest_file < NUM_JFILES-1; oldest_file++) { for (u_int16_t bad_owi_file = oldest_file + 1; bad_owi_file < NUM_JFILES; bad_owi_file++) { m.journal_create(NUM_JFILES, NUM_JFILES, oldest_file, bad_owi_file); m.write_journal(true, 16); stringstream fn; fn << test_dir << "/" << base_filename << "." << JRNL_INFO_EXTENSION; jinf ji(fn.str(), false); try { ji.analyze(); BOOST_FAIL("Failed to detect irregular OWI flag in min-sized ae journal file \"" << fn.str() << "\""); } catch (const jexception& e) {} // ignore - expected m.destroy_journal(); } } cout << "done" << endl; } QPID_AUTO_TEST_SUITE_END()