Search in sources :

Example 6 with GraknTxJanus

use of ai.grakn.kb.internal.GraknTxJanus in project grakn by graknlabs.

the class TxFactoryJanusTest method testMultithreadedRetrievalOfGraphs.

@Test
public void testMultithreadedRetrievalOfGraphs() {
    Set<Future> futures = new HashSet<>();
    ExecutorService pool = Executors.newFixedThreadPool(10);
    when(session.keyspace()).thenReturn(Keyspace.of("simplekeyspace"));
    TxFactoryJanus factory = new TxFactoryJanus(session);
    for (int i = 0; i < 200; i++) {
        futures.add(pool.submit(() -> {
            GraknTxJanus graph = factory.open(GraknTxType.WRITE);
            assertFalse("Grakn graph is closed", graph.isClosed());
            assertFalse("Internal tinkerpop graph is closed", graph.getTinkerPopGraph().isClosed());
            graph.putEntityType("A Thing");
            try {
                graph.close();
            } catch (InvalidKBException e) {
                e.printStackTrace();
            }
        }));
    }
    boolean exceptionThrown = false;
    for (Future future : futures) {
        try {
            future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
            exceptionThrown = true;
        }
        assertFalse(exceptionThrown);
    }
}
Also used : GraknTxJanus(ai.grakn.kb.internal.GraknTxJanus) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) InvalidKBException(ai.grakn.exception.InvalidKBException) ExecutionException(java.util.concurrent.ExecutionException) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

GraknTxJanus (ai.grakn.kb.internal.GraknTxJanus)6 Test (org.junit.Test)5 InvalidKBException (ai.grakn.exception.InvalidKBException)1 LocalDateTime (java.time.LocalDateTime)1 HashSet (java.util.HashSet)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 JanusGraph (org.janusgraph.core.JanusGraph)1 StandardJanusGraph (org.janusgraph.graphdb.database.StandardJanusGraph)1