use of org.corfudb.protocols.wireprotocol.LogData in project CorfuDB by CorfuDB.
the class StreamLogFilesTest method testStreamLogDataCorruption.
@Test
public void testStreamLogDataCorruption() throws Exception {
// This test manipulates a log file directly and manipulates
// log records by overwriting some parts of the record simulating
// different data corruption scenarios
String logDir = getContext().getServerConfig().get("--log-path") + File.separator + "log";
StreamLog log = new StreamLogFiles(getContext(), false);
ByteBuf b = Unpooled.buffer();
byte[] streamEntry = "Payload".getBytes();
Serializers.CORFU.serialize(streamEntry, b);
// Write to two segments
long address0 = 0;
long address1 = StreamLogFiles.RECORDS_PER_LOG_FILE + 1L;
log.append(address0, new LogData(DataType.DATA, b));
log.append(address1, new LogData(DataType.DATA, b));
assertThat(log.read(address0).getPayload(null)).isEqualTo(streamEntry);
log.close();
final int OVERWRITE_DELIMITER = 0xFFFF;
final int OVERWRITE_BYTES = 4;
// Overwrite 2 bytes of the checksum and 2 bytes of the entry's address
String logFilePath1 = logDir + File.separator + 0 + ".log";
String logFilePath2 = logDir + File.separator + 1 + ".log";
RandomAccessFile file1 = new RandomAccessFile(logFilePath1, "rw");
RandomAccessFile file2 = new RandomAccessFile(logFilePath2, "rw");
ByteBuffer metaDataBuf = ByteBuffer.allocate(METADATA_SIZE);
file1.getChannel().read(metaDataBuf);
metaDataBuf.flip();
Metadata metadata = Metadata.parseFrom(metaDataBuf.array());
final int offset1 = METADATA_SIZE + metadata.getLength();
final int offset2 = METADATA_SIZE + metadata.getLength() + Short.BYTES + OVERWRITE_BYTES;
// Corrupt delimiter in the first segment
file1.seek(offset1);
file1.writeShort(0);
file1.close();
assertThatThrownBy(() -> new StreamLogFiles(getContext(), false).read(0L)).isInstanceOf(DataCorruptionException.class);
// Corrupt metadata in the second segment
file2.seek(offset2);
file2.writeInt(OVERWRITE_DELIMITER);
file2.close();
assertThatThrownBy(() -> new StreamLogFiles(getContext(), false)).isInstanceOf(DataCorruptionException.class);
}
use of org.corfudb.protocols.wireprotocol.LogData in project CorfuDB by CorfuDB.
the class StreamLogFilesTest method testStreamLogBadChecksum.
@Test
public void testStreamLogBadChecksum() {
// This test generates a stream log file without computing checksums, then
// tries to read from the same log file with checksum enabled. The expected
// behaviour is to throw a DataCorruptionException because a checksum cannot
// be computed for stream entries that haven't been written with a checksum
StreamLog log = new StreamLogFiles(getContext(), true);
ByteBuf b = Unpooled.buffer();
byte[] streamEntry = "Payload".getBytes();
Serializers.CORFU.serialize(streamEntry, b);
long address0 = 0;
log.append(address0, new LogData(DataType.DATA, b));
assertThat(log.read(address0).getPayload(null)).isEqualTo(streamEntry);
log.close();
// Re-open stream log with checksum enabled
assertThatThrownBy(() -> new StreamLogFiles(getContext(), false)).isInstanceOf(RuntimeException.class);
}
use of org.corfudb.protocols.wireprotocol.LogData in project CorfuDB by CorfuDB.
the class StreamLogWithRankedAddressSpaceTest method testCompact.
@Test
// compact on ranked address space not activated yet
@Ignore
public void testCompact() throws Exception {
StreamLogFiles log = new StreamLogFiles(getContext(), false);
long address = 0;
for (long x = 0; x < RECORDS_TO_WRITE; x++) {
writeToLog(log, address, DataType.DATA, "Payload", x);
}
LogData value1 = log.read(address);
long size1 = new File(log.getSegmentHandleForAddress(address).getFileName()).length();
log.compact();
LogData value2 = log.read(address);
long size2 = new File(log.getSegmentHandleForAddress(address).getFileName()).length();
assertEquals(value1.getRank(), value2.getRank());
assertNotEquals(size2, size1);
}
use of org.corfudb.protocols.wireprotocol.LogData in project CorfuDB by CorfuDB.
the class StreamLogWithRankedAddressSpaceTest method testProposalsLowerRank.
@Test
public void testProposalsLowerRank() {
StreamLogFiles log = new StreamLogFiles(getContext(), false);
long address = 0;
writeToLog(log, address, DataType.RANK_ONLY, "v-1", 2);
LogData value1 = log.read(address);
assertTrue(new String(value1.getData()).contains("v-1"));
try {
writeToLog(log, address, DataType.RANK_ONLY, "v-2", 1);
fail();
} catch (DataOutrankedException e) {
// expected
}
LogData value2 = log.read(address);
assertTrue(new String(value2.getData()).contains("v-1"));
log.close();
}
use of org.corfudb.protocols.wireprotocol.LogData in project CorfuDB by CorfuDB.
the class StreamLogWithRankedAddressSpaceTest method testLowerRankAgainstProposal.
@Test
public void testLowerRankAgainstProposal() {
StreamLogFiles log = new StreamLogFiles(getContext(), false);
long address = 0;
writeToLog(log, address, DataType.RANK_ONLY, "v-1", 2);
LogData value1 = log.read(address);
assertTrue(new String(value1.getData()).contains("v-1"));
try {
writeToLog(log, address, DataType.DATA, "v-2", 1);
fail();
} catch (DataOutrankedException e) {
// expected
}
LogData value2 = log.read(address);
assertTrue(new String(value2.getData()).contains("v-1"));
log.close();
}
Aggregations