Skip to content

Commit 33c7d06

Browse files
committed
refactor(test): removed all usage of legacy query engine, and most usage of legacy sql script from tests
1 parent 9833fc0 commit 33c7d06

File tree

8 files changed

+99
-110
lines changed

8 files changed

+99
-110
lines changed

core/src/test/java/com/orientechnologies/orient/core/sql/executor/OMatchStatementExecutionTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1540,7 +1540,7 @@ public void testBigEntryPoint() {
15401540

15411541
ODocument doc = db.newInstance("testBigEntryPoint2");
15421542
doc.field("b", "b");
1543-
doc.save();
1543+
db.save(doc);
15441544

15451545
List<ODocument> qResult =
15461546
collect(

tests/src/test/java/com/orientechnologies/orient/test/database/auto/ConcurrentCommandAndOpenTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package com.orientechnologies.orient.test.database.auto;
1717

18-
import com.orientechnologies.orient.core.command.script.OCommandScript;
1918
import com.orientechnologies.orient.core.config.OGlobalConfiguration;
2019
import com.orientechnologies.orient.core.db.ODatabaseSession;
2120
import org.testng.Assert;
@@ -44,7 +43,7 @@ public void concurrentCommands() throws Exception {
4443
public void run() {
4544
try (ODatabaseSession db = openSession("admin", "admin")) {
4645
// System.out.println("Start sleeping...");
47-
db.command(new OCommandScript("SQL", "sleep 5000")).execute();
46+
db.execute("SQL", "sleep 5000").close();
4847
// System.out.println("Sleeping done!");
4948
}
5049
}

tests/src/test/java/com/orientechnologies/orient/test/database/auto/JSONTest.java

+33-32
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import com.orientechnologies.orient.core.serialization.serializer.record.string.ORecordSerializerSchemaAware2CSV;
3030
import com.orientechnologies.orient.core.sql.executor.OResult;
3131
import com.orientechnologies.orient.core.sql.executor.OResultSet;
32-
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
3332
import com.orientechnologies.orient.object.db.OObjectDatabaseTx;
3433
import java.util.ArrayList;
3534
import java.util.Collection;
@@ -458,21 +457,21 @@ public void testToJSONWithNoLazyLoadAndClosedDatabase() {
458457
.collect(Collectors.toList());
459458

460459
for (ODocument doc : result) {
461-
doc.reload("*:0");
460+
database.reload(doc, "*:0", true);
462461
String jsonFull = doc.toJSON();
463462
ORID rid = doc.getIdentity();
464463
database.close();
465464
reopendb("admin", "admin");
466465
doc = database.load(rid);
467466
doc.setLazyLoad(false);
468-
doc.reload("*:0");
467+
database.reload(doc, "*:0", true);
469468
database.close();
470469
String jsonLoaded = doc.toJSON();
471470
Assert.assertEquals(jsonLoaded, jsonFull);
472471
reopendb("admin", "admin");
473472
doc = database.load(rid);
474473
doc.setLazyLoad(false);
475-
doc.load("*:0");
474+
database.load(doc, "*:0");
476475
database.close();
477476
jsonLoaded = doc.toJSON();
478477

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

484483
for (ODocument doc : result) {
485-
doc.reload("*:1");
484+
database.reload(doc, "*:1", true);
486485
String jsonFull = doc.toJSON();
487486
ORID rid = doc.getIdentity();
488487
database.close();
489488
reopendb("admin", "admin");
490489
doc = database.load(rid);
491490
doc.setLazyLoad(false);
492-
doc.reload("*:1");
491+
database.reload(doc, "*:1", true);
493492
database.close();
494493
String jsonLoaded = doc.toJSON();
495494
Assert.assertEquals(jsonFull, jsonLoaded);
496495
reopendb("admin", "admin");
497496
doc = database.load(rid);
498497
doc.setLazyLoad(false);
499-
doc.load("*:1");
498+
database.load(doc, "*:1");
500499
database.close();
501500
jsonLoaded = doc.toJSON();
502501

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

515514
final ODocument loadedDoc = database.load(doc.getIdentity());
516515
Assert.assertEquals(doc, loadedDoc);
@@ -521,7 +520,7 @@ public void testArrayOfArray() {
521520
doc.fromJSON(
522521
"{\"@type\": \"d\",\"@class\": \"Track\",\"type\": \"LineString\",\"coordinates\": [ [ 100,"
523522
+ " 0 ], [ 101, 1 ] ]}");
524-
doc.save();
523+
database.save(doc);
525524
final ODocument loadedDoc = database.load(doc.getIdentity());
526525
Assert.assertTrue(doc.hasSameContentOf(loadedDoc));
527526
}
@@ -531,7 +530,7 @@ public void testLongTypes() {
531530
doc.fromJSON(
532531
"{\"@type\": \"d\",\"@class\": \"Track\",\"type\": \"LineString\",\"coordinates\": [ ["
533532
+ " 32874387347347, 0 ], [ -23736753287327, 1 ] ]}");
534-
doc.save();
533+
database.save(doc);
535534
final ODocument loadedDoc = database.load(doc.getIdentity());
536535
Assert.assertTrue(doc.hasSameContentOf(loadedDoc));
537536
}
@@ -542,7 +541,7 @@ public void testSpecialChars() {
542541
new ODocument()
543542
.fromJSON(
544543
"{Field:{\"Key1\":[\"Value1\",\"Value2\"],\"Key2\":{\"%%dummy%%\":null},\"Key3\":\"Value3\"}}");
545-
doc.save(database.getClusterNameById(database.getDefaultClusterId()));
544+
database.save(doc, database.getClusterNameById(database.getDefaultClusterId()));
546545

547546
final ODocument loadedDoc = database.load(doc.getIdentity());
548547
Assert.assertEquals(doc, loadedDoc);
@@ -983,13 +982,13 @@ public void testEmbeddedRIDBagDeserialisationWhenFieldTypeIsProvided() throws Ex
983982
public void testNestedLinkCreation() {
984983
ODocument jaimeDoc = new ODocument("NestedLinkCreation");
985984
jaimeDoc.field("name", "jaime");
986-
jaimeDoc.save();
985+
database.save(jaimeDoc);
987986

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

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

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

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

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

10511051
Assert.assertTrue(traverse.isEmpty());
@@ -1057,15 +1057,15 @@ public void testNestedLinkCreation() {
10571057
public void testNestedLinkCreationFieldTypes() {
10581058
ODocument jaimeDoc = new ODocument("NestedLinkCreationFieldTypes");
10591059
jaimeDoc.field("name", "jaime");
1060-
jaimeDoc.save();
1060+
database.save(jaimeDoc);
10611061

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

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

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

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

11211121
List<ORID> traverse = traverseMap.remove(o.getIdentity());
1122-
for (OIdentifiable id :
1123-
new OSQLSynchQuery<ODocument>("traverse * from " + o.getIdentity().toString())) {
1124-
Assert.assertTrue(traverse.remove(id.getIdentity()));
1122+
OResultSet results = database.query("traverse * from " + o.getIdentity().toString());
1123+
while (results.hasNext()) {
1124+
OResult result = results.next();
1125+
Assert.assertTrue(traverse.remove(result.getIdentity().get()));
11251126
}
11261127
Assert.assertTrue(traverse.isEmpty());
11271128
}
@@ -1131,11 +1132,11 @@ public void testNestedLinkCreationFieldTypes() {
11311132
public void testInnerDocCreation() {
11321133
ODocument adamDoc = new ODocument("InnerDocCreation");
11331134
adamDoc.fromJSON("{\"name\":\"adam\"}");
1134-
adamDoc.save();
1135+
database.save(adamDoc);
11351136

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

11401141
Map<ORID, ODocument> contentMap = new HashMap<ORID, ODocument>();
11411142
ODocument adam = new ODocument("InnerDocCreation");
@@ -1183,14 +1184,14 @@ public void testInnerDocCreation() {
11831184
public void testInnerDocCreationFieldTypes() {
11841185
ODocument adamDoc = new ODocument("InnerDocCreationFieldTypes");
11851186
adamDoc.fromJSON("{\"name\":\"adam\"}");
1186-
adamDoc.save();
1187+
database.save(adamDoc);
11871188

11881189
ODocument eveDoc = new ODocument("InnerDocCreationFieldTypes");
11891190
eveDoc.fromJSON(
11901191
"{\"@type\":\"d\", \"@fieldTypes\" : \"friends=z\", \"name\":\"eve\",\"friends\":["
11911192
+ adamDoc.getIdentity()
11921193
+ "]}");
1193-
eveDoc.save();
1194+
database.save(eveDoc);
11941195

11951196
Map<ORID, ODocument> contentMap = new HashMap<ORID, ODocument>();
11961197
ODocument adam = new ODocument("InnerDocCreationFieldTypes");
@@ -1249,12 +1250,12 @@ public void testJSONTxDocInsertOnly() {
12491250
database.begin();
12501251
final ODocument eveDoc = new ODocument(classNameDocOne);
12511252
eveDoc.field("name", "eve");
1252-
eveDoc.save();
1253+
database.save(eveDoc);
12531254

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

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

12791280
ODocument adamDoc = new ODocument("JSONTxDocOne");
12801281
adamDoc.field("name", "adam");
1281-
adamDoc.save();
1282+
database.save(adamDoc);
12821283

12831284
database.begin();
12841285
ODocument eveDoc = new ODocument("JSONTxDocOne");
12851286
eveDoc.field("name", "eve");
1286-
eveDoc.save();
1287+
database.save(eveDoc);
12871288

12881289
final ODocument nestedWithTypeD = new ODocument("JSONTxDocTwo");
12891290
nestedWithTypeD.fromJSON(
@@ -1292,7 +1293,7 @@ public void testJSONTxDoc() {
12921293
+ ","
12931294
+ adamDoc.toJSON()
12941295
+ "]}");
1295-
nestedWithTypeD.save();
1296+
database.save(nestedWithTypeD);
12961297

12971298
database.commit();
12981299

tests/src/test/java/com/orientechnologies/orient/test/database/auto/SQLBatchTest.java

+26-31
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
*/
1616
package com.orientechnologies.orient.test.database.auto;
1717

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

3735
/** Issue #4349 (https://github.com/orientechnologies/orientdb/issues/4349) */
3836
public void createEdgeFailIfNoSourceOrTargetVertices() {
39-
try {
40-
executeBatch(
41-
"BEGIN\n"
42-
+ "LET credential = INSERT INTO V SET email = '123', password = '123'\n"
43-
+ "LET order = SELECT FROM V WHERE cannotFindThisAttribute = true\n"
44-
+ "LET edge = CREATE EDGE E FROM $credential TO $order set crazyName = 'yes'\n"
45-
+ "COMMIT\n"
46-
+ "RETURN $credential");
47-
48-
Assert.fail("Tx has been committed while a rollback was expected");
49-
} catch (OCommandExecutionException e) {
50-
51-
OResultSet result = database.query("select from V where email = '123'");
52-
Assert.assertTrue(!result.hasNext());
53-
54-
result = database.query("select from E where crazyName = 'yes'");
55-
Assert.assertTrue(!result.hasNext());
56-
57-
} catch (Exception e) {
58-
Assert.fail("Error but not what was expected");
59-
}
37+
executeBatch(
38+
"BEGIN;"
39+
+ "LET $credential = CREATE VERTEX V SET email = '123', password = '123';"
40+
+ "LET $order = SELECT FROM V WHERE cannotFindThisAttribute = true;"
41+
+ "LET $edge = CREATE EDGE E FROM $credential TO $order set crazyName = 'yes';"
42+
+ "IF ($edge.size() == 0) {"
43+
+ " ROLLBACK;"
44+
+ "} "
45+
+ "IF ($edge.size() > 0) {"
46+
+ " COMMIT;"
47+
+ "} "
48+
+ "RETURN $credential ");
49+
50+
OResultSet result = database.query("select from V where email = '123'");
51+
Assert.assertTrue(!result.hasNext());
52+
53+
result = database.query("select from E where crazyName = 'yes'");
54+
Assert.assertTrue(!result.hasNext());
6055
}
6156

6257
public void testInlineArray() {
@@ -81,10 +76,10 @@ public void testInlineArray() {
8176
+ ";"
8277
+ "CREATE VERTEX "
8378
+ className2
84-
+ " SET foos=[$a,$b,$c];"
85-
+ "COMMIT";
79+
+ " SET foos=[$a[0],$b[0],$c[0]];"
80+
+ "COMMIT;";
8681

87-
database.command(new OCommandScript(script)).execute();
82+
database.execute("sql", script).close();
8883

8984
List<OResult> result = database.query("select from " + className2).stream().toList();
9085
Assert.assertEquals(result.size(), 1);
@@ -115,13 +110,13 @@ public void testInlineArray2() {
115110
+ "LET c = CREATE VERTEX "
116111
+ className1
117112
+ ";"
118-
+ "LET foos = [$a,$b,$c];"
113+
+ "LET foos = [$a[0],$b[0],$c[0]];"
119114
+ "CREATE VERTEX "
120115
+ className2
121116
+ " SET foos= $foos;"
122-
+ "COMMIT";
117+
+ "COMMIT;";
123118

124-
database.command(new OCommandScript(script)).execute();
119+
database.execute("sql", script).close();
125120

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

135-
private Object executeBatch(final String batch) {
136-
return database.command(new OCommandScript("sql", batch)).execute();
130+
private void executeBatch(final String batch) {
131+
database.execute("sql", batch).close();
137132
}
138133
}

0 commit comments

Comments
 (0)