use of alluxio.master.journal.JournalReader in project alluxio by Alluxio.
the class UfsJournalReaderTest method readIncompleteLogSecondary.
/**
* Secondary master cannot read incomplete logs.
*/
@Test
public void readIncompleteLogSecondary() throws Exception {
long endSN = 10;
buildCompletedLog(0, endSN);
buildIncompleteLog(endSN, endSN + 1);
try (JournalReader reader = mJournal.getReader(false)) {
int sn = 0;
while (reader.advance() != State.DONE) {
assertEquals(sn, reader.getEntry().getSequenceNumber());
sn++;
}
assertEquals(endSN, sn);
assertEquals(sn, reader.getNextSequenceNumber());
}
}
use of alluxio.master.journal.JournalReader in project alluxio by Alluxio.
the class UfsJournalReaderTest method readCheckpoint.
/**
* Reads checkpoint.
*/
@Test
public void readCheckpoint() throws Exception {
long endSN = CHECKPOINT_SIZE;
byte[] checkpointBytes = buildCheckpoint(endSN);
try (JournalReader reader = mJournal.getReader(true)) {
State state;
boolean foundCheckpoint = false;
while ((state = reader.advance()) != State.DONE) {
switch(state) {
case CHECKPOINT:
foundCheckpoint = true;
assertArrayEquals(checkpointBytes, IOUtils.toByteArray(reader.getCheckpoint()));
break;
case LOG:
case DONE:
default:
throw new IllegalStateException("Unexpected state: " + state);
}
}
assertTrue(foundCheckpoint);
assertEquals(endSN, reader.getNextSequenceNumber());
}
}
use of alluxio.master.journal.JournalReader in project alluxio by Alluxio.
the class UfsJournalReaderTest method readIncompleteLogPrimary.
/**
* Reads incomplete logs in a primary master.
*/
@Test
public void readIncompleteLogPrimary() throws Exception {
long endSN = 10;
buildCompletedLog(0, endSN);
buildIncompleteLog(endSN, endSN + 1);
try (JournalReader reader = mJournal.getReader(true)) {
int sn = 0;
while (reader.advance() != State.DONE) {
assertEquals(sn, reader.getEntry().getSequenceNumber());
sn++;
}
assertEquals(endSN + 1, sn);
assertEquals(sn, reader.getNextSequenceNumber());
}
}
use of alluxio.master.journal.JournalReader in project alluxio by Alluxio.
the class UfsJournalReaderTest method readCheckpointAndLogsSnNotMatch.
/**
* Reads checkpoint and logs. The checkpoint's last sequence number does not match any one of
* the logs' sequence number.
*/
@Test
public void readCheckpointAndLogsSnNotMatch() throws Exception {
long fileSize = 10;
buildCheckpoint(fileSize * 3 + 1);
for (int i = 0; i < 10; i++) {
buildCompletedLog(i * fileSize, (i + 1) * fileSize);
}
try (JournalReader reader = mJournal.getReader(true)) {
while (reader.advance() != State.DONE) {
}
assertEquals(10 * fileSize, reader.getNextSequenceNumber());
}
}
use of alluxio.master.journal.JournalReader in project alluxio by Alluxio.
the class UfsJournalLogWriterTest method checkJournalEntries.
/**
* Checks that journal entries with sequence number between startSN (inclusive) and endSN
* (exclusive) exist in the current journal files.
*
* @param startSN start sequence number (inclusive)
* @param endSN end sequence number (exclusive)
*/
private void checkJournalEntries(long startSN, long endSN) throws IOException, InvalidJournalEntryException {
try (JournalReader reader = new UfsJournalReader(mJournal, startSN, true)) {
long seq = startSN;
while (reader.advance() == State.LOG) {
Assert.assertEquals(seq, reader.getEntry().getSequenceNumber());
seq++;
}
Assert.assertEquals(endSN, seq);
}
}
Aggregations