use of com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx in project orientdb by orientechnologies.
the class ServerClusterAsyncGraphTest method executeTest.
@Override
protected void executeTest() throws Exception {
{
OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server0/databases/" + getDatabaseName());
OrientGraphNoTx g = factory.getNoTx();
try {
g.createVertexType("Post");
g.createVertexType("User");
g.createEdgeType("Own");
g.addVertex("class:User");
g.command(new OCommandSQL("insert into Post (content, timestamp) values('test', 1)")).execute();
} finally {
g.shutdown();
}
}
// CHECK VERTEX CREATION ON ALL THE SERVERS
for (int s = 0; s < SERVERS; ++s) {
OrientGraphFactory factory2 = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
OrientGraphNoTx g2 = factory2.getNoTx();
try {
Iterable<OrientVertex> result = g2.command(new OCommandSQL("select from Post")).execute();
Assert.assertTrue(result.iterator().hasNext());
Assert.assertNotNull(result.iterator().next());
} finally {
g2.shutdown();
}
}
{
OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server0/databases/" + getDatabaseName());
OrientGraphNoTx g = factory.getNoTx();
try {
g.command(new OCommandSQL("create edge Own from (select from User) to (select from Post)").onAsyncReplicationError(new OAsyncReplicationError() {
@Override
public ACTION onAsyncReplicationError(Throwable iException, int iRetry) {
return iException instanceof ONeedRetryException && iRetry <= 3 ? ACTION.RETRY : ACTION.IGNORE;
}
})).execute();
} finally {
g.shutdown();
}
}
Thread.sleep(1000);
// CHECK VERTEX CREATION ON ALL THE SERVERS
for (int s = 0; s < SERVERS; ++s) {
OrientGraphFactory factory2 = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
OrientGraphNoTx g2 = factory2.getNoTx();
try {
Iterable<OrientVertex> result = g2.command(new OCommandSQL("select from Own")).execute();
Assert.assertTrue(result.iterator().hasNext());
Assert.assertNotNull(result.iterator().next());
result = g2.command(new OCommandSQL("select from Post")).execute();
Assert.assertTrue(result.iterator().hasNext());
final OrientVertex v = result.iterator().next();
Assert.assertNotNull(v);
final Iterable<Edge> inEdges = v.getEdges(Direction.IN);
Assert.assertTrue(inEdges.iterator().hasNext());
Assert.assertNotNull(inEdges.iterator().next());
result = g2.command(new OCommandSQL("select from User")).execute();
Assert.assertTrue(result.iterator().hasNext());
final OrientVertex v2 = result.iterator().next();
Assert.assertNotNull(v2);
final Iterable<Edge> outEdges = v2.getEdges(Direction.OUT);
Assert.assertTrue(outEdges.iterator().hasNext());
Assert.assertNotNull(outEdges.iterator().next());
} finally {
g2.shutdown();
}
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx in project orientdb by orientechnologies.
the class TestAsyncReplMode2ServersOverflow method exec.
protected void exec(final String iClient) {
counter.countDown();
try {
counter.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
OrientBaseGraph graph = new OrientGraphNoTx(getLocalURL());
try {
int i = 0;
for (; i < TOTAL; ++i) {
final OrientVertex v = graph.addVertex(null);
Assert.assertTrue(v.getIdentity().isPersistent());
}
} catch (Throwable e) {
if (exceptionInThread == null)
exceptionInThread = e;
} finally {
System.out.println("Shutting down");
graph.shutdown();
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx in project orientdb by orientechnologies.
the class OrientDbCreationHelper method createSchemaDB.
public static void createSchemaDB(ODatabaseDocumentTx db) {
OSchema schema = db.getMetadata().getSchema();
// item
OClass item = schema.createClass("Item");
item.createProperty("stringKey", OType.STRING).createIndex(INDEX_TYPE.UNIQUE);
item.createProperty("intKey", OType.INTEGER).createIndex(INDEX_TYPE.UNIQUE);
item.createProperty("date", OType.DATE).createIndex(INDEX_TYPE.NOTUNIQUE);
item.createProperty("time", OType.DATETIME).createIndex(INDEX_TYPE.NOTUNIQUE);
item.createProperty("text", OType.STRING);
item.createProperty("score", OType.DECIMAL);
item.createProperty("length", OType.LONG).createIndex(INDEX_TYPE.NOTUNIQUE);
item.createProperty("published", OType.BOOLEAN).createIndex(INDEX_TYPE.NOTUNIQUE);
item.createProperty("title", OType.STRING).createIndex(INDEX_TYPE.NOTUNIQUE);
item.createProperty("author", OType.STRING).createIndex(INDEX_TYPE.NOTUNIQUE);
item.createProperty("tags", OType.EMBEDDEDLIST);
// class Article
OClass article = schema.createClass("Article");
article.createProperty("uuid", OType.INTEGER).createIndex(INDEX_TYPE.UNIQUE);
article.createProperty("date", OType.DATE).createIndex(INDEX_TYPE.NOTUNIQUE);
article.createProperty("title", OType.STRING);
article.createProperty("content", OType.STRING);
// article.createProperty("attachment", OType.LINK);
// author
OClass author = schema.createClass("Author");
author.createProperty("uuid", OType.LONG).createIndex(INDEX_TYPE.UNIQUE);
author.createProperty("name", OType.STRING).setMin("3");
author.createProperty("rating", OType.DOUBLE);
author.createProperty("articles", OType.LINKLIST, article);
// link article-->author
article.createProperty("author", OType.LINK, author);
// Graph
OrientGraphNoTx graph = new OrientGraphNoTx(db);
OrientVertexType post = graph.createVertexType("Post");
post.createProperty("uuid", OType.LONG);
post.createProperty("title", OType.STRING);
post.createProperty("date", OType.DATE).createIndex(INDEX_TYPE.NOTUNIQUE);
post.createProperty("content", OType.STRING);
OrientVertexType writer = graph.createVertexType("Writer");
writer.createProperty("uuid", OType.LONG).createIndex(INDEX_TYPE.UNIQUE);
writer.createProperty("name", OType.STRING);
writer.createProperty("is_active", OType.BOOLEAN);
writer.createProperty("isActive", OType.BOOLEAN);
graph.createEdgeType("Writes");
schema.reload();
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx in project orientdb by orientechnologies.
the class ServerClusterRemoteInsertBalancedTest method testRoundRobinOnConnect.
private void testRoundRobinOnConnect() {
final OrientGraphFactory factory = new OrientGraphFactory("remote:localhost/" + getDatabaseName());
factory.setConnectionStrategy(OStorageRemote.CONNECTION_STRATEGY.ROUND_ROBIN_CONNECT.toString());
OrientGraphNoTx graph = factory.getNoTx();
graph.createVertexType("Client");
graph.shutdown();
Map<Integer, Integer> clusterIds = new HashMap<Integer, Integer>();
for (int i = 0; i < ITERATIONS; ++i) {
graph = factory.getNoTx();
try {
final OrientVertex v = graph.addVertex("class:Client");
Integer value = clusterIds.get(v.getIdentity().getClusterId());
if (value == null)
value = 1;
else
value++;
clusterIds.put(v.getIdentity().getClusterId(), value);
} finally {
graph.shutdown();
}
}
Assert.assertTrue(clusterIds.size() > 1);
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx in project orientdb by orientechnologies.
the class ServerClusterSchemaTest method executeTest.
@Override
protected void executeTest() throws Exception {
for (int s = 0; s < SERVERS; ++s) {
OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
OrientGraphNoTx g = factory.getNoTx();
try {
System.out.println("Creating vertex class Client" + s + " against server " + g + "...");
OrientVertexType t = g.createVertexType("Client" + s);
t.createProperty("name", OType.STRING).setMandatory(true);
System.out.println("Creating vertex class Knows" + s + " against server " + g + "...");
g.createEdgeType("Knows" + s);
} finally {
g.shutdown();
}
}
for (int s = 0; s < SERVERS; ++s) {
System.out.println("Checking vertices classes on server " + s + "...");
OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
OrientGraphNoTx g = factory.getNoTx();
try {
for (int i = 0; i < SERVERS; ++i) {
Assert.assertNotNull(g.getVertexType("Client" + i));
Assert.assertNotNull(g.getEdgeType("Knows" + i));
}
} finally {
g.shutdown();
}
}
for (int s = 0; s < SERVERS; ++s) {
System.out.println("Add vertices on server " + s + "...");
OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
OrientGraphNoTx g = factory.getNoTx();
try {
for (int i = 0; i < SERVERS; ++i) {
try {
final OrientVertex v = g.addVertex("class:" + "Client" + i);
Assert.assertTrue(false);
} catch (OValidationException e) {
// EXPECTED
}
}
} finally {
g.shutdown();
}
}
for (int s = 0; s < SERVERS; ++s) {
System.out.println("Add vertices in TX on server " + s + "...");
OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
OrientGraph g = factory.getTx();
try {
for (int i = 0; i < SERVERS; ++i) {
try {
final OrientVertex v = g.addVertex("class:" + "Client" + i);
g.commit();
Assert.assertTrue(false);
} catch (ONeedRetryException e) {
// EXPECTED
} catch (OValidationException e) {
// EXPECTED
}
}
} finally {
g.shutdown();
}
}
}
Aggregations