use of org.corfudb.protocols.wireprotocol.LogData in project CorfuDB by CorfuDB.
the class StreamLogFilesTest method testOverwriteException.
@Test
public void testOverwriteException() {
StreamLog log = new StreamLogFiles(getContext(), false);
ByteBuf b = Unpooled.buffer();
byte[] streamEntry = "Payload".getBytes();
Serializers.CORFU.serialize(streamEntry, b);
long address0 = 0;
log.append(address0, new LogData(DataType.DATA, b));
assertThatThrownBy(() -> log.append(address0, new LogData(DataType.DATA, b))).isInstanceOf(OverwriteException.class);
}
use of org.corfudb.protocols.wireprotocol.LogData in project CorfuDB by CorfuDB.
the class StreamLogFilesTest method testReadingUnknownAddress.
@Test
public void testReadingUnknownAddress() {
StreamLog log = new StreamLogFiles(getContext(), false);
ByteBuf b = Unpooled.buffer();
byte[] streamEntry = "Payload".getBytes();
Serializers.CORFU.serialize(streamEntry, b);
long address0 = 0;
long address1 = 1;
long address2 = 2;
log.append(address0, new LogData(DataType.DATA, b));
log.append(address2, new LogData(DataType.DATA, b));
assertThat(log.read(address1)).isNull();
}
use of org.corfudb.protocols.wireprotocol.LogData in project CorfuDB by CorfuDB.
the class StreamLogFilesTest method writeToLog.
private void writeToLog(StreamLog log, long address) {
ByteBuf b = Unpooled.buffer();
byte[] streamEntry = "Payload".getBytes();
Serializers.CORFU.serialize(streamEntry, b);
log.append(address, new LogData(DataType.DATA, b));
}
use of org.corfudb.protocols.wireprotocol.LogData in project CorfuDB by CorfuDB.
the class StreamLogFilesTest method multiThreadedReadWrite.
@Test
public void multiThreadedReadWrite() throws Exception {
String logDir = getDirPath();
StreamLog log = new StreamLogFiles(getContext(), false);
ByteBuf b = Unpooled.buffer();
byte[] streamEntry = "Payload".getBytes();
Serializers.CORFU.serialize(streamEntry, b);
final int num_threads = PARAMETERS.CONCURRENCY_SOME;
final int num_entries = PARAMETERS.NUM_ITERATIONS_LOW;
scheduleConcurrently(num_threads, threadNumber -> {
int base = threadNumber * num_entries;
for (int i = base; i < base + num_entries; i++) {
long address = (long) i;
log.append(address, new LogData(DataType.DATA, b));
}
});
executeScheduled(num_threads, PARAMETERS.TIMEOUT_LONG);
// verify that addresses 0 to 2000 have been used up
for (int x = 0; x < num_entries * num_threads; x++) {
long address = (long) x;
LogData data = log.read(address);
byte[] bytes = (byte[]) data.getPayload(null);
assertThat(bytes).isEqualTo(streamEntry);
}
}
use of org.corfudb.protocols.wireprotocol.LogData in project CorfuDB by CorfuDB.
the class StreamLogFilesTest method testSync.
@Test
@SuppressWarnings("checkstyle:magicnumber")
public void testSync() throws Exception {
StreamLogFiles log = new StreamLogFiles(getContext(), false);
ByteBuf b = Unpooled.buffer();
byte[] streamEntry = "Payload".getBytes();
Serializers.CORFU.serialize(streamEntry, b);
long seg1 = StreamLogFiles.RECORDS_PER_LOG_FILE * 0 + 1;
long seg2 = StreamLogFiles.RECORDS_PER_LOG_FILE * 1 + 1;
long seg3 = StreamLogFiles.RECORDS_PER_LOG_FILE * 2 + 1;
log.append(seg1, new LogData(DataType.DATA, b));
log.append(seg2, new LogData(DataType.DATA, b));
log.append(seg3, new LogData(DataType.DATA, b));
assertThat(log.getChannelsToSync().size()).isEqualTo(3);
log.sync(true);
assertThat(log.getChannelsToSync().size()).isEqualTo(0);
}
Aggregations