Skip to content

Commit

Permalink
refactor(test): removed all usage of legacy query engine, and most us…
Browse files Browse the repository at this point in the history
…age of legacy sql script from tests
  • Loading branch information
tglman committed Nov 20, 2024
1 parent 9833fc0 commit 33c7d06
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1540,7 +1540,7 @@ public void testBigEntryPoint() {

ODocument doc = db.newInstance("testBigEntryPoint2");
doc.field("b", "b");
doc.save();
db.save(doc);

List<ODocument> qResult =
collect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.orientechnologies.orient.test.database.auto;

import com.orientechnologies.orient.core.command.script.OCommandScript;
import com.orientechnologies.orient.core.config.OGlobalConfiguration;
import com.orientechnologies.orient.core.db.ODatabaseSession;
import org.testng.Assert;
Expand Down Expand Up @@ -44,7 +43,7 @@ public void concurrentCommands() throws Exception {
public void run() {
try (ODatabaseSession db = openSession("admin", "admin")) {
// System.out.println("Start sleeping...");
db.command(new OCommandScript("SQL", "sleep 5000")).execute();
db.execute("SQL", "sleep 5000").close();
// System.out.println("Sleeping done!");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.orientechnologies.orient.core.serialization.serializer.record.string.ORecordSerializerSchemaAware2CSV;
import com.orientechnologies.orient.core.sql.executor.OResult;
import com.orientechnologies.orient.core.sql.executor.OResultSet;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
import com.orientechnologies.orient.object.db.OObjectDatabaseTx;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -458,21 +457,21 @@ public void testToJSONWithNoLazyLoadAndClosedDatabase() {
.collect(Collectors.toList());

for (ODocument doc : result) {
doc.reload("*:0");
database.reload(doc, "*:0", true);
String jsonFull = doc.toJSON();
ORID rid = doc.getIdentity();
database.close();
reopendb("admin", "admin");
doc = database.load(rid);
doc.setLazyLoad(false);
doc.reload("*:0");
database.reload(doc, "*:0", true);
database.close();
String jsonLoaded = doc.toJSON();
Assert.assertEquals(jsonLoaded, jsonFull);
reopendb("admin", "admin");
doc = database.load(rid);
doc.setLazyLoad(false);
doc.load("*:0");
database.load(doc, "*:0");
database.close();
jsonLoaded = doc.toJSON();

Expand All @@ -482,21 +481,21 @@ public void testToJSONWithNoLazyLoadAndClosedDatabase() {
if (database.isClosed()) reopendb("admin", "admin");

for (ODocument doc : result) {
doc.reload("*:1");
database.reload(doc, "*:1", true);
String jsonFull = doc.toJSON();
ORID rid = doc.getIdentity();
database.close();
reopendb("admin", "admin");
doc = database.load(rid);
doc.setLazyLoad(false);
doc.reload("*:1");
database.reload(doc, "*:1", true);
database.close();
String jsonLoaded = doc.toJSON();
Assert.assertEquals(jsonFull, jsonLoaded);
reopendb("admin", "admin");
doc = database.load(rid);
doc.setLazyLoad(false);
doc.load("*:1");
database.load(doc, "*:1");
database.close();
jsonLoaded = doc.toJSON();

Expand All @@ -510,7 +509,7 @@ public void testSpecialChar() {
new ODocument()
.fromJSON(
"{name:{\"%Field\":[\"value1\",\"value2\"],\"%Field2\":{},\"%Field3\":\"value3\"}}");
doc.save(database.getClusterNameById(database.getDefaultClusterId()));
database.save(doc, database.getClusterNameById(database.getDefaultClusterId()));

final ODocument loadedDoc = database.load(doc.getIdentity());
Assert.assertEquals(doc, loadedDoc);
Expand All @@ -521,7 +520,7 @@ public void testArrayOfArray() {
doc.fromJSON(
"{\"@type\": \"d\",\"@class\": \"Track\",\"type\": \"LineString\",\"coordinates\": [ [ 100,"
+ " 0 ], [ 101, 1 ] ]}");
doc.save();
database.save(doc);
final ODocument loadedDoc = database.load(doc.getIdentity());
Assert.assertTrue(doc.hasSameContentOf(loadedDoc));
}
Expand All @@ -531,7 +530,7 @@ public void testLongTypes() {
doc.fromJSON(
"{\"@type\": \"d\",\"@class\": \"Track\",\"type\": \"LineString\",\"coordinates\": [ ["
+ " 32874387347347, 0 ], [ -23736753287327, 1 ] ]}");
doc.save();
database.save(doc);
final ODocument loadedDoc = database.load(doc.getIdentity());
Assert.assertTrue(doc.hasSameContentOf(loadedDoc));
}
Expand All @@ -542,7 +541,7 @@ public void testSpecialChars() {
new ODocument()
.fromJSON(
"{Field:{\"Key1\":[\"Value1\",\"Value2\"],\"Key2\":{\"%%dummy%%\":null},\"Key3\":\"Value3\"}}");
doc.save(database.getClusterNameById(database.getDefaultClusterId()));
database.save(doc, database.getClusterNameById(database.getDefaultClusterId()));

final ODocument loadedDoc = database.load(doc.getIdentity());
Assert.assertEquals(doc, loadedDoc);
Expand Down Expand Up @@ -983,13 +982,13 @@ public void testEmbeddedRIDBagDeserialisationWhenFieldTypeIsProvided() throws Ex
public void testNestedLinkCreation() {
ODocument jaimeDoc = new ODocument("NestedLinkCreation");
jaimeDoc.field("name", "jaime");
jaimeDoc.save();
database.save(jaimeDoc);

// The link between jaime and cersei is saved properly - the #2263 test case
ODocument cerseiDoc = new ODocument("NestedLinkCreation");
cerseiDoc.fromJSON(
"{\"@type\":\"d\",\"name\":\"cersei\",\"valonqar\":" + jaimeDoc.toJSON() + "}");
cerseiDoc.save();
database.save(cerseiDoc);

// The link between jamie and tyrion is not saved properly
ODocument tyrionDoc = new ODocument("NestedLinkCreation");
Expand All @@ -998,7 +997,7 @@ public void testNestedLinkCreation() {
+ " \"relationship\":\"brother\",\"contact\":"
+ jaimeDoc.toJSON()
+ "}}");
tyrionDoc.save();
database.save(tyrionDoc);

final Map<ORID, ODocument> contentMap = new HashMap<ORID, ODocument>();

Expand Down Expand Up @@ -1043,9 +1042,10 @@ public void testNestedLinkCreation() {
Assert.assertTrue(content.hasSameContentOf(o));

List<ORID> traverse = traverseMap.remove(o.getIdentity());
for (OIdentifiable id :
new OSQLSynchQuery<ODocument>("traverse * from " + o.getIdentity().toString())) {
Assert.assertTrue(traverse.remove(id.getIdentity()));
OResultSet results = database.query("traverse * from " + o.getIdentity().toString());
while (results.hasNext()) {
OResult result = results.next();
Assert.assertTrue(traverse.remove(result.getIdentity().get()));
}

Assert.assertTrue(traverse.isEmpty());
Expand All @@ -1057,15 +1057,15 @@ public void testNestedLinkCreation() {
public void testNestedLinkCreationFieldTypes() {
ODocument jaimeDoc = new ODocument("NestedLinkCreationFieldTypes");
jaimeDoc.field("name", "jaime");
jaimeDoc.save();
database.save(jaimeDoc);

// The link between jaime and cersei is saved properly - the #2263 test case
ODocument cerseiDoc = new ODocument("NestedLinkCreationFieldTypes");
cerseiDoc.fromJSON(
"{\"@type\":\"d\",\"@fieldTypes\":\"valonqar=x\",\"name\":\"cersei\",\"valonqar\":"
+ jaimeDoc.getIdentity()
+ "}");
cerseiDoc.save();
database.save(cerseiDoc);

// The link between jamie and tyrion is not saved properly
ODocument tyrionDoc = new ODocument("NestedLinkCreationFieldTypes");
Expand All @@ -1074,7 +1074,7 @@ public void testNestedLinkCreationFieldTypes() {
+ " \"@fieldTypes\":\"contact=x\",\"relationship\":\"brother\",\"contact\":"
+ jaimeDoc.getIdentity()
+ "}}");
tyrionDoc.save();
database.save(tyrionDoc);

final Map<ORID, ODocument> contentMap = new HashMap<ORID, ODocument>();

Expand Down Expand Up @@ -1119,9 +1119,10 @@ public void testNestedLinkCreationFieldTypes() {
Assert.assertTrue(content.hasSameContentOf(o));

List<ORID> traverse = traverseMap.remove(o.getIdentity());
for (OIdentifiable id :
new OSQLSynchQuery<ODocument>("traverse * from " + o.getIdentity().toString())) {
Assert.assertTrue(traverse.remove(id.getIdentity()));
OResultSet results = database.query("traverse * from " + o.getIdentity().toString());
while (results.hasNext()) {
OResult result = results.next();
Assert.assertTrue(traverse.remove(result.getIdentity().get()));
}
Assert.assertTrue(traverse.isEmpty());
}
Expand All @@ -1131,11 +1132,11 @@ public void testNestedLinkCreationFieldTypes() {
public void testInnerDocCreation() {
ODocument adamDoc = new ODocument("InnerDocCreation");
adamDoc.fromJSON("{\"name\":\"adam\"}");
adamDoc.save();
database.save(adamDoc);

ODocument eveDoc = new ODocument("InnerDocCreation");
eveDoc.fromJSON("{\"@type\":\"d\",\"name\":\"eve\",\"friends\":[" + adamDoc.toJSON() + "]}");
eveDoc.save();
database.save(eveDoc);

Map<ORID, ODocument> contentMap = new HashMap<ORID, ODocument>();
ODocument adam = new ODocument("InnerDocCreation");
Expand Down Expand Up @@ -1183,14 +1184,14 @@ public void testInnerDocCreation() {
public void testInnerDocCreationFieldTypes() {
ODocument adamDoc = new ODocument("InnerDocCreationFieldTypes");
adamDoc.fromJSON("{\"name\":\"adam\"}");
adamDoc.save();
database.save(adamDoc);

ODocument eveDoc = new ODocument("InnerDocCreationFieldTypes");
eveDoc.fromJSON(
"{\"@type\":\"d\", \"@fieldTypes\" : \"friends=z\", \"name\":\"eve\",\"friends\":["
+ adamDoc.getIdentity()
+ "]}");
eveDoc.save();
database.save(eveDoc);

Map<ORID, ODocument> contentMap = new HashMap<ORID, ODocument>();
ODocument adam = new ODocument("InnerDocCreationFieldTypes");
Expand Down Expand Up @@ -1249,12 +1250,12 @@ public void testJSONTxDocInsertOnly() {
database.begin();
final ODocument eveDoc = new ODocument(classNameDocOne);
eveDoc.field("name", "eve");
eveDoc.save();
database.save(eveDoc);

final ODocument nestedWithTypeD = new ODocument(classNameDocTwo);
nestedWithTypeD.fromJSON(
"{\"@type\":\"d\",\"event_name\":\"world cup 2014\",\"admin\":[" + eveDoc.toJSON() + "]}");
nestedWithTypeD.save();
database.save(nestedWithTypeD);
database.commit();
Assert.assertEquals(database.countClass(classNameDocOne), 1);

Expand All @@ -1278,12 +1279,12 @@ public void testJSONTxDoc() {

ODocument adamDoc = new ODocument("JSONTxDocOne");
adamDoc.field("name", "adam");
adamDoc.save();
database.save(adamDoc);

database.begin();
ODocument eveDoc = new ODocument("JSONTxDocOne");
eveDoc.field("name", "eve");
eveDoc.save();
database.save(eveDoc);

final ODocument nestedWithTypeD = new ODocument("JSONTxDocTwo");
nestedWithTypeD.fromJSON(
Expand All @@ -1292,7 +1293,7 @@ public void testJSONTxDoc() {
+ ","
+ adamDoc.toJSON()
+ "]}");
nestedWithTypeD.save();
database.save(nestedWithTypeD);

database.commit();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
*/
package com.orientechnologies.orient.test.database.auto;

import com.orientechnologies.orient.core.command.script.OCommandScript;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.exception.OCommandExecutionException;
import com.orientechnologies.orient.core.sql.executor.OResult;
import com.orientechnologies.orient.core.sql.executor.OResultSet;
import java.util.List;
Expand All @@ -36,27 +34,24 @@ public SQLBatchTest(@Optional String url) {

/** Issue #4349 (https://github.com/orientechnologies/orientdb/issues/4349) */
public void createEdgeFailIfNoSourceOrTargetVertices() {
try {
executeBatch(
"BEGIN\n"
+ "LET credential = INSERT INTO V SET email = '123', password = '123'\n"
+ "LET order = SELECT FROM V WHERE cannotFindThisAttribute = true\n"
+ "LET edge = CREATE EDGE E FROM $credential TO $order set crazyName = 'yes'\n"
+ "COMMIT\n"
+ "RETURN $credential");

Assert.fail("Tx has been committed while a rollback was expected");
} catch (OCommandExecutionException e) {

OResultSet result = database.query("select from V where email = '123'");
Assert.assertTrue(!result.hasNext());

result = database.query("select from E where crazyName = 'yes'");
Assert.assertTrue(!result.hasNext());

} catch (Exception e) {
Assert.fail("Error but not what was expected");
}
executeBatch(
"BEGIN;"
+ "LET $credential = CREATE VERTEX V SET email = '123', password = '123';"
+ "LET $order = SELECT FROM V WHERE cannotFindThisAttribute = true;"
+ "LET $edge = CREATE EDGE E FROM $credential TO $order set crazyName = 'yes';"
+ "IF ($edge.size() == 0) {"
+ " ROLLBACK;"
+ "} "
+ "IF ($edge.size() > 0) {"
+ " COMMIT;"
+ "} "
+ "RETURN $credential ");

OResultSet result = database.query("select from V where email = '123'");
Assert.assertTrue(!result.hasNext());

result = database.query("select from E where crazyName = 'yes'");
Assert.assertTrue(!result.hasNext());
}

public void testInlineArray() {
Expand All @@ -81,10 +76,10 @@ public void testInlineArray() {
+ ";"
+ "CREATE VERTEX "
+ className2
+ " SET foos=[$a,$b,$c];"
+ "COMMIT";
+ " SET foos=[$a[0],$b[0],$c[0]];"
+ "COMMIT;";

database.command(new OCommandScript(script)).execute();
database.execute("sql", script).close();

List<OResult> result = database.query("select from " + className2).stream().toList();
Assert.assertEquals(result.size(), 1);
Expand Down Expand Up @@ -115,13 +110,13 @@ public void testInlineArray2() {
+ "LET c = CREATE VERTEX "
+ className1
+ ";"
+ "LET foos = [$a,$b,$c];"
+ "LET foos = [$a[0],$b[0],$c[0]];"
+ "CREATE VERTEX "
+ className2
+ " SET foos= $foos;"
+ "COMMIT";
+ "COMMIT;";

database.command(new OCommandScript(script)).execute();
database.execute("sql", script).close();

List<OResult> result = database.query("select from " + className2).stream().toList();
Assert.assertEquals(result.size(), 1);
Expand All @@ -132,7 +127,7 @@ public void testInlineArray2() {
Assert.assertTrue(foos.get(2) instanceof OIdentifiable);
}

private Object executeBatch(final String batch) {
return database.command(new OCommandScript("sql", batch)).execute();
private void executeBatch(final String batch) {
database.execute("sql", batch).close();
}
}
Loading

0 comments on commit 33c7d06

Please sign in to comment.