Skip to content

Commit

Permalink
refactor:use new query engine in some enterprise test
Browse files Browse the repository at this point in the history
  • Loading branch information
tglman committed Sep 28, 2023
1 parent f90b9d9 commit 960d0f9
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
import com.orientechnologies.common.util.OCallable;
import com.orientechnologies.orient.core.Orient;
import com.orientechnologies.orient.core.config.OGlobalConfiguration;
import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal;
import com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.tinkerpop.blueprints.impls.orient.OrientBaseGraph;
Expand Down Expand Up @@ -320,27 +322,27 @@ protected void executeWhen(final Callable<Boolean> condition, final Callable act

protected void executeWhen(
int serverId,
OCallable<Boolean, ODatabaseDocumentTx> condition,
OCallable<Boolean, ODatabaseDocumentTx> action)
OCallable<Boolean, ODatabaseDocument> condition,
OCallable<Boolean, ODatabaseDocument> action)
throws Exception {
final ODatabaseDocumentTx db =
final ODatabaseDocument db =
new ODatabaseDocumentTx(getDatabaseURL(serverInstance.get(serverId)))
.open("admin", "admin");
try {
executeWhen(db, condition, action);
} finally {
if (!db.isClosed()) {
ODatabaseRecordThreadLocal.instance().set(db);
ODatabaseRecordThreadLocal.instance().set((ODatabaseDocumentInternal) db);
db.close();
ODatabaseRecordThreadLocal.instance().set(null);
}
}
}

