use of com.tinkerpop.blueprints.impls.orient.OrientVertex 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.OrientVertex 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();
}
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientVertex in project orientdb by orientechnologies.
the class OrientDbCreationHelper method createWriterAndPosts.
public static void createWriterAndPosts(OrientBaseGraph db, int totAuthors, int totArticles) throws IOException {
int articleSerial = 0;
for (int a = 1; a <= totAuthors; ++a) {
OrientVertex writer = db.addVertex("class:Writer");
writer.setProperty("uuid", a);
writer.setProperty("name", "happy writer");
writer.setProperty("is_active", Boolean.TRUE);
writer.setProperty("isActive", Boolean.TRUE);
for (int i = 1; i <= totArticles; ++i) {
OrientVertex post = db.addVertex("class:Post");
Calendar instance = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
Date time = instance.getTime();
post.setProperty("date", time, OType.DATE);
post.setProperty("uuid", articleSerial++);
post.setProperty("title", "the title");
post.setProperty("content", "the content");
db.addEdge("class:Writes", writer, post, null);
}
}
//additional wrong data
OrientVertex writer = db.addVertex("class:Writer");
writer.setProperty("uuid", totAuthors * 2);
writer.setProperty("name", "happy writer");
writer.setProperty("is_active", Boolean.TRUE);
writer.setProperty("isActive", Boolean.TRUE);
OrientVertex post = db.addVertex("class:Post");
//no date!!
post.setProperty("uuid", articleSerial * 2);
post.setProperty("title", "the title");
post.setProperty("content", "the content");
db.addEdge("class:Writes", writer, post, null);
}
use of com.tinkerpop.blueprints.impls.orient.OrientVertex in project orientdb by orientechnologies.
the class DbListenerTest method testEmbeddedDbListenersGraph.
@Test
public void testEmbeddedDbListenersGraph() throws IOException {
if (database.getURL().startsWith("remote:"))
return;
if (database.exists())
ODatabaseHelper.deleteDatabase(database, getStorageType());
ODatabaseHelper.createDatabase(database, url, getStorageType());
database.open("admin", "admin");
OrientGraph g = new OrientGraph(database);
OrientVertex v = g.addVertex(null);
v.setProperty("name", "Jay");
g.commit();
final DocumentChangeListener cl = new DocumentChangeListener(g);
v.setProperty("surname", "Miner");
g.shutdown();
Assert.assertEquals(cl.getChanges().size(), 1);
ODatabaseHelper.deleteDatabase(database, getStorageType());
ODatabaseHelper.createDatabase(database, url, getStorageType());
}
use of com.tinkerpop.blueprints.impls.orient.OrientVertex in project orientdb by orientechnologies.
the class GraphDatabaseTest method testDeleteOfVerticesAndEdgesWithDeleteCommandAndUnsafe.
public void testDeleteOfVerticesAndEdgesWithDeleteCommandAndUnsafe() {
Iterable<OIdentifiable> deletedVertices = database.command(new OCommandSQL("delete from GraphVehicle return before limit 1 unsafe")).execute();
Assert.assertTrue(deletedVertices.iterator().hasNext());
OrientVertex v = (OrientVertex) deletedVertices.iterator().next();
Integer confirmDeleted = database.command(new OCommandSQL("delete from " + v.getIdentity() + " unsafe")).execute();
Assert.assertFalse(deletedVertices.iterator().hasNext());
Assert.assertEquals(confirmDeleted.intValue(), 0);
Iterable<Edge> edges = v.getEdges(Direction.BOTH);
for (Edge e : edges) {
Integer deletedEdges = database.command(new OCommandSQL("delete from " + ((OrientEdge) e).getIdentity() + " unsafe")).execute();
Assert.assertEquals(deletedEdges.intValue(), 1);
}
}
Aggregations