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);
}
}
Aggregations