protected void executeWhen(
final ODatabaseDocumentTx db,
OCallable<Boolean, ODatabaseDocumentTx> condition,
OCallable<Boolean, ODatabaseDocumentTx> action) {
final ODatabaseDocument db,
OCallable<Boolean, ODatabaseDocument> condition,
OCallable<Boolean, ODatabaseDocument> action) {
while (true) {
db.activateOnCurrentThread();
if (condition.call(db)) {
Expand Down Expand Up @@ -407,10 +409,10 @@ protected void waitForDatabaseIsOnline(

protected void waitFor(
final int serverId,
final OCallable<Boolean, ODatabaseDocumentTx> condition,
final OCallable<Boolean, ODatabaseDocument> condition,
final long timeout) {
try {
ODatabaseDocumentTx db =
ODatabaseDocument db =
new ODatabaseDocumentTx(getDatabaseURL(serverInstance.get(serverId)))
.open("admin", "admin");
try {
Expand All @@ -437,7 +439,7 @@ protected void waitFor(

} finally {
if (!db.isClosed()) {
ODatabaseRecordThreadLocal.instance().set(db);
ODatabaseRecordThreadLocal.instance().set((ODatabaseDocumentInternal) db);
db.close();
ODatabaseRecordThreadLocal.instance().set(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import com.orientechnologies.common.util.OCallable;
import com.orientechnologies.orient.core.Orient;
import com.orientechnologies.orient.core.config.OGlobalConfiguration;
import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal;
import com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.tinkerpop.blueprints.impls.orient.OrientBaseGraph;
Expand Down Expand Up @@ -333,27 +335,27 @@ protected void executeWhen(final Callable<Boolean> condition, final Callable act

protected void executeWhen(
int serverId,
OCallable<Boolean, ODatabaseDocumentTx> condition,
OCallable<Boolean, ODatabaseDocumentTx> action)
OCallable<Boolean, ODatabaseDocument> condition,
OCallable<Boolean, ODatabaseDocument> action)
throws Exception {
final ODatabaseDocumentTx db =
final ODatabaseDocument db =
new ODatabaseDocumentTx(getDatabaseURL(serverInstance.get(serverId)))
.open("admin", "admin");
try {
executeWhen(db, condition, action);
} finally {
if (!db.isClosed()) {
ODatabaseRecordThreadLocal.instance().set(db);
ODatabaseRecordThreadLocal.instance().set((ODatabaseDocumentInternal) db);
db.close();
ODatabaseRecordThreadLocal.instance().set(null);
}
}
}

protected void executeWhen(
final ODatabaseDocumentTx db,
OCallable<Boolean, ODatabaseDocumentTx> condition,
OCallable<Boolean, ODatabaseDocumentTx> action) {
final ODatabaseDocument db,
OCallable<Boolean, ODatabaseDocument> condition,
OCallable<Boolean, ODatabaseDocument> action) {
while (true) {
db.activateOnCurrentThread();
if (condition.call(db)) {
Expand Down Expand Up @@ -420,10 +422,10 @@ protected void waitForDatabaseIsOnline(

protected void waitFor(
final int serverId,
final OCallable<Boolean, ODatabaseDocumentTx> condition,
final OCallable<Boolean, ODatabaseDocument> condition,
final long timeout) {
try {
ODatabaseDocumentTx db =
ODatabaseDocument db =
new ODatabaseDocumentTx(getDatabaseURL(serverInstance.get(serverId)))
.open("admin", "admin");
try {
Expand All @@ -450,7 +452,7 @@ protected void waitFor(

} finally {
if (!db.isClosed()) {
ODatabaseRecordThreadLocal.instance().set(db);
ODatabaseRecordThreadLocal.instance().set((ODatabaseDocumentInternal) db);
db.close();
ODatabaseRecordThreadLocal.instance().set(null);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.orientechnologies.orient.server.distributed;

import com.orientechnologies.orient.core.config.OGlobalConfiguration;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.OCommandSQL;
Expand Down Expand Up @@ -66,7 +67,7 @@ protected void executeTest() throws Exception {
Assert.assertTrue(austinDc.contains("usa-1"));
Assert.assertTrue(austinDc.contains("usa-2"));

ODatabaseDocumentTx db = new ODatabaseDocumentTx("remote:localhost:2424/" + getDatabaseName());
ODatabaseDocument db = new ODatabaseDocumentTx("remote:localhost:2424/" + getDatabaseName());
db.open("admin", "admin");
try {
db.command("INSERT into Item (name) values ('foo')").close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.orientechnologies.common.log.OLogManager;
import com.orientechnologies.orient.client.remote.OServerAdmin;
import com.orientechnologies.orient.core.Orient;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.sql.executor.OResult;
import com.orientechnologies.orient.server.OServer;
Expand Down Expand Up @@ -83,7 +84,7 @@ public static void afterClass() {

@Test
public void createDropClassTest() throws IOException {
ODatabaseDocumentTx db = new ODatabaseDocumentTx("remote:localhost/" + TESTDB);
ODatabaseDocument db = new ODatabaseDocumentTx("remote:localhost/" + TESTDB);
db.open("admin", "admin");

server.getSystemDatabase().execute(null, "delete from OAuditingLog where database = ?", TESTDB);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.orientechnologies.orient.client.remote.OServerAdmin;
import com.orientechnologies.orient.core.Orient;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.exception.OSecurityAccessException;
import com.orientechnologies.orient.core.security.symmetrickey.OSymmetricKey;
Expand Down Expand Up @@ -73,7 +74,7 @@ public void shouldTestSpecificAESKeyFailure() throws Exception {
OSymmetricKey sk = new OSymmetricKey("AES", "AAC7LeGkFbmHEYNTz5GwDw==");

// "test" is the username. It's specified in the security.json resource file.
ODatabaseDocumentTx db = new ODatabaseDocumentTx(DATABASE_URL);
ODatabaseDocument db = new ODatabaseDocumentTx(DATABASE_URL);
// We encrypt the username and specify the Base64-encoded JSON document as the password.
db.open("test", sk.encrypt("AES/CBC/PKCS5Padding", "test"));
db.close();
Expand All @@ -85,7 +86,7 @@ public void shouldTestSpecificAESKey() throws Exception {
OSymmetricKey sk = new OSymmetricKey("AES", "8BC7LeGkFbmHEYNTz5GwDw==");

// "test" is the username. It's specified in the security.json resource file.
ODatabaseDocumentTx db = new ODatabaseDocumentTx(DATABASE_URL);
ODatabaseDocument db = new ODatabaseDocumentTx(DATABASE_URL);
// We encrypt the username and specify the Base64-encoded JSON document as the password.
db.open("test", sk.encrypt("AES/CBC/PKCS5Padding", "test"));
db.close();
Expand All @@ -97,7 +98,7 @@ public void shouldTestKeyFile() throws Exception {
OSymmetricKey.fromStream("AES", new FileInputStream(SERVER_DIRECTORY + "/config/AES.key"));

// "test2" is the username. It's specified in the security.json resource file.
ODatabaseDocumentTx db = new ODatabaseDocumentTx(DATABASE_URL);
ODatabaseDocument db = new ODatabaseDocumentTx(DATABASE_URL);
// We encrypt the username and specify the Base64-encoded JSON document as the password.
db.open("test2", sk.encrypt("AES/CBC/PKCS5Padding", "test2"));
db.close();
Expand All @@ -113,7 +114,7 @@ public void shouldTestKeystore() throws Exception {
"password");

// "test3" is the username. It's specified in the security.json resource file.
ODatabaseDocumentTx db = new ODatabaseDocumentTx(DATABASE_URL);
ODatabaseDocument db = new ODatabaseDocumentTx(DATABASE_URL);
// We encrypt the username and specify the Base64-encoded JSON document as the password.
db.open("test3", sk.encrypt("AES/CBC/PKCS5Padding", "test3"));
db.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.orientechnologies.orient.client.remote.OServerAdmin;
import com.orientechnologies.orient.core.Orient;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.security.symmetrickey.OSymmetricKey;
import com.orientechnologies.orient.server.OServer;
Expand Down Expand Up @@ -120,7 +121,7 @@ public void shouldTestSystemUserWithKeyFile() throws Exception {
OSymmetricKey.fromStream("AES", new FileInputStream(SERVER_DIRECTORY + "/config/AES.key"));

// "sysuser" is the username. We just created it in OSystem.
ODatabaseDocumentTx db = new ODatabaseDocumentTx(DATABASE_URL);
ODatabaseDocument db = new ODatabaseDocumentTx(DATABASE_URL);
// We encrypt the username and specify the Base64-encoded JSON document as the password.
db.open(sysuser, sk.encrypt("AES/CBC/PKCS5Padding", sysuser));
db.close();
Expand Down Expand Up @@ -153,7 +154,7 @@ public void shouldTestSystemUserWithKeystore() throws Exception {
"password");

// "sysuser" is the username. We just created it in OSystem.
ODatabaseDocumentTx db = new ODatabaseDocumentTx(DATABASE_URL);
ODatabaseDocument db = new ODatabaseDocumentTx(DATABASE_URL);
// We encrypt the username and specify the Base64-encoded JSON document as the password.
db.open(sysuser, sk.encrypt("AES/CBC/PKCS5Padding", sysuser));
db.close();
Expand Down

0 comments on commit 960d0f9

Please sign in to comment.