graph.tx().onReadWrite(Transaction.READ_WRITE_BEHAVIOR.MANUAL); try { latch.await();
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_TRANSACTIONS) public void shouldAllowReferenceOfVertexIdOutsideOfOriginalThreadManual() throws Exception { g.tx().onReadWrite(Transaction.READ_WRITE_BEHAVIOR.MANUAL); g.tx().open(); final Vertex v1 = graph.addVertex("name", "stephen"); final AtomicReference<Object> id = new AtomicReference<>(); final Thread t = new Thread(() -> { g.tx().open(); id.set(v1.id()); }); t.start(); t.join(); assertEquals(v1.id(), id.get()); g.tx().rollback(); }
@Watched @Override public void clear(Graph graph, Configuration config) throws Exception { TestGraph testGraph = (TestGraph) graph; if (testGraph == null || !testGraph.initedBackend()) { return; } String graphName = config.getString(CoreOptions.STORE.name()); if (testGraph.closed()) { if (this.graphs.get(graphName) == testGraph) { this.graphs.remove(graphName); } return; } // Reset consumers graph.tx().onReadWrite(Transaction.READ_WRITE_BEHAVIOR.AUTO); graph.tx().onClose(Transaction.CLOSE_BEHAVIOR.ROLLBACK); // Ensure tx clean graph.tx().rollback(); // Clear all data Class<?> testClass = (Class<?>) config.getProperty(TEST_CLASS); testGraph.clearAll(testClass.getCanonicalName()); LOG.debug("Clear graph '{}'", graphName); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_TRANSACTIONS) public void shouldAllowReferenceOfEdgeIdOutsideOfOriginalThreadManual() throws Exception { g.tx().onReadWrite(Transaction.READ_WRITE_BEHAVIOR.MANUAL); g.tx().open(); final Vertex v1 = graph.addVertex(); final Edge e = v1.addEdge("self", v1, "weight", 0.5d); final AtomicReference<Object> id = new AtomicReference<>(); final Thread t = new Thread(() -> { g.tx().open(); id.set(e.id()); }); t.start(); t.join(); assertEquals(e.id(), id.get()); g.tx().rollback(); }
@Test @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = FEATURE_TRANSACTIONS) public void shouldHaveExceptionConsistencyWhenOnReadWriteToNull() { try { g.tx().onReadWrite(null); fail("An exception should be thrown when onClose behavior is set to null"); } catch (Exception ex) { validateException(Transaction.Exceptions.onReadWriteBehaviorCannotBeNull(), ex); } }
@Test @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = FEATURE_TRANSACTIONS) public void shouldHaveExceptionConsistencyWhenUsingManualTransaction() { g.tx().onReadWrite(Transaction.READ_WRITE_BEHAVIOR.MANUAL); try { graph.addVertex(); fail("An exception should be thrown when read/write behavior is manual and no transaction is opened"); } catch (Exception ex) { validateException(Transaction.Exceptions.transactionMustBeOpenToReadWrite(), ex); } }
@Test @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = FEATURE_TRANSACTIONS) public void shouldHaveExceptionConsistencyWhenUsingManualTransactionOnCommit() { g.tx().onReadWrite(Transaction.READ_WRITE_BEHAVIOR.MANUAL); try { g.tx().commit(); fail("An exception should be thrown when read/write behavior is manual and no transaction is opened"); } catch (Exception ex) { validateException(Transaction.Exceptions.transactionMustBeOpenToReadWrite(), ex); } }
@Test @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = FEATURE_TRANSACTIONS) public void shouldHaveExceptionConsistencyWhenUsingManualTransactionOnRollback() { g.tx().onReadWrite(Transaction.READ_WRITE_BEHAVIOR.MANUAL); try { g.tx().rollback(); fail("An exception should be thrown when read/write behavior is manual and no transaction is opened"); } catch (Exception ex) { validateException(Transaction.Exceptions.transactionMustBeOpenToReadWrite(), ex); } }
@Test @LoadGraphWith(MODERN) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = FEATURE_TRANSACTIONS) public void shouldTraverseIfAutoTxEnabledAndOriginalTxIsClosed() { // this should be the default, but manually set in just in case the implementation has other ideas g.tx().onReadWrite(Transaction.READ_WRITE_BEHAVIOR.AUTO); // close down the current transaction final Traversal t = g.V().has("name", "marko"); g.tx().rollback(); // the traversal should still work since there are auto transactions assertEquals(1, IteratorUtils.count(t)); }
@Test @LoadGraphWith(MODERN) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = FEATURE_TRANSACTIONS) public void shouldTraverseIfManualTxEnabledAndOriginalTxIsClosed() { // auto should be the default, so force manual g.tx().onReadWrite(Transaction.READ_WRITE_BEHAVIOR.MANUAL); // close down the current transaction and fire up a fresh one g.tx().open(); final Traversal t = g.V().has("name", "marko"); g.tx().rollback(); // the traversal should still work since there are auto transactions g.tx().open(); assertEquals(1, IteratorUtils.count(t)); g.tx().rollback(); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_TRANSACTIONS) public void shouldAllowReferenceOfVertexOutsideOfOriginalTransactionalContextManual() { g.tx().onReadWrite(Transaction.READ_WRITE_BEHAVIOR.MANUAL); g.tx().open(); final Vertex v1 = graph.addVertex("name", "stephen"); g.tx().commit(); g.tx().open(); assertEquals("stephen", v1.value("name")); g.tx().rollback(); g.tx().open(); assertEquals("stephen", v1.value("name")); g.tx().close(); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_TRANSACTIONS) public void shouldAllowReferenceOfEdgeOutsideOfOriginalTransactionalContextManual() { g.tx().onReadWrite(Transaction.READ_WRITE_BEHAVIOR.MANUAL); g.tx().open(); final Vertex v1 = graph.addVertex(); final Edge e = v1.addEdge("self", v1, "weight", 0.5d); g.tx().commit(); g.tx().open(); assertEquals(0.5d, e.value("weight"), 0.00001d); g.tx().rollback(); g.tx().open(); assertEquals(0.5d, e.value("weight"), 0.00001d); g.tx().close(); }
@Test @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = FEATURE_TRANSACTIONS) public void shouldHaveExceptionConsistencyWhenOnReadWriteToNull() { try { g.tx().onReadWrite(null); fail("An exception should be thrown when onClose behavior is set to null"); } catch (Exception ex) { validateException(Transaction.Exceptions.onReadWriteBehaviorCannotBeNull(), ex); } }
@Test @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = FEATURE_TRANSACTIONS) public void shouldHaveExceptionConsistencyWhenUsingManualTransaction() { g.tx().onReadWrite(Transaction.READ_WRITE_BEHAVIOR.MANUAL); try { graph.addVertex(); fail("An exception should be thrown when read/write behavior is manual and no transaction is opened"); } catch (Exception ex) { validateException(Transaction.Exceptions.transactionMustBeOpenToReadWrite(), ex); } }
@Test @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = FEATURE_TRANSACTIONS) public void shouldHaveExceptionConsistencyWhenUsingManualTransactionOnRollback() { g.tx().onReadWrite(Transaction.READ_WRITE_BEHAVIOR.MANUAL); try { g.tx().rollback(); fail("An exception should be thrown when read/write behavior is manual and no transaction is opened"); } catch (Exception ex) { validateException(Transaction.Exceptions.transactionMustBeOpenToReadWrite(), ex); } }
@Test @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = FEATURE_TRANSACTIONS) public void shouldHaveExceptionConsistencyWhenUsingManualTransactionOnCommit() { g.tx().onReadWrite(Transaction.READ_WRITE_BEHAVIOR.MANUAL); try { g.tx().commit(); fail("An exception should be thrown when read/write behavior is manual and no transaction is opened"); } catch (Exception ex) { validateException(Transaction.Exceptions.transactionMustBeOpenToReadWrite(), ex); } }
@Test @LoadGraphWith(MODERN) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = FEATURE_TRANSACTIONS) public void shouldTraverseIfAutoTxEnabledAndOriginalTxIsClosed() { // this should be the default, but manually set in just in case the implementation has other ideas g.tx().onReadWrite(Transaction.READ_WRITE_BEHAVIOR.AUTO); // close down the current transaction final Traversal t = g.V().has("name", "marko"); g.tx().rollback(); // the traversal should still work since there are auto transactions assertEquals(1, IteratorUtils.count(t)); }
@Test @LoadGraphWith(MODERN) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = FEATURE_TRANSACTIONS) public void shouldTraverseIfManualTxEnabledAndOriginalTxIsClosed() { // auto should be the default, so force manual g.tx().onReadWrite(Transaction.READ_WRITE_BEHAVIOR.MANUAL); // close down the current transaction and fire up a fresh one g.tx().open(); final Traversal t = g.V().has("name", "marko"); g.tx().rollback(); // the traversal should still work since there are auto transactions g.tx().open(); assertEquals(1, IteratorUtils.count(t)); g.tx().rollback(); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_TRANSACTIONS) public void shouldAllowReferenceOfVertexOutsideOfOriginalTransactionalContextManual() { g.tx().onReadWrite(Transaction.READ_WRITE_BEHAVIOR.MANUAL); g.tx().open(); final Vertex v1 = graph.addVertex("name", "stephen"); g.tx().commit(); g.tx().open(); assertEquals("stephen", v1.value("name")); g.tx().rollback(); g.tx().open(); assertEquals("stephen", v1.value("name")); g.tx().close(); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_TRANSACTIONS) public void shouldAllowReferenceOfEdgeOutsideOfOriginalTransactionalContextManual() { g.tx().onReadWrite(Transaction.READ_WRITE_BEHAVIOR.MANUAL); g.tx().open(); final Vertex v1 = graph.addVertex(); final Edge e = v1.addEdge("self", v1, "weight", 0.5d); g.tx().commit(); g.tx().open(); assertEquals(0.5d, e.value("weight"), 0.00001d); g.tx().rollback(); g.tx().open(); assertEquals(0.5d, e.value("weight"), 0.00001d); g.tx().close(); }