use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.
the class TestGraphTransactionOnBatch method testReferToNotExistingVertex.
/**
* This test is different from the original reported, because in case of empty query result the 'create edge ' command just don't
* create edges without failing
*
*/
@Test
public void testReferToNotExistingVertex() {
try {
db.command(new OCommandScript("sql", "begin \n \n LET t2 = create vertex V set Mid = \"2\" \n" + "LET t5 = select from V where Mid = '123456789' \n LET t3 = create edge E from $t5 to $t2 \n" + "\n commit \n return [$t3] ")).execute();
Assert.fail();
} catch (OCommandExecutionException e) {
}
List<ODocument> res = db.query(new OSQLSynchQuery("select from E"));
Assert.assertEquals(res.size(), 0);
}
use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.
the class TestGraphTransactionOnBatch method testDuplicateEdgeRollback.
@Test
public void testDuplicateEdgeRollback() {
OClass clazz = db.getMetadata().getSchema().createClass("Test");
clazz.setSuperClass(E);
clazz.createProperty("aKey", OType.STRING).createIndex(INDEX_TYPE.UNIQUE);
try {
db.command(new OCommandScript("sql", "BEGIN \n LET a = create vertex V \n LET b = create vertex V \n LET c =create edge Test from $a to $b SET aKey = \"12345\" \n LET d =create edge Test from $a to $b SET aKey = \"12345\" \n COMMIT \n" + " RETURN $c")).execute();
Assert.fail("expected record duplicate exception");
} catch (ORecordDuplicatedException ex) {
}
List<ODocument> res = db.query(new OSQLSynchQuery("select from Test"));
Assert.assertEquals(0, res.size());
}
use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.
the class OConsoleDatabaseAppTest method testWrongCommand.
@Test
public void testWrongCommand() {
String dbUrl = "memory:OConsoleDatabaseAppTest2";
StringBuilder builder = new StringBuilder();
builder.append("create database " + dbUrl + ";\n");
builder.append("create class foo;\n");
builder.append("insert into foo set name = 'foo';\n");
builder.append("insert into foo set name = 'bla';\n");
// <- wrong command, this should break the console
builder.append("blabla;\n");
builder.append("update foo set surname = 'bar' where name = 'foo';\n");
ConsoleTest c = new ConsoleTest(new String[] { builder.toString() });
OConsoleDatabaseApp console = c.console();
try {
console.run();
ODatabaseDocumentTx db = new ODatabaseDocumentTx(dbUrl);
db.open("admin", "admin");
try {
List<ODocument> result = db.query(new OSQLSynchQuery<ODocument>("select from foo where name = 'foo'"));
Assert.assertEquals(1, result.size());
ODocument doc = result.get(0);
Assert.assertNull(doc.field("surname"));
} finally {
db.close();
}
} finally {
console.close();
}
}
use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.
the class OConsoleDatabaseAppTest method testSimple.
@Test
public void testSimple() {
String dbUrl = "memory:OConsoleDatabaseAppTest";
StringBuilder builder = new StringBuilder();
builder.append("create database " + dbUrl + ";\n");
builder.append("profile storage on;\n");
builder.append("create class foo;\n");
builder.append("config;\n");
builder.append("list classes;\n");
builder.append("list properties;\n");
builder.append("list clusters;\n");
builder.append("list indexes;\n");
builder.append("info class OUser;\n");
builder.append("info property OUser.name;\n");
builder.append("begin;\n");
builder.append("insert into foo set name = 'foo';\n");
builder.append("insert into foo set name = 'bla';\n");
builder.append("update foo set surname = 'bar' where name = 'foo';\n");
builder.append("commit;\n");
builder.append("select from foo;\n");
builder.append("create class bar;\n");
builder.append("create property bar.name STRING;\n");
builder.append("create index bar_name on bar (name) NOTUNIQUE;\n");
builder.append("insert into bar set name = 'foo';\n");
builder.append("delete from bar;\n");
builder.append("begin;\n");
builder.append("insert into bar set name = 'foo';\n");
builder.append("rollback;\n");
builder.append("create vertex V set name = 'foo';\n");
builder.append("create vertex V set name = 'bar';\n");
builder.append("traverse out() from V;\n");
builder.append("create edge from (select from V where name = 'foo') to (select from V where name = 'bar');\n");
builder.append("traverse out() from V;\n");
// builder.append("create user TestUser identified by password ROLE ['reader','writer'];\n");
builder.append("drop user TestUser;\n");
builder.append("profile storage off;\n");
builder.append("repair database -v;\n");
ConsoleTest c = new ConsoleTest(new String[] { builder.toString() });
OConsoleDatabaseApp console = c.console();
try {
console.run();
ODatabaseDocumentTx db = new ODatabaseDocumentTx(dbUrl);
db.open("admin", "admin");
try {
List<ODocument> result = db.query(new OSQLSynchQuery<ODocument>("select from foo where name = 'foo'"));
Assert.assertEquals(1, result.size());
ODocument doc = result.get(0);
Assert.assertEquals("bar", doc.field("surname"));
result = db.query(new OSQLSynchQuery<ODocument>("select from bar"));
Assert.assertEquals(0, result.size());
} finally {
db.close();
}
OrientGraph graph = new OrientGraph(dbUrl);
try {
Iterable<Vertex> result = graph.command(new OSQLSynchQuery<Vertex>("select expand(out()) from (select from V where name = 'foo')")).execute();
Iterator<Vertex> iterator = result.iterator();
Assert.assertTrue(iterator.hasNext());
Vertex next = iterator.next();
Assert.assertEquals("bar", next.getProperty("name"));
Assert.assertFalse(iterator.hasNext());
} finally {
graph.shutdown();
}
} finally {
console.close();
}
}
use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.
the class OGremlinConsoleTest method testGraphMLImportWithSmallBatch.
@Test
public void testGraphMLImportWithSmallBatch() {
final String INPUT_FILE = "src/test/resources/graph-example-2.xml";
String dbUrl = "memory:testGraphMLImportWithSmallBatch";
StringBuilder builder = new StringBuilder();
builder.append("create database " + dbUrl + ";\n");
builder.append("import database " + INPUT_FILE + " batchSize=10;\n");
OConsoleDatabaseApp console = new TestOGremlinConsole(new String[] { builder.toString() });
try {
console.run();
ODatabaseDocumentTx db = new ODatabaseDocumentTx(dbUrl);
db.open("admin", "admin");
try {
List<ODocument> result = db.query(new OSQLSynchQuery<ODocument>("select from V"));
Assert.assertFalse(result.isEmpty());
} finally {
db.close();
}
} finally {
console.close();
}
}
Aggregations