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

Classes

class  ReportCollector
 
class  StringDest
 
class  StringSource
 

Public Member Functions

 LogTest ()
 
 ~LogTest ()
 
void ReopenForAppend ()
 
void Write (const std::string &msg)
 
size_t WrittenBytes () const
 
std::string Read ()
 
void IncrementByte (int offset, int delta)
 
void SetByte (int offset, char new_byte)
 
void ShrinkSize (int bytes)
 
void FixChecksum (int header_offset, int len)
 
void ForceError ()
 
size_t DroppedBytes () const
 
std::string ReportMessage () const
 
std::string MatchError (const std::string &msg) const
 
void WriteInitialOffsetLog ()
 
void StartReadingAt (uint64_t initial_offset)
 
void CheckOffsetPastEndReturnsNoRecords (uint64_t offset_past_end)
 
void CheckInitialOffsetRecord (uint64_t initial_offset, int expected_record_offset)
 

Private Attributes

StringDest dest_
 
StringSource source_
 
ReportCollector report_
 
bool reading_
 
Writerwriter_
 
Readerreader_
 

Static Private Attributes

static size_t initial_offset_record_sizes_ []
 
static uint64_t initial_offset_last_record_offsets_ []
 
static int num_initial_offset_records_
 

Detailed Description

Definition at line 39 of file log_test.cc.

Constructor & Destructor Documentation

§ LogTest()

leveldb::log::LogTest::LogTest ( )
inline

Definition at line 116 of file log_test.cc.

116  : reading_(false),
117  writer_(new Writer(&dest_)),
118  reader_(new Reader(&source_, &report_, true/*checksum*/,
119  0/*initial_offset*/)) {
120  }
StringSource source_
Definition: log_test.cc:104
ReportCollector report_
Definition: log_test.cc:105

§ ~LogTest()

leveldb::log::LogTest::~LogTest ( )
inline

Definition at line 122 of file log_test.cc.

122  {
123  delete writer_;
124  delete reader_;
125  }

Member Function Documentation

§ CheckInitialOffsetRecord()

void leveldb::log::LogTest::CheckInitialOffsetRecord ( uint64_t  initial_offset,
int  expected_record_offset 
)
inline

Definition at line 220 of file log_test.cc.

221  {
223  reading_ = true;
224  source_.contents_ = Slice(dest_.contents_);
225  Reader* offset_reader = new Reader(&source_, &report_, true/*checksum*/,
226  initial_offset);
227 
228  // Read all records from expected_record_offset through the last one.
229  ASSERT_LT(expected_record_offset, num_initial_offset_records_);
230  for (; expected_record_offset < num_initial_offset_records_;
231  ++expected_record_offset) {
232  Slice record;
233  std::string scratch;
234  ASSERT_TRUE(offset_reader->ReadRecord(&record, &scratch));
235  ASSERT_EQ(initial_offset_record_sizes_[expected_record_offset],
236  record.size());
237  ASSERT_EQ(initial_offset_last_record_offsets_[expected_record_offset],
238  offset_reader->LastRecordOffset());
239  ASSERT_EQ((char)('a' + expected_record_offset), record.data()[0]);
240  }
241  delete offset_reader;
242  }
static uint64_t initial_offset_last_record_offsets_[]
Definition: log_test.cc:112
void WriteInitialOffsetLog()
Definition: log_test.cc:195
#define ASSERT_EQ(a, b)
Definition: testharness.h:107
static size_t initial_offset_record_sizes_[]
Definition: log_test.cc:111
static int num_initial_offset_records_
Definition: log_test.cc:113
#define ASSERT_LT(a, b)
Definition: testharness.h:112
#define ASSERT_TRUE(c)
Definition: testharness.h:105
StringSource source_
Definition: log_test.cc:104
ReportCollector report_
Definition: log_test.cc:105
Here is the call graph for this function:
Here is the caller graph for this function:

§ CheckOffsetPastEndReturnsNoRecords()

void leveldb::log::LogTest::CheckOffsetPastEndReturnsNoRecords ( uint64_t  offset_past_end)
inline

