use of com.tinkerpop.blueprints.impls.orient.OrientGraphFactory in project orientdb by orientechnologies.
the class TestShardingManualSync method executeTest.
@Override
protected void executeTest() throws Exception {
final OrientGraphFactory localFactoryEurope = new OrientGraphFactory("plocal:target/server0/databases/" + getDatabaseName());
OrientGraphFactory localFactoryUsa = new OrientGraphFactory("plocal:target/server1/databases/" + getDatabaseName());
final ORID v1Identity;
OrientGraphNoTx graphNoTxEurope = localFactoryEurope.getNoTx();
try {
final OrientVertexType clientType = graphNoTxEurope.createVertexType("Client-Type");
for (int i = 1; i < serverInstance.size(); ++i) {
final String serverName = serverInstance.get(i).getServerInstance().getDistributedManager().getLocalNodeName();
clientType.addCluster("client_" + serverName);
}
final OrientVertex v1 = graphNoTxEurope.addVertex("class:Client-Type");
v1Identity = v1.getIdentity();
log("Created vertex " + v1Identity + "...");
} finally {
graphNoTxEurope.shutdown();
}
OrientGraphNoTx graphNoTxUsa = localFactoryUsa.getNoTx();
try {
Assert.assertEquals(1, graphNoTxUsa.countVertices());
} finally {
graphNoTxUsa.shutdown();
localFactoryUsa.close();
}
final String clusterName;
graphNoTxEurope = localFactoryEurope.getNoTx();
try {
Assert.assertEquals(1, graphNoTxEurope.countVertices());
// CHANGE THE WRITE QUORUM = 1
final OModifiableDistributedConfiguration dCfg = serverInstance.get(0).server.getDistributedManager().getDatabaseConfiguration(getDatabaseName()).modify();
ODocument newCfg = dCfg.getDocument().field("writeQuorum", 1);
serverInstance.get(0).server.getDistributedManager().updateCachedDatabaseConfiguration(getDatabaseName(), dCfg, true);
// CREATE A NEW RECORD ON SERVER 0 BYPASSING REPLICATION
final ODocument v2 = new ODocument("Client");
((ORecordId) v2.getIdentity()).setClusterId(v1Identity.getClusterId());
((ORecordId) v2.getIdentity()).setClusterPosition(v1Identity.getClusterPosition() + 1);
final Object result = createRemoteRecord(0, v2, new String[] { serverInstance.get(0).getServerInstance().getDistributedManager().getLocalNodeName() });
Assert.assertFalse(result instanceof Throwable);
Assert.assertEquals(2, graphNoTxEurope.countVertices());
clusterName = graphNoTxEurope.getRawGraph().getClusterNameById(v2.getIdentity().getClusterId());
Assert.assertEquals(2, graphNoTxEurope.countVertices());
} finally {
graphNoTxEurope.shutdown();
}
// TEST SECOND VERTEX IS MISSING ON USA NODE
localFactoryUsa = new OrientGraphFactory("plocal:target/server1/databases/" + getDatabaseName());
graphNoTxUsa = localFactoryUsa.getNoTx();
try {
Assert.assertEquals(1, graphNoTxUsa.countVertices());
log("Manually syncing cluster client-type of node USA...");
graphNoTxUsa.command(new OCommandSQL("ha sync cluster `" + clusterName + "`")).execute();
Assert.assertEquals(2, graphNoTxUsa.countVertices());
} finally {
graphNoTxUsa.shutdown();
}
localFactoryEurope.close();
localFactoryUsa.close();
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraphFactory in project orientdb by orientechnologies.
the class DbCreationTest method testZipCompression.
public void testZipCompression() {
if (database == null || !database.getURL().startsWith("plocal:"))
return;
OGlobalConfiguration.STORAGE_COMPRESSION_METHOD.setValue("gzip");
final String buildDirectory = System.getProperty("buildDirectory", ".");
String dburl = "plocal:" + buildDirectory + "/test-db/" + this.getClass().getSimpleName();
final OrientGraphFactory factory = new OrientGraphFactory(dburl, "admin", "admin");
if (factory.exists())
factory.drop();
factory.close();
OrientGraphNoTx db = factory.getNoTx();
db.drop();
OGlobalConfiguration.STORAGE_COMPRESSION_METHOD.setValue(OGlobalConfiguration.STORAGE_COMPRESSION_METHOD.getValue());
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraphFactory in project orientdb by orientechnologies.
the class GraphTransactionConsistency method testTransactionConsistency.
public void testTransactionConsistency() throws InterruptedException {
final OrientGraphFactory factory = new OrientGraphFactory("plocal:target/GraphTransactionConsistency", false);
database = txMode ? factory.getTx() : factory.getNoTx();
System.out.println("Checking consistency of database...");
System.out.println("Records found V=" + database.countVertices() + " E=" + database.countEdges());
final Iterable<OrientVertex> vertices = database.command(new OCommandSQL("select from V")).execute();
for (OrientVertex v : vertices) {
final ODocument doc = v.getRecord();
Assert.assertNotNull(doc);
final ORidBag out = doc.field("out_");
if (out != null) {
for (Iterator<OIdentifiable> it = out.rawIterator(); it.hasNext(); ) {
final OIdentifiable edge = it.next();
Assert.assertNotNull(edge);
final ODocument rec = edge.getRecord();
Assert.assertNotNull(rec);
Assert.assertNotNull(rec.field("out"));
Assert.assertEquals(((ODocument) rec.field("out")).getIdentity(), v.getIdentity());
Assert.assertNotNull(rec.field("in"));
}
}
final ORidBag in = doc.field("in_");
if (in != null) {
for (Iterator<OIdentifiable> it = in.rawIterator(); it.hasNext(); ) {
final OIdentifiable edge = it.next();
Assert.assertNotNull(edge);
final ODocument rec = edge.getRecord();
Assert.assertNotNull(rec);
Assert.assertNotNull(rec.field("in"));
Assert.assertEquals(((ODocument) rec.field("in")).getIdentity(), v.getIdentity());
Assert.assertNotNull(rec.field("out"));
}
}
}
System.out.println("Consistency ok.");
final Thread[] threads = new Thread[THREADS];
for (int i = 0; i < THREADS; ++i) {
final int threadNum = i;
threads[i] = new Thread(new Runnable() {
@Override
public void run() {
OrientBaseGraph graph = txMode ? factory.getTx() : factory.getNoTx();
try {
System.out.println("THREAD " + threadNum + " Start transactions (" + TXNUM + ")");
for (int i = 0; i < TXNUM; ++i) {
final OrientVertex v1 = graph.addVertex(null, "v", i, "type", "Main", "lastUpdate", new Date());
for (int e = 0; e < EDGENUM; ++e) {
final OrientVertex v2 = graph.addVertex(null, "v", i, "e", e, "type", "Connected", "lastUpdate", new Date());
v1.addEdge("E", v2);
}
if (i % TXBATCH == 0) {
System.out.println("THREAD " + threadNum + " Committing batch of " + TXBATCH + " (i=" + i + ")");
System.out.flush();
graph.commit();
System.out.println("THREAD " + threadNum + " Commit ok - records found V=" + graph.countVertices() + " E=" + graph.countEdges());
System.out.flush();
}
}
} finally {
graph.shutdown();
}
}
});
Thread.sleep(1000);
threads[i].start();
}
for (int i = 0; i < THREADS; ++i) {
try {
threads[i].join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
database.shutdown();
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraphFactory in project orientdb by orientechnologies.
the class BackupTest method main.
public static void main(String[] args) throws IOException {
File backupFile = new File("testbackup.zip");
OutputStream oS = new FileOutputStream(backupFile);
OrientGraphFactory factory = new OrientGraphFactory("plocal:backupTest", "admin", "admin");
OrientGraphNoTx graphNoTx = factory.getNoTx();
graphNoTx.getRawGraph().backup(oS, null, null, null, 1, 1024);
ZipFile zipFile = new ZipFile(backupFile);
Enumeration enumeration = zipFile.entries();
System.out.format("ZipFile : %s%n", zipFile);
while (enumeration.hasMoreElements()) {
Object entry = enumeration.nextElement();
System.out.format(" Entry : %s%n", entry);
}
factory.close();
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraphFactory in project orientdb by orientechnologies.
the class SuperNodeGraphSpeedTest method init.
@Override
@Test(enabled = false)
public void init() throws Exception {
String buildDirectory = System.getProperty("buildDirectory", ".");
if (buildDirectory == null) {
buildDirectory = ".";
}
final OrientGraphFactory factory = new OrientGraphFactory("plocal:" + buildDirectory + "/SuperNodeGraphSpeedTest", "admin", "admin");
if (factory.exists())
factory.drop();
graph = factory.getNoTx();
superNode = graph.addVertex(null);
factory.close();
}
Aggregations