2013-04-26 20:25:45 +05:30
|
|
|
#include "test_utils.h"
|
|
|
|
|
2013-05-01 21:03:24 +05:30
|
|
|
#include "persistent-data/space-maps/core.h"
|
|
|
|
|
2013-05-28 18:18:10 +05:30
|
|
|
using namespace persistent_data;
|
2016-06-07 15:42:27 +05:30
|
|
|
using namespace std;
|
|
|
|
using namespace test;
|
2013-05-28 18:18:10 +05:30
|
|
|
|
2013-04-26 20:25:45 +05:30
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
void test::zero_block(block_manager<>::ptr bm, block_address b)
|
|
|
|
{
|
|
|
|
block_manager<>::write_ref wr = bm->write_lock(b);
|
2014-07-29 16:04:26 +05:30
|
|
|
memset(wr.data(), 0, 4096);
|
2013-04-26 20:25:45 +05:30
|
|
|
}
|
|
|
|
|
2013-05-28 18:18:10 +05:30
|
|
|
transaction_manager::ptr
|
|
|
|
test::open_temporary_tm(block_manager<>::ptr bm)
|
2013-05-01 21:03:24 +05:30
|
|
|
{
|
|
|
|
space_map::ptr sm(new core_map(bm->get_nr_blocks()));
|
|
|
|
transaction_manager::ptr tm(new transaction_manager(bm, sm));
|
|
|
|
return tm;
|
|
|
|
}
|
|
|
|
|
2013-04-26 20:25:45 +05:30
|
|
|
//----------------------------------------------------------------
|
2016-06-07 15:42:27 +05:30
|
|
|
|
|
|
|
temp_file::temp_file(string const &name_base, unsigned meg_size)
|
|
|
|
: path_(gen_path(name_base))
|
|
|
|
{
|
|
|
|
int fd = ::open(path_.c_str(), O_CREAT | O_RDWR, 0666);
|
|
|
|
if (fd < 0)
|
|
|
|
throw runtime_error("couldn't open file");
|
|
|
|
|
|
|
|
if (::fallocate(fd, 0, 0, 1024 * 1024 * meg_size))
|
|
|
|
throw runtime_error("couldn't fallocate");
|
|
|
|
|
|
|
|
::close(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
temp_file::~temp_file()
|
|
|
|
{
|
|
|
|
// ::unlink(path_.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
string const &
|
|
|
|
temp_file::get_path() const
|
|
|
|
{
|
|
|
|
return path_;
|
|
|
|
}
|
|
|
|
|
|
|
|
string
|
|
|
|
temp_file::gen_path(string const &base)
|
|
|
|
{
|
|
|
|
return string("./") + base + string(".tmp");
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|