use of org.apache.ignite.raft.jraft.util.ByteBufferCollector in project ignite-3 by apache.
the class LocalFileReaderTest method testReadSmallInitBuffer.
@Test
public void testReadSmallInitBuffer() throws Exception {
final ByteBufferCollector bufRef = ByteBufferCollector.allocate(2);
final String data = writeData();
assertReadResult(bufRef, data);
}
use of org.apache.ignite.raft.jraft.util.ByteBufferCollector in project ignite-3 by apache.
the class SnapshotFileReaderTest method testReadMetaFile.
@Test
public void testReadMetaFile() throws Exception {
final ByteBufferCollector bufRef = ByteBufferCollector.allocate(1024);
final LocalFileMetaOutter.LocalFileMeta meta = addDataMeta();
assertEquals(-1, this.reader.readFile(bufRef, Snapshot.JRAFT_SNAPSHOT_META_FILE, 0, Integer.MAX_VALUE));
final ByteBuffer buf = bufRef.getBuffer();
buf.flip();
final LocalSnapshotMetaTable newTable = new LocalSnapshotMetaTable(new RaftOptions());
newTable.loadFromIoBufferAsRemote(buf);
assertEquals(meta, newTable.getFileMeta("data"));
}
use of org.apache.ignite.raft.jraft.util.ByteBufferCollector in project ignite-3 by apache.
the class CopySessionTest method testOnRpcReturnedEOF.
@Test
public void testOnRpcReturnedEOF() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
Thread t = new Thread(() -> {
try {
// test join, should return
session.join();
latch.countDown();
} catch (final InterruptedException e) {
// No-op.
}
});
try {
t.start();
assertNull(this.session.getRpcCall());
final ByteBufferCollector bufRef = ByteBufferCollector.allocate(0);
this.session.setDestBuf(bufRef);
this.session.onRpcReturned(Status.OK(), raftOpts.getRaftMessagesFactory().getFileResponse().readSize(100).eof(true).data(new ByteString(new byte[100])).build());
assertEquals(100, bufRef.capacity());
// should be flip
assertEquals(0, bufRef.getBuffer().position());
assertEquals(100, bufRef.getBuffer().remaining());
assertNull(this.session.getRpcCall());
latch.await();
} finally {
t.join();
}
}
use of org.apache.ignite.raft.jraft.util.ByteBufferCollector in project ignite-3 by apache.
the class LocalSnapshotCopier method loadMetaTable.
private void loadMetaTable() throws InterruptedException {
final ByteBufferCollector metaBuf = ByteBufferCollector.allocate(0);
Session session = null;
try {
this.lock.lock();
try {
if (this.cancelled) {
if (isOk()) {
setError(RaftError.ECANCELED, "ECANCELED");
}
return;
}
session = this.copier.startCopy2IoBuffer(Snapshot.JRAFT_SNAPSHOT_META_FILE, metaBuf, null);
this.curSession = session;
} finally {
this.lock.unlock();
}
// join out of lock.
session.join();
this.lock.lock();
try {
this.curSession = null;
} finally {
this.lock.unlock();
}
if (!session.status().isOk() && isOk()) {
LOG.warn("Fail to copy meta file: {}", session.status());
setError(session.status().getCode(), session.status().getErrorMsg());
return;
}
if (!this.remoteSnapshot.getMetaTable().loadFromIoBufferAsRemote(metaBuf.getBuffer())) {
LOG.warn("Bad meta_table format");
setError(-1, "Bad meta_table format from remote");
return;
}
Requires.requireTrue(this.remoteSnapshot.getMetaTable().hasMeta(), "Invalid remote snapshot meta:%s", this.remoteSnapshot.getMetaTable().getMeta());
} finally {
if (session != null) {
Utils.closeQuietly(session);
}
}
}
Aggregations