Search in sources :

Example 1 with RootCauseMatcher

use of org.neo4j.test.mockito.matcher.RootCauseMatcher in project neo4j by neo4j.

the class CommunityLockAcquisitionTimeoutIT method timeoutOnAcquiringSharedLock.

@Test(timeout = TEST_TIMEOUT)
public void timeoutOnAcquiringSharedLock() throws Exception {
    expectedException.expect(new RootCauseMatcher<>(LockAcquisitionTimeoutException.class, "The transaction has been terminated. " + "Retry your operation in a new transaction, and you should see a successful result. " + "Unable to acquire lock within configured timeout. " + "Unable to acquire lock for resource: SCHEMA with id: 0 within 2000 millis."));
    try (Transaction ignored = database.beginTx()) {
        database.schema().indexFor(marker).on(TEST_PROPERTY_NAME).create();
        Future<Void> propertySetFuture = secondTransactionExecutor.executeDontWait(state -> {
            try (Transaction nestedTransaction = database.beginTx()) {
                ResourceIterator<Node> nodes = database.findNodes(marker);
                Node node = nodes.next();
                node.addLabel(Label.label("anotherLabel"));
                nestedTransaction.success();
            }
            return null;
        });
        secondTransactionExecutor.waitUntilWaiting(sharedLockWaitingPredicate());
        clockExecutor.execute((OtherThreadExecutor.WorkerCommand<Void, Void>) state -> {
            fakeClock.forward(3, TimeUnit.SECONDS);
            return null;
        });
        propertySetFuture.get();
        fail("Should throw termination exception.");
    }
}
Also used : ResourceIterator(org.neo4j.graphdb.ResourceIterator) GraphDatabaseFactoryState(org.neo4j.graphdb.factory.GraphDatabaseFactoryState) Label(org.neo4j.graphdb.Label) BeforeClass(org.junit.BeforeClass) SystemNanoClock(org.neo4j.time.SystemNanoClock) RootCauseMatcher(org.neo4j.test.mockito.matcher.RootCauseMatcher) CommunityEditionModule(org.neo4j.kernel.impl.factory.CommunityEditionModule) GraphDatabaseFacadeFactory(org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory) Node(org.neo4j.graphdb.Node) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) GraphDatabaseDependencies(org.neo4j.kernel.GraphDatabaseDependencies) GraphDatabaseBuilder(org.neo4j.graphdb.factory.GraphDatabaseBuilder) Future(java.util.concurrent.Future) LockAcquisitionTimeoutException(org.neo4j.kernel.impl.locking.LockAcquisitionTimeoutException) FakeClock(org.neo4j.time.FakeClock) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) After(org.junit.After) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) ClassRule(org.junit.ClassRule) Transaction(org.neo4j.graphdb.Transaction) ExpectedException(org.junit.rules.ExpectedException) OtherThreadExecutor(org.neo4j.test.OtherThreadExecutor) AfterClass(org.junit.AfterClass) Config(org.neo4j.kernel.configuration.Config) DatabaseInfo(org.neo4j.kernel.impl.factory.DatabaseInfo) Predicate(java.util.function.Predicate) TestDirectory(org.neo4j.test.rule.TestDirectory) Test(org.junit.Test) CommunityLockClient(org.neo4j.kernel.impl.locking.community.CommunityLockClient) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Rule(org.junit.Rule) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade) PlatformModule(org.neo4j.kernel.impl.factory.PlatformModule) Clock(java.time.Clock) GraphDatabaseSettings(org.neo4j.graphdb.factory.GraphDatabaseSettings) Clocks(org.neo4j.time.Clocks) LockAcquisitionTimeoutException(org.neo4j.kernel.impl.locking.LockAcquisitionTimeoutException) Transaction(org.neo4j.graphdb.Transaction) OtherThreadExecutor(org.neo4j.test.OtherThreadExecutor) Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

Example 2 with RootCauseMatcher

use of org.neo4j.test.mockito.matcher.RootCauseMatcher in project neo4j by neo4j.

the class CommunityLockAcquisitionTimeoutIT method timeoutOnAcquiringExclusiveLock.

@Test(timeout = 5000)
public void timeoutOnAcquiringExclusiveLock() throws Exception {
    expectedException.expect(new RootCauseMatcher<>(LockAcquisitionTimeoutException.class, "The transaction has been terminated. " + "Retry your operation in a new transaction, and you should see a successful result. " + "Unable to acquire lock within configured timeout. " + "Unable to acquire lock for resource: NODE with id: 0 within 2000 millis."));
    try (Transaction ignored = database.beginTx()) {
        ResourceIterator<Node> nodes = database.findNodes(marker);
        Node node = nodes.next();
        node.setProperty(TEST_PROPERTY_NAME, "b");
        Future<Void> propertySetFuture = secondTransactionExecutor.executeDontWait(state -> {
            try (Transaction transaction1 = database.beginTx()) {
                node.setProperty(TEST_PROPERTY_NAME, "b");
                transaction1.success();
            }
            return null;
        });
        secondTransactionExecutor.waitUntilWaiting(exclusiveLockWaitingPredicate());
        clockExecutor.execute((OtherThreadExecutor.WorkerCommand<Void, Void>) state -> {
            fakeClock.forward(3, TimeUnit.SECONDS);
            return null;
        });
        propertySetFuture.get();
        fail("Should throw termination exception.");
    }
}
Also used : ResourceIterator(org.neo4j.graphdb.ResourceIterator) GraphDatabaseFactoryState(org.neo4j.graphdb.factory.GraphDatabaseFactoryState) Label(org.neo4j.graphdb.Label) BeforeClass(org.junit.BeforeClass) SystemNanoClock(org.neo4j.time.SystemNanoClock) RootCauseMatcher(org.neo4j.test.mockito.matcher.RootCauseMatcher) CommunityEditionModule(org.neo4j.kernel.impl.factory.CommunityEditionModule) GraphDatabaseFacadeFactory(org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory) Node(org.neo4j.graphdb.Node) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) GraphDatabaseDependencies(org.neo4j.kernel.GraphDatabaseDependencies) GraphDatabaseBuilder(org.neo4j.graphdb.factory.GraphDatabaseBuilder) Future(java.util.concurrent.Future) LockAcquisitionTimeoutException(org.neo4j.kernel.impl.locking.LockAcquisitionTimeoutException) FakeClock(org.neo4j.time.FakeClock) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) After(org.junit.After) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) ClassRule(org.junit.ClassRule) Transaction(org.neo4j.graphdb.Transaction) ExpectedException(org.junit.rules.ExpectedException) OtherThreadExecutor(org.neo4j.test.OtherThreadExecutor) AfterClass(org.junit.AfterClass) Config(org.neo4j.kernel.configuration.Config) DatabaseInfo(org.neo4j.kernel.impl.factory.DatabaseInfo) Predicate(java.util.function.Predicate) TestDirectory(org.neo4j.test.rule.TestDirectory) Test(org.junit.Test) CommunityLockClient(org.neo4j.kernel.impl.locking.community.CommunityLockClient) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Rule(org.junit.Rule) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade) PlatformModule(org.neo4j.kernel.impl.factory.PlatformModule) Clock(java.time.Clock) GraphDatabaseSettings(org.neo4j.graphdb.factory.GraphDatabaseSettings) Clocks(org.neo4j.time.Clocks) LockAcquisitionTimeoutException(org.neo4j.kernel.impl.locking.LockAcquisitionTimeoutException) Transaction(org.neo4j.graphdb.Transaction) OtherThreadExecutor(org.neo4j.test.OtherThreadExecutor) Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

Aggregations

File (java.io.File)2 Clock (java.time.Clock)2 Map (java.util.Map)2 Future (java.util.concurrent.Future)2 TimeUnit (java.util.concurrent.TimeUnit)2 Predicate (java.util.function.Predicate)2 After (org.junit.After)2 AfterClass (org.junit.AfterClass)2 Assert.fail (org.junit.Assert.fail)2 BeforeClass (org.junit.BeforeClass)2 ClassRule (org.junit.ClassRule)2 Rule (org.junit.Rule)2 Test (org.junit.Test)2 ExpectedException (org.junit.rules.ExpectedException)2 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)2 Label (org.neo4j.graphdb.Label)2 Node (org.neo4j.graphdb.Node)2 ResourceIterator (org.neo4j.graphdb.ResourceIterator)2 Transaction (org.neo4j.graphdb.Transaction)2 GraphDatabaseBuilder (org.neo4j.graphdb.factory.GraphDatabaseBuilder)2