Skip to content

Commit

Permalink
refactor: reduce used of legacy API in test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
tglman committed Dec 18, 2023
1 parent 4c6da04 commit ff34dd0
Show file tree
Hide file tree
Showing 55 changed files with 223 additions and 221 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.orientechnologies.orient.core.serialization.serializer.stream;

import com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.BaseMemoryInternalDatabase;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.id.ORecordId;
import com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage;
Expand All @@ -15,31 +14,16 @@
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class OStreamSerializerSBTreeIndexRIDContainerTest {
private ODatabaseDocumentTx database;
private OStreamSerializerSBTreeIndexRIDContainer streamSerializerSBTreeIndexRIDContainer;

@Before
public void beforeClass() {
database = new ODatabaseDocumentTx("memory:" + this.getClass().getSimpleName());
database.create();
streamSerializerSBTreeIndexRIDContainer = new OStreamSerializerSBTreeIndexRIDContainer();
}

@After
public void afterClass() {
database.drop();
}
public class OStreamSerializerSBTreeIndexRIDContainerTest extends BaseMemoryInternalDatabase {
private OStreamSerializerSBTreeIndexRIDContainer streamSerializerSBTreeIndexRIDContainer =
new OStreamSerializerSBTreeIndexRIDContainer();;

@Test
public void testSerializeInByteBufferEmbeddedNonDurable() throws IOException {
final OAbstractPaginatedStorage storage =
(OAbstractPaginatedStorage) ODatabaseRecordThreadLocal.instance().get().getStorage();
final OAbstractPaginatedStorage storage = (OAbstractPaginatedStorage) db.getStorage();
final OAtomicOperationsManager atomicOperationsManager = storage.getAtomicOperationsManager();
atomicOperationsManager.startAtomicOperation(null);
try {
Expand Down Expand Up @@ -91,8 +75,7 @@ public void testSerializeInByteBufferEmbeddedNonDurable() throws IOException {

@Test
public void testSerializeInByteBufferEmbeddedDurable() throws IOException {
final OAbstractPaginatedStorage storage =
(OAbstractPaginatedStorage) ODatabaseRecordThreadLocal.instance().get().getStorage();
final OAbstractPaginatedStorage storage = (OAbstractPaginatedStorage) db.getStorage();
final OAtomicOperationsManager atomicOperationsManager = storage.getAtomicOperationsManager();
atomicOperationsManager.startAtomicOperation(null);
try {
Expand Down Expand Up @@ -144,8 +127,7 @@ public void testSerializeInByteBufferEmbeddedDurable() throws IOException {

@Test
public void testSerializeInByteBufferNonEmbeddedDurable() throws IOException {
final OAbstractPaginatedStorage storage =
(OAbstractPaginatedStorage) ODatabaseRecordThreadLocal.instance().get().getStorage();
final OAbstractPaginatedStorage storage = (OAbstractPaginatedStorage) db.getStorage();
final OAtomicOperationsManager atomicOperationsManager = storage.getAtomicOperationsManager();
atomicOperationsManager.startAtomicOperation(null);
try {
Expand Down Expand Up @@ -197,8 +179,7 @@ public void testSerializeInByteBufferNonEmbeddedDurable() throws IOException {

@Test
public void testSerializeWALChangesEmbeddedNonDurable() throws IOException {
final OAbstractPaginatedStorage storage =
(OAbstractPaginatedStorage) ODatabaseRecordThreadLocal.instance().get().getStorage();
final OAbstractPaginatedStorage storage = (OAbstractPaginatedStorage) db.getStorage();
final OAtomicOperationsManager atomicOperationsManager = storage.getAtomicOperationsManager();
atomicOperationsManager.startAtomicOperation(null);
try {
Expand Down Expand Up @@ -247,8 +228,7 @@ public void testSerializeWALChangesEmbeddedNonDurable() throws IOException {

@Test
public void testSerializeWALChangesEmbeddedDurable() throws IOException {
final OAbstractPaginatedStorage storage =
(OAbstractPaginatedStorage) ODatabaseRecordThreadLocal.instance().get().getStorage();
final OAbstractPaginatedStorage storage = (OAbstractPaginatedStorage) db.getStorage();
final OAtomicOperationsManager atomicOperationsManager = storage.getAtomicOperationsManager();
atomicOperationsManager.startAtomicOperation(null);
try {
Expand Down Expand Up @@ -298,8 +278,7 @@ public void testSerializeWALChangesEmbeddedDurable() throws IOException {

@Test
public void testSerializeWALChangesNonEmbeddedNonDurable() throws IOException {
final OAbstractPaginatedStorage storage =
(OAbstractPaginatedStorage) ODatabaseRecordThreadLocal.instance().get().getStorage();
final OAbstractPaginatedStorage storage = (OAbstractPaginatedStorage) db.getStorage();
final OAtomicOperationsManager atomicOperationsManager = storage.getAtomicOperationsManager();
atomicOperationsManager.startAtomicOperation(null);
try {
Expand Down Expand Up @@ -349,8 +328,7 @@ public void testSerializeWALChangesNonEmbeddedNonDurable() throws IOException {

@Test
public void testSerializeWALChangesNonEmbeddedDurable() throws IOException {
final OAbstractPaginatedStorage storage =
(OAbstractPaginatedStorage) ODatabaseRecordThreadLocal.instance().get().getStorage();
final OAbstractPaginatedStorage storage = (OAbstractPaginatedStorage) db.getStorage();
final OAtomicOperationsManager atomicOperationsManager = storage.getAtomicOperationsManager();
atomicOperationsManager.startAtomicOperation(null);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.orientechnologies.orient.core.command.OCommandOutputListener;
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.tool.ODatabaseCompare;
Expand Down Expand Up @@ -42,8 +43,8 @@
*/
public class LocalPaginatedStorageRestoreFromWAL {
private static File buildDir;
private ODatabaseDocumentTx testDocumentTx;
private ODatabaseDocumentTx baseDocumentTx;
private ODatabaseDocumentInternal testDocumentTx;
private ODatabaseDocumentInternal baseDocumentTx;
private ExecutorService executorService = Executors.newCachedThreadPool();

private static void copyFile(String from, String to) throws IOException {
Expand Down Expand Up @@ -281,7 +282,7 @@ else if (storageFile.getName().equals("baseLocalPaginatedStorageRestoreFromWAL.2
}
}

private void createSchema(ODatabaseDocumentTx databaseDocumentTx) {
private void createSchema(ODatabaseDocumentInternal databaseDocumentTx) {
ODatabaseRecordThreadLocal.instance().set(databaseDocumentTx);

OSchema schema = databaseDocumentTx.getMetadata().getSchema();
Expand All @@ -303,7 +304,7 @@ public Void call() throws Exception {

Random random = new Random();

final ODatabaseDocumentTx db = new ODatabaseDocumentTx(baseDocumentTx.getURL());
final ODatabaseDocumentInternal db = new ODatabaseDocumentTx(baseDocumentTx.getURL());
db.open("admin", "admin");
try {
List<ORID> testTwoList = new ArrayList<ORID>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.orientechnologies.common.io.OFileUtils;
import com.orientechnologies.orient.core.command.OCommandOutputListener;
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.tool.ODatabaseCompare;
Expand Down Expand Up @@ -46,8 +47,8 @@
*/
public class LocalPaginatedStorageRestoreFromWALAndAddAdditionalRecords {
private static File buildDir;
private ODatabaseDocumentTx testDocumentTx;
private ODatabaseDocumentTx baseDocumentTx;
private ODatabaseDocumentInternal testDocumentTx;
private ODatabaseDocumentInternal baseDocumentTx;
private ExecutorService executorService = Executors.newCachedThreadPool();

@BeforeClass
Expand Down Expand Up @@ -253,7 +254,7 @@ else if (fileToCopy.endsWith(
});
}

private void createSchema(ODatabaseDocumentTx databaseDocumentTx) {
private void createSchema(ODatabaseDocumentInternal databaseDocumentTx) {
ODatabaseRecordThreadLocal.instance().set(databaseDocumentTx);

OSchema schema = databaseDocumentTx.getMetadata().getSchema();
Expand All @@ -270,8 +271,8 @@ private void createSchema(ODatabaseDocumentTx databaseDocumentTx) {
}

public class DataPropagationTask implements Callable<Void> {
private ODatabaseDocumentTx baseDB;
private ODatabaseDocumentTx testDB;
private ODatabaseDocumentInternal baseDB;
private ODatabaseDocumentInternal testDB;
private long seed;

public DataPropagationTask(long seed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.orientechnologies.orient.core.command.OCommandOutputListener;
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.db.tool.ODatabaseCompare;
import com.orientechnologies.orient.core.id.ORID;
Expand Down Expand Up @@ -42,8 +44,8 @@
* @since 14.06.13
*/
public class LocalPaginatedStorageRestoreTx {
private ODatabaseDocumentTx testDocumentTx;
private ODatabaseDocumentTx baseDocumentTx;
private ODatabaseDocumentInternal testDocumentTx;
private ODatabaseDocumentInternal baseDocumentTx;
private File buildDir;

private ExecutorService executorService = Executors.newCachedThreadPool();
Expand Down Expand Up @@ -240,7 +242,7 @@ else if (storageFile
}
}

private void createSchema(ODatabaseDocumentTx databaseDocumentTx) {
private void createSchema(ODatabaseDocumentInternal databaseDocumentTx) {
ODatabaseRecordThreadLocal.instance().set(databaseDocumentTx);

OSchema schema = databaseDocumentTx.getMetadata().getSchema();
Expand All @@ -262,7 +264,7 @@ public Void call() throws Exception {

Random random = new Random();

final ODatabaseDocumentTx db = new ODatabaseDocumentTx(baseDocumentTx.getURL());
final ODatabaseDocument db = new ODatabaseDocumentTx(baseDocumentTx.getURL());
db.open("admin", "admin");
int rollbacksCount = 0;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import com.orientechnologies.common.io.OFileUtils;
import com.orientechnologies.orient.core.command.OCommandOutputListener;
import com.orientechnologies.orient.core.config.OGlobalConfiguration;
import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal;
import com.orientechnologies.orient.core.db.OPartitionedDatabasePool;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.db.record.ridbag.ORidBag;
import com.orientechnologies.orient.core.db.tool.ODatabaseCompare;
Expand Down Expand Up @@ -82,7 +84,7 @@ public void testRun() throws Exception {
dbURL = "plocal:" + dbDirectory;

System.out.println("Create database");
ODatabaseDocumentTx databaseDocumentTx = new ODatabaseDocumentTx(dbURL);
ODatabaseDocumentInternal databaseDocumentTx = new ODatabaseDocumentTx(dbURL);
databaseDocumentTx.create();

System.out.println("Create schema");
Expand Down Expand Up @@ -156,7 +158,8 @@ public void testRun() throws Exception {
storage.close(true, false);

System.out.println("Create backup database");
final ODatabaseDocumentTx backedUpDb = new ODatabaseDocumentTx("plocal:" + backedUpDbDirectory);
final ODatabaseDocumentInternal backedUpDb =
new ODatabaseDocumentTx("plocal:" + backedUpDbDirectory);
backedUpDb.create(backupDir.getAbsolutePath());

final OStorage backupStorage = backedUpDb.getStorage();
Expand Down Expand Up @@ -216,7 +219,7 @@ private final class NonTxInserter extends Inserter {
public Void call() throws Exception {
while (!stop) {
while (true) {
ODatabaseDocumentTx db = pool.acquire();
ODatabaseDocument db = pool.acquire();
try {
flowLock.acquireReadLock();
try {
Expand Down Expand Up @@ -252,7 +255,7 @@ public Void call() throws Exception {

while (!stop) {
while (true) {
ODatabaseDocumentTx db = pool.acquire();
ODatabaseDocument db = pool.acquire();
try {
flowLock.acquireReadLock();
try {
Expand Down Expand Up @@ -287,7 +290,7 @@ public Void call() throws Exception {
private abstract class Inserter implements Callable<Void> {
protected final Random random = new Random();

protected void insertRecord(ODatabaseDocumentTx db) {
protected void insertRecord(ODatabaseDocument db) {
final int docId;
final int classes = classCounter.get();

Expand Down Expand Up @@ -350,7 +353,7 @@ protected void insertRecord(ODatabaseDocumentTx db) {
private final class IncrementalBackupThread implements Runnable {
@Override
public void run() {
ODatabaseDocumentTx db = new ODatabaseDocumentTx(dbURL);
ODatabaseDocument db = new ODatabaseDocumentTx(dbURL);
db.open("admin", "admin");
try {
flowLock.acquireReadLock();
Expand All @@ -372,7 +375,7 @@ public void run() {
private final class ClassAdder implements Runnable {
@Override
public void run() {
ODatabaseDocumentTx databaseDocumentTx = new ODatabaseDocumentTx(dbURL);
ODatabaseDocument databaseDocumentTx = new ODatabaseDocumentTx(dbURL);
databaseDocumentTx.open("admin", "admin");
try {
flowLock.acquireReadLock();
Expand All @@ -398,7 +401,7 @@ public Void call() throws Exception {
int counter = 0;
while (!stop) {
while (true) {
ODatabaseDocumentTx databaseDocumentTx = pool.acquire();
ODatabaseDocument databaseDocumentTx = pool.acquire();
try {
flowLock.acquireReadLock();
try {
Expand Down Expand Up @@ -470,7 +473,7 @@ private final class ClassDeleter implements Runnable {

@Override
public void run() {
ODatabaseDocumentTx db = pool.acquire();
ODatabaseDocument db = pool.acquire();
try {
flowLock.acquireWriteLock();
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.orientechnologies.orient.core.storage.index.hashindex.local.v2;

import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.exception.OCommandInterruptedException;
import com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage;
Expand All @@ -19,22 +20,21 @@
* @since 5/15/14
*/
public class HashTableDirectoryV2Test {
private static ODatabaseDocumentTx databaseDocumentTx;
private static ODatabaseDocumentInternal db;

private static HashTableDirectory directory;

@BeforeClass
public static void beforeClass() throws IOException {
databaseDocumentTx =
new ODatabaseDocumentTx("memory:" + HashTableDirectoryV2Test.class.getSimpleName());
if (databaseDocumentTx.exists()) {
databaseDocumentTx.open("admin", "admin");
databaseDocumentTx.drop();
db = new ODatabaseDocumentTx("memory:" + HashTableDirectoryV2Test.class.getSimpleName());
if (db.exists()) {
db.open("admin", "admin");
db.drop();
}

databaseDocumentTx.create();
db.create();

OAbstractPaginatedStorage storage = (OAbstractPaginatedStorage) databaseDocumentTx.getStorage();
OAbstractPaginatedStorage storage = (OAbstractPaginatedStorage) db.getStorage();
directory =
new HashTableDirectory(".tsc", "hashTableDirectoryTest", "hashTableDirectoryTest", storage);

Expand All @@ -49,7 +49,7 @@ public static void afterClass() throws Exception {
directory.delete(atomicOperation);
completeTx();

databaseDocumentTx.drop();
db.drop();
}

@Before
Expand All @@ -63,21 +63,21 @@ public void afterMethod() throws IOException {
}

private static OAtomicOperation startTx() throws IOException {
OAbstractPaginatedStorage storage = (OAbstractPaginatedStorage) databaseDocumentTx.getStorage();
OAbstractPaginatedStorage storage = (OAbstractPaginatedStorage) db.getStorage();
OAtomicOperationsManager manager = storage.getAtomicOperationsManager();
Assert.assertNull(manager.getCurrentOperation());
return manager.startAtomicOperation(null);
}

private static void rollbackTx() throws IOException {
OAbstractPaginatedStorage storage = (OAbstractPaginatedStorage) databaseDocumentTx.getStorage();
OAbstractPaginatedStorage storage = (OAbstractPaginatedStorage) db.getStorage();
OAtomicOperationsManager manager = storage.getAtomicOperationsManager();
manager.endAtomicOperation(new OCommandInterruptedException(""));
Assert.assertNull(manager.getCurrentOperation());
}

private static void completeTx() throws IOException {
OAbstractPaginatedStorage storage = (OAbstractPaginatedStorage) databaseDocumentTx.getStorage();
OAbstractPaginatedStorage storage = (OAbstractPaginatedStorage) db.getStorage();
OAtomicOperationsManager manager = storage.getAtomicOperationsManager();
manager.endAtomicOperation(null);
Assert.assertNull(manager.getCurrentOperation());
Expand Down
Loading

0 comments on commit ff34dd0

Please sign in to comment.