Search in sources :

Example 1 with DatabaseNotFoundException

use of com.torodb.core.exceptions.user.DatabaseNotFoundException 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);
}
Also used : ApplierContext(com.torodb.mongodb.repl.oplogreplier.ApplierContext) Context(com.codahale.metrics.Timer.Context) Timer(com.codahale.metrics.Timer) RetrierAbortException(com.torodb.core.retrier.RetrierAbortException) DatabaseNotFoundException(com.torodb.core.exceptions.user.DatabaseNotFoundException) OplogOperation(com.eightkdata.mongowp.server.api.oplog.OplogOperation) RetrierGiveUpException(com.torodb.core.retrier.RetrierGiveUpException) ApplierContext(com.torodb.mongodb.repl.oplogreplier.ApplierContext) Test(org.junit.Test)

Example 2 with DatabaseNotFoundException

use of com.torodb.core.exceptions.user.DatabaseNotFoundException in project torodb by torodb.

the class SqlWriteTorodTransaction method getMetaDatabaseOrThrowException.

@Nonnull
protected MutableMetaDatabase getMetaDatabaseOrThrowException(@Nonnull String dbName) throws DatabaseNotFoundException {
    MutableMetaSnapshot metaSnapshot = getInternalTransaction().getMetaSnapshot();
    MutableMetaDatabase metaDb = metaSnapshot.getMetaDatabaseByName(dbName);
    if (metaDb == null) {
        throw new DatabaseNotFoundException(dbName);
    }
    return metaDb;
}
Also used : MutableMetaSnapshot(com.torodb.core.transaction.metainf.MutableMetaSnapshot) DatabaseNotFoundException(com.torodb.core.exceptions.user.DatabaseNotFoundException) MutableMetaDatabase(com.torodb.core.transaction.metainf.MutableMetaDatabase) Nonnull(javax.annotation.Nonnull)

Example 3 with DatabaseNotFoundException

use of com.torodb.core.exceptions.user.DatabaseNotFoundException in project torodb by torodb.

the class SimpleAnalyzedOplogBatchExecutorTest method testVisit_SingleOp_UserEx.

@Test
public void testVisit_SingleOp_UserEx() throws Exception {
    //GIVEN
    OplogOperation operation = mock(OplogOperation.class);
    SingleOpAnalyzedOplogBatch batch = new SingleOpAnalyzedOplogBatch(operation);
    ApplierContext applierContext = new ApplierContext.Builder().setReapplying(true).setUpdatesAsUpserts(true).build();
    Timer timer = mock(Timer.class);
    Context context = mock(Context.class);
    given(metrics.getSingleOpTimer(operation)).willReturn(timer);
    given(timer.time()).willReturn(context);
    doThrow(new DatabaseNotFoundException("test")).when(executor).execute(operation, applierContext);
    //WHEN
    try {
        executor.visit(batch, applierContext);
        fail("An exception was expected");
    } catch (RetrierGiveUpException | RetrierAbortException ignore) {
    }
    //THEN
    then(metrics).should().getSingleOpTimer(operation);
    then(timer).should().time();
    then(executor).should(times(1)).execute(operation, applierContext);
}
Also used : ApplierContext(com.torodb.mongodb.repl.oplogreplier.ApplierContext) Context(com.codahale.metrics.Timer.Context) Timer(com.codahale.metrics.Timer) RetrierAbortException(com.torodb.core.retrier.RetrierAbortException) DatabaseNotFoundException(com.torodb.core.exceptions.user.DatabaseNotFoundException) OplogOperation(com.eightkdata.mongowp.server.api.oplog.OplogOperation) RetrierGiveUpException(com.torodb.core.retrier.RetrierGiveUpException) ApplierContext(com.torodb.mongodb.repl.oplogreplier.ApplierContext) Test(org.junit.Test)

Aggregations

DatabaseNotFoundException (com.torodb.core.exceptions.user.DatabaseNotFoundException)3 Timer (com.codahale.metrics.Timer)2 Context (com.codahale.metrics.Timer.Context)2 OplogOperation (com.eightkdata.mongowp.server.api.oplog.OplogOperation)2 RetrierAbortException (com.torodb.core.retrier.RetrierAbortException)2 RetrierGiveUpException (com.torodb.core.retrier.RetrierGiveUpException)2 ApplierContext (com.torodb.mongodb.repl.oplogreplier.ApplierContext)2 Test (org.junit.Test)2 MutableMetaDatabase (com.torodb.core.transaction.metainf.MutableMetaDatabase)1 MutableMetaSnapshot (com.torodb.core.transaction.metainf.MutableMetaSnapshot)1 Nonnull (javax.annotation.Nonnull)1