diff --git a/tests/src/test/java/com/orientechnologies/orient/test/database/auto/CRUDObjectPhysicalTest.java b/tests/src/test/java/com/orientechnologies/orient/test/database/auto/CRUDObjectPhysicalTest.java index 1ce99b99178..d55d8014652 100755 --- a/tests/src/test/java/com/orientechnologies/orient/test/database/auto/CRUDObjectPhysicalTest.java +++ b/tests/src/test/java/com/orientechnologies/orient/test/database/auto/CRUDObjectPhysicalTest.java @@ -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); } diff --git a/tests/src/test/java/com/orientechnologies/orient/test/database/auto/CRUDObjectPhysicalTestSchemaFull.java b/tests/src/test/java/com/orientechnologies/orient/test/database/auto/CRUDObjectPhysicalTestSchemaFull.java index a836570db34..1e809362b43 100755 --- a/tests/src/test/java/com/orientechnologies/orient/test/database/auto/CRUDObjectPhysicalTestSchemaFull.java +++ b/tests/src/test/java/com/orientechnologies/orient/test/database/auto/CRUDObjectPhysicalTestSchemaFull.java @@ -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); } diff --git a/tests/src/test/java/com/orientechnologies/orient/test/database/auto/DbImportExportRidbagTest.java b/tests/src/test/java/com/orientechnologies/orient/test/database/auto/DbImportExportRidbagTest.java index cc9938188fc..412233a8f7b 100755 --- a/tests/src/test/java/com/orientechnologies/orient/test/database/auto/DbImportExportRidbagTest.java +++ b/tests/src/test/java/com/orientechnologies/orient/test/database/auto/DbImportExportRidbagTest.java @@ -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; @@ -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); @@ -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); diff --git a/tests/src/test/java/com/orientechnologies/orient/test/database/auto/DbImportExportTest.java b/tests/src/test/java/com/orientechnologies/orient/test/database/auto/DbImportExportTest.java index b66796a8b27..82ffb247e27 100755 --- a/tests/src/test/java/com/orientechnologies/orient/test/database/auto/DbImportExportTest.java +++ b/tests/src/test/java/com/orientechnologies/orient/test/database/auto/DbImportExportTest.java @@ -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; @@ -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( @@ -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); diff --git a/tests/src/test/java/com/orientechnologies/orient/test/database/auto/DbImportStreamExportTest.java b/tests/src/test/java/com/orientechnologies/orient/test/database/auto/DbImportStreamExportTest.java index 95eaad0bf22..c553d247a32 100755 --- a/tests/src/test/java/com/orientechnologies/orient/test/database/auto/DbImportStreamExportTest.java +++ b/tests/src/test/java/com/orientechnologies/orient/test/database/auto/DbImportStreamExportTest.java @@ -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; @@ -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); @@ -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); diff --git a/tests/src/test/java/com/orientechnologies/orient/test/database/auto/DocumentDBBaseTest.java b/tests/src/test/java/com/orientechnologies/orient/test/database/auto/DocumentDBBaseTest.java index efa12879237..8fc3be54798 100755 --- a/tests/src/test/java/com/orientechnologies/orient/test/database/auto/DocumentDBBaseTest.java +++ b/tests/src/test/java/com/orientechnologies/orient/test/database/auto/DocumentDBBaseTest.java @@ -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; @@ -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()); @@ -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(); } diff --git a/tests/src/test/java/com/orientechnologies/orient/test/database/auto/MultipleDBTest.java b/tests/src/test/java/com/orientechnologies/orient/test/database/auto/MultipleDBTest.java index a2b671a8e16..eb008da5e3c 100755 --- a/tests/src/test/java/com/orientechnologies/orient/test/database/auto/MultipleDBTest.java +++ b/tests/src/test/java/com/orientechnologies/orient/test/database/auto/MultipleDBTest.java @@ -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; @@ -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 t = new Callable() { @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"); @@ -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(); @@ -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 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(); @@ -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; } @@ -165,8 +152,6 @@ public Void call() throws InterruptedException, IOException { } for (Future future : threads) future.get(); - - // System.out.println("Test testObjectMultipleDBsThreaded ended"); } @Test @@ -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 t = new Callable() { @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++) { @@ -219,24 +196,16 @@ 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); @@ -244,33 +213,23 @@ public Void call() throws InterruptedException, IOException { for (int j = 0; j < operations_read; j++) { List 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; } @@ -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) { diff --git a/tests/src/test/java/com/orientechnologies/orient/test/database/auto/ObjectDBBaseTest.java b/tests/src/test/java/com/orientechnologies/orient/test/database/auto/ObjectDBBaseTest.java index 27aa9eeba44..0a4e7d7cb9f 100644 --- a/tests/src/test/java/com/orientechnologies/orient/test/database/auto/ObjectDBBaseTest.java +++ b/tests/src/test/java/com/orientechnologies/orient/test/database/auto/ObjectDBBaseTest.java @@ -6,7 +6,6 @@ import com.orientechnologies.orient.core.db.ODatabaseSession; import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; import com.orientechnologies.orient.core.db.object.ODatabaseObject; -import com.orientechnologies.orient.object.db.OObjectDatabasePool; import com.orientechnologies.orient.object.db.OObjectDatabaseTx; import java.io.IOException; import org.testng.annotations.Optional; @@ -70,17 +69,20 @@ protected void reopendb(String user, String password) { } protected void reopenpool(String user, String password) { - database = OObjectDatabasePool.global().acquire(url, user, password); + if (!database.isClosed()) { + database.close(); + } + database = new OObjectDatabaseTx(this.url); + database.open(user, password); } protected ODatabaseObject openpool(String user, String password) { - return OObjectDatabasePool.global().acquire(url, user, password); + return session("", user, password); } protected void dropdb() throws IOException { String prefix = url.substring(0, url.indexOf(':') + 1); logger.info("deleting database %s", url); - ODatabaseHelper.dropDatabase( - OObjectDatabasePool.global().acquire(url, "admin", "admin"), prefix); + ODatabaseHelper.dropDatabase(session("", "admin", "admin"), prefix); } } diff --git a/tests/src/test/java/com/orientechnologies/orient/test/database/auto/ServerTest.java b/tests/src/test/java/com/orientechnologies/orient/test/database/auto/ServerTest.java index 81825e7d2bd..ad0005dfd0f 100755 --- a/tests/src/test/java/com/orientechnologies/orient/test/database/auto/ServerTest.java +++ b/tests/src/test/java/com/orientechnologies/orient/test/database/auto/ServerTest.java @@ -15,12 +15,12 @@ */ package com.orientechnologies.orient.test.database.auto; -import com.orientechnologies.orient.client.remote.OServerAdmin; +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.db.document.ODatabaseDocumentTx; import com.orientechnologies.orient.core.record.impl.ODocument; import java.io.IOException; -import java.util.Map; +import java.util.List; import org.testng.Assert; import org.testng.annotations.Optional; import org.testng.annotations.Parameters; @@ -28,54 +28,46 @@ @Test public class ServerTest extends DocumentDBBaseTest { - private String serverURL; @Parameters(value = "url") public ServerTest(@Optional String url) { super(url); - - serverURL = url.substring(0, url.lastIndexOf('/')); } @Test public void testDbList() throws IOException { - OServerAdmin server = new OServerAdmin(serverURL); + OrientDB ctx = new OrientDB("remote:localhost", "root", "root", OrientDBConfig.defaultConfig()); + try { - server.connect("root", "root"); - Map dbs = server.listDatabases(); + List dbs = ctx.list(); Assert.assertFalse(dbs.isEmpty()); } finally { - server.close(); + ctx.close(); } } @Test public void testOpenCloseCreateClass() throws IOException { - OServerAdmin admin = new OServerAdmin("remote:localhost/doubleOpenTest"); - admin.connect("root", "root"); - admin.createDatabase("document", "memory"); - admin.close(); + OrientDB ctx = new OrientDB("remote:localhost", "root", "root", OrientDBConfig.defaultConfig()); + ctx.execute( + "create database doubleOpenTest memory users(admin identified by 'admin' role admin)"); - ODatabaseDocument db = new ODatabaseDocumentTx("remote:localhost/doubleOpenTest"); + ODatabaseDocument db = ctx.open("doubleOpenTest", "admin", "admin"); try { - db.open("admin", "admin"); ODocument d = new ODocument("User"); - d.save(); + db.save(d); } finally { db.close(); } - + db = ctx.open("doubleOpenTest", "admin", "admin"); try { - db.open("admin", "admin"); ODocument d = new ODocument("User"); - d.save(); + db.save(d); } finally { db.close(); } - admin = new OServerAdmin("remote:localhost/doubleOpenTest"); - admin.connect("root", "root"); - admin.dropDatabase("memory"); - admin.close(); + ctx.drop("doubleOpenTest"); + ctx.close(); } }