Skip to content

Commit

Permalink
refactor(test): removed usage of legacy query engine in core tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tglman committed Nov 12, 2024
1 parent 3ac67af commit 6b558bd
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -564,15 +564,6 @@ public void testExpandOnEmbedded() {
}
}

@Test
public void testFlattenOnEmbedded() {
List<ODocument> qResult =
db.command(new OCommandSQL("select flatten(address) from foo where name = 'a'")).execute();

assertEquals(qResult.size(), 1);
assertEquals(qResult.get(0).field("city"), "NY");
}

@Test
public void testLimit() {
OResultSet qResult = db.query("select from foo limit 3");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import com.orientechnologies.orient.core.record.OElement;
import com.orientechnologies.orient.core.record.OVertex;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.OCommandSQL;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -1302,30 +1301,6 @@ public void testJson3() {
// assertEquals(0, doc.field("sub[0].uuid"));
}

@Test
public void testUnique() {
StringBuilder query = new StringBuilder();
query.append("match ");
query.append(
"{class:DiamondV, as: one, where: (uid = 0)}.out('DiamondE').out('DiamondE'){as: two} ");
query.append("return one, two");

List<ODocument> result = db.command(new OCommandSQL(query.toString())).execute();
assertEquals(1, result.size());

query = new StringBuilder();
query.append("match ");
query.append(
"{class:DiamondV, as: one, where: (uid = 0)}.out('DiamondE').out('DiamondE'){as: two} ");
query.append("return one.uid, two.uid");

result = db.command(new OCommandSQL(query.toString())).execute();
assertEquals(1, result.size());
// ODocument doc = result.get(0);
// assertEquals("foo", doc.field("name"));
// assertEquals(0, doc.field("sub[0].uuid"));
}

@Test
public void testManagedElements() {
List<OIdentifiable> managedByB = getManagedElements("b");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import static org.assertj.core.api.Assertions.assertThat;

import com.orientechnologies.orient.core.config.OGlobalConfiguration;
import com.orientechnologies.orient.core.db.OrientDB;
import com.orientechnologies.orient.core.db.OrientDBConfig;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.OCommandSQL;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
Expand All @@ -26,19 +25,19 @@ public void before() {

@Test
public void testLockReleaseAfterIncrement() throws InterruptedException {
OrientDB orientDB = new OrientDB("memory:", OrientDBConfig.defaultConfig());
final ORID id;
ODatabaseDocument db = null;
try {

db = new ODatabaseDocumentTx("memory:" + TestQueryRecordLockUnlock.class.getSimpleName());
db.create();
orientDB.execute(
"create database "
+ TestQueryRecordLockUnlock.class.getSimpleName()
+ " memory users(admin identified by 'adminpwd' role admin)");
try (ODatabaseDocument db =
orientDB.open(TestQueryRecordLockUnlock.class.getSimpleName(), "admin", "adminpwd")) {
ODocument doc = new ODocument();
doc.field("count", 0);
doc = db.save(doc, db.getClusterNameById(db.getDefaultClusterId()));
id = doc.getIdentity();
db.commit();
} finally {
if (db != null) db.close();
}
int thread = 10;

Expand All @@ -49,63 +48,47 @@ public void testLockReleaseAfterIncrement() throws InterruptedException {

@Override
public void run() {
ODatabaseDocumentTx db = null;
try {
db =
new ODatabaseDocumentTx(
"memory:" + TestQueryRecordLockUnlock.class.getSimpleName());
db.open("admin", "admin");
try (ODatabaseDocument db =
orientDB.open(
TestQueryRecordLockUnlock.class.getSimpleName(), "admin", "adminpwd")) {
for (int j = 0; j < 10; j++) {
db.getLocalCache().deleteRecord(id);
String asql =
"update "
+ id.toString()
+ " INCREMENT count = 1 where count < 50 lock record";
db.command(new OCommandSQL(asql)).execute(id);
"update " + id.toString() + " set count += 1 where count < 50 lock record";
db.command(asql);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (db != null) {
db.close();
}
}
}
});
}
pool.shutdown();
pool.awaitTermination(1, TimeUnit.HOURS);
try {
db = new ODatabaseDocumentTx("memory:" + TestQueryRecordLockUnlock.class.getSimpleName());
db.open("admin", "admin");
try (ODatabaseDocument db =
orientDB.open(TestQueryRecordLockUnlock.class.getSimpleName(), "admin", "adminpwd")) {
ODocument doc = db.load(id);
// assertEquals(50, doc.field("count"));

assertThat(doc.<Integer>field("count")).isEqualTo(50);

} finally {
if (db != null) {
db.drop();
}
}
orientDB.close();
}

@Test
@Ignore
public void testLockWithSubqueryRecord() throws InterruptedException {
final ORID id;
ODatabaseDocument db = null;
try {

db = new ODatabaseDocumentTx("memory:" + TestQueryRecordLockUnlock.class.getSimpleName());
db.create();
OrientDB orientDB = new OrientDB("memory:", OrientDBConfig.defaultConfig());
orientDB.execute(
"create database "
+ TestQueryRecordLockUnlock.class.getSimpleName()
+ " memory users(admin identified by 'adminpwd' role admin)");
try (ODatabaseDocument db =
orientDB.open(TestQueryRecordLockUnlock.class.getSimpleName(), "admin", "adminpwd")) {
ODocument doc = new ODocument();
doc.field("count", 0);
doc = db.save(doc, db.getClusterNameById(db.getDefaultClusterId()));
id = doc.getIdentity();
db.commit();
} finally {
if (db != null) db.close();
}
int thread = 10;

Expand All @@ -116,61 +99,49 @@ public void testLockWithSubqueryRecord() throws InterruptedException {

@Override
public void run() {
ODatabaseDocument db = null;
try {
db =
new ODatabaseDocumentTx(
"memory:" + TestQueryRecordLockUnlock.class.getSimpleName());
db.open("admin", "admin");
try (ODatabaseDocument db =
orientDB.open(
TestQueryRecordLockUnlock.class.getSimpleName(), "admin", "adminpwd")) {
for (int j = 0; j < 10; j++) {
String asql =
"update (select from "
+ id.toString()
+ ") INCREMENT count = 1 where count < 50 lock record";
db.command(new OCommandSQL(asql)).execute(id);
+ ") set count += 1 where count < 50 lock record";
db.command(asql).close();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (db != null) {
db.close();
}
}
}
});
}
pool.shutdown();
pool.awaitTermination(1, TimeUnit.HOURS);
try {
db = new ODatabaseDocumentTx("memory:" + TestQueryRecordLockUnlock.class.getSimpleName());
db.open("admin", "admin");
try (ODatabaseDocument db =
orientDB.open(TestQueryRecordLockUnlock.class.getSimpleName(), "admin", "adminpwd")) {
ODocument doc = db.load(id);
// assertEquals(50, doc.field("count"));

assertThat(doc.<Integer>field("count")).isEqualTo(50);

} finally {
if (db != null) {
db.drop();
}
}
orientDB.close();
}

@Test
public void testLockReleaseAfterIncrementOpenClose() throws InterruptedException {
final ORID id;
ODatabaseDocument db = null;
try {

db = new ODatabaseDocumentTx("memory:" + TestQueryRecordLockUnlock.class.getSimpleName());
db.create();
OrientDB orientDB = new OrientDB("memory:", OrientDBConfig.defaultConfig());
orientDB.execute(
"create database "
+ TestQueryRecordLockUnlock.class.getSimpleName()
+ " memory users(admin identified by 'adminpwd' role admin)");
try (ODatabaseDocument db =
orientDB.open(TestQueryRecordLockUnlock.class.getSimpleName(), "admin", "adminpwd")) {
ODocument doc = new ODocument();
doc.field("count", 0);
doc = db.save(doc, db.getClusterNameById(db.getDefaultClusterId()));
id = doc.getIdentity();
db.commit();
} finally {
if (db != null) db.close();
}
int thread = 10;

Expand All @@ -181,44 +152,32 @@ public void testLockReleaseAfterIncrementOpenClose() throws InterruptedException

@Override
public void run() {
ODatabaseDocument db = null;
for (int j = 0; j < 10; j++) {
try {
db =
new ODatabaseDocumentTx(
"memory:" + TestQueryRecordLockUnlock.class.getSimpleName());
db.open("admin", "admin");
try (ODatabaseDocument db =
orientDB.open(
TestQueryRecordLockUnlock.class.getSimpleName(), "admin", "adminpwd")) {
String asql =
"update "
+ id.toString()
+ " INCREMENT count = 1 where count < 50 lock record";
db.command(new OCommandSQL(asql)).execute(id);
"update " + id.toString() + " set count += 1 where count < 50 lock record";
String ex =
db.command("explain " + asql).getExecutionPlan().get().prettyPrint(0, 0);
System.out.println("start : " + ex);
db.command(asql).close();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (db != null) {
db.close();
}
}
}
}
});
}
pool.shutdown();
pool.awaitTermination(1, TimeUnit.HOURS);
try {
db = new ODatabaseDocumentTx("memory:" + TestQueryRecordLockUnlock.class.getSimpleName());
db.open("admin", "admin");
try (ODatabaseDocument db =
orientDB.open(TestQueryRecordLockUnlock.class.getSimpleName(), "admin", "adminpwd")) {
ODocument doc = db.load(id);
// assertEquals(50, doc.field("count"));

assertThat(doc.<Integer>field("count")).isEqualTo(50);

} finally {
if (db != null) {
db.drop();
}
}
orientDB.close();
}

@After
Expand Down

0 comments on commit 6b558bd

Please sign in to comment.