use of io.atomix.storage.buffer.Buffer in project atomix by atomix.
the class JournalSegmentDescriptorTest method testDescriptorPersist.
/**
* Tests persisting the segment descriptor.
*/
@Test
public void testDescriptorPersist() {
Buffer buffer = FileBuffer.allocate(file, JournalSegmentDescriptor.BYTES);
JournalSegmentDescriptor descriptor = JournalSegmentDescriptor.builder(buffer).withId(2).withIndex(1025).withMaxSegmentSize(1024 * 1024).withMaxEntries(2048).build();
assertEquals(descriptor.id(), 2);
assertEquals(descriptor.version(), JournalSegmentDescriptor.VERSION);
assertEquals(descriptor.index(), 1025);
assertEquals(descriptor.maxSegmentSize(), 1024 * 1024);
assertEquals(descriptor.maxEntries(), 2048);
buffer.close();
descriptor = new JournalSegmentDescriptor(FileBuffer.allocate(file, JournalSegmentDescriptor.BYTES));
assertEquals(descriptor.id(), 2);
assertEquals(descriptor.version(), JournalSegmentDescriptor.VERSION);
assertEquals(descriptor.index(), 1025);
assertEquals(descriptor.maxSegmentSize(), 1024 * 1024);
descriptor.close();
descriptor = new JournalSegmentDescriptor(FileBuffer.allocate(file, JournalSegmentDescriptor.BYTES));
assertEquals(descriptor.id(), 2);
assertEquals(descriptor.version(), JournalSegmentDescriptor.VERSION);
assertEquals(descriptor.index(), 1025);
assertEquals(descriptor.maxSegmentSize(), 1024 * 1024);
}
use of io.atomix.storage.buffer.Buffer in project atomix by atomix.
the class SnapshotDescriptorTest method testCopySnapshotDescriptor.
@Test
public void testCopySnapshotDescriptor() throws Exception {
SnapshotDescriptor descriptor = SnapshotDescriptor.builder().withIndex(2).withTimestamp(3).build();
Buffer buffer = HeapBuffer.allocate(SnapshotDescriptor.BYTES);
descriptor.copyTo(buffer);
buffer.flip();
descriptor = new SnapshotDescriptor(buffer);
assertEquals(2, descriptor.index());
assertEquals(3, descriptor.timestamp());
}
use of io.atomix.storage.buffer.Buffer in project atomix by atomix.
the class SegmentedJournal method createMemorySegment.
/**
* Creates a new segment.
*/
private JournalSegment<E> createMemorySegment(JournalSegmentDescriptor descriptor) {
File segmentFile = JournalSegmentFile.createSegmentFile(name, directory, descriptor.id());
Buffer buffer = HeapBuffer.allocate(Math.min(DEFAULT_BUFFER_SIZE, descriptor.maxSegmentSize()), Integer.MAX_VALUE);
descriptor.copyTo(buffer);
JournalSegment<E> segment = newSegment(new JournalSegmentFile(segmentFile), descriptor);
log.debug("Created memory segment: {}", segment);
return segment;
}
use of io.atomix.storage.buffer.Buffer in project atomix by atomix.
the class SegmentedJournal method loadMemorySegment.
/**
* Loads a segment.
*/
private JournalSegment<E> loadMemorySegment(long segmentId) {
File file = JournalSegmentFile.createSegmentFile(name, directory, segmentId);
Buffer buffer = HeapBuffer.allocate(Math.min(DEFAULT_BUFFER_SIZE, maxSegmentSize), Integer.MAX_VALUE);
JournalSegmentDescriptor descriptor = new JournalSegmentDescriptor(buffer);
JournalSegment<E> segment = newSegment(new JournalSegmentFile(file), descriptor);
log.debug("Loaded memory segment: {}", descriptor.id());
return segment;
}
use of io.atomix.storage.buffer.Buffer in project atomix by atomix.
the class SegmentedJournal method createMappedSegment.
/**
* Creates a new segment.
*/
private JournalSegment<E> createMappedSegment(JournalSegmentDescriptor descriptor) {
File segmentFile = JournalSegmentFile.createSegmentFile(name, directory, descriptor.id());
Buffer buffer = MappedBuffer.allocate(segmentFile, Math.min(DEFAULT_BUFFER_SIZE, descriptor.maxSegmentSize()), Integer.MAX_VALUE);
descriptor.copyTo(buffer);
JournalSegment<E> segment = newSegment(new JournalSegmentFile(segmentFile), descriptor);
log.debug("Created memory mapped segment: {}", segment);
return segment;
}
Aggregations