Skip to content

Commit

Permalink
refactor:removed legacy APIs usages from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tglman committed Jan 12, 2025
1 parent 081b1f7 commit 60fd05c
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 95 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.orientechnologies.orient.core.index;

import com.orientechnologies.orient.core.db.OPartitionedDatabasePool;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.db.ODatabasePool;
import com.orientechnologies.orient.core.db.ODatabaseSession;
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.metadata.schema.OClass;
import com.orientechnologies.orient.core.metadata.schema.OType;
import com.orientechnologies.orient.core.record.impl.ODocument;
Expand All @@ -18,22 +21,24 @@
import org.junit.Test;

public class OLiveIndexRebuildTest {
private final OPartitionedDatabasePool pool =
new OPartitionedDatabasePool("memory:liveIndexRebuild", "admin", "admin");
private OrientDB ctx;
private ODatabasePool pool;

private final String indexName = "liveIndex";
private final String className = "liveIndexClass";
private final String propertyName = "liveIndexProperty";

private final String databaseURL = "memory:liveIndexRebuild";
private final AtomicBoolean stop = new AtomicBoolean();

@Test
@Ignore
public void testLiveIndexRebuild() throws Exception {
final ODatabaseDocumentTx database = new ODatabaseDocumentTx(databaseURL);
database.create();

ctx = new OrientDB("memory:", OrientDBConfig.defaultConfig());
ctx.execute(
"create database liveIndexRebuild memory users(admin identified by 'adminpwd' role"
+ " 'admin')");
pool = ctx.cachedPool("liveIndexRebuild", "admin", "adminpwd");
ODatabaseSession database = pool.acquire();
final OClass clazz = database.getMetadata().getSchema().createClass(className);
clazz.createProperty(propertyName, OType.INTEGER);

Expand All @@ -42,7 +47,7 @@ public void testLiveIndexRebuild() throws Exception {
for (int i = 0; i < 1000000; i++) {
ODocument document = new ODocument(className);
document.field(propertyName, i);
document.save();
database.save(document);
}

ExecutorService executorService = Executors.newFixedThreadPool(6);
Expand Down Expand Up @@ -89,7 +94,7 @@ public Void call() throws Exception {
long rebuildCount = 0;
while (!stop.get()) {
for (int i = 0; i < 10; i++) {
final ODatabaseDocumentTx database = pool.acquire();
final ODatabaseDocument database = pool.acquire();
try {
long start = System.nanoTime();
database.command("rebuild index " + indexName).close();
Expand Down Expand Up @@ -125,7 +130,7 @@ public long[] call() throws Exception {
try {

while (!stop.get()) {
ODatabaseDocumentTx database = pool.acquire();
ODatabaseDocument database = pool.acquire();
try {
long start = System.nanoTime();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
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.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.db.OrientDB;
import com.orientechnologies.orient.core.db.OrientDBConfig;
import com.orientechnologies.orient.core.db.tool.ODatabaseCompare;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.metadata.schema.OClass;
Expand Down Expand Up @@ -42,6 +43,7 @@
*/
public class LocalPaginatedStorageRestoreFromWAL {
private static File buildDir;
private OrientDB ctx;
private ODatabaseDocumentInternal testDocumentTx;
private ODatabaseDocumentInternal baseDocumentTx;
private ExecutorService executorService = Executors.newCachedThreadPool();
Expand Down Expand Up @@ -85,26 +87,25 @@ public static void afterClass() {

@Before
public void beforeMethod() {
baseDocumentTx =
new ODatabaseDocumentTx(
"plocal:" + buildDir.getAbsolutePath() + "/baseLocalPaginatedStorageRestoreFromWAL");
if (baseDocumentTx.exists()) {
baseDocumentTx.open("admin", "admin");
baseDocumentTx.drop();
ctx = new OrientDB("plocal:" + buildDir.getAbsolutePath(), OrientDBConfig.defaultConfig());
if (ctx.exists("baseLocalPaginatedStorageRestoreFromWAL")) {
ctx.drop("baseLocalPaginatedStorageRestoreFromWAL");
}
ctx.execute(
"create database baseLocalPaginatedStorageRestoreFromWAL plocal users(admin identified by"
+ " 'adminpwd' role admin)");

baseDocumentTx.create();
baseDocumentTx =
(ODatabaseDocumentInternal)
ctx.open("baseLocalPaginatedStorageRestoreFromWAL", "admin", "adminpwd");

createSchema(baseDocumentTx);
}

@After
public void afterMethod() {
testDocumentTx.open("admin", "admin");
testDocumentTx.drop();

baseDocumentTx.open("admin", "admin");
baseDocumentTx.drop();
ctx.drop("testLocalPaginatedStorageRestoreFromWAL");
ctx.drop("baseLocalPaginatedStorageRestoreFromWAL");
}

@Test
Expand All @@ -123,10 +124,8 @@ public void testSimpleRestore() throws Exception {
baseStorage.close();

testDocumentTx =
new ODatabaseDocumentTx(
"plocal:" + buildDir.getAbsolutePath() + "/testLocalPaginatedStorageRestoreFromWAL");
testDocumentTx.open("admin", "admin");
testDocumentTx.close();
(ODatabaseDocumentInternal)
ctx.open("testLocalPaginatedStorageRestoreFromWAL", "admin", "adminpwd");

ODatabaseCompare databaseCompare =
new ODatabaseCompare(
Expand Down Expand Up @@ -299,8 +298,9 @@ public Void call() throws Exception {

Random random = new Random();

final ODatabaseDocumentInternal db = new ODatabaseDocumentTx(baseDocumentTx.getURL());
db.open("admin", "admin");
final ODatabaseDocumentInternal db =
(ODatabaseDocumentInternal)
ctx.open("baseLocalPaginatedStorageRestoreFromWAL", "admin", "adminpwd");
try {
List<ORID> testTwoList = new ArrayList<ORID>();
List<ORID> firstDocs = new ArrayList<ORID>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.orientechnologies.orient.core.storage.ridbag.sbtree;

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.db.ODatabaseSession;
import com.orientechnologies.orient.core.db.OrientDB;
import com.orientechnologies.orient.core.db.OrientDBConfig;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.db.record.ridbag.ORidBag;
import com.orientechnologies.orient.core.exception.OConcurrentModificationException;
Expand Down Expand Up @@ -48,6 +49,7 @@ public class OSBTreeRidBagConcurrencyMultiRidBag {

private int topThreshold;
private int bottomThreshold;
private OrientDB ctx;

@Before
public void beforeMethod() {
Expand All @@ -58,6 +60,17 @@ public void beforeMethod() {

OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.setValue(30);
OGlobalConfiguration.RID_BAG_SBTREEBONSAI_TO_EMBEDDED_THRESHOLD.setValue(20);
ctx = new OrientDB("embedded:./target/testdb/", OrientDBConfig.defaultConfig());
if (ctx.exists("OSBTreeRidBagConcurrencyMultiRidBag")) {
ctx.drop("OSBTreeRidBagConcurrencyMultiRidBag");
}
ctx.execute(
"create database OSBTreeRidBagConcurrencyMultiRidBag plocal users(admin identified by"
+ " 'adminpwd' role admin)")
.close();
ODatabaseSession db = ctx.open("OSBTreeRidBagConcurrencyMultiRidBag", "admin", "adminpwd");
db.createClass("WithRidbag");
db.close();
}

@After
Expand All @@ -68,19 +81,13 @@ public void afterMethod() {

@Test
public void testConcurrency() throws Exception {
ODatabaseDocument db = new ODatabaseDocumentTx(URL);
if (db.exists()) {
db.open("admin", "admin");
db.drop();
}

db.create();
ODatabaseSession db = ctx.open("OSBTreeRidBagConcurrencyMultiRidBag", "admin", "adminpwd");
for (int i = 0; i < 100; i++) {
ODocument document = new ODocument();
ODocument document = new ODocument("WithRidbag");
ORidBag ridBag = new ORidBag();
document.field("ridBag", ridBag);

document.save();
db.save(document);

ridTreePerDocument.put(document.getIdentity(), new ConcurrentSkipListSet<ORID>());
lastClusterPosition.set(document.getIdentity().getClusterPosition());
Expand Down Expand Up @@ -129,22 +136,21 @@ public void testConcurrency() throws Exception {
System.out.println(
"Total records added : " + db.countClusterElements(db.getDefaultClusterId()));
System.out.println("Total rids added : " + amountOfRids);

db.drop();
ctx.drop("");
ctx.close();
}

public final class DocumentAdder implements Runnable {
@Override
public void run() {
ODatabaseDocument db = new ODatabaseDocumentTx(URL);
db.open("admin", "admin");

try {
ODocument document = new ODocument();
try (ODatabaseSession db =
ctx.open("OSBTreeRidBagConcurrencyMultiRidBag", "admin", "adminpwd")) {
ODocument document = new ODocument("WithRidbag");
ORidBag ridBag = new ORidBag();
document.field("ridBag", ridBag);

document.save();
db.save(document);
ridTreePerDocument.put(document.getIdentity(), new ConcurrentSkipListSet<ORID>());

while (true) {
Expand All @@ -154,11 +160,6 @@ public void run() {
position, document.getIdentity().getClusterPosition())) break;
} else break;
}
} catch (RuntimeException e) {
e.printStackTrace();
throw e;
} finally {
db.close();
}
}
}
Expand All @@ -176,18 +177,17 @@ public Void call() throws Exception {
long addedRecords = 0;
int retries = 0;

ODatabaseDocument db = new ODatabaseDocumentTx(URL);
db.open("admin", "admin");

final int defaultClusterId = db.getDefaultClusterId();
latch.await();
try {
try (ODatabaseSession db =
ctx.open("OSBTreeRidBagConcurrencyMultiRidBag", "admin", "adminpwd")) {
while (cont) {
List<ORID> ridsToAdd = new ArrayList<ORID>();
for (int i = 0; i < 10; i++) {
ridsToAdd.add(new ORecordId(0, positionCounter.incrementAndGet()));
}

final int defaultClusterId = db.getClass("WithRidbag").getDefaultClusterId();

final long position = random.nextInt(lastClusterPosition.get().intValue());
final ORID orid = new ORecordId(defaultClusterId, position);

Expand All @@ -212,11 +212,6 @@ public Void call() throws Exception {
ridTree.addAll(ridsToAdd);
addedRecords += ridsToAdd.size();
}
} catch (RuntimeException e) {
e.printStackTrace();
throw e;
} finally {
db.close();
}

System.out.println(
Expand Down Expand Up @@ -244,12 +239,10 @@ public Void call() throws Exception {
long deletedRecords = 0;
int retries = 0;

ODatabaseDocument db = new ODatabaseDocumentTx(URL);
db.open("admin", "admin");

final int defaultClusterId = db.getDefaultClusterId();
latch.await();
try {
try (ODatabaseSession db =
ctx.open("OSBTreeRidBagConcurrencyMultiRidBag", "admin", "adminpwd")) {
final int defaultClusterId = db.getClass("WithRidbag").getDefaultClusterId();
while (cont) {
final long position = random.nextInt(lastClusterPosition.get().intValue());
final ORID orid = new ORecordId(defaultClusterId, position);
Expand Down Expand Up @@ -287,11 +280,6 @@ public Void call() throws Exception {
break;
}
}
} catch (RuntimeException e) {
e.printStackTrace();
throw e;
} finally {
db.close();
}

System.out.println(
Expand Down
Loading

0 comments on commit 60fd05c

Please sign in to comment.