Search in sources :

Example 11 with ComException

use of org.neo4j.com.ComException in project neo4j by neo4j.

the class PropertyConstraintsStressIT method performInserts.

/**
     * Inserts a bunch of new nodes with the label and property key currently set in the fields in this class, where
     * running this method twice will insert nodes with duplicate property values, assuming property key or label has
     * not changed.
     */
private WorkerCommand<Object, Integer> performInserts(final HighlyAvailableGraphDatabase slave, final boolean constraintCompliant) {
    return new WorkerCommand<Object, Integer>() {

        @Override
        public Integer doWork(Object state) throws Exception {
            int i = 0;
            try {
                for (; i < 100; i++) {
                    try (Transaction tx = slave.beginTx()) {
                        constraintOps.createEntity(slave, labelOrRelType, property, "value" + i, constraintCompliant);
                        tx.success();
                    }
                }
            } catch (TransactionFailureException | TransientTransactionFailureException e) {
            // Swallowed on purpose, we except it to fail sometimes due to either
            //  - constraint violation on master
            //  - concurrent schema operation on master
            } catch (ConstraintViolationException e) {
            // Constraint violation detected on slave while building transaction
            } catch (ComException e) {
            // Happens sometimes, cause:
            // - The lock session requested to start is already in use.
            //   Please retry your request in a few seconds.
            }
            return i;
        }
    };
}
Also used : ComException(org.neo4j.com.ComException) WorkerCommand(org.neo4j.test.OtherThreadExecutor.WorkerCommand) TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) TransientTransactionFailureException(org.neo4j.graphdb.TransientTransactionFailureException) Transaction(org.neo4j.graphdb.Transaction) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) TransientTransactionFailureException(org.neo4j.graphdb.TransientTransactionFailureException)

Example 12 with ComException

use of org.neo4j.com.ComException in project neo4j by neo4j.

the class SlaveTokenCreatorTest method mustTranslateComExceptionsToTransientTransactionFailures.

@Test(expected = TransientTransactionFailureException.class)
public void mustTranslateComExceptionsToTransientTransactionFailures() throws Exception {
    when(fixture.callMasterMethod(master, requestContext, name)).thenThrow(new ComException());
    tokenCreator.getOrCreate(name);
}
Also used : ComException(org.neo4j.com.ComException) Test(org.junit.Test)

Example 13 with ComException

use of org.neo4j.com.ComException in project neo4j by neo4j.

the class SlaveTransactionCommitProcessTest method mustTranslateComExceptionsToTransientTransactionFailures.

@Test(expected = TransientTransactionFailureException.class)
public void mustTranslateComExceptionsToTransientTransactionFailures() throws Exception {
    when(master.commit(requestContext, tx)).thenThrow(new ComException());
    // When
    commitProcess.commit(new TransactionToApply(tx), CommitEvent.NULL, TransactionApplicationMode.INTERNAL);
// Then we assert that the right exception is thrown
}
Also used : ComException(org.neo4j.com.ComException) TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) Test(org.junit.Test)

Example 14 with ComException

use of org.neo4j.com.ComException in project neo4j by neo4j.

the class SlaveUpdatePullerTest method shouldCapExcessiveComExceptionLogging.

@Test
public void shouldCapExcessiveComExceptionLogging() throws Exception {
    OngoingStubbing<Response<Void>> updatePullStubbing = when(master.pullUpdates(any(RequestContext.class)));
    updatePullStubbing.thenThrow(new ComException());
    for (int i = 0; i < SlaveUpdatePuller.LOG_CAP + 20; i++) {
        updatePuller.pullUpdates();
    }
    logProvider.assertContainsThrowablesMatching(0, repeat(new ComException(), SlaveUpdatePuller.LOG_CAP));
    // And we should be able to recover afterwards
    updatePullStubbing.thenReturn(Response.EMPTY).thenThrow(new ComException());
    // This one will succeed and unlock the circuit breaker
    updatePuller.pullUpdates();
    // And then we log another exception
    updatePuller.pullUpdates();
    logProvider.assertContainsThrowablesMatching(0, repeat(new ComException(), SlaveUpdatePuller.LOG_CAP + 1));
}
Also used : Response(org.neo4j.com.Response) ComException(org.neo4j.com.ComException) Test(org.junit.Test)

Example 15 with ComException

use of org.neo4j.com.ComException in project graphdb by neo4j-attic.

the class TestBackup method makeSureStoreIdIsEnforced.

@Test
public void makeSureStoreIdIsEnforced() throws Exception {
    // Create data set X on server A
    DbRepresentation initialDataSetRepresentation = createInitialDataSet(serverPath);
    ServerInterface server = startServer(serverPath);
    // Grab initial backup from server A
    OnlineBackup backup = OnlineBackup.from("localhost");
    backup.full(backupPath);
    assertEquals(initialDataSetRepresentation, DbRepresentation.of(backupPath));
    shutdownServer(server);
    // Create data set X+Y on server B 
    createInitialDataSet(otherServerPath);
    addMoreData(otherServerPath);
    server = startServer(otherServerPath);
    // Data should be OK, but store id check should prevent that.
    try {
        backup.incremental(backupPath);
        fail("Shouldn't work");
    } catch (ComException e) {
    // Good
    }
    shutdownServer(server);
    // Just make sure incremental backup can be received properly from
    // server A, even after a failed attempt from server B
    DbRepresentation furtherRepresentation = addMoreData(serverPath);
    server = startServer(serverPath);
    backup.incremental(backupPath);
    assertEquals(furtherRepresentation, DbRepresentation.of(backupPath));
    shutdownServer(server);
}
Also used : ComException(org.neo4j.com.ComException) DbRepresentation(org.neo4j.test.DbRepresentation) Test(org.junit.Test)

Aggregations

ComException (org.neo4j.com.ComException)23 Test (org.junit.Test)12 RequestContext (org.neo4j.com.RequestContext)9 ZooKeeperException (org.neo4j.kernel.ha.zookeeper.ZooKeeperException)3 IOException (java.io.IOException)2 URI (java.net.URI)2 Node (org.neo4j.graphdb.Node)2 Relationship (org.neo4j.graphdb.Relationship)2 MismatchingStoreIdException (org.neo4j.kernel.impl.store.MismatchingStoreIdException)2 URISyntaxException (java.net.URISyntaxException)1 ReadableByteChannel (java.nio.channels.ReadableByteChannel)1 Callable (java.util.concurrent.Callable)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1 Future (java.util.concurrent.Future)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1