Search in sources :

Example 11 with KernelEventHandler

use of org.neo4j.graphdb.event.KernelEventHandler in project neo4j by neo4j.

the class TestKernelEvents method testRegisterUnregisterHandlers.

@Test
public void testRegisterUnregisterHandlers() {
    GraphDatabaseService graphDb = new TestGraphDatabaseFactory().newImpermanentDatabase();
    KernelEventHandler handler1 = new DummyKernelEventHandler(RESOURCE1) {

        @Override
        public ExecutionOrder orderComparedTo(KernelEventHandler other) {
            return ExecutionOrder.DOESNT_MATTER;
        }
    };
    KernelEventHandler handler2 = new DummyKernelEventHandler(RESOURCE2) {

        @Override
        public ExecutionOrder orderComparedTo(KernelEventHandler other) {
            return ExecutionOrder.DOESNT_MATTER;
        }
    };
    try {
        graphDb.unregisterKernelEventHandler(handler1);
        fail("Shouldn't be able to do unregister on a " + "unregistered handler");
    } catch (IllegalStateException e) {
    /* Good */
    }
    assertTrue(handler1 == graphDb.registerKernelEventHandler(handler1));
    assertTrue(handler1 == graphDb.registerKernelEventHandler(handler1));
    assertTrue(handler1 == graphDb.unregisterKernelEventHandler(handler1));
    try {
        graphDb.unregisterKernelEventHandler(handler1);
        fail("Shouldn't be able to do unregister on a " + "unregistered handler");
    } catch (IllegalStateException e) {
    /* Good */
    }
    assertTrue(handler1 == graphDb.registerKernelEventHandler(handler1));
    assertTrue(handler2 == graphDb.registerKernelEventHandler(handler2));
    assertTrue(handler1 == graphDb.unregisterKernelEventHandler(handler1));
    assertTrue(handler2 == graphDb.unregisterKernelEventHandler(handler2));
    graphDb.shutdown();
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) KernelEventHandler(org.neo4j.graphdb.event.KernelEventHandler) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Test(org.junit.Test)

Aggregations

KernelEventHandler (org.neo4j.graphdb.event.KernelEventHandler)11 Test (org.junit.Test)8 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)4 ErrorState (org.neo4j.graphdb.event.ErrorState)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 EmbeddedGraphDatabase (org.neo4j.kernel.EmbeddedGraphDatabase)2 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)2