Skip to content

Commit

Permalink
refactor: removed usages of legacy APIs from tests, mainly agent and …
Browse files Browse the repository at this point in the history
…security module
  • Loading branch information
tglman committed Jan 11, 2025
1 parent 93e1372 commit 081b1f7
Show file tree
Hide file tree
Showing 17 changed files with 341 additions and 474 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.orientechnologies.orient.core.db.OrientDBEmbedded;
import com.orientechnologies.orient.core.db.OrientDBInternal;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.db.tool.ODatabaseCompare;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.metadata.schema.OSchema;
Expand Down Expand Up @@ -124,11 +123,6 @@ public void testParallelBackup() throws Exception {

} finally {

try {
ODatabaseDocumentTx.closeAll();
} catch (Exception ex) {
logger.error("", ex);
}
if (orientDB.isOpen()) {
try {
orientDB.close();
Expand Down Expand Up @@ -232,7 +226,6 @@ public void testParallelBackupEncryption() throws Exception {

} finally {
try {
ODatabaseDocumentTx.closeAll();
OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.setValue(null);
} catch (Exception ex) {
logger.error("", ex);
Expand Down Expand Up @@ -278,7 +271,7 @@ public Void call() throws Exception {
document.field("num", num);
document.field("data", data);

document.save();
db.save(document);
} catch (OModificationOperationProhibitedException e) {
System.out.println("Modification prohibited ... wait ...");
Thread.sleep(1000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
import com.orientechnologies.common.io.OFileUtils;
import com.orientechnologies.orient.core.command.OCommandOutputListener;
import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.db.ODatabaseType;
import com.orientechnologies.orient.core.db.OrientDB;
import com.orientechnologies.orient.core.db.OrientDBConfig;
import com.orientechnologies.orient.core.db.OrientDBInternal;
import com.orientechnologies.orient.core.db.tool.ODatabaseCompare;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.metadata.schema.OSchema;
import com.orientechnologies.orient.core.metadata.schema.OType;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.storage.OStorage;
import java.io.File;
import java.io.IOException;
import org.junit.After;
Expand All @@ -47,18 +48,28 @@
public class StorageBackupTestWithLuceneIndex {
private String buildDirectory;

private OrientDB ctx;
private ODatabaseDocumentInternal db;
private String dbDirectory;
private String dbName;
private String dbBackupName;
private String backedUpDbDirectory;

@Before
public void before() {
buildDirectory = System.getProperty("buildDirectory", ".");
dbDirectory =
buildDirectory + File.separator + StorageBackupTestWithLuceneIndex.class.getSimpleName();
buildDirectory = System.getProperty("buildDirectory", "./target");
dbDirectory = buildDirectory + "/backup-tests";
dbName = StorageBackupTestWithLuceneIndex.class.getSimpleName();
dbBackupName = StorageBackupTestWithLuceneIndex.class.getSimpleName() + "BackUp";

OFileUtils.deleteRecursively(new File(dbDirectory));
db = new ODatabaseDocumentTx("plocal:" + dbDirectory);
db.create();
ctx = new OrientDB("embedded:" + dbDirectory, OrientDBConfig.defaultConfig());
ctx.execute(
"create database "
+ dbName
+ " plocal users(admin identified by 'adminpwd' role admin)")
.close();
db = (ODatabaseDocumentInternal) ctx.open(dbName, "admin", "adminpwd");

backedUpDbDirectory =
buildDirectory
Expand All @@ -69,19 +80,11 @@ public void before() {

@After
public void after() {
if (db.exists()) {
if (db.isClosed()) {
db.open("admin", "admin");
}
db.drop();
if (ctx.exists(dbName)) {
ctx.drop(dbName);
}

final ODatabaseDocument backedUpDb = new ODatabaseDocumentTx("plocal:" + backedUpDbDirectory);
if (backedUpDb.exists()) {
if (backedUpDb.isClosed()) {
backedUpDb.open("admin", "admin");
backedUpDb.drop();
}
if (ctx.exists(dbBackupName)) {
ctx.drop(dbBackupName);
}

OFileUtils.deleteRecursively(new File(dbDirectory));
Expand All @@ -108,29 +111,30 @@ public void testSingeThreadFullBackup() throws IOException {
final ODocument document = new ODocument("BackupClass");
document.field("num", 1);
document.field("name", "Storage");
document.save();
db.save(document);

final File backupDir = new File(buildDirectory, "backupDir");
OFileUtils.deleteRecursively(backupDir);

if (!backupDir.exists()) Assert.assertTrue(backupDir.mkdirs());

db.incrementalBackup(backupDir.getAbsolutePath());
final OStorage storage = db.getStorage();
db.close();

storage.close(true);

OFileUtils.deleteRecursively(new File(backedUpDbDirectory));

final ODatabaseDocumentInternal backedUpDb =
new ODatabaseDocumentTx("plocal:" + backedUpDbDirectory);
backedUpDb.create(backupDir.getAbsolutePath());

final OStorage backupStorage = backedUpDb.getStorage();
backedUpDb.close();
OrientDBInternal internal = OrientDBInternal.extract(ctx);
internal.restore(
dbBackupName,
null,
null,
ODatabaseType.PLOCAL,
backupDir.getAbsolutePath(),
OrientDBConfig.defaultConfig());

backupStorage.close(true);
final ODatabaseDocumentInternal backedUpDb =
(ODatabaseDocumentInternal) ctx.open(dbBackupName, "admin", "adminpwd");
db = (ODatabaseDocumentInternal) ctx.open(dbName, "admin", "adminpwd");

final ODatabaseCompare compare =
new ODatabaseCompare(
Expand All @@ -146,7 +150,8 @@ public void onMessage(String iText) {
Assert.assertTrue(compare.compare());
}

// @Test
@Test
@Ignore
public void testSingeThreadIncrementalBackup() throws IOException {

final OSchema schema = db.getMetadata().getSchema();
Expand All @@ -170,37 +175,36 @@ public void testSingeThreadIncrementalBackup() throws IOException {
ODocument document = new ODocument("BackupClass");
document.field("num", 1);
document.field("name", "Storage");
document.save();
db.save(document);

db.incrementalBackup(backupDir.getAbsolutePath());

document = new ODocument("BackupClass");
document.field("num", 1);
document.field("name", "Storage1");
document.save();
db.save(document);

db.incrementalBackup(backupDir.getAbsolutePath());

final OStorage storage = db.getStorage();
db.close();

storage.close(true);

final String backedUpDbDirectory =
buildDirectory
+ File.separator
+ StorageBackupTestWithLuceneIndex.class.getSimpleName()
+ "BackUp";
OFileUtils.deleteRecursively(new File(backedUpDbDirectory));

OrientDBInternal internal = OrientDBInternal.extract(ctx);
internal.restore(
dbBackupName,
null,
null,
ODatabaseType.PLOCAL,
backupDir.getAbsolutePath(),
OrientDBConfig.defaultConfig());
final ODatabaseDocumentInternal backedUpDb =
new ODatabaseDocumentTx("plocal:" + backedUpDbDirectory);
backedUpDb.create(backupDir.getAbsolutePath());

final OStorage backupStorage = backedUpDb.getStorage();
backedUpDb.close();

backupStorage.close(true);
(ODatabaseDocumentInternal) ctx.open(dbBackupName, "admin", "adminpwd");
db = (ODatabaseDocumentInternal) ctx.open(dbName, "admin", "adminpwd");

final ODatabaseCompare compare =
new ODatabaseCompare(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
import com.orientechnologies.common.log.OLogger;
import com.orientechnologies.common.util.OCallable;
import com.orientechnologies.orient.core.Orient;
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 java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -66,7 +63,6 @@ private static void syntaxError() {
}

public void init(final int servers) {
ODatabaseDocumentTx.closeAll();

GroupProperty.WAIT_SECONDS_BEFORE_JOIN.setSystemProperty("1");

Expand Down Expand Up @@ -277,7 +273,6 @@ protected void prepare(
onAfterDatabaseCreation(graph);
} finally {
graph.close();
ODatabaseDocumentTx.closeAll();
}
}

Expand Down Expand Up @@ -316,25 +311,6 @@ protected void executeWhen(final Callable<Boolean> condition, final Callable act
}
}

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

protected void executeWhen(
final ODatabaseDocument db,
OCallable<Boolean, ODatabaseDocument> condition,
Expand Down Expand Up @@ -398,47 +374,6 @@ protected void waitForDatabaseIsOnline(
}
}

protected void waitFor(
final int serverId,
final OCallable<Boolean, ODatabaseDocument> condition,
final long timeout) {
try {
ODatabaseDocument db =
new ODatabaseDocumentTx(getDatabaseURL(serverInstance.get(serverId)))
.open("admin", "admin");
try {

final long startTime = System.currentTimeMillis();

while (true) {
if (condition.call(db)) {
break;
}

if (timeout > 0 && System.currentTimeMillis() - startTime > timeout) {
logger.error("TIMEOUT on wait-for condition (timeout=%d)", null, timeout);
break;
}

try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// IGNORE IT
}
}

} finally {
if (!db.isClosed()) {
ODatabaseRecordThreadLocal.instance().set((ODatabaseDocumentInternal) db);
db.close();
ODatabaseRecordThreadLocal.instance().set(null);
}
}
} catch (Exception e) {
// INGORE IT
}
}

protected void waitFor(
final long timeout, final OCallable<Boolean, Void> condition, final String message) {
final long startTime = System.currentTimeMillis();
Expand Down
Loading

0 comments on commit 081b1f7

Please sign in to comment.