use of com.eightkdata.mongowp.server.api.oplog.OplogOperation in project torodb by torodb.
the class ContinuousOplogFetcherTest method testOldOplog.
@Test(expected = RollbackReplicationException.class)
public void testOldOplog() throws Exception {
int oplogSize = 2;
List<OplogOperation> oplog = createInsertStream(this::createSimpleInsert).limit(oplogSize).collect(Collectors.toList());
oplogSupplier = () -> oplog;
OplogOperation lastOp = oplog.get(oplog.size() - 1);
ContinuousOplogFetcher fetcher = factory.createFetcher(0, opTimeFactory.getNextOpTime(lastOp.getOpTime()));
fetcher.fetch();
}
use of com.eightkdata.mongowp.server.api.oplog.OplogOperation in project torodb by torodb.
the class ContinuousOplogFetcherTest method testMediumOplog.
@Test
public void testMediumOplog() throws Exception {
int oplogSize = 1000;
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 ContinuousOplogFetcherTest method testBigOplog.
@Test
public void testBigOplog() throws Exception {
int oplogSize = 100000;
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 OplogTestParser method getOps.
private static List<OplogOperation> getOps(BsonDocument doc) {
BsonValue<?> oplogValue = doc.get("oplog");
if (oplogValue == null) {
throw new AssertionError("Does not contain oplog");
}
AtomicInteger tsFactory = new AtomicInteger();
AtomicInteger tFactory = new AtomicInteger();
BsonInt32 twoInt32 = DefaultBsonValues.newInt(2);
return oplogValue.asArray().asList().stream().map(BsonValue::asDocument).map(child -> {
BsonDocumentBuilder builder = new BsonDocumentBuilder(child);
if (child.get("ts") == null) {
builder.appendUnsafe("ts", DefaultBsonValues.newTimestamp(tsFactory.incrementAndGet(), tFactory.incrementAndGet()));
}
if (child.get("h") == null) {
builder.appendUnsafe("h", DefaultBsonValues.INT32_ONE);
}
if (child.get("v") == null) {
builder.appendUnsafe("v", twoInt32);
}
return builder.build();
}).map(child -> {
try {
return OplogOperationParser.fromBson(child);
} catch (MongoException ex) {
throw new AssertionError("Invalid oplog operation", ex);
}
}).collect(Collectors.toList());
}
use of com.eightkdata.mongowp.server.api.oplog.OplogOperation in project torodb by torodb.
the class SimpleAnalyzedOplogBatchExecutorTest method testVisit_CudAnalyzedOplog_UserEx.
@Test
public void testVisit_CudAnalyzedOplog_UserEx() throws Exception {
//GIVEN
OplogOperation lastOp = mock(OplogOperation.class);
CudAnalyzedOplogBatch batch = mock(CudAnalyzedOplogBatch.class);
ApplierContext applierContext = new ApplierContext.Builder().setReapplying(true).setUpdatesAsUpserts(true).build();
given(batch.getOriginalBatch()).willReturn(Lists.newArrayList(mock(OplogOperation.class), mock(OplogOperation.class), mock(OplogOperation.class), lastOp));
Timer timer = mock(Timer.class);
Context context = mock(Context.class);
given(metrics.getCudBatchTimer()).willReturn(timer);
given(timer.time()).willReturn(context);
doThrow(new DatabaseNotFoundException("test")).when(executor).execute(eq(batch), any());
//WHEN
try {
executor.visit(batch, applierContext);
fail("An exception was expected");
} catch (RetrierGiveUpException | RetrierAbortException ignore) {
}
//THEN
then(metrics).should().getCudBatchTimer();
then(timer).should().time();
then(executor).should(times(1)).execute(batch, applierContext);
}
Aggregations