Skip to content

Commit

Permalink
refactor: reduced usages of legacy APIs in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tglman committed Jan 20, 2025
1 parent 91acf6a commit a58a7ec
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,7 @@ public void create() {
}
}

@Test(dependsOnMethods = "create", expectedExceptions = UnsupportedOperationException.class)
public void testReleasedPoolDatabase() {
database.open("admin", "admin");
}

@Test(dependsOnMethods = "testReleasedPoolDatabase")
@Test(dependsOnMethods = "create")
public void testCreate() {
Assert.assertEquals(database.countClass("Account") - startRecordNumber, TOT_RECORDS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,7 @@ public void create() {
}
}

@Test(dependsOnMethods = "create", expectedExceptions = UnsupportedOperationException.class)
public void testReleasedPoolDatabase() {
database.open("admin", "admin");
}

@Test(dependsOnMethods = "testReleasedPoolDatabase")
@Test(dependsOnMethods = "create")
public void testCreate() {
Assert.assertEquals(database.countClusterElements("Account") - startRecordNumber, TOT_RECORDS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.orientechnologies.orient.core.command.OCommandOutputListener;
import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal;
import com.orientechnologies.orient.core.db.ODatabaseSession;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.db.tool.ODatabaseCompare;
import com.orientechnologies.orient.core.db.tool.ODatabaseExport;
import com.orientechnologies.orient.core.db.tool.ODatabaseImport;
Expand Down Expand Up @@ -83,9 +82,7 @@ public void testDbImport() throws IOException {
if (importDir.exists()) for (File f : importDir.listFiles()) f.delete();
else importDir.mkdir();

ODatabaseDocumentInternal database =
new ODatabaseDocumentTx(getStorageType() + ":" + testPath + "/" + NEW_DB_URL);
database.create();
ODatabaseDocumentInternal database = (ODatabaseDocumentInternal) createdb("test-import");

ODatabaseImport dbImport = new ODatabaseImport(database, testPath + "/" + exportFilePath, this);
dbImport.setMaxRidbagStringSizeBeforeLazyImport(50);
Expand All @@ -112,11 +109,9 @@ public void testCompareDatabases() throws IOException {
// EXECUTES ONLY IF NOT REMOTE ON CI/RELEASE TEST ENV
}

ODatabaseDocumentInternal first = new ODatabaseDocumentTx(url);
first.open("admin", "admin");
ODatabaseDocumentInternal first = (ODatabaseDocumentInternal) openSession("admin", "admin");
ODatabaseDocumentInternal second =
new ODatabaseDocumentTx(getStorageType() + ":" + testPath + "/" + NEW_DB_URL);
second.open("admin", "admin");
(ODatabaseDocumentInternal) this.openSession("test-import", "admin", "admin");

final ODatabaseCompare databaseCompare = new ODatabaseCompare(first, second, this);
databaseCompare.setCompareEntriesForAutomaticIndexes(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.orientechnologies.orient.core.db.OrientDBConfig;
import com.orientechnologies.orient.core.db.OrientDBConfigBuilder;
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.db.tool.ODatabaseExport;
import com.orientechnologies.orient.core.db.tool.ODatabaseImport;
Expand Down Expand Up @@ -92,9 +91,7 @@ public void testDbImport() throws IOException {
importDir.mkdir();
}

final ODatabaseDocument database =
new ODatabaseDocumentTx(getStorageType() + ":" + testPath + "/" + NEW_DB_URL);
database.create();
final ODatabaseDocument database = createdb("test-import");

final ODatabaseImport dbImport =
new ODatabaseImport(
Expand Down Expand Up @@ -123,8 +120,7 @@ public void testCompareDatabases() throws IOException {
}
ODatabaseDocumentInternal first = (ODatabaseDocumentInternal) openSession("admin", "admin");
ODatabaseDocumentInternal second =
new ODatabaseDocumentTx(getStorageType() + ":" + testPath + "/" + NEW_DB_URL);
second.open("admin", "admin");
(ODatabaseDocumentInternal) openSession("test-import", "admin", "admin");

final ODatabaseCompare databaseCompare = new ODatabaseCompare(first, second, this);
databaseCompare.setCompareEntriesForAutomaticIndexes(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.orientechnologies.orient.core.command.OCommandOutputListener;
import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal;
import com.orientechnologies.orient.core.db.ODatabaseSession;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.db.tool.ODatabaseCompare;
import com.orientechnologies.orient.core.db.tool.ODatabaseExport;
import com.orientechnologies.orient.core.db.tool.ODatabaseImport;
Expand Down Expand Up @@ -81,8 +80,7 @@ public void testDbImport() throws IOException {
}

final ODatabaseDocumentInternal database =
new ODatabaseDocumentTx(getStorageType() + ":" + testPath + "/" + NEW_DB_URL);
database.create();
(ODatabaseDocumentInternal) this.createdb("test-import");

final ODatabaseImport dbImport =
new ODatabaseImport(database, new FileInputStream(importDir), this);
Expand Down Expand Up @@ -110,8 +108,7 @@ public void testCompareDatabases() throws IOException {
}
ODatabaseDocumentInternal first = (ODatabaseDocumentInternal) openSession("admin", "admin");
ODatabaseDocumentInternal second =
new ODatabaseDocumentTx(getStorageType() + ":" + testPath + "/" + NEW_DB_URL);
second.open("admin", "admin");
(ODatabaseDocumentInternal) openSession("test-import", "admin", "admin");

final ODatabaseCompare databaseCompare = new ODatabaseCompare(first, second, this);
databaseCompare.setCompareEntriesForAutomaticIndexes(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import com.orientechnologies.orient.client.db.ODatabaseHelper;
import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal;
import com.orientechnologies.orient.core.db.ODatabaseSession;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import java.io.IOException;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
Expand Down Expand Up @@ -43,6 +45,13 @@ protected ODatabaseSession openSession(String user, String password) {
return session;
}

protected ODatabaseSession openSession(String database, String user, String password) {
ODatabaseSession session =
new ODatabaseDocumentTx(getStorageType() + ":" + "./target/" + database);
session.open(user, password);
return session;
}

protected void dropdb() {
try {
ODatabaseHelper.deleteDatabase(database, getStorageType());
Expand All @@ -51,6 +60,29 @@ protected void dropdb() {
}
}

protected void dropdb(String name) {
final ODatabaseSession db =
new ODatabaseDocumentTx(getStorageType() + ":" + "./target/" + name);
try {
ODatabaseHelper.dropDatabase(db, getStorageType());
} catch (Exception e) {
throw new RuntimeException(e);
}
}

protected ODatabaseSession createdb(String database) throws IOException {
final ODatabaseSession db =
new ODatabaseDocumentTx(getStorageType() + ":" + "./target/" + database);
db.create();
return db;
}

protected void dropAndCreateDatabase(String suffix) throws IOException {
ODatabaseDocument database = new ODatabaseDocumentTx(url + suffix);
ODatabaseHelper.dropDatabase(database, getStorageType());
ODatabaseHelper.createDatabase(database, url + suffix, getStorageType());
}

protected boolean existsdb() {
return database.exists();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
*/
package com.orientechnologies.orient.test.database.auto;

import com.orientechnologies.orient.client.db.ODatabaseHelper;
import com.orientechnologies.orient.client.remote.OStorageRemote;
import com.orientechnologies.orient.core.db.ODatabase;
import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal;
import com.orientechnologies.orient.core.db.ODatabaseInternal;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.db.ODatabaseSession;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.executor.OResult;
import com.orientechnologies.orient.core.util.OURLConnection;
import com.orientechnologies.orient.core.util.OURLHelper;
import com.orientechnologies.orient.object.db.OObjectDatabaseTx;
import java.io.IOException;
import java.util.Collections;
Expand Down Expand Up @@ -79,21 +80,23 @@ public void testObjectMultipleDBsThreaded() throws Exception {

for (int i = 0; i < dbs; i++) {

final String dbUrl = url + i;
final String suffix = "" + i;

Callable<Void> t =
new Callable<Void>() {

@Override
public Void call() throws InterruptedException, IOException {
OObjectDatabaseTx tx = new OObjectDatabaseTx(dbUrl);

ODatabaseHelper.deleteDatabase(tx, getStorageType());
ODatabaseHelper.createDatabase(tx, dbUrl, getStorageType());
OURLConnection data = OURLHelper.parse(url);
dropdb(data.getDbName() + suffix);
createdb(data.getDbName() + suffix);
OObjectDatabaseTx tx =
new OObjectDatabaseTx(
(ODatabaseDocumentInternal)
openSession(data.getDbName() + suffix, "admin", "admin"));

try {
if (tx.isClosed()) {
tx.open("admin", "admin");
}

tx.set(ODatabase.ATTRIBUTES.MINIMUMCLUSTERS, 1);
tx.getMetadata().getSchema().getOrCreateClass("DummyObject");
Expand All @@ -108,11 +111,6 @@ public Void call() throws InterruptedException, IOException {
// CAN'T WORK FOR LHPEPS CLUSTERS BECAUSE CLUSTER POSITION CANNOT BE KNOWN
Assert.assertEquals(
((ORID) dummy.getId()).getClusterPosition(), j, "RID was " + dummy.getId());

// if ((j + 1) % 20000 == 0) {
// System.out.println("(" + getDbId(tx) + ") " + "Operations (WRITE) executed: " +
// (j + 1));
// }
}
long end = System.currentTimeMillis();

Expand All @@ -123,18 +121,12 @@ public Void call() throws InterruptedException, IOException {
+ "Executed operations (WRITE) in: "
+ (end - start)
+ " ms";
// System.out.println(time);
times.add(time);

start = System.currentTimeMillis();
for (int j = 0; j < operations_read; j++) {
List<OResult> l = tx.query(" select * from DummyObject ").stream().toList();
Assert.assertEquals(l.size(), operations_write);

// if ((j + 1) % 20000 == 0) {
// System.out.println("(" + getDbId(tx) + ") " + "Operations (READ) executed: " +
// j + 1);
// }
}
end = System.currentTimeMillis();

Expand All @@ -145,17 +137,12 @@ public Void call() throws InterruptedException, IOException {
+ "Executed operations (READ) in: "
+ (end - start)
+ " ms";
// System.out.println(time);
times.add(time);

tx.close();

} finally {
// System.out.println("(" + getDbId(tx) + ") " + "Dropping");
// System.out.flush();
ODatabaseHelper.deleteDatabase(tx, getStorageType());
// System.out.println("(" + getDbId(tx) + ") " + "Dropped");
// System.out.flush();
dropdb(tx.getName());
}
return null;
}
Expand All @@ -165,8 +152,6 @@ public Void call() throws InterruptedException, IOException {
}

for (Future future : threads) future.get();

// System.out.println("Test testObjectMultipleDBsThreaded ended");
}

@Test
Expand All @@ -182,29 +167,21 @@ public void testDocumentMultipleDBsThreaded() throws Exception {

for (int i = 0; i < dbs; i++) {

final String dbUrl = url + i;

final String suffix = "" + i;
Callable<Void> t =
new Callable<Void>() {

@Override
public Void call() throws InterruptedException, IOException {
ODatabaseDocumentInternal tx = new ODatabaseDocumentTx(dbUrl);

ODatabaseHelper.deleteDatabase(tx, getStorageType());
// System.out.println("Thread " + this + " is creating database " + dbUrl);
// System.out.flush();
ODatabaseHelper.createDatabase(tx, dbUrl, getStorageType());
OURLConnection data = OURLHelper.parse(url);
dropdb(data.getDbName() + suffix);
createdb(data.getDbName() + suffix);
ODatabaseSession tx = openSession(data.getDbName() + suffix, "admin", "admin");

try {
// System.out.println("(" + getDbId(tx) + ") " + "Created");
// System.out.flush();

if (tx.isClosed()) {
tx.open("admin", "admin");
}

tx.getMetadata().getSchema().createClass("DummyObject", 1, null);
tx.getMetadata().getSchema().createClass("DummyObject", 1);

long start = System.currentTimeMillis();
for (int j = 0; j < operations_write; j++) {
Expand All @@ -219,58 +196,40 @@ public Void call() throws InterruptedException, IOException {
dummy.getIdentity().getClusterPosition(),
j,
"RID was " + dummy.getIdentity());

// if ((j + 1) % 20000 == 0) {
// System.out.println("(" + getDbId(tx) + ") " + "Operations (WRITE) executed: " +
// (j + 1));
// System.out.flush();
// }
}
long end = System.currentTimeMillis();

String time =
"("
+ getDbId(tx)
+ tx.getName()
+ ") "
+ "Executed operations (WRITE) in: "
+ (end - start)
+ " ms";
// System.out.println(time);
// System.out.flush();

times.add(time);

start = System.currentTimeMillis();
for (int j = 0; j < operations_read; j++) {
List<OResult> l = tx.query(" select * from DummyObject ").stream().toList();
Assert.assertEquals(l.size(), operations_write);

// if ((j + 1) % 20000 == 0) {
// System.out.println("(" + getDbId(tx) + ") " + "Operations (READ) executed: " +
// j + 1);
// System.out.flush();
// }
}
end = System.currentTimeMillis();

time =
"("
+ getDbId(tx)
+ tx.getName()
+ ") "
+ "Executed operations (READ) in: "
+ (end - start)
+ " ms";
// System.out.println(time);
// System.out.flush();

times.add(time);

} finally {
tx.close();

// System.out.println("Thread " + this + " is dropping database " + dbUrl);
// System.out.flush();
ODatabaseHelper.deleteDatabase(tx, getStorageType());
dropdb(tx.getName());
}
return null;
}
Expand All @@ -280,10 +239,6 @@ public Void call() throws InterruptedException, IOException {
}

for (Future future : results) future.get();

// System.out.println("Test testDocumentMultipleDBsThreaded ended");
// System.out.flush();

}

private String getDbId(ODatabaseInternal tx) {
Expand Down
Loading

0 comments on commit a58a7ec

Please sign in to comment.