Definition at line 208 of file log_test.cc.

208  {
210  reading_ = true;
211  source_.contents_ = Slice(dest_.contents_);
212  Reader* offset_reader = new Reader(&source_, &report_, true/*checksum*/,
213  WrittenBytes() + offset_past_end);
214  Slice record;
215  std::string scratch;
216  ASSERT_TRUE(!offset_reader->ReadRecord(&record, &scratch));
217  delete offset_reader;
218  }
void WriteInitialOffsetLog()
Definition: log_test.cc:195
#define ASSERT_TRUE(c)
Definition: testharness.h:105
StringSource source_
Definition: log_test.cc:104
ReportCollector report_
Definition: log_test.cc:105
size_t WrittenBytes() const
Definition: log_test.cc:137
Here is the call graph for this function:
Here is the caller graph for this function:

§ DroppedBytes()

size_t leveldb::log::LogTest::DroppedBytes ( ) const
inline

Definition at line 178 of file log_test.cc.

178  {
179  return report_.dropped_bytes_;
180  }
ReportCollector report_
Definition: log_test.cc:105
Here is the caller graph for this function:

§ FixChecksum()

void leveldb::log::LogTest::FixChecksum ( int  header_offset,
int  len 
)
inline

Definition at line 167 of file log_test.cc.

167  {
168  // Compute crc of type/len/data
169  uint32_t crc = crc32c::Value(&dest_.contents_[header_offset+6], 1 + len);
170  crc = crc32c::Mask(crc);
171  EncodeFixed32(&dest_.contents_[header_offset], crc);
172  }
void EncodeFixed32(char *buf, uint32_t value)
Definition: coding.cc:9
uint32_t Mask(uint32_t crc)
Definition: crc32c.h:31
uint32_t Value(const char *data, size_t n)
Definition: crc32c.h:20
Here is the call graph for this function:
Here is the caller graph for this function:

§ ForceError()

void leveldb::log::LogTest::ForceError ( )
inline

Definition at line 174 of file log_test.cc.

174  {
175  source_.force_error_ = true;
176  }
StringSource source_
Definition: log_test.cc:104
Here is the caller graph for this function:

§ IncrementByte()

void leveldb::log::LogTest::IncrementByte ( int  offset,
int  delta 
)
inline

Definition at line 155 of file log_test.cc.

155  {
156  dest_.contents_[offset] += delta;
157  }
Here is the caller graph for this function:

§ MatchError()

std::string leveldb::log::LogTest::MatchError ( const std::string &  msg) const
inline

Definition at line 187 of file log_test.cc.

187  {
188  if (report_.message_.find(msg) == std::string::npos) {
189  return report_.message_;
190  } else {
191  return "OK";
192  }
193  }
ReportCollector report_
Definition: log_test.cc:105
Here is the caller graph for this function:

§ Read()

std::string leveldb::log::LogTest::Read ( )
inline

Definition at line 141 of file log_test.cc.

141  {
142  if (!reading_) {
143  reading_ = true;
144  source_.contents_ = Slice(dest_.contents_);
145  }
146  std::string scratch;
147  Slice record;
148  if (reader_->ReadRecord(&record, &scratch)) {
149  return record.ToString();
150  } else {
151  return "EOF";
152  }
153  }
bool ReadRecord(Slice *record, std::string *scratch)
Definition: log_reader.cc:60
StringSource source_
Definition: log_test.cc:104
Here is the call graph for this function:
Here is the caller graph for this function:

§ ReopenForAppend()

void leveldb::log::LogTest::ReopenForAppend ( )
inline

Definition at line 127 of file log_test.cc.

127  {
128  delete writer_;
129  writer_ = new Writer(&dest_, dest_.contents_.size());
130  }
Here is the caller graph for this function:

§ ReportMessage()

std::string leveldb::log::LogTest::ReportMessage ( ) const
inline

Definition at line 182 of file log_test.cc.

182  {
183  return report_.message_;
184  }
ReportCollector report_
Definition: log_test.cc:105
Here is the caller graph for this function:

§ SetByte()

void leveldb::log::LogTest::SetByte ( int  offset,
char  new_byte 
)
inline

Definition at line 159 of file log_test.cc.

159  {
160  dest_.contents_[offset] = new_byte;
161  }
Here is the caller graph for this function:

§ ShrinkSize()

void leveldb::log::LogTest::ShrinkSize ( int  bytes)
inline

Definition at line 163 of file log_test.cc.

163  {
164  dest_.contents_.resize(dest_.contents_.size() - bytes);
165  }
Here is the caller graph for this function:

§ StartReadingAt()

void leveldb::log::LogTest::StartReadingAt ( uint64_t  initial_offset)
inline

Definition at line 203 of file log_test.cc.

203  {
204  delete reader_;
205  reader_ = new Reader(&source_, &report_, true/*checksum*/, initial_offset);
206  }
StringSource source_
Definition: log_test.cc:104
ReportCollector report_
Definition: log_test.cc:105
Here is the caller graph for this function:

§ Write()

void leveldb::log::LogTest::Write ( const std::string &  msg)
inline

Definition at line 132 of file log_test.cc.

132  {
133  ASSERT_TRUE(!reading_) << "Write() after starting to read";
134  writer_->AddRecord(Slice(msg));
135  }
#define ASSERT_TRUE(c)
Definition: testharness.h:105
Status AddRecord(const Slice &slice)
Definition: log_writer.cc:36
Here is the call graph for this function:
Here is the caller graph for this function:

§ WriteInitialOffsetLog()

void leveldb::log::LogTest::WriteInitialOffsetLog ( )
inline

Definition at line 195 of file log_test.cc.

195  {
196  for (int i = 0; i < num_initial_offset_records_; i++) {
197  std::string record(initial_offset_record_sizes_[i],
198  static_cast<char>('a' + i));
199  Write(record);
200  }
201  }
static size_t initial_offset_record_sizes_[]
Definition: log_test.cc:111
static int num_initial_offset_records_
Definition: log_test.cc:113
void Write(const std::string &msg)
Definition: log_test.cc:132
Here is the call graph for this function:
Here is the caller graph for this function:

§ WrittenBytes()

size_t leveldb::log::LogTest::WrittenBytes ( ) const
inline

Definition at line 137 of file log_test.cc.

137  {
138  return dest_.contents_.size();
139  }
Here is the caller graph for this function:

Member Data Documentation

§ dest_

StringDest leveldb::log::LogTest::dest_
private

Definition at line 103 of file log_test.cc.

§ initial_offset_last_record_offsets_

uint64_t leveldb::log::LogTest::initial_offset_last_record_offsets_
staticprivate
Initial value:
=
{0,
kHeaderSize + 10000,
2 * (kHeaderSize + 10000),
2 * (kHeaderSize + 10000) +
(2 * log::kBlockSize - 1000) + 3 * kHeaderSize,
2 * (kHeaderSize + 10000) +
(2 * log::kBlockSize - 1000) + 3 * kHeaderSize
+ kHeaderSize + 1,
}

Definition at line 112 of file log_test.cc.

§ initial_offset_record_sizes_

size_t leveldb::log::LogTest::initial_offset_record_sizes_
staticprivate
Initial value:
=
{10000,
10000,
2 * log::kBlockSize - 1000,
1,
13716,
}

Definition at line 111 of file log_test.cc.

§ num_initial_offset_records_

int leveldb::log::LogTest::num_initial_offset_records_
staticprivate
Initial value:

Definition at line 113 of file log_test.cc.

§ reader_

Reader* leveldb::log::LogTest::reader_
private

Definition at line 108 of file log_test.cc.

§ reading_

bool leveldb::log::LogTest::reading_
private

Definition at line 106 of file log_test.cc.

§ report_

ReportCollector leveldb::log::LogTest::report_
private

Definition at line 105 of file log_test.cc.

§ source_

StringSource leveldb::log::LogTest::source_
private

Definition at line 104 of file log_test.cc.

§ writer_

Writer* leveldb::log::LogTest::writer_
private

Definition at line 107 of file log_test.cc.


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