@Override public void clear(Graph g, final Configuration configuration) throws Exception { if (null != g) { while (g instanceof WrappedGraph) g = ((WrappedGraph<? extends Graph>) g).getBaseGraph(); TitanGraph graph = (TitanGraph) g; if (graph.isOpen()) { if (g.tx().isOpen()) g.tx().rollback(); g.close(); } } WriteConfiguration config = new CommonsConfiguration(configuration); BasicConfiguration readConfig = new BasicConfiguration(GraphDatabaseConfiguration.ROOT_NS, config, BasicConfiguration.Restriction.NONE); if (readConfig.has(GraphDatabaseConfiguration.STORAGE_BACKEND)) { TitanGraphBaseTest.clearGraph(config); } }
@Override public void clear(Graph g, final Configuration configuration) throws Exception { if (null != g) { while (g instanceof WrappedGraph) g = ((WrappedGraph<? extends Graph>) g).getBaseGraph(); JanusGraph graph = (JanusGraph) g; if (graph.isOpen()) { if (g.tx().isOpen()) g.tx().rollback(); try { g.close(); } catch (IOException | IllegalStateException e) { logger.warn("Titan graph may not have closed cleanly", e); } } } WriteConfiguration config = new CommonsConfiguration(configuration); BasicConfiguration readConfig = new BasicConfiguration(GraphDatabaseConfiguration.ROOT_NS, config, BasicConfiguration.Restriction.NONE); if (readConfig.has(GraphDatabaseConfiguration.STORAGE_BACKEND)) { JanusGraphBaseTest.clearGraph(config); } }
/** * Proxies calls through to the underlying {@link Graph#tx()}. */ public Transaction tx() { return this.graph.tx(); }
@Override public void run() { try { latchCommitInOtherThread.await(); } catch (InterruptedException ie) { throw new RuntimeException(ie); } // try to commit the other transaction graph.tx().commit(); latchCommittedInOtherThread.countDown(); } };
@Override public Transaction tx() { return this.starVertex.graph().tx(); }
/** * Utility method that commits if the graph supports transactions and executes an assertion function before and * after the commit. It assumes that the assertion should be true before and after the commit. */ public void tryCommit(final Graph graph, final Consumer<Graph> assertFunction) { assertFunction.accept(graph); if (graph.features().graph().supportsTransactions()) { graph.tx().commit(); assertFunction.accept(graph); } }
@Test @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_TRANSACTIONS) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_THREADED_TRANSACTIONS) public void shouldOpenTxWhenThreadedTransactionIsCreated() throws Exception { // threaded transactions should be immediately open on creation final Graph threadedG = g.tx().createThreadedTx(); assertThat(threadedG.tx().isOpen(), is(true)); threadedG.tx().rollback(); assertThat(threadedG.tx().isOpen(), is(false)); }
/** * Utility method that commits if the graph supports transactions. */ public void tryCommit(final Graph graph) { if (graph.features().graph().supportsTransactions()) graph.tx().commit(); }
/** * Utility method that rollsback if the graph supports transactions. */ public void tryRollback(final Graph graph) { if (graph.features().graph().supportsTransactions()) graph.tx().rollback(); }
@Override public void execute(final Vertex sourceVertex, final Messenger<Tuple> messenger, final Memory memory) { try { executeInternal(sourceVertex, messenger, memory); } catch (Exception e) { if (graph.features().graph().supportsTransactions()) { graph.tx().rollback(); } throw e; } }
@Test @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = FEATURE_TRANSACTIONS) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = FEATURE_THREADED_TRANSACTIONS, supported = false) public void shouldThrowOnThreadedTransactionNotSupported() { try { graph.tx().createThreadedTx(); fail("An exception should be thrown since the threaded transaction feature is not supported"); } catch (Exception e) { validateException(Transaction.Exceptions.threadedTransactionsNotSupported(), e); } } }
final Vertex john = g.addV().property("name", "John").property("age", 3).property("length", 110).next(); final Vertex mike = g.addV().property("name", "Mike").property("age", 4).property("length", 130).next(); aGraph.tx().commit();