protected void exec(final String iClient) {
    counter.countDown();

    try {
      counter.await();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    OrientBaseGraph graph = new OrientGraph(getLocalURL());

    OrientVertex vertex1 = graph.getVertex(vertex1Id);

    try {
      int i = 0;
      for (; i < TOTAL; ++i) {

        for (int retry = 0; retry < 20; ++retry) {
          try {
            OrientVertex vertex2 = graph.addVertex("vertextype", (String) null);
            vertex1.addEdge("edgetype", vertex2);
            graph.commit();

            System.out.println(
                iClient + " - successfully committed version: " + vertex1.getRecord().getVersion());
          } catch (ONeedRetryException e) {
            System.out.println(
                iClient
                    + " - caught conflict, reloading vertex. v="
                    + vertex1.getRecord().getVersion());
            vertex1.reload();
          }
        }
      }

      // STATISTICALLY HERE AT LEAST ON CONFLICT HAS BEEN RECEIVED
      vertex1.reload();

      Assert.assertTrue(vertex1.getRecord().getVersion() > TOTAL * 2 + 1);
      Assert.assertEquals(TOTAL, i);

    } catch (Throwable e) {
      if (exceptionInThread == null) exceptionInThread = e;

    } finally {
      System.out.println("Shutting down");
      graph.shutdown();

      sleep(1000);
    }
  }
Exemplo n.º 2
0
 public ODocument createLink(String sourceId, String destId, String edgeName)
     throws DocumentNotFoundException {
   DbHelper.requestTransaction();
   OrientEdge edge = null;
   try {
     OrientVertex sourceVertex = StorageUtils.getNodeVertex(sourceId);
     OrientVertex destVertex = StorageUtils.getNodeVertex(destId);
     UUID token = UUID.randomUUID();
     edge = (OrientEdge) sourceVertex.addEdge(edgeName, destVertex);
     edge.getRecord().field(BaasBoxPrivateFields.ID.toString(), token.toString());
     edge.getRecord().field(BaasBoxPrivateFields.AUTHOR.toString(), DbHelper.currentUsername());
     edge.getRecord().field(BaasBoxPrivateFields.CREATION_DATE.toString(), new Date());
     edge.save();
     DbHelper.commitTransaction();
   } catch (DocumentNotFoundException e) {
     DbHelper.rollbackTransaction();
     throw e;
   }
   // edge.getGraph().commit();
   return edge.getRecord();
 }