diff --git a/agent/src/test/java/com/orientechnologies/orient/core/storage/impl/local/paginated/StorageBackupMTIT.java b/agent/src/test/java/com/orientechnologies/orient/core/storage/impl/local/paginated/StorageBackupMTIT.java index e8557e3a120..ffd540ea72a 100755 --- a/agent/src/test/java/com/orientechnologies/orient/core/storage/impl/local/paginated/StorageBackupMTIT.java +++ b/agent/src/test/java/com/orientechnologies/orient/core/storage/impl/local/paginated/StorageBackupMTIT.java @@ -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; @@ -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(); @@ -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); @@ -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); diff --git a/agent/src/test/java/com/orientechnologies/orient/core/storage/impl/local/paginated/StorageBackupTestWithLuceneIndex.java b/agent/src/test/java/com/orientechnologies/orient/core/storage/impl/local/paginated/StorageBackupTestWithLuceneIndex.java index 537ad35430d..ef3837283b4 100755 --- a/agent/src/test/java/com/orientechnologies/orient/core/storage/impl/local/paginated/StorageBackupTestWithLuceneIndex.java +++ b/agent/src/test/java/com/orientechnologies/orient/core/storage/impl/local/paginated/StorageBackupTestWithLuceneIndex.java @@ -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; @@ -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 @@ -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)); @@ -108,7 +111,7 @@ 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); @@ -116,21 +119,22 @@ public void testSingeThreadFullBackup() throws IOException { 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( @@ -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(); @@ -170,22 +175,18 @@ 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 @@ -193,14 +194,17 @@ public void testSingeThreadIncrementalBackup() throws IOException { + "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( diff --git a/agent/src/test/java/com/orientechnologies/orient/server/distributed/AbstractEnterpriseServerClusterTest.java b/agent/src/test/java/com/orientechnologies/orient/server/distributed/AbstractEnterpriseServerClusterTest.java index fba15512f21..4898368921e 100755 --- a/agent/src/test/java/com/orientechnologies/orient/server/distributed/AbstractEnterpriseServerClusterTest.java +++ b/agent/src/test/java/com/orientechnologies/orient/server/distributed/AbstractEnterpriseServerClusterTest.java @@ -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; @@ -66,7 +63,6 @@ private static void syntaxError() { } public void init(final int servers) { - ODatabaseDocumentTx.closeAll(); GroupProperty.WAIT_SECONDS_BEFORE_JOIN.setSystemProperty("1"); @@ -277,7 +273,6 @@ protected void prepare( onAfterDatabaseCreation(graph); } finally { graph.close(); - ODatabaseDocumentTx.closeAll(); } } @@ -316,25 +311,6 @@ protected void executeWhen(final Callable condition, final Callable act } } - protected void executeWhen( - int serverId, - OCallable condition, - OCallable 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 condition, @@ -398,47 +374,6 @@ protected void waitForDatabaseIsOnline( } } - protected void waitFor( - final int serverId, - final OCallable 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 condition, final String message) { final long startTime = System.currentTimeMillis(); diff --git a/agent/src/test/java/com/orientechnologies/orient/server/distributed/AbstractServerClusterTest.java b/agent/src/test/java/com/orientechnologies/orient/server/distributed/AbstractServerClusterTest.java index c8ba7e40e12..fdccc582781 100755 --- a/agent/src/test/java/com/orientechnologies/orient/server/distributed/AbstractServerClusterTest.java +++ b/agent/src/test/java/com/orientechnologies/orient/server/distributed/AbstractServerClusterTest.java @@ -23,10 +23,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; @@ -89,7 +86,6 @@ private static void syntaxError() { } public void init(final int servers) { - ODatabaseDocumentTx.closeAll(); GroupProperty.WAIT_SECONDS_BEFORE_JOIN.setSystemProperty("1"); @@ -290,7 +286,6 @@ protected void prepare( onAfterDatabaseCreation(graph); } finally { graph.close(); - ODatabaseDocumentTx.closeAll(); } } @@ -329,25 +324,6 @@ protected void executeWhen(final Callable condition, final Callable act } } - protected void executeWhen( - int serverId, - OCallable condition, - OCallable 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 condition, @@ -411,47 +387,6 @@ protected void waitForDatabaseIsOnline( } } - protected void waitFor( - final int serverId, - final OCallable 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 condition, final String message) { final long startTime = System.currentTimeMillis(); diff --git a/agent/src/test/java/com/orientechnologies/orient/server/distributed/ConnectionStrategiesEEIT.java b/agent/src/test/java/com/orientechnologies/orient/server/distributed/ConnectionStrategiesEEIT.java index c5c28253129..07d5b353131 100755 --- a/agent/src/test/java/com/orientechnologies/orient/server/distributed/ConnectionStrategiesEEIT.java +++ b/agent/src/test/java/com/orientechnologies/orient/server/distributed/ConnectionStrategiesEEIT.java @@ -11,7 +11,6 @@ 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.ODatabaseDocumentTx; import com.orientechnologies.orient.core.sql.executor.OResultSet; import com.orientechnologies.orient.server.OServer; import java.io.IOException; @@ -260,6 +259,5 @@ public void after() throws InterruptedException { server0.shutdown(); server1.shutdown(); server2.shutdown(); - ODatabaseDocumentTx.closeAll(); } } diff --git a/agent/src/test/java/com/orientechnologies/orient/server/distributed/HAMultiDCCrudTest.java b/agent/src/test/java/com/orientechnologies/orient/server/distributed/HAMultiDCCrudTest.java index 885c8151f07..62142b74965 100755 --- a/agent/src/test/java/com/orientechnologies/orient/server/distributed/HAMultiDCCrudTest.java +++ b/agent/src/test/java/com/orientechnologies/orient/server/distributed/HAMultiDCCrudTest.java @@ -1,7 +1,8 @@ package com.orientechnologies.orient.server.distributed; +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.sql.executor.OResultSet; import java.util.Collections; import java.util.List; @@ -64,16 +65,18 @@ protected void executeTest() throws Exception { Assert.assertTrue(austinDc.contains("usa-1")); Assert.assertTrue(austinDc.contains("usa-2")); - ODatabaseDocument db = new ODatabaseDocumentTx("remote:localhost:2424/" + getDatabaseName()); - db.open("admin", "admin"); + OrientDB ctx = new OrientDB("remote:localhost:2424", OrientDBConfig.defaultConfig()); + OrientDB ctx1 = new OrientDB("remote:localhost:2425", OrientDBConfig.defaultConfig()); + OrientDB ctx2 = new OrientDB("remote:localhost:2426", OrientDBConfig.defaultConfig()); + + ODatabaseDocument db = ctx.open(getDatabaseName(), "admin", "admin"); try { db.command("INSERT into Item (name) values ('foo')").close(); } finally { db.close(); } - db = new ODatabaseDocumentTx("remote:localhost:2425/" + getDatabaseName()); - db.open("admin", "admin"); + db = ctx1.open(getDatabaseName(), "admin", "admin"); try { OResultSet result = db.command("select set(name) as names from Item"); Assert.assertEquals(Collections.singleton("foo"), result.next().getProperty("names")); @@ -91,8 +94,7 @@ protected void executeTest() throws Exception { } // TRY AN INSERT AGAINST THE DC WITHOUT QUORUM EXPECTING TO FAIL - db = new ODatabaseDocumentTx("remote:localhost:2426/" + getDatabaseName()); - db.open("admin", "admin"); + db = ctx2.open(getDatabaseName(), "admin", "admin"); try { db.command("INSERT into Item (map) values ({'a':'b'}) return @this").close(); Assert.fail("Quorum not reached, but no failure has been caught"); @@ -106,8 +108,7 @@ protected void executeTest() throws Exception { serverInstance.get(0).getServerInstance().shutdown(); // RETRY AN INSERT AND CHECK IT FAILS (NO QUORUM) - db = new ODatabaseDocumentTx("remote:localhost:2425/" + getDatabaseName()); - db.open("admin", "admin"); + db = ctx1.open(getDatabaseName(), "admin", "admin"); try { db.command("INSERT into Item (map) values ({'a':'b'}) return @this").close(); Assert.fail("Quorum not reached, but no failure has been caught"); @@ -126,13 +127,15 @@ protected void executeTest() throws Exception { 30000); // RETRY AN INSERT AND CHECK IT DOESN'T FAILS (QUORUM REACHED) - db = new ODatabaseDocumentTx("remote:localhost:2425/" + getDatabaseName()); - db.open("admin", "admin"); + db = ctx1.open(getDatabaseName(), "admin", "admin"); try { db.command("INSERT into Item (map) values ({'a':'b'}) return @this").close(); } finally { db.close(); } + ctx.close(); + ctx1.close(); + ctx2.close(); } @Override diff --git a/agent/src/test/java/com/orientechnologies/orient/server/distributed/ServerRun.java b/agent/src/test/java/com/orientechnologies/orient/server/distributed/ServerRun.java index 8219e97cab8..9423d3dbc17 100755 --- a/agent/src/test/java/com/orientechnologies/orient/server/distributed/ServerRun.java +++ b/agent/src/test/java/com/orientechnologies/orient/server/distributed/ServerRun.java @@ -18,7 +18,6 @@ import com.orientechnologies.common.io.OFileUtils; import com.orientechnologies.common.util.OCallable; import com.orientechnologies.orient.core.Orient; -import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; import com.orientechnologies.orient.server.OServer; import com.orientechnologies.orient.server.OServerMain; import com.orientechnologies.orient.server.hazelcast.OHazelcastPlugin; @@ -167,9 +166,7 @@ public void terminateServer() { closeStorages(); } - public void closeStorages() { - ODatabaseDocumentTx.closeAll(); - } + public void closeStorages() {} protected String getServerHome() { return getServerHome(serverId); diff --git a/core/src/test/java/com/orientechnologies/orient/core/index/OPropertySBTreeRidBagIndexDefinitionTest.java b/core/src/test/java/com/orientechnologies/orient/core/index/OPropertySBTreeRidBagIndexDefinitionTest.java index e665f373381..931add5849f 100644 --- a/core/src/test/java/com/orientechnologies/orient/core/index/OPropertySBTreeRidBagIndexDefinitionTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/index/OPropertySBTreeRidBagIndexDefinitionTest.java @@ -1,8 +1,9 @@ package com.orientechnologies.orient.core.index; import com.orientechnologies.orient.core.config.OGlobalConfiguration; +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 org.junit.After; import org.junit.Before; @@ -12,25 +13,27 @@ */ public class OPropertySBTreeRidBagIndexDefinitionTest extends OPropertyRidBagAbstractIndexDefinition { + private OrientDB context; protected ODatabaseDocument database; private int topThreshold; private int bottomThreshold; - public OPropertySBTreeRidBagIndexDefinitionTest() { + @Before + public void beforeMethod() { final String buildDirectory = System.getProperty("buildDirectory", "."); - final String url = "plocal:" + buildDirectory + "/test-db/" + this.getClass().getSimpleName(); - database = new ODatabaseDocumentTx(url); - if (database.exists()) { - database.open("admin", "admin"); - database.drop(); + String dbName = this.getClass().getSimpleName(); + context = + new OrientDB("embedded:" + buildDirectory + "/test-db/", OrientDBConfig.defaultConfig()); + if (context.exists(dbName)) { + context.drop(dbName); } + context + .execute( + "create database " + + dbName + + " plocal users(admin identified by 'adminpwd' role admin)") + .close(); - database.create(); - database.close(); - } - - @Before - public void beforeMethod2() { super.beforeMethod(); topThreshold = @@ -41,13 +44,14 @@ public void beforeMethod2() { OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.setValue(-1); OGlobalConfiguration.RID_BAG_SBTREEBONSAI_TO_EMBEDDED_THRESHOLD.setValue(-1); - database.open("admin", "admin"); + database = context.open(this.getClass().getSimpleName(), "admin", "adminpwd"); } @After public void afterMethod() { database.close(); - + context.drop(this.getClass().getSimpleName()); + context.close(); OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.setValue(topThreshold); OGlobalConfiguration.RID_BAG_SBTREEBONSAI_TO_EMBEDDED_THRESHOLD.setValue(bottomThreshold); } diff --git a/core/src/test/java/com/orientechnologies/orient/core/sql/OLiveQueryV2Test.java b/core/src/test/java/com/orientechnologies/orient/core/sql/OLiveQueryV2Test.java index 8b52fd9bfed..989bf698040 100755 --- a/core/src/test/java/com/orientechnologies/orient/core/sql/OLiveQueryV2Test.java +++ b/core/src/test/java/com/orientechnologies/orient/core/sql/OLiveQueryV2Test.java @@ -20,13 +20,12 @@ package com.orientechnologies.orient.core.sql; import com.orientechnologies.common.exception.OException; -import com.orientechnologies.orient.core.OCreateDatabaseUtil; -import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal; +import com.orientechnologies.orient.core.db.ODatabaseSession; import com.orientechnologies.orient.core.db.OLiveQueryMonitor; import com.orientechnologies.orient.core.db.OLiveQueryResultListener; 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.db.record.OIdentifiable; import com.orientechnologies.orient.core.id.ORID; import com.orientechnologies.orient.core.metadata.schema.OClass; @@ -43,11 +42,34 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; +import org.junit.After; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; /** @author Luigi Dell'Aquila (l.dellaquila - at - orientdb.com) */ public class OLiveQueryV2Test { + + private OrientDB context; + private ODatabaseSession db; + + @Before + public void before() { + context = new OrientDB("memory:", OrientDBConfig.defaultConfig()); + context + .execute( + "create database OLiveQueryV2Test memory users (admin identified by 'adminpwd' role" + + " admin, reader identified by 'readerpwd' role reader)") + .close(); + db = context.open("OLiveQueryV2Test", "admin", "adminpwd"); + } + + @After + public void after() { + db.close(); + context.close(); + } + class MyLiveQueryListener implements OLiveQueryResultListener { public CountDownLatch latch; @@ -84,238 +106,195 @@ public void onEnd(ODatabaseDocument database) {} @Test public void testLiveInsert() throws InterruptedException { - ODatabaseDocument db = new ODatabaseDocumentTx("memory:OLiveQueryV2Test"); - db.activateOnCurrentThread(); - db.create(); - try { - db.getMetadata().getSchema().createClass("test"); - db.getMetadata().getSchema().createClass("test2"); - MyLiveQueryListener listener = new MyLiveQueryListener(new CountDownLatch(2)); + db.getMetadata().getSchema().createClass("test"); + db.getMetadata().getSchema().createClass("test2"); + MyLiveQueryListener listener = new MyLiveQueryListener(new CountDownLatch(2)); - OLiveQueryMonitor monitor = db.live("select from test", listener); - Assert.assertNotNull(monitor); + OLiveQueryMonitor monitor = db.live("select from test", listener); + Assert.assertNotNull(monitor); - db.command("insert into test set name = 'foo', surname = 'bar'").close(); - db.command("insert into test set name = 'foo', surname = 'baz'").close(); - db.command("insert into test2 set name = 'foo'").close(); + db.command("insert into test set name = 'foo', surname = 'bar'").close(); + db.command("insert into test set name = 'foo', surname = 'baz'").close(); + db.command("insert into test2 set name = 'foo'").close(); - Assert.assertTrue(listener.latch.await(1, TimeUnit.MINUTES)); + Assert.assertTrue(listener.latch.await(1, TimeUnit.MINUTES)); + + monitor.unSubscribe(); + + db.command("insert into test set name = 'foo', surname = 'bax'").close(); + db.command("insert into test2 set name = 'foo'").close(); + db.command("insert into test set name = 'foo', surname = 'baz'").close(); - monitor.unSubscribe(); - - db.command("insert into test set name = 'foo', surname = 'bax'").close(); - db.command("insert into test2 set name = 'foo'").close(); - db.command("insert into test set name = 'foo', surname = 'baz'").close(); - - Assert.assertEquals(listener.ops.size(), 2); - for (OResult doc : listener.ops) { - Assert.assertEquals(doc.getProperty("@class"), "test"); - Assert.assertEquals(doc.getProperty("name"), "foo"); - ORID rid = doc.getProperty("@rid"); - Assert.assertTrue(rid.isPersistent()); - } - } finally { - db.drop(); + Assert.assertEquals(listener.ops.size(), 2); + for (OResult doc : listener.ops) { + Assert.assertEquals(doc.getProperty("@class"), "test"); + Assert.assertEquals(doc.getProperty("name"), "foo"); + ORID rid = doc.getProperty("@rid"); + Assert.assertTrue(rid.isPersistent()); } } @Test public void testLiveInsertOnCluster() { - final OrientDB context = - OCreateDatabaseUtil.createDatabase( - "testLiveInsertOnCluster", "embedded:", OCreateDatabaseUtil.TYPE_MEMORY); - try (ODatabaseDocumentInternal db = - (ODatabaseDocumentInternal) - context.open( - "testLiveInsertOnCluster", "admin", OCreateDatabaseUtil.NEW_ADMIN_PASSWORD)) { - - OClass clazz = db.getMetadata().getSchema().createClass("test"); - - int defaultCluster = clazz.getDefaultClusterId(); - String clusterName = db.getStorage().getClusterNameById(defaultCluster); - - OLiveQueryV2Test.MyLiveQueryListener listener = - new OLiveQueryV2Test.MyLiveQueryListener(new CountDownLatch(1)); - - db.live(" select from cluster:" + clusterName, listener); - - db.command("insert into cluster:" + clusterName + " set name = 'foo', surname = 'bar'"); - - try { - Assert.assertTrue(listener.latch.await(1, TimeUnit.MINUTES)); - } catch (InterruptedException e) { - e.printStackTrace(); - } - Assert.assertEquals(listener.ops.size(), 1); - for (OResult doc : listener.ops) { - Assert.assertEquals(doc.getProperty("name"), "foo"); - ORID rid = doc.getProperty("@rid"); - Assert.assertTrue(rid.isPersistent()); - Assert.assertNotNull(rid); - } + + OClass clazz = db.getMetadata().getSchema().createClass("test"); + + int defaultCluster = clazz.getDefaultClusterId(); + String clusterName = db.getClusterNameById(defaultCluster); + + OLiveQueryV2Test.MyLiveQueryListener listener = + new OLiveQueryV2Test.MyLiveQueryListener(new CountDownLatch(1)); + + db.live(" select from cluster:" + clusterName, listener); + + db.command("insert into cluster:" + clusterName + " set name = 'foo', surname = 'bar'"); + + try { + Assert.assertTrue(listener.latch.await(1, TimeUnit.MINUTES)); + } catch (InterruptedException e) { + e.printStackTrace(); + } + Assert.assertEquals(listener.ops.size(), 1); + for (OResult doc : listener.ops) { + Assert.assertEquals(doc.getProperty("name"), "foo"); + ORID rid = doc.getProperty("@rid"); + Assert.assertTrue(rid.isPersistent()); + Assert.assertNotNull(rid); } } @Test public void testLiveWithWhereCondition() { - final OrientDB context = - OCreateDatabaseUtil.createDatabase( - "testLiveWithWhereCondition", "embedded:", OCreateDatabaseUtil.TYPE_MEMORY); - try (ODatabaseDocumentInternal db = - (ODatabaseDocumentInternal) - context.open( - "testLiveWithWhereCondition", "admin", OCreateDatabaseUtil.NEW_ADMIN_PASSWORD)) { - - OClass clazz = db.getMetadata().getSchema().createClass("test"); - - int defaultCluster = clazz.getDefaultClusterId(); - String clusterName = db.getStorage().getClusterNameById(defaultCluster); - - OLiveQueryV2Test.MyLiveQueryListener listener = - new OLiveQueryV2Test.MyLiveQueryListener(new CountDownLatch(1)); - - db.live("select from V where id = 1", listener); - - db.command("insert into V set id = 1"); - - try { - Assert.assertTrue(listener.latch.await(1, TimeUnit.MINUTES)); - } catch (InterruptedException e) { - e.printStackTrace(); - } - Assert.assertEquals(listener.ops.size(), 1); - for (OResult doc : listener.ops) { - Assert.assertEquals(doc.getProperty("id"), Integer.valueOf(1)); - ORID rid = doc.getProperty("@rid"); - Assert.assertTrue(rid.isPersistent()); - Assert.assertNotNull(rid); - } + + OLiveQueryV2Test.MyLiveQueryListener listener = + new OLiveQueryV2Test.MyLiveQueryListener(new CountDownLatch(1)); + + db.live("select from V where id = 1", listener); + + db.command("insert into V set id = 1"); + + try { + Assert.assertTrue(listener.latch.await(1, TimeUnit.MINUTES)); + } catch (InterruptedException e) { + e.printStackTrace(); + } + Assert.assertEquals(listener.ops.size(), 1); + for (OResult doc : listener.ops) { + Assert.assertEquals(doc.getProperty("id"), Integer.valueOf(1)); + ORID rid = doc.getProperty("@rid"); + Assert.assertTrue(rid.isPersistent()); + Assert.assertNotNull(rid); } } @Test public void testRestrictedLiveInsert() throws ExecutionException, InterruptedException { - ODatabaseDocument db = new ODatabaseDocumentTx("memory:OLiveQueryTest"); - db.activateOnCurrentThread(); - db.create(); - try { - OSchema schema = db.getMetadata().getSchema(); - OClass oRestricted = schema.getClass("ORestricted"); - schema.createClass("test", oRestricted); - - int liveMatch = 2; - OResultSet query = db.query("select from OUSer where name = 'reader'"); - - final OIdentifiable reader = query.next().getIdentity().get(); - final OIdentifiable current = db.getUser().getIdentity(); - - ExecutorService executorService = Executors.newSingleThreadExecutor(); - - final CountDownLatch latch = new CountDownLatch(1); - final CountDownLatch dataArrived = new CountDownLatch(liveMatch); - Future future = - executorService.submit( - new Callable() { - @Override - public Integer call() throws Exception { - ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:OLiveQueryTest"); - db.open("reader", "reader"); - - final AtomicInteger integer = new AtomicInteger(0); - db.live( - "live select from test", - new OLiveQueryResultListener() { - - @Override - public void onCreate(ODatabaseDocument database, OResult data) { - integer.incrementAndGet(); - dataArrived.countDown(); - } - - @Override - public void onUpdate( - ODatabaseDocument database, OResult before, OResult after) { - integer.incrementAndGet(); - dataArrived.countDown(); - } - - @Override - public void onDelete(ODatabaseDocument database, OResult data) { - integer.incrementAndGet(); - dataArrived.countDown(); - } - - @Override - public void onError(ODatabaseDocument database, OException exception) {} - - @Override - public void onEnd(ODatabaseDocument database) {} - }); - - latch.countDown(); - Assert.assertTrue(dataArrived.await(1, TimeUnit.MINUTES)); - return integer.get(); - } - }); - - latch.await(); - - db.command("insert into test set name = 'foo', surname = 'bar'").close(); - - db.command( - "insert into test set name = 'foo', surname = 'bar', _allow=?", - new ArrayList() { - { - add(current); - add(reader); - } - }) - .close(); - - Integer integer = future.get(); - Assert.assertEquals(integer.intValue(), liveMatch); - } finally { - db.drop(); - } + OSchema schema = db.getMetadata().getSchema(); + OClass oRestricted = schema.getClass("ORestricted"); + schema.createClass("test", oRestricted); + + int liveMatch = 2; + OResultSet query = db.query("select from OUSer where name = 'reader'"); + + final OIdentifiable reader = query.next().getIdentity().get(); + final OIdentifiable current = db.getUser().getIdentity(); + + ExecutorService executorService = Executors.newSingleThreadExecutor(); + + final CountDownLatch latch = new CountDownLatch(1); + final CountDownLatch dataArrived = new CountDownLatch(liveMatch); + Future future = + executorService.submit( + new Callable() { + @Override + public Integer call() throws Exception { + ODatabaseSession db = context.open("OLiveQueryV2Test", "reader", "readerpwd"); + + final AtomicInteger integer = new AtomicInteger(0); + db.live( + "live select from test", + new OLiveQueryResultListener() { + + @Override + public void onCreate(ODatabaseDocument database, OResult data) { + integer.incrementAndGet(); + dataArrived.countDown(); + } + + @Override + public void onUpdate( + ODatabaseDocument database, OResult before, OResult after) { + integer.incrementAndGet(); + dataArrived.countDown(); + } + + @Override + public void onDelete(ODatabaseDocument database, OResult data) { + integer.incrementAndGet(); + dataArrived.countDown(); + } + + @Override + public void onError(ODatabaseDocument database, OException exception) {} + + @Override + public void onEnd(ODatabaseDocument database) {} + }); + + latch.countDown(); + Assert.assertTrue(dataArrived.await(1, TimeUnit.MINUTES)); + return integer.get(); + } + }); + + latch.await(); + + db.command("insert into test set name = 'foo', surname = 'bar'").close(); + + db.command( + "insert into test set name = 'foo', surname = 'bar', _allow=?", + new ArrayList() { + { + add(current); + add(reader); + } + }) + .close(); + + Integer integer = future.get(); + Assert.assertEquals(integer.intValue(), liveMatch); } @Test public void testLiveProjections() throws InterruptedException { - ODatabaseDocument db = new ODatabaseDocumentTx("memory:OLiveQueryV2Test"); - db.activateOnCurrentThread(); - db.create(); - try { - db.getMetadata().getSchema().createClass("test"); - db.getMetadata().getSchema().createClass("test2"); - MyLiveQueryListener listener = new MyLiveQueryListener(new CountDownLatch(2)); - - OLiveQueryMonitor monitor = db.live("select @class, @rid as rid, name from test", listener); - Assert.assertNotNull(monitor); - - db.command("insert into test set name = 'foo', surname = 'bar'").close(); - db.command("insert into test set name = 'foo', surname = 'baz'").close(); - db.command("insert into test2 set name = 'foo'").close(); - - Assert.assertTrue(listener.latch.await(5, TimeUnit.SECONDS)); - - monitor.unSubscribe(); - - db.command("insert into test set name = 'foo', surname = 'bax'").close(); - db.command("insert into test2 set name = 'foo'").close(); - ; - db.command("insert into test set name = 'foo', surname = 'baz'").close(); - - Assert.assertEquals(listener.ops.size(), 2); - for (OResult doc : listener.ops) { - Assert.assertEquals(doc.getProperty("@class"), "test"); - Assert.assertEquals(doc.getProperty("name"), "foo"); - Assert.assertNull(doc.getProperty("surname")); - ORID rid = doc.getProperty("rid"); - Assert.assertTrue(rid.isPersistent()); - } - } finally { - db.drop(); + db.getMetadata().getSchema().createClass("test"); + db.getMetadata().getSchema().createClass("test2"); + MyLiveQueryListener listener = new MyLiveQueryListener(new CountDownLatch(2)); + + OLiveQueryMonitor monitor = db.live("select @class, @rid as rid, name from test", listener); + Assert.assertNotNull(monitor); + + db.command("insert into test set name = 'foo', surname = 'bar'").close(); + db.command("insert into test set name = 'foo', surname = 'baz'").close(); + db.command("insert into test2 set name = 'foo'").close(); + + Assert.assertTrue(listener.latch.await(5, TimeUnit.SECONDS)); + + monitor.unSubscribe(); + + db.command("insert into test set name = 'foo', surname = 'bax'").close(); + db.command("insert into test2 set name = 'foo'").close(); + ; + db.command("insert into test set name = 'foo', surname = 'baz'").close(); + + Assert.assertEquals(listener.ops.size(), 2); + for (OResult doc : listener.ops) { + Assert.assertEquals(doc.getProperty("@class"), "test"); + Assert.assertEquals(doc.getProperty("name"), "foo"); + Assert.assertNull(doc.getProperty("surname")); + ORID rid = doc.getProperty("rid"); + Assert.assertTrue(rid.isPersistent()); } } } diff --git a/object/src/main/java/com/orientechnologies/orient/object/db/OObjectLazyList.java b/object/src/main/java/com/orientechnologies/orient/object/db/OObjectLazyList.java index f2552022117..355c98b1fb7 100644 --- a/object/src/main/java/com/orientechnologies/orient/object/db/OObjectLazyList.java +++ b/object/src/main/java/com/orientechnologies/orient/object/db/OObjectLazyList.java @@ -514,8 +514,8 @@ private void convertAndDetachAll( .getProxiedInstance( doc.getClassName(), getDatabase().getEntityManager(), doc, sourceRecord); o = - ((OObjectDatabaseTx) getDatabase()) - .detachAll(o, nonProxiedInstance, alreadyDetached, lazyObjects); + OObjectEntitySerializer.detachAll( + o, getDatabase(), nonProxiedInstance, alreadyDetached, lazyObjects); super.set(iIndex, (TYPE) o); } } diff --git a/object/src/main/java/com/orientechnologies/orient/object/db/OObjectLazyMap.java b/object/src/main/java/com/orientechnologies/orient/object/db/OObjectLazyMap.java index 6bcc771dd06..26520964b45 100644 --- a/object/src/main/java/com/orientechnologies/orient/object/db/OObjectLazyMap.java +++ b/object/src/main/java/com/orientechnologies/orient/object/db/OObjectLazyMap.java @@ -288,8 +288,8 @@ protected void convertAndDetachAll( getDatabase() .getUserObjectByRecord((ORecord) ((OIdentifiable) e.getValue()).getRecord(), null); o = - ((OObjectDatabaseTx) getDatabase()) - .detachAll(o, nonProxiedInstance, alreadyDetached, lazyObjects); + OObjectEntitySerializer.detachAll( + o, getDatabase(), nonProxiedInstance, alreadyDetached, lazyObjects); super.put(e.getKey(), o); } diff --git a/object/src/main/java/com/orientechnologies/orient/object/db/OObjectLazySet.java b/object/src/main/java/com/orientechnologies/orient/object/db/OObjectLazySet.java index 71867d86b68..fd44c466433 100644 --- a/object/src/main/java/com/orientechnologies/orient/object/db/OObjectLazySet.java +++ b/object/src/main/java/com/orientechnologies/orient/object/db/OObjectLazySet.java @@ -22,6 +22,7 @@ import com.orientechnologies.orient.core.id.ORID; import com.orientechnologies.orient.core.record.ORecord; import com.orientechnologies.orient.core.record.impl.ODocument; +import com.orientechnologies.orient.object.enhancement.OObjectEntitySerializer; import com.orientechnologies.orient.object.enhancement.OObjectProxyMethodHandler; import java.io.Serializable; import java.util.Collection; @@ -324,14 +325,14 @@ protected void convertAndDetachAll( fetchPlan); super.add( (TYPE) - ((OObjectDatabaseTx) getDatabase()) - .detachAll(e, nonProxiedInstance, alreadyDetached, lazyObjects)); + OObjectEntitySerializer.detachAll( + e, getDatabase(), nonProxiedInstance, alreadyDetached, lazyObjects)); } else if (e instanceof ODocument) { e = database.getUserObjectByRecord((ORecord) e, fetchPlan); super.add( (TYPE) - ((OObjectDatabaseTx) getDatabase()) - .detachAll(e, nonProxiedInstance, alreadyDetached, lazyObjects)); + OObjectEntitySerializer.detachAll( + e, getDatabase(), nonProxiedInstance, alreadyDetached, lazyObjects)); } else add((TYPE) e); } } diff --git a/security/src/test/java/com/orientechnologies/security/kerberos/KerberosClientTest.java b/security/src/test/java/com/orientechnologies/security/kerberos/KerberosClientTest.java index eab64fd5b2b..9e1a61dfd35 100644 --- a/security/src/test/java/com/orientechnologies/security/kerberos/KerberosClientTest.java +++ b/security/src/test/java/com/orientechnologies/security/kerberos/KerberosClientTest.java @@ -1,9 +1,10 @@ package com.orientechnologies.security.kerberos; -import com.orientechnologies.orient.client.remote.OServerAdmin; import com.orientechnologies.orient.core.config.OGlobalConfiguration; +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.document.ODatabaseDocument; -import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; import com.orientechnologies.orient.core.exception.OSecurityException; import com.orientechnologies.security.AbstractSecurityTest; import java.io.IOException; @@ -22,22 +23,20 @@ public class KerberosClientTest extends AbstractSecurityTest { private static final String kerbServer = "kerby.odbrealm.com"; private static final String testDB = "TestDB"; - private static final String url = "remote:" + kerbServer + "/" + testDB; private static final String kerbUser = "orientdb@ODBREALM.COM"; private static final String spn = "OrientDB/kerby.odbrealm.com"; private static final String ccache = "/home/jenkins/ccache"; @BeforeClass public static void beforeClass() throws Exception { - OServerAdmin serverAd = new OServerAdmin(kerbServer); - serverAd.connect("root", "password"); + OrientDB remote = + new OrientDB("remote:" + kerbServer, "root", "password", OrientDBConfig.defaultConfig()); - if (!serverAd.existsDatabase(testDB, "plocal")) { - serverAd.createDatabase(testDB, "graph", "plocal"); + if (!remote.exists(testDB)) { + remote.create(testDB, ODatabaseType.MEMORY); // orientdb@ODBREALM.COM - ODatabaseDocument db = new ODatabaseDocumentTx(url); - db.open("root", "password"); + ODatabaseDocument db = remote.open(testDB, "root", "password"); try { // Create the Kerberos client user. @@ -50,7 +49,7 @@ public static void beforeClass() throws Exception { } } - serverAd.close(); + remote.close(); OGlobalConfiguration.CLIENT_CREDENTIAL_INTERCEPTOR.setValue( "com.orientechnologies.orient.core.security.kerberos.OKerberosCredentialInterceptor"); @@ -67,11 +66,12 @@ public void defaultSPNTest() throws InterruptedException, IOException { Assert.assertTrue(fileExists(ccache)); OGlobalConfiguration.CLIENT_KRB5_CCNAME.setValue(ccache); + OrientDB remote = new OrientDB("remote:" + kerbServer, OrientDBConfig.defaultConfig()); - ODatabaseDocument db = new ODatabaseDocumentTx(url); - db.open(kerbUser, ""); + ODatabaseDocument db = remote.open(testDB, kerbUser, ""); db.close(); + remote.close(); } @Test @@ -81,11 +81,11 @@ public void explicitSPNTest() throws InterruptedException, IOException { Assert.assertTrue(fileExists(ccache)); OGlobalConfiguration.CLIENT_KRB5_CCNAME.setValue(ccache); - - ODatabaseDocument db = new ODatabaseDocumentTx(url); - db.open(kerbUser, spn); + OrientDB remote = new OrientDB("remote:" + kerbServer, OrientDBConfig.defaultConfig()); + ODatabaseDocument db = remote.open(testDB, kerbUser, spn); db.close(); + remote.close(); } @Test(expected = OSecurityException.class) @@ -95,10 +95,10 @@ public void shouldFailAuthenticationTest() throws InterruptedException, IOExcept shellCommand(String.format("echo password | kinit -c %s orientdb", ccache)); OGlobalConfiguration.CLIENT_KRB5_CCNAME.setValue(wrongcache); - - ODatabaseDocument db = new ODatabaseDocumentTx(url); - db.open(kerbUser, spn); + OrientDB remote = new OrientDB("remote:" + kerbServer, OrientDBConfig.defaultConfig()); + ODatabaseDocument db = remote.open(testDB, kerbUser, spn); db.close(); + remote.close(); } } diff --git a/security/src/test/java/com/orientechnologies/security/symmetrickey/OSecuritySymmetricKeyTest.java b/security/src/test/java/com/orientechnologies/security/symmetrickey/OSecuritySymmetricKeyTest.java index 6d0ccfe8a1e..8477538b7bb 100755 --- a/security/src/test/java/com/orientechnologies/security/symmetrickey/OSecuritySymmetricKeyTest.java +++ b/security/src/test/java/com/orientechnologies/security/symmetrickey/OSecuritySymmetricKeyTest.java @@ -4,7 +4,6 @@ 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.exception.OSecurityAccessException; import com.orientechnologies.orient.core.security.symmetrickey.OSymmetricKey; import com.orientechnologies.orient.server.OServer; @@ -82,11 +81,12 @@ public static void afterClass() { public void shouldTestSpecificAESKeyFailure() throws Exception { OSymmetricKey sk = new OSymmetricKey("AES", "AAC7LeGkFbmHEYNTz5GwDw=="); + OrientDB remote = new OrientDB("remote:localhost", OrientDBConfig.defaultConfig()); // "test" is the username. It's specified in the security.json resource file. - ODatabaseDocument db = new ODatabaseDocumentTx(DATABASE_URL); // We encrypt the username and specify the Base64-encoded JSON document as the password. - db.open("test", sk.encrypt("AES/CBC/PKCS5Padding", "test")); + ODatabaseDocument db = remote.open(TESTDB, "test", sk.encrypt("AES/CBC/PKCS5Padding", "test")); db.close(); + remote.close(); } @Test @@ -94,11 +94,12 @@ public void shouldTestSpecificAESKey() throws Exception { // This key is specified in the security.json resource file. OSymmetricKey sk = new OSymmetricKey("AES", "8BC7LeGkFbmHEYNTz5GwDw=="); + OrientDB remote = new OrientDB("remote:localhost", OrientDBConfig.defaultConfig()); // "test" is the username. It's specified in the security.json resource file. - ODatabaseDocument db = new ODatabaseDocumentTx(DATABASE_URL); // We encrypt the username and specify the Base64-encoded JSON document as the password. - db.open("test", sk.encrypt("AES/CBC/PKCS5Padding", "test")); + ODatabaseDocument db = remote.open(TESTDB, "test", sk.encrypt("AES/CBC/PKCS5Padding", "test")); db.close(); + remote.close(); } @Test @@ -106,11 +107,13 @@ public void shouldTestKeyFile() throws Exception { OSymmetricKey sk = OSymmetricKey.fromStream("AES", new FileInputStream(SERVER_DIRECTORY + "/config/AES.key")); + OrientDB remote = new OrientDB("remote:localhost", OrientDBConfig.defaultConfig()); // "test2" is the username. It's specified in the security.json resource file. - ODatabaseDocument db = new ODatabaseDocumentTx(DATABASE_URL); // We encrypt the username and specify the Base64-encoded JSON document as the password. - db.open("test2", sk.encrypt("AES/CBC/PKCS5Padding", "test2")); + ODatabaseDocument db = + remote.open(TESTDB, "test2", sk.encrypt("AES/CBC/PKCS5Padding", "test2")); db.close(); + remote.close(); } @Test @@ -122,10 +125,12 @@ public void shouldTestKeystore() throws Exception { "keyAlias", "password"); + OrientDB remote = new OrientDB("remote:localhost", OrientDBConfig.defaultConfig()); // "test3" is the username. It's specified in the security.json resource file. - ODatabaseDocument db = new ODatabaseDocumentTx(DATABASE_URL); // We encrypt the username and specify the Base64-encoded JSON document as the password. - db.open("test3", sk.encrypt("AES/CBC/PKCS5Padding", "test3")); + ODatabaseDocument db = + remote.open(TESTDB, "test3", sk.encrypt("AES/CBC/PKCS5Padding", "test3")); db.close(); + remote.close(); } } diff --git a/security/src/test/java/com/orientechnologies/security/symmetrickey/OSystemSymmetricKeyTest.java b/security/src/test/java/com/orientechnologies/security/symmetrickey/OSystemSymmetricKeyTest.java index c181d70d507..45d2d963a33 100755 --- a/security/src/test/java/com/orientechnologies/security/symmetrickey/OSystemSymmetricKeyTest.java +++ b/security/src/test/java/com/orientechnologies/security/symmetrickey/OSystemSymmetricKeyTest.java @@ -4,7 +4,6 @@ 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.security.symmetrickey.OSymmetricKey; import com.orientechnologies.orient.server.OServer; import com.orientechnologies.security.AbstractSecurityTest; @@ -103,11 +102,13 @@ public void shouldTestSystemUserWithKey() throws Exception { OSymmetricKey sk = new OSymmetricKey("AES", "8BC7LeGkFbmHEYNTz5GwDw=="); + OrientDB remote = new OrientDB("remote:localhost", OrientDBConfig.defaultConfig()); // "sysuser" is the username. We just created it in OSystem. - ODatabaseDocument db = new ODatabaseDocumentTx(DATABASE_URL); // We encrypt the username and specify the Base64-encoded JSON document as the password. - db.open(sysuser, sk.encrypt("AES/CBC/PKCS5Padding", sysuser)); + ODatabaseDocument db = + remote.open(TESTDB, sysuser, sk.encrypt("AES/CBC/PKCS5Padding", sysuser)); db.close(); + remote.close(); } @Test @@ -135,11 +136,13 @@ public void shouldTestSystemUserWithKeyFile() throws Exception { OSymmetricKey sk = OSymmetricKey.fromStream("AES", new FileInputStream(SERVER_DIRECTORY + "/config/AES.key")); + OrientDB remote = new OrientDB("remote:localhost", OrientDBConfig.defaultConfig()); // "sysuser" is the username. We just created it in OSystem. - ODatabaseDocument db = new ODatabaseDocumentTx(DATABASE_URL); // We encrypt the username and specify the Base64-encoded JSON document as the password. - db.open(sysuser, sk.encrypt("AES/CBC/PKCS5Padding", sysuser)); + ODatabaseDocument db = + remote.open(TESTDB, sysuser, sk.encrypt("AES/CBC/PKCS5Padding", sysuser)); db.close(); + remote.close(); } @Test @@ -171,10 +174,12 @@ public void shouldTestSystemUserWithKeystore() throws Exception { "keyAlias", "password"); + OrientDB remote = new OrientDB("remote:localhost", OrientDBConfig.defaultConfig()); // "sysuser" is the username. We just created it in OSystem. - ODatabaseDocument db = new ODatabaseDocumentTx(DATABASE_URL); // We encrypt the username and specify the Base64-encoded JSON document as the password. - db.open(sysuser, sk.encrypt("AES/CBC/PKCS5Padding", sysuser)); + ODatabaseDocument db = + remote.open(TESTDB, sysuser, sk.encrypt("AES/CBC/PKCS5Padding", sysuser)); db.close(); + remote.close(); } } 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 0cb781b88ee..e8b9f13f6b1 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 @@ -1,10 +1,14 @@ package com.orientechnologies.orient.test.database.auto; +import com.orientechnologies.common.log.OLogManager; +import com.orientechnologies.common.log.OLogger; +import com.orientechnologies.orient.client.db.ODatabaseHelper; 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; import org.testng.annotations.Parameters; import org.testng.annotations.Test; @@ -15,6 +19,8 @@ */ @Test public class ObjectDBBaseTest extends BaseTest { + private static final OLogger logger = OLogManager.instance().logger(ObjectDBBaseTest.class); + public ObjectDBBaseTest() {} @Parameters(value = "url") @@ -52,4 +58,11 @@ protected void reopenpool(String user, String password) { protected ODatabaseObject openpool(String user, String password) { return OObjectDatabasePool.global().acquire(url, 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); + } } diff --git a/tests/src/test/java/com/orientechnologies/orient/test/database/auto/ObjectEnhancingTestSchemaFull.java b/tests/src/test/java/com/orientechnologies/orient/test/database/auto/ObjectEnhancingTestSchemaFull.java index 3c4399fb397..8ac122d8a0f 100644 --- a/tests/src/test/java/com/orientechnologies/orient/test/database/auto/ObjectEnhancingTestSchemaFull.java +++ b/tests/src/test/java/com/orientechnologies/orient/test/database/auto/ObjectEnhancingTestSchemaFull.java @@ -17,10 +17,8 @@ import com.orientechnologies.common.log.OLogManager; import com.orientechnologies.common.log.OLogger; -import com.orientechnologies.orient.client.db.ODatabaseHelper; import com.orientechnologies.orient.core.id.ORID; import com.orientechnologies.orient.core.record.impl.ODocument; -import com.orientechnologies.orient.object.db.OObjectDatabasePool; import com.orientechnologies.orient.object.enhancement.OObjectEntityEnhancer; import com.orientechnologies.orient.object.enhancement.OObjectMethodFilter; import com.orientechnologies.orient.test.domain.base.CustomMethodFilterTestClass; @@ -106,9 +104,6 @@ protected String getFieldName(String methodName, String prefix) { @AfterClass public void end() 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); + dropdb(); } }