use of com.eightkdata.mongowp.server.api.oplog.OplogOperation in project torodb by torodb.
the class SimpleAnalyzedOplogBatchExecutorTest method testExecute_OplogOperation.
@Test
public void testExecute_OplogOperation() throws Exception {
//GIVEN
OplogOperation op = mock(OplogOperation.class);
ApplierContext applierContext = new ApplierContext.Builder().setReapplying(true).setUpdatesAsUpserts(true).build();
//WHEN
executor.execute(op, applierContext);
//THEN
then(server).should().openConnection();
then(conn).should().close();
then(conn).should().openExclusiveWriteTransaction();
then(writeTrans).should().close();
then(applier).should().apply(op, writeTrans, applierContext);
}
use of com.eightkdata.mongowp.server.api.oplog.OplogOperation in project torodb by torodb.
the class ContinuousOplogFetcherTest method testShortOplog.
@Test
public void testShortOplog() throws Exception {
int oplogSize = 2;
List<OplogOperation> oplog = createInsertStream(this::createSimpleInsert).limit(oplogSize).collect(Collectors.toList());
oplogSupplier = () -> oplog;
OplogOperation firstOp = oplog.get(0);
ContinuousOplogFetcher fetcher = factory.createFetcher(firstOp.getHash(), firstOp.getOpTime());
List<OplogOperation> recivedOplog = new ArrayList<>(oplogSize);
OplogBatch batch = null;
while (batch == null || !(batch.isLastOne() || batch.isReadyForMore())) {
batch = fetcher.fetch();
recivedOplog.addAll(batch.getOps());
}
assertEquals("Unexpected number of oplog entries fetched: ", oplog.size() - 1, recivedOplog.size());
assertEquals(oplog.subList(1, oplog.size()), recivedOplog);
}
use of com.eightkdata.mongowp.server.api.oplog.OplogOperation in project torodb by torodb.
the class StaticOplogReader method getBetweenIterator.
private Iterator<OplogOperation> getBetweenIterator(OpTime from, boolean includeFrom, OpTime to, boolean includeTo) {
OpTime includedFrom;
OpTime excludedTo;
if (includeFrom || !oplog.containsKey(from)) {
includedFrom = from;
} else {
//_from_ is excluded, but subMap includes it!
SortedMap<OpTime, OplogOperation> tailMap = oplog.tailMap(from);
if (tailMap.size() > 1) {
includedFrom = tailMap.keySet().iterator().next();
} else {
//the _from_ key is the only key greater or equal than _from_ and we want to exclude it
return Collections.emptyIterator();
}
}
Iterator<OplogOperation> excludingIt = oplog.subMap(includedFrom, to).values().iterator();
if (includeTo) {
OplogOperation toOp = oplog.get(to);
if (toOp != null) {
return Iterators.concat(excludingIt, Collections.singleton(toOp).iterator());
}
}
return excludingIt;
}
Aggregations