public void clopen(Object... settings) {
   config = getConfiguration();
   if (mgmt != null && mgmt.isOpen()) mgmt.rollback();
   if (null != tx && tx.isOpen()) tx.commit();
   if (settings != null && settings.length > 0) {
     Map<TestConfigOption, Object> options = validateConfigOptions(settings);
     TitanManagement gconf = null;
     ModifiableConfiguration lconf =
         new ModifiableConfiguration(
             GraphDatabaseConfiguration.ROOT_NS, config, BasicConfiguration.Restriction.LOCAL);
     for (Map.Entry<TestConfigOption, Object> option : options.entrySet()) {
       if (option.getKey().option.isLocal()) {
         lconf.set(option.getKey().option, option.getValue(), option.getKey().umbrella);
       } else {
         if (gconf == null) gconf = graph.openManagement();
         gconf.set(
             ConfigElement.getPath(option.getKey().option, option.getKey().umbrella),
             option.getValue());
       }
     }
     if (gconf != null) gconf.commit();
     lconf.close();
   }
   if (null != graph && graph.isOpen()) graph.close();
   Preconditions.checkNotNull(config);
   open(config);
 }
 @Test
 public void testMemoryLeakage() {
   long memoryBaseline = 0;
   SummaryStatistics stats = new SummaryStatistics();
   int numRuns = 25;
   for (int r = 0; r < numRuns; r++) {
     if (r == 1 || r == (numRuns - 1)) {
       memoryBaseline = MemoryAssess.getMemoryUse();
       stats.addValue(memoryBaseline);
       // System.out.println("Memory before run "+(r+1)+": " + memoryBaseline / 1024 + " KB");
     }
     for (int t = 0; t < 1000; t++) {
       graph.addVertex(null);
       graph.rollback();
       TitanTransaction tx = graph.newTransaction();
       tx.addVertex();
       tx.rollback();
     }
     if (r == 1 || r == (numRuns - 1)) {
       memoryBaseline = MemoryAssess.getMemoryUse();
       stats.addValue(memoryBaseline);
       // System.out.println("Memory after run " + (r + 1) + ": " + memoryBaseline / 1024 + " KB");
     }
     clopen();
   }
   System.out.println(
       "Average: " + stats.getMean() + " Std. Dev: " + stats.getStandardDeviation());
   assertTrue(stats.getStandardDeviation() < stats.getMin());
 }
  @Test
  public void testSingleTxDeepTraversals() throws Exception {
    // 1) Write random graph (copied from above)
    final int numV = 5000;
    final int numE = 50;
    final String label = "knows";
    final Random random = new Random();
    final long[] vids = writeGraph(numV, numE, label);

    final int repetitions = 1000;
    long start = System.currentTimeMillis();

    TitanTransaction tx = graph.buildTransaction().readOnly().start();
    for (int r = 0; r < repetitions; r++) {
      TitanVertex v = tx.getVertex(vids[random.nextInt(numV)]);
      assertTrue(
          (int) Math.pow(numE, 2)
              <= Iterables.size(new GremlinPipeline<Vertex, Vertex>(v).both(label).both(label)));
      assertEquals(
          (int) Math.pow(numE, 2),
          Iterables.size(new GremlinPipeline<Vertex, Vertex>(v).out(label).out(label)));
    }
    tx.commit();

    System.out.println(
        "Time in ms for ["
            + (repetitions)
            + "] traversals in single tx: "
            + (System.currentTimeMillis() - start));
  }
Beispiel #4
0
 @Override
 public synchronized void shutdown() {
   for (TitanTransaction tx : openTx.keySet()) {
     tx.commit();
   }
   openTx.clear();
   txs = null;
 }
Beispiel #5
0
 @Override
 public void stopTransaction(final Conclusion conclusion) {
   TitanTransaction tx = txs.get();
   if (tx != null) {
     assert tx.isOpen();
     tx.stopTransaction(conclusion);
     txs.remove();
     openTx.remove(tx);
   }
 }
 public EdgeLabel makeKeyedEdgeLabel(String name, PropertyKey sort, PropertyKey signature) {
   EdgeLabel relType =
       ((StandardEdgeLabelMaker) tx.makeEdgeLabel(name))
           .sortKey(sort)
           .signature(signature)
           .directed()
           .make();
   return relType;
 }
  public static TitanTransaction getTx(Traversal.Admin<?, ?> traversal) {
    TitanTransaction tx = null;
    Optional<Graph> optGraph = TraversalHelper.getRootTraversal(traversal.asAdmin()).getGraph();

    if (traversal instanceof FulgoraElementTraversal) {
      tx = (TitanTransaction) optGraph.get();
    } else {
      if (!optGraph.isPresent())
        throw new IllegalArgumentException("Traversal is not bound to a graph: " + traversal);
      Graph graph = optGraph.get();
      if (graph instanceof TitanTransaction) tx = (TitanTransaction) graph;
      else if (graph instanceof TitanBlueprintsGraph)
        tx = ((TitanBlueprintsGraph) graph).getCurrentThreadTx();
      else
        throw new IllegalArgumentException(
            "Traversal is not bound to a Titan Graph, but: " + graph);
    }
    if (tx == null)
      throw new IllegalArgumentException(
          "Not a valid start step for a Titan traversal: " + traversal);
    if (tx.isOpen()) return tx;
    else return ((StandardTitanTx) tx).getNextTx();
  }
 public static TitanVertex getVertex(TitanTransaction tx, String key, Object value) {
   return (TitanVertex) getOnlyElement(tx.query().has(key, value).vertices(), null);
 }
 public void newTx() {
   if (null != tx && tx.isOpen()) tx.commit();
   // tx = graph.newThreadBoundTransaction();
   tx = graph.newTransaction();
 }
  public void close() {
    if (mgmt != null && mgmt.isOpen()) mgmt.rollback();
    if (null != tx && tx.isOpen()) tx.commit();

    if (null != graph && graph.isOpen()) graph.close();
  }