Skip to content

Commit

Permalink
tests: fix test case using new api
Browse files Browse the repository at this point in the history
Signed-off-by: Xinze Chi <xinze@xsky.com>
  • Loading branch information
XinzeChi committed Nov 6, 2015
1 parent cfd8492 commit 3d2b66d
Showing 1 changed file with 56 additions and 25 deletions.
81 changes: 56 additions & 25 deletions src/test/test_filejournal.cc
Expand Up @@ -12,6 +12,7 @@
#include "include/Context.h"
#include "common/Mutex.h"
#include "common/safe_io.h"
#include "os/JournalingObjectStore.h"

Finisher *finisher;
Cond sync_cond;
Expand Down Expand Up @@ -137,9 +138,11 @@ TEST(TestFileJournal, WriteSmall) {
ASSERT_EQ(0, j.create());
j.make_writeable();

list<ObjectStore::Transaction*> tls;
bufferlist bl;
bl.append("small");
j.submit_entry(1, bl, 0, new C_SafeCond(&wait_lock, &cond, &done));
int orig_len = j._op_journal_transactions_prepare(tls, bl);
j.submit_entry(1, bl, orig_len, new C_SafeCond(&wait_lock, &cond, &done));
wait();

j.close();
Expand All @@ -165,9 +168,10 @@ TEST(TestFileJournal, WriteBig) {
memset(foo, 1, sizeof(foo));
bl.append(foo, sizeof(foo));
}
j.submit_entry(1, bl, 0, new C_SafeCond(&wait_lock, &cond, &done));
list<ObjectStore::Transaction*> tls;
int orig_len = j._op_journal_transactions_prepare(tls, bl);
j.submit_entry(1, bl, orig_len, new C_SafeCond(&wait_lock, &cond, &done));
wait();

j.close();
}
}
Expand All @@ -187,14 +191,15 @@ TEST(TestFileJournal, WriteMany) {

C_GatherBuilder gb(g_ceph_context, new C_SafeCond(&wait_lock, &cond, &done));

list<ObjectStore::Transaction*> tls;
bufferlist bl;
bl.append("small");
uint64_t seq = 1;
for (int i=0; i<100; i++) {
bl.append("small");
j.submit_entry(seq++, bl, 0, gb.new_sub());
int orig_len = j._op_journal_transactions_prepare(tls, bl);
j.submit_entry(seq++, bl, orig_len, gb.new_sub());
}

gb.activate();

wait();
Expand All @@ -220,7 +225,9 @@ TEST(TestFileJournal, WriteManyVecs) {

bufferlist first;
first.append("small");
j.submit_entry(1, first, 0, gb.new_sub());
list<ObjectStore::Transaction*> tls;
int orig_len = j._op_journal_transactions_prepare(tls, first);
j.submit_entry(1, first, orig_len, gb.new_sub());

bufferlist bl;
for (int i=0; i<IOV_MAX * 2; i++) {
Expand All @@ -229,7 +236,8 @@ TEST(TestFileJournal, WriteManyVecs) {
bl.append(bp);
}
bufferlist origbl = bl;
j.submit_entry(2, bl, 0, gb.new_sub());
orig_len = j._op_journal_transactions_prepare(tls, bl);
j.submit_entry(2, bl, orig_len, gb.new_sub());
gb.activate();
wait();

Expand All @@ -253,6 +261,8 @@ TEST(TestFileJournal, ReplaySmall) {
g_ceph_context->_conf->set_val("journal_write_header_frequency", "0");
g_ceph_context->_conf->apply_changes(NULL);

list<ObjectStore::Transaction*> tls;

for (unsigned i = 0 ; i < 3; ++i) {
SCOPED_TRACE(subtests[i].description);
fsid.generate_random();
Expand All @@ -265,11 +275,14 @@ TEST(TestFileJournal, ReplaySmall) {

bufferlist bl;
bl.append("small");
j.submit_entry(1, bl, 0, gb.new_sub());
int orig_len = j._op_journal_transactions_prepare(tls, bl);
j.submit_entry(1, bl, orig_len, gb.new_sub());
bl.append("small");
j.submit_entry(2, bl, 0, gb.new_sub());
orig_len = j._op_journal_transactions_prepare(tls, bl);
j.submit_entry(2, bl, orig_len, gb.new_sub());
bl.append("small");
j.submit_entry(3, bl, 0, gb.new_sub());
orig_len = j._op_journal_transactions_prepare(tls, bl);
j.submit_entry(3, bl, orig_len, gb.new_sub());
gb.activate();
wait();

Expand Down Expand Up @@ -306,6 +319,7 @@ TEST(TestFileJournal, ReplayCorrupt) {
g_ceph_context->_conf->set_val("journal_write_header_frequency", "0");
g_ceph_context->_conf->apply_changes(NULL);

list<ObjectStore::Transaction*> tls;
for (unsigned i = 0 ; i < 3; ++i) {
SCOPED_TRACE(subtests[i].description);
fsid.generate_random();
Expand All @@ -320,13 +334,17 @@ TEST(TestFileJournal, ReplayCorrupt) {
const char *newneedle = "in a haystack";
bufferlist bl;
bl.append(needle);
j.submit_entry(1, bl, 0, gb.new_sub());
int orig_len = j._op_journal_transactions_prepare(tls, bl);
j.submit_entry(1, bl, orig_len, gb.new_sub());
bl.append(needle);
j.submit_entry(2, bl, 0, gb.new_sub());
orig_len = j._op_journal_transactions_prepare(tls, bl);
j.submit_entry(2, bl, orig_len, gb.new_sub());
bl.append(needle);
j.submit_entry(3, bl, 0, gb.new_sub());
orig_len = j._op_journal_transactions_prepare(tls, bl);
j.submit_entry(3, bl, orig_len, gb.new_sub());
bl.append(needle);
j.submit_entry(4, bl, 0, gb.new_sub());
orig_len = j._op_journal_transactions_prepare(tls, bl);
j.submit_entry(4, bl, orig_len, gb.new_sub());
gb.activate();
wait();

Expand All @@ -342,10 +360,10 @@ TEST(TestFileJournal, ReplayCorrupt) {
for (unsigned o=0; o < sizeof(buf) - strlen(needle); o++) {
if (memcmp(buf+o, needle, strlen(needle)) == 0) {
if (n >= 2) {
cout << "replacing at offset " << o << std::endl;
memcpy(buf+o, newneedle, strlen(newneedle));
cout << "replacing at offset " << o << std::endl;
memcpy(buf+o, newneedle, strlen(newneedle));
} else {
cout << "leaving at offset " << o << std::endl;
cout << "leaving at offset " << o << std::endl;
}
n++;
}
Expand Down Expand Up @@ -398,13 +416,15 @@ TEST(TestFileJournal, WriteTrim) {
memset(foo, 1, sizeof(foo));

uint64_t seq = 1, committed = 0;
list<ObjectStore::Transaction*> tls;

for (unsigned i=0; i<size_mb*2; i++) {
bl.clear();
bl.push_back(buffer::copy(foo, sizeof(foo)));
bl.zero();
ls.push_back(new C_Sync);
j.submit_entry(seq++, bl, 0, ls.back()->c);
int orig_len = j._op_journal_transactions_prepare(tls, bl);
j.submit_entry(seq++, bl, orig_len, ls.back()->c);

while (ls.size() > size_mb/2) {
delete ls.front();
Expand All @@ -430,6 +450,7 @@ TEST(TestFileJournal, WriteTrimSmall) {
g_ceph_context->_conf->set_val("journal_ignore_corruption", "false");
g_ceph_context->_conf->set_val("journal_write_header_frequency", "0");
g_ceph_context->_conf->apply_changes(NULL);
list<ObjectStore::Transaction*> tls;

for (unsigned i = 0 ; i < 3; ++i) {
SCOPED_TRACE(subtests[i].description);
Expand All @@ -453,7 +474,8 @@ TEST(TestFileJournal, WriteTrimSmall) {
bl.push_back(buffer::copy(foo, sizeof(foo) / 128));
bl.zero();
ls.push_back(new C_Sync);
j.submit_entry(seq++, bl, 0, ls.back()->c);
int orig_len = j._op_journal_transactions_prepare(tls, bl);
j.submit_entry(seq++, bl, orig_len, ls.back()->c);

while (ls.size() > size_mb/2) {
delete ls.front();
Expand All @@ -478,6 +500,7 @@ TEST(TestFileJournal, ReplayDetectCorruptFooterMagic) {
g_ceph_context->_conf->set_val("journal_write_header_frequency", "1");
g_ceph_context->_conf->apply_changes(NULL);

list<ObjectStore::Transaction*> tls;
for (unsigned i = 0 ; i < 3; ++i) {
SCOPED_TRACE(subtests[i].description);
fsid.generate_random();
Expand All @@ -492,14 +515,16 @@ TEST(TestFileJournal, ReplayDetectCorruptFooterMagic) {
for (unsigned i = 1; i <= 4; ++i) {
bufferlist bl;
bl.append(needle);
j.submit_entry(i, bl, 0, gb.new_sub());
int orig_len = j._op_journal_transactions_prepare(tls, bl);
j.submit_entry(i, bl, orig_len, gb.new_sub());
}
gb.activate();
wait();

bufferlist bl;
bl.append("needle");
j.submit_entry(5, bl, 0, new C_SafeCond(&wait_lock, &cond, &done));
int orig_len = j._op_journal_transactions_prepare(tls, bl);
j.submit_entry(5, bl, orig_len, new C_SafeCond(&wait_lock, &cond, &done));
wait();

j.close();
Expand Down Expand Up @@ -532,6 +557,7 @@ TEST(TestFileJournal, ReplayDetectCorruptPayload) {
g_ceph_context->_conf->set_val("journal_write_header_frequency", "1");
g_ceph_context->_conf->apply_changes(NULL);

list<ObjectStore::Transaction*> tls;
for (unsigned i = 0 ; i < 3; ++i) {
SCOPED_TRACE(subtests[i].description);
fsid.generate_random();
Expand All @@ -546,14 +572,16 @@ TEST(TestFileJournal, ReplayDetectCorruptPayload) {
for (unsigned i = 1; i <= 4; ++i) {
bufferlist bl;
bl.append(needle);
j.submit_entry(i, bl, 0, gb.new_sub());
int orig_len = j._op_journal_transactions_prepare(tls, bl);
j.submit_entry(i, bl, orig_len, gb.new_sub());
}
gb.activate();
wait();

bufferlist bl;
bl.append("needle");
j.submit_entry(5, bl, 0, new C_SafeCond(&wait_lock, &cond, &done));
int orig_len = j._op_journal_transactions_prepare(tls, bl);
j.submit_entry(5, bl, orig_len, new C_SafeCond(&wait_lock, &cond, &done));
wait();

j.close();
Expand Down Expand Up @@ -586,6 +614,7 @@ TEST(TestFileJournal, ReplayDetectCorruptHeader) {
g_ceph_context->_conf->set_val("journal_write_header_frequency", "1");
g_ceph_context->_conf->apply_changes(NULL);

list<ObjectStore::Transaction*> tls;
for (unsigned i = 0 ; i < 3; ++i) {
SCOPED_TRACE(subtests[i].description);
fsid.generate_random();
Expand All @@ -600,14 +629,16 @@ TEST(TestFileJournal, ReplayDetectCorruptHeader) {
for (unsigned i = 1; i <= 4; ++i) {
bufferlist bl;
bl.append(needle);
j.submit_entry(i, bl, 0, gb.new_sub());
int orig_len = j._op_journal_transactions_prepare(tls, bl);
j.submit_entry(i, bl, orig_len, gb.new_sub());
}
gb.activate();
wait();

bufferlist bl;
bl.append("needle");
j.submit_entry(5, bl, 0, new C_SafeCond(&wait_lock, &cond, &done));
int orig_len = j._op_journal_transactions_prepare(tls, bl);
j.submit_entry(5, bl, orig_len, new C_SafeCond(&wait_lock, &cond, &done));
wait();

j.close();
Expand Down

0 comments on commit 3d2b66d

Please sign in to comment.