Package com.tinkerpop.blueprints

Examples of com.tinkerpop.blueprints.TransactionalGraph


public class FramedTransactionalGraphTest {
  @Test
  public void testTransactions() {

    TransactionalGraph t = Mockito.mock(TransactionalGraph.class);
    FramedTransactionalGraph<TransactionalGraph> g = new FramedTransactionalGraph<TransactionalGraph>(t, new FramedGraphConfiguration());
    g.commit();
    Mockito.verify(t).commit();
    Mockito.reset(t);
   
View Full Code Here


    FramedGraph<Graph> framed = graphFactory.create(base);
    Assert.assertEquals(base, framed.getBaseGraph());
   
    Mockito.verify(mockModule, Mockito.times(1)).configure(Mockito.any(Graph.class), Mockito.any(FramedGraphConfiguration.class));
   
    TransactionalGraph baseTransactional = Mockito.mock(TransactionalGraph.class);
    FramedTransactionalGraph<TransactionalGraph> framedTransactional = graphFactory.create(baseTransactional);
    Assert.assertEquals(baseTransactional, framedTransactional.getBaseGraph());

    Mockito.verify(mockModule, Mockito.times(2)).configure(Mockito.any(TransactionalGraph.class), Mockito.any(FramedGraphConfiguration.class));
  }
View Full Code Here

  @Test(expected=UnsupportedOperationException.class)
  public void testWrappingError() {
    Graph wrapper = Mockito.mock(Graph.class);
    Mockito.when(mockModule.configure(Mockito.any(Graph.class), Mockito.any(FramedGraphConfiguration.class))).thenReturn(wrapper);
    FramedGraphFactory graphFactory = new FramedGraphFactory(mockModule);
    TransactionalGraph baseTransactional = Mockito.mock(TransactionalGraph.class);
    graphFactory.create(baseTransactional);
  }
View Full Code Here

public class AbstractModuleTest {

  @Test
  public void testNoWrapping() {
    Graph baseGraph = Mockito.mock(Graph.class);
    TransactionalGraph baseTransactionalGraph = Mockito.mock(TransactionalGraph.class);
   
    FramedGraphConfiguration config = new FramedGraphConfiguration();
    AbstractModule module = Mockito.mock(AbstractModule.class);
    Mockito.when(module.doConfigure(Mockito.any(Graph.class), Mockito.any(FramedGraphConfiguration.class))).thenCallRealMethod();
   
View Full Code Here

 
 
  @Test
  public void testWrapping() {
    Graph baseGraph = Mockito.mock(Graph.class);
    TransactionalGraph baseTransactionalGraph = Mockito.mock(TransactionalGraph.class);
   
    Graph wrappedGraph = Mockito.mock(Graph.class);
    TransactionalGraph wrappedTransactionalGraph = Mockito.mock(TransactionalGraph.class);
   
    FramedGraphConfiguration config = new FramedGraphConfiguration();
    AbstractModule module = Mockito.mock(AbstractModule.class);
    Mockito.when(module.doConfigure(Mockito.any(Graph.class), Mockito.any(FramedGraphConfiguration.class))).thenReturn(wrappedGraph);
   
View Full Code Here

        printPerformance(graph.toString(), null, "testKeyIndex", this.stopWatch());
        graph.shutdown();
    }

    public void testTx() {
        TransactionalGraph graph = (TransactionalGraph) graphTest.generateGraph();
        ((SparkseeGraph) graph).typeScope.set(true);
        this.stopWatch();

        graph.commit();

        graph.addVertex(null).setProperty("name", "sergio");
        graph.addVertex(null).setProperty("name", "marko");
        assertTrue(graph.getVertices("name", "sergio").iterator().next()
                .getProperty("name").equals("sergio"));
        graph.commit();
        assertTrue(((SparkseeGraph) graph).getRawSession(false) == null);

        assertTrue(graph.getVertices("name", "sergio").iterator().next().getProperty("name").equals("sergio"));
        graph.commit();
        assertTrue(((SparkseeGraph) graph).getRawSession(false) == null);
        graph.commit();
        assertTrue(((SparkseeGraph) graph).getRawSession(false) == null);

        graph.addVertex(null);
        graph.shutdown();
        assertTrue(((SparkseeGraph) graph).getRawSession(false) == null);
        printPerformance(graph.toString(), null, "testTx", this.stopWatch());
        graph.shutdown();
    }
View Full Code Here

            finished = true;
        }
    }

    public void testMultipleSessions() throws InterruptedException, IOException {
        TransactionalGraph graph = (TransactionalGraph) graphTest.generateGraph();
        ((SparkseeGraph) graph).typeScope.set(true);
        this.stopWatch();

        // This test requires a multiple sessions license,
        // so just executed if a license has been given,
        // see SparkseeGraphTest#generateGraph(...) -> blueprints-sparksee.cfg

        com.sparsity.sparksee.gdb.SparkseeConfig cfg = new com.sparsity.sparksee.gdb.SparkseeConfig();
        if (cfg.getLicense() == null || cfg.getLicense().length() == 0) {
            printPerformance(graph.toString(), null, "skip because no license", this.stopWatch());
            graph.shutdown();
            return;
        }

        new GraphMLReader(graph).inputGraph(GraphMLReader.class.getResourceAsStream("graph-example-2.xml"));
        printPerformance(graph.toString(), null, "load", this.stopWatch());

        List<SessionThread> threads = new ArrayList<SessionThread>();
        for (int i = 0; i < 10; i++)
            threads.add(new SessionThread(graph));
        this.stopWatch();
        for (SessionThread th : threads)
            th.start();

        Thread.sleep(5000);

        for (SessionThread th : threads)
            th.stop = true;
        int acum = 0;
        for (SessionThread th : threads) {
            while (!th.finished)
                ;
            acum += th.counter;
        }

        printPerformance(graph.toString(), acum, "tx (sessions)", this.stopWatch());
        graph.shutdown();
    }
View Full Code Here

     * Helper method that will attempt to get a transactional graph instance if the graph can be cast to such.
     *
     * @return the transactional graph or null if it is not transactional
     */
    public TransactionalGraph tryGetTransactionalGraph() {
        TransactionalGraph transactionalGraph = null;
        if (this.graph.getFeatures().supportsTransactions
                && this.graph instanceof TransactionalGraph) {
            transactionalGraph = (TransactionalGraph) graph;
        }

View Full Code Here

     * Determines if the graph is transactional or not.
     *
     * @return true if transactional and false otherwise.
     */
    public boolean isTransactionalGraph() {
        final TransactionalGraph transactionalGraph = tryGetTransactionalGraph();
        return transactionalGraph != null;
    }
View Full Code Here

    /**
     * Stops a transaction with success if the graph is transactional.  If the graph is not transactional,
     * the method does nothing.
     */
    public void tryCommit() {
        final TransactionalGraph transactionalGraph = tryGetTransactionalGraph();
        if (transactionalGraph != null) {
            // will leave this as stopTransaction until we completely remove it from blueprints so as to get as
            // much backward compatibility as we can
            //transactionalGraph.commit();
            transactionalGraph.stopTransaction(TransactionalGraph.Conclusion.SUCCESS);
        }
    }
View Full Code Here

TOP

Related Classes of com.tinkerpop.blueprints.TransactionalGraph

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.