From fa2eac62b15d49ffef36ded7c7451f8b695ead18 Mon Sep 17 00:00:00 2001 From: Tglman Date: Mon, 23 Oct 2023 14:55:54 +0100 Subject: [PATCH] refactor: removed usage of deprecated API from test cases --- .../security/ORestricetedUserCleanUpTest.java | 98 ++++++------- .../OCommandExecutorSQLCreateEdgeTest.java | 30 +--- .../OCommandExecutorSQLDeleteVertexTest.java | 22 +-- .../OCreateUserStatementExecutionTest.java | 19 +-- .../ODropPropertyStatementExecutionTest.java | 19 +-- .../ODropSequenceStatementExecutionTest.java | 19 +-- .../ODropUserStatementExecutionTest.java | 19 +-- .../ODropViewStatementExecutionTest.java | 24 +--- .../OExplainStatementExecutionTest.java | 20 +-- .../OOptimizeDatabaseExecutionTest.java | 28 +--- .../OProfileStatementExecutionTest.java | 20 +-- .../ORollbackStatementExecutionTest.java | 19 +-- .../sql/executor/OScriptExecutionTest.java | 19 +-- .../OSelectStatementExecutionTest.java | 25 +--- .../OSelectStatementExecutionTestIT.java | 20 +-- .../OSleepStatementExecutionTest.java | 19 +-- .../OTraverseStatementExecutionTest.java | 24 +--- .../misc/OSQLFunctionIndexKeySizeTest.java | 8 +- .../sql/OCustomSQLFunctionsTest.java | 19 +-- .../sql/functions/sql/OFunctionSqlTest.java | 13 +- ...DuplicateDictionaryIndexChangesTxTest.java | 103 ++++++++------ .../DuplicateNonUniqueIndexChangesTxTest.java | 108 ++++++++------ .../tx/DuplicateUniqueIndexChangesTxTest.java | 133 +++++++++++------- 23 files changed, 298 insertions(+), 530 deletions(-) diff --git a/core/src/test/java/com/orientechnologies/orient/core/metadata/security/ORestricetedUserCleanUpTest.java b/core/src/test/java/com/orientechnologies/orient/core/metadata/security/ORestricetedUserCleanUpTest.java index 3a94b9dc490..b7efc2121bc 100755 --- a/core/src/test/java/com/orientechnologies/orient/core/metadata/security/ORestricetedUserCleanUpTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/metadata/security/ORestricetedUserCleanUpTest.java @@ -1,8 +1,7 @@ package com.orientechnologies.orient.core.metadata.security; +import com.orientechnologies.BaseMemoryDatabase; import com.orientechnologies.common.directmemory.ODirectMemoryAllocator; -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.metadata.schema.OSchema; import com.orientechnologies.orient.core.record.impl.ODocument; @@ -11,65 +10,58 @@ import org.junit.Assert; import org.junit.Test; -public class ORestricetedUserCleanUpTest { +public class ORestricetedUserCleanUpTest extends BaseMemoryDatabase { @Test public void testAutoCleanUserAfterDelate() { - ODatabaseDocument db = - new ODatabaseDocumentTx("memory:" + ORestricetedUserCleanUpTest.class.getSimpleName()); - db.create(); - try { - OSchema schema = db.getMetadata().getSchema(); - schema.createClass("TestRecord", schema.getClass(OSecurityShared.RESTRICTED_CLASSNAME)); + OSchema schema = db.getMetadata().getSchema(); + schema.createClass("TestRecord", schema.getClass(OSecurityShared.RESTRICTED_CLASSNAME)); - System.gc(); - ODirectMemoryAllocator.instance().checkTrackedPointerLeaks(); + System.gc(); + ODirectMemoryAllocator.instance().checkTrackedPointerLeaks(); - OSecurity security = db.getMetadata().getSecurity(); - OUser auser = security.createUser("auser", "wherever", new String[] {}); - OUser reader = security.getUser("admin"); - ODocument doc = new ODocument("TestRecord"); - Set users = new HashSet(); - users.add(auser.getIdentity()); - users.add(reader.getIdentity()); - doc.field(OSecurityShared.ALLOW_READ_FIELD, users); - doc.field(OSecurityShared.ALLOW_UPDATE_FIELD, users); - doc.field(OSecurityShared.ALLOW_DELETE_FIELD, users); - doc.field(OSecurityShared.ALLOW_ALL_FIELD, users); - ODocument rid = db.save(doc); + OSecurity security = db.getMetadata().getSecurity(); + OUser auser = security.createUser("auser", "wherever", new String[] {}); + OUser reader = security.getUser("admin"); + ODocument doc = new ODocument("TestRecord"); + Set users = new HashSet(); + users.add(auser.getIdentity()); + users.add(reader.getIdentity()); + doc.field(OSecurityShared.ALLOW_READ_FIELD, users); + doc.field(OSecurityShared.ALLOW_UPDATE_FIELD, users); + doc.field(OSecurityShared.ALLOW_DELETE_FIELD, users); + doc.field(OSecurityShared.ALLOW_ALL_FIELD, users); + ODocument rid = db.save(doc); - System.gc(); - ODirectMemoryAllocator.instance().checkTrackedPointerLeaks(); - security.dropUser("auser"); - db.getLocalCache().clear(); - doc = db.load(rid.getIdentity()); - Assert.assertEquals(((Set) doc.field(OSecurityShared.ALLOW_ALL_FIELD)).size(), 2); - Assert.assertEquals(((Set) doc.field(OSecurityShared.ALLOW_UPDATE_FIELD)).size(), 2); - Assert.assertEquals(((Set) doc.field(OSecurityShared.ALLOW_DELETE_FIELD)).size(), 2); - Assert.assertEquals(((Set) doc.field(OSecurityShared.ALLOW_ALL_FIELD)).size(), 2); - doc.field("abc", "abc"); - doc.save(); + System.gc(); + ODirectMemoryAllocator.instance().checkTrackedPointerLeaks(); + security.dropUser("auser"); + db.getLocalCache().clear(); + doc = db.load(rid.getIdentity()); + Assert.assertEquals(((Set) doc.field(OSecurityShared.ALLOW_ALL_FIELD)).size(), 2); + Assert.assertEquals(((Set) doc.field(OSecurityShared.ALLOW_UPDATE_FIELD)).size(), 2); + Assert.assertEquals(((Set) doc.field(OSecurityShared.ALLOW_DELETE_FIELD)).size(), 2); + Assert.assertEquals(((Set) doc.field(OSecurityShared.ALLOW_ALL_FIELD)).size(), 2); + doc.field("abc", "abc"); + doc.save(); - System.gc(); - ODirectMemoryAllocator.instance().checkTrackedPointerLeaks(); - db.getLocalCache().clear(); - doc = db.load(rid.getIdentity()); - ((Set) doc.field(OSecurityShared.ALLOW_ALL_FIELD)).remove(null); - ((Set) doc.field(OSecurityShared.ALLOW_UPDATE_FIELD)).remove(null); - ((Set) doc.field(OSecurityShared.ALLOW_DELETE_FIELD)).remove(null); - ((Set) doc.field(OSecurityShared.ALLOW_ALL_FIELD)).remove(null); + System.gc(); + ODirectMemoryAllocator.instance().checkTrackedPointerLeaks(); + db.getLocalCache().clear(); + doc = db.load(rid.getIdentity()); + ((Set) doc.field(OSecurityShared.ALLOW_ALL_FIELD)).remove(null); + ((Set) doc.field(OSecurityShared.ALLOW_UPDATE_FIELD)).remove(null); + ((Set) doc.field(OSecurityShared.ALLOW_DELETE_FIELD)).remove(null); + ((Set) doc.field(OSecurityShared.ALLOW_ALL_FIELD)).remove(null); - Assert.assertEquals(((Set) doc.field(OSecurityShared.ALLOW_ALL_FIELD)).size(), 1); - Assert.assertEquals(((Set) doc.field(OSecurityShared.ALLOW_UPDATE_FIELD)).size(), 1); - Assert.assertEquals(((Set) doc.field(OSecurityShared.ALLOW_DELETE_FIELD)).size(), 1); - Assert.assertEquals(((Set) doc.field(OSecurityShared.ALLOW_ALL_FIELD)).size(), 1); - doc.field("abc", "abc"); - doc.save(); - System.gc(); - ODirectMemoryAllocator.instance().checkTrackedPointerLeaks(); - } finally { - db.drop(); - } + Assert.assertEquals(((Set) doc.field(OSecurityShared.ALLOW_ALL_FIELD)).size(), 1); + Assert.assertEquals(((Set) doc.field(OSecurityShared.ALLOW_UPDATE_FIELD)).size(), 1); + Assert.assertEquals(((Set) doc.field(OSecurityShared.ALLOW_DELETE_FIELD)).size(), 1); + Assert.assertEquals(((Set) doc.field(OSecurityShared.ALLOW_ALL_FIELD)).size(), 1); + doc.field("abc", "abc"); + doc.save(); + System.gc(); + ODirectMemoryAllocator.instance().checkTrackedPointerLeaks(); System.gc(); ODirectMemoryAllocator.instance().checkTrackedPointerLeaks(); diff --git a/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OCommandExecutorSQLCreateEdgeTest.java b/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OCommandExecutorSQLCreateEdgeTest.java index f405b8e0682..85bab19d016 100644 --- a/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OCommandExecutorSQLCreateEdgeTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OCommandExecutorSQLCreateEdgeTest.java @@ -1,7 +1,7 @@ package com.orientechnologies.orient.core.sql.executor; +import com.orientechnologies.BaseMemoryDatabase; import com.orientechnologies.orient.core.command.script.OCommandScript; -import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; import com.orientechnologies.orient.core.db.record.ridbag.ORidBag; import com.orientechnologies.orient.core.metadata.schema.OSchema; import com.orientechnologies.orient.core.record.impl.ODocument; @@ -10,33 +10,20 @@ import java.util.Collection; import java.util.HashMap; import java.util.List; -import org.junit.After; import org.junit.Assert; -import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** @author Artem Orobets (enisher-at-gmail.com) */ @RunWith(JUnit4.class) -public class OCommandExecutorSQLCreateEdgeTest { +public class OCommandExecutorSQLCreateEdgeTest extends BaseMemoryDatabase { - private ODatabaseDocumentTx db; private ODocument owner1; private ODocument owner2; - @Before - public void setUp() throws Exception { - db = - new ODatabaseDocumentTx( - "memory:" + OCommandExecutorSQLCreateEdgeTest.class.getSimpleName()); - - if (db.exists()) { - db.open("admin", "admin"); - db.drop(); - } - - db.create(); + public void beforeTest() { + super.beforeTest(); final OSchema schema = db.getMetadata().getSchema(); schema.createClass("Owner", schema.getClass("V")); @@ -50,15 +37,6 @@ public void setUp() throws Exception { owner2.save(); } - @After - public void tearDown() throws Exception { - db.drop(); - - db = null; - owner1 = null; - owner2 = null; - } - @Test public void testParametersBinding() throws Exception { db.command( diff --git a/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OCommandExecutorSQLDeleteVertexTest.java b/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OCommandExecutorSQLDeleteVertexTest.java index eaa2961edd2..0608b411f6c 100644 --- a/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OCommandExecutorSQLDeleteVertexTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OCommandExecutorSQLDeleteVertexTest.java @@ -19,38 +19,24 @@ */ package com.orientechnologies.orient.core.sql.executor; -import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; +import com.orientechnologies.BaseMemoryDatabase; import com.orientechnologies.orient.core.metadata.schema.OSchema; import com.orientechnologies.orient.core.record.impl.ODocument; import com.orientechnologies.orient.core.sql.OCommandSQL; import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery; import java.util.List; -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 OCommandExecutorSQLDeleteVertexTest { +public class OCommandExecutorSQLDeleteVertexTest extends BaseMemoryDatabase { - private ODatabaseDocumentTx db; - - @Before - public void init() throws Exception { - db = - new ODatabaseDocumentTx( - "memory:" + OCommandExecutorSQLDeleteVertexTest.class.getSimpleName()); - db.create(); + public void beforeTest() { + super.beforeTest(); final OSchema schema = db.getMetadata().getSchema(); schema.createClass("User", schema.getClass("V")); } - @After - public void tearDown() throws Exception { - db.drop(); - db = null; - } - @Test public void testDeleteVertexLimit() throws Exception { // for issue #4148 diff --git a/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OCreateUserStatementExecutionTest.java b/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OCreateUserStatementExecutionTest.java index 2ba759eb99e..531044645aa 100644 --- a/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OCreateUserStatementExecutionTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OCreateUserStatementExecutionTest.java @@ -1,27 +1,12 @@ package com.orientechnologies.orient.core.sql.executor; -import com.orientechnologies.orient.core.db.document.ODatabaseDocument; -import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; +import com.orientechnologies.BaseMemoryDatabase; import java.util.List; -import org.junit.AfterClass; import org.junit.Assert; -import org.junit.BeforeClass; import org.junit.Test; /** @author Luigi Dell'Aquila (l.dellaquila-(at)-orientdb.com) */ -public class OCreateUserStatementExecutionTest { - static ODatabaseDocument db; - - @BeforeClass - public static void beforeClass() { - db = new ODatabaseDocumentTx("memory:OCreateUserStatementExecutionTest"); - db.create(); - } - - @AfterClass - public static void afterClass() { - db.close(); - } +public class OCreateUserStatementExecutionTest extends BaseMemoryDatabase { @Test public void testPlain() { diff --git a/core/src/test/java/com/orientechnologies/orient/core/sql/executor/ODropPropertyStatementExecutionTest.java b/core/src/test/java/com/orientechnologies/orient/core/sql/executor/ODropPropertyStatementExecutionTest.java index c92671f8bc3..a53008be584 100644 --- a/core/src/test/java/com/orientechnologies/orient/core/sql/executor/ODropPropertyStatementExecutionTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/sql/executor/ODropPropertyStatementExecutionTest.java @@ -1,30 +1,15 @@ package com.orientechnologies.orient.core.sql.executor; -import com.orientechnologies.orient.core.db.document.ODatabaseDocument; -import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; +import com.orientechnologies.BaseMemoryDatabase; import com.orientechnologies.orient.core.exception.OCommandExecutionException; 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 org.junit.AfterClass; import org.junit.Assert; -import org.junit.BeforeClass; import org.junit.Test; /** @author Luigi Dell'Aquila (l.dellaquila-(at)-orientdb.com) */ -public class ODropPropertyStatementExecutionTest { - static ODatabaseDocument db; - - @BeforeClass - public static void beforeClass() { - db = new ODatabaseDocumentTx("memory:ODropPropertyStatementExecutionTest"); - db.create(); - } - - @AfterClass - public static void afterClass() { - db.close(); - } +public class ODropPropertyStatementExecutionTest extends BaseMemoryDatabase { @Test public void testPlain() { diff --git a/core/src/test/java/com/orientechnologies/orient/core/sql/executor/ODropSequenceStatementExecutionTest.java b/core/src/test/java/com/orientechnologies/orient/core/sql/executor/ODropSequenceStatementExecutionTest.java index 5d01c4a8da8..6982b71748b 100644 --- a/core/src/test/java/com/orientechnologies/orient/core/sql/executor/ODropSequenceStatementExecutionTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/sql/executor/ODropSequenceStatementExecutionTest.java @@ -1,30 +1,15 @@ package com.orientechnologies.orient.core.sql.executor; -import com.orientechnologies.orient.core.db.document.ODatabaseDocument; -import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; +import com.orientechnologies.BaseMemoryDatabase; import com.orientechnologies.orient.core.exception.OCommandExecutionException; import com.orientechnologies.orient.core.exception.ODatabaseException; import com.orientechnologies.orient.core.metadata.sequence.OSequence; import com.orientechnologies.orient.core.metadata.sequence.OSequenceLibrary; -import org.junit.AfterClass; import org.junit.Assert; -import org.junit.BeforeClass; import org.junit.Test; /** @author Luigi Dell'Aquila (l.dellaquila-(at)-orientdb.com) */ -public class ODropSequenceStatementExecutionTest { - static ODatabaseDocument db; - - @BeforeClass - public static void beforeClass() { - db = new ODatabaseDocumentTx("memory:ODropSequenceStatementExecutionTest"); - db.create(); - } - - @AfterClass - public static void afterClass() { - db.close(); - } +public class ODropSequenceStatementExecutionTest extends BaseMemoryDatabase { @Test public void testPlain() { diff --git a/core/src/test/java/com/orientechnologies/orient/core/sql/executor/ODropUserStatementExecutionTest.java b/core/src/test/java/com/orientechnologies/orient/core/sql/executor/ODropUserStatementExecutionTest.java index 52881d46fca..9dd5f40d412 100644 --- a/core/src/test/java/com/orientechnologies/orient/core/sql/executor/ODropUserStatementExecutionTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/sql/executor/ODropUserStatementExecutionTest.java @@ -1,27 +1,12 @@ package com.orientechnologies.orient.core.sql.executor; -import com.orientechnologies.orient.core.db.document.ODatabaseDocument; -import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; +import com.orientechnologies.BaseMemoryDatabase; import java.util.List; -import org.junit.AfterClass; import org.junit.Assert; -import org.junit.BeforeClass; import org.junit.Test; /** @author Luigi Dell'Aquila (l.dellaquila-(at)-orientdb.com) */ -public class ODropUserStatementExecutionTest { - static ODatabaseDocument db; - - @BeforeClass - public static void beforeClass() { - db = new ODatabaseDocumentTx("memory:ODropUserStatementExecutionTest"); - db.create(); - } - - @AfterClass - public static void afterClass() { - db.close(); - } +public class ODropUserStatementExecutionTest extends BaseMemoryDatabase { @Test public void testPlain() { diff --git a/core/src/test/java/com/orientechnologies/orient/core/sql/executor/ODropViewStatementExecutionTest.java b/core/src/test/java/com/orientechnologies/orient/core/sql/executor/ODropViewStatementExecutionTest.java index 09a39d4ecdd..086a609b8ff 100644 --- a/core/src/test/java/com/orientechnologies/orient/core/sql/executor/ODropViewStatementExecutionTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/sql/executor/ODropViewStatementExecutionTest.java @@ -1,32 +1,12 @@ package com.orientechnologies.orient.core.sql.executor; -import com.orientechnologies.orient.core.db.document.ODatabaseDocument; -import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; -import com.orientechnologies.orient.core.metadata.schema.OClass; +import com.orientechnologies.BaseMemoryDatabase; import com.orientechnologies.orient.core.metadata.schema.OSchema; -import org.junit.AfterClass; import org.junit.Assert; -import org.junit.BeforeClass; import org.junit.Test; /** @author Luigi Dell'Aquila (l.dellaquila-(at)-orientdb.com) */ -public class ODropViewStatementExecutionTest { - static ODatabaseDocument db; - - @BeforeClass - public static void beforeClass() { - db = new ODatabaseDocumentTx("memory:ODropViewStatementExecutionTest"); - db.create(); - OClass v = db.getMetadata().getSchema().getClass("V"); - if (v == null) { - db.getMetadata().getSchema().createClass("V"); - } - } - - @AfterClass - public static void afterClass() { - db.close(); - } +public class ODropViewStatementExecutionTest extends BaseMemoryDatabase { @Test public void testPlain() { diff --git a/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OExplainStatementExecutionTest.java b/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OExplainStatementExecutionTest.java index 93ba81c95c7..ca22052b9a4 100644 --- a/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OExplainStatementExecutionTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OExplainStatementExecutionTest.java @@ -1,28 +1,12 @@ package com.orientechnologies.orient.core.sql.executor; -import com.orientechnologies.orient.core.db.document.ODatabaseDocument; -import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; +import com.orientechnologies.BaseMemoryDatabase; import java.util.Optional; -import org.junit.AfterClass; import org.junit.Assert; -import org.junit.BeforeClass; import org.junit.Test; /** @author Luigi Dell'Aquila (l.dellaquila-(at)-orientdb.com) */ -public class OExplainStatementExecutionTest { - static ODatabaseDocument db; - - @BeforeClass - public static void beforeClass() { - - db = new ODatabaseDocumentTx("memory:OExplainStatementExecutionTest"); - db.create(); - } - - @AfterClass - public static void afterClass() { - db.close(); - } +public class OExplainStatementExecutionTest extends BaseMemoryDatabase { @Test public void testExplainSelectNoTarget() { diff --git a/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OOptimizeDatabaseExecutionTest.java b/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OOptimizeDatabaseExecutionTest.java index 460a6f1dfb1..feb905c7479 100644 --- a/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OOptimizeDatabaseExecutionTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OOptimizeDatabaseExecutionTest.java @@ -1,37 +1,13 @@ package com.orientechnologies.orient.core.sql.executor; -import com.orientechnologies.orient.core.db.document.ODatabaseDocument; -import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; -import com.orientechnologies.orient.core.metadata.schema.OClass; +import com.orientechnologies.BaseMemoryDatabase; import com.orientechnologies.orient.core.metadata.schema.OSchema; import com.orientechnologies.orient.core.record.OVertex; -import org.junit.AfterClass; import org.junit.Assert; -import org.junit.BeforeClass; import org.junit.Test; /** @author Luigi Dell'Aquila (l.dellaquila-(at)-orientdb.com) */ -public class OOptimizeDatabaseExecutionTest { - static ODatabaseDocument db; - - @BeforeClass - public static void beforeClass() { - db = new ODatabaseDocumentTx("memory:OOptimizeDatabaseExecutionTest"); - db.create(); - OClass v = db.getMetadata().getSchema().getClass("V"); - if (v == null) { - db.getMetadata().getSchema().createClass("V"); - } - OClass e = db.getMetadata().getSchema().getClass("E"); - if (e == null) { - db.getMetadata().getSchema().createClass("E"); - } - } - - @AfterClass - public static void afterClass() { - db.drop(); - } +public class OOptimizeDatabaseExecutionTest extends BaseMemoryDatabase { @Test public void test() { diff --git a/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OProfileStatementExecutionTest.java b/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OProfileStatementExecutionTest.java index 040a4332895..d2527e00fa9 100644 --- a/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OProfileStatementExecutionTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OProfileStatementExecutionTest.java @@ -1,27 +1,11 @@ package com.orientechnologies.orient.core.sql.executor; -import com.orientechnologies.orient.core.db.document.ODatabaseDocument; -import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; -import org.junit.AfterClass; +import com.orientechnologies.BaseMemoryDatabase; import org.junit.Assert; -import org.junit.BeforeClass; import org.junit.Test; /** @author Luigi Dell'Aquila (l.dellaquila-(at)-orientdb.com) */ -public class OProfileStatementExecutionTest { - static ODatabaseDocument db; - - @BeforeClass - public static void beforeClass() { - - db = new ODatabaseDocumentTx("memory:OProfileStatementExecutionTest"); - db.create(); - } - - @AfterClass - public static void afterClass() { - db.close(); - } +public class OProfileStatementExecutionTest extends BaseMemoryDatabase { @Test public void testProfile() { diff --git a/core/src/test/java/com/orientechnologies/orient/core/sql/executor/ORollbackStatementExecutionTest.java b/core/src/test/java/com/orientechnologies/orient/core/sql/executor/ORollbackStatementExecutionTest.java index 59227dc7926..6af6783b9f1 100644 --- a/core/src/test/java/com/orientechnologies/orient/core/sql/executor/ORollbackStatementExecutionTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/sql/executor/ORollbackStatementExecutionTest.java @@ -2,27 +2,12 @@ import static com.orientechnologies.orient.core.sql.executor.ExecutionPlanPrintUtils.printExecutionPlan; -import com.orientechnologies.orient.core.db.document.ODatabaseDocument; -import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; -import org.junit.AfterClass; +import com.orientechnologies.BaseMemoryDatabase; import org.junit.Assert; -import org.junit.BeforeClass; import org.junit.Test; /** @author Luigi Dell'Aquila (l.dellaquila-(at)-orientdb.com) */ -public class ORollbackStatementExecutionTest { - static ODatabaseDocument db; - - @BeforeClass - public static void beforeClass() { - db = new ODatabaseDocumentTx("memory:ORollbackStatementExecutionTest"); - db.create(); - } - - @AfterClass - public static void afterClass() { - db.close(); - } +public class ORollbackStatementExecutionTest extends BaseMemoryDatabase { @Test public void testBegin() { diff --git a/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OScriptExecutionTest.java b/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OScriptExecutionTest.java index 0f82ed49098..032d2adc867 100644 --- a/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OScriptExecutionTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OScriptExecutionTest.java @@ -1,29 +1,14 @@ package com.orientechnologies.orient.core.sql.executor; -import com.orientechnologies.orient.core.db.document.ODatabaseDocument; -import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; +import com.orientechnologies.BaseMemoryDatabase; import com.orientechnologies.orient.core.exception.OConcurrentModificationException; import com.orientechnologies.orient.core.sql.OCommandSQLParsingException; import java.math.BigDecimal; -import org.junit.AfterClass; import org.junit.Assert; -import org.junit.BeforeClass; import org.junit.Test; /** @author Luigi Dell'Aquila (l.dellaquila-(at)-orientdb.com) */ -public class OScriptExecutionTest { - static ODatabaseDocument db; - - @BeforeClass - public static void beforeClass() { - db = new ODatabaseDocumentTx("memory:OScriptExecutionTest"); - db.create(); - } - - @AfterClass - public static void afterClass() { - db.drop(); - } +public class OScriptExecutionTest extends BaseMemoryDatabase { @Test public void testTwoInserts() { diff --git a/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OSelectStatementExecutionTest.java b/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OSelectStatementExecutionTest.java index f97f0a77c1f..577b5caa9da 100755 --- a/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OSelectStatementExecutionTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OSelectStatementExecutionTest.java @@ -2,12 +2,11 @@ import static com.orientechnologies.orient.core.sql.executor.ExecutionPlanPrintUtils.printExecutionPlan; +import com.orientechnologies.BaseMemoryDatabase; import com.orientechnologies.common.concur.OTimeoutException; import com.orientechnologies.orient.core.command.OCommandContext; import com.orientechnologies.orient.core.config.OGlobalConfiguration; import com.orientechnologies.orient.core.db.ODatabaseSession; -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.db.viewmanager.ViewCreationListener; import com.orientechnologies.orient.core.exception.OCommandExecutionException; @@ -35,25 +34,11 @@ import java.util.Random; import java.util.UUID; import java.util.concurrent.CountDownLatch; -import org.junit.AfterClass; import org.junit.Assert; -import org.junit.BeforeClass; import org.junit.Test; /** @author Luigi Dell'Aquila (l.dellaquila-(at)-orientdb.com) */ -public class OSelectStatementExecutionTest { - static ODatabaseDocument db; - - @BeforeClass - public static void beforeClass() { - db = new ODatabaseDocumentTx("memory:OSelectStatementExecutionTest"); - db.create(); - } - - @AfterClass - public static void afterClass() { - db.close(); - } +public class OSelectStatementExecutionTest extends BaseMemoryDatabase { @Test public void testSelectNoTarget() { @@ -1002,8 +987,7 @@ public void testQueryMetadataDatabase() { Assert.assertTrue(result.hasNext()); OResult item = result.next(); - Assert.assertEquals( - OSelectStatementExecutionTest.class.getSimpleName(), item.getProperty("name")); + Assert.assertEquals("testQueryMetadataDatabase", item.getProperty("name")); Assert.assertFalse(result.hasNext()); result.close(); } @@ -1015,8 +999,7 @@ public void testQueryMetadataStorage() { Assert.assertTrue(result.hasNext()); OResult item = result.next(); - Assert.assertEquals( - OSelectStatementExecutionTest.class.getSimpleName(), item.getProperty("name")); + Assert.assertEquals("testQueryMetadataStorage", item.getProperty("name")); Assert.assertFalse(result.hasNext()); result.close(); } diff --git a/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OSelectStatementExecutionTestIT.java b/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OSelectStatementExecutionTestIT.java index 225cd053f46..d99415cca92 100644 --- a/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OSelectStatementExecutionTestIT.java +++ b/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OSelectStatementExecutionTestIT.java @@ -1,30 +1,14 @@ package com.orientechnologies.orient.core.sql.executor; -import com.orientechnologies.orient.core.db.document.ODatabaseDocument; -import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; +import com.orientechnologies.BaseMemoryDatabase; import com.orientechnologies.orient.core.record.impl.ODocument; import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery; import java.util.List; -import org.junit.AfterClass; import org.junit.Assert; -import org.junit.BeforeClass; import org.junit.Test; /** Created by tglman on 09/06/17. */ -public class OSelectStatementExecutionTestIT { - static ODatabaseDocument db; - - @BeforeClass - public static void beforeClass() { - - db = new ODatabaseDocumentTx("memory:OSelectStatementExecutionTest"); - db.create(); - } - - @AfterClass - public static void afterClass() { - db.close(); - } +public class OSelectStatementExecutionTestIT extends BaseMemoryDatabase { @Test public void stressTestNew() { diff --git a/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OSleepStatementExecutionTest.java b/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OSleepStatementExecutionTest.java index 0d3b48235bd..73eebbf2b14 100644 --- a/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OSleepStatementExecutionTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OSleepStatementExecutionTest.java @@ -2,27 +2,12 @@ import static com.orientechnologies.orient.core.sql.executor.ExecutionPlanPrintUtils.printExecutionPlan; -import com.orientechnologies.orient.core.db.document.ODatabaseDocument; -import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; -import org.junit.AfterClass; +import com.orientechnologies.BaseMemoryDatabase; import org.junit.Assert; -import org.junit.BeforeClass; import org.junit.Test; /** @author Luigi Dell'Aquila (l.dellaquila-(at)-orientdb.com) */ -public class OSleepStatementExecutionTest { - static ODatabaseDocument db; - - @BeforeClass - public static void beforeClass() { - db = new ODatabaseDocumentTx("memory:OSleepStatementExecutionTest"); - db.create(); - } - - @AfterClass - public static void afterClass() { - db.close(); - } +public class OSleepStatementExecutionTest extends BaseMemoryDatabase { @Test public void testBasic() { diff --git a/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OTraverseStatementExecutionTest.java b/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OTraverseStatementExecutionTest.java index f81a6286a5d..0482e98aa32 100644 --- a/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OTraverseStatementExecutionTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/sql/executor/OTraverseStatementExecutionTest.java @@ -1,32 +1,12 @@ package com.orientechnologies.orient.core.sql.executor; -import com.orientechnologies.orient.core.db.document.ODatabaseDocument; -import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; +import com.orientechnologies.BaseMemoryDatabase; import java.util.Collection; -import org.junit.AfterClass; import org.junit.Assert; -import org.junit.BeforeClass; import org.junit.Test; /** @author Luigi Dell'Aquila (l.dellaquila-(at)-orientdb.com) */ -public class OTraverseStatementExecutionTest { - static ODatabaseDocument db; - - @BeforeClass - public static void beforeClass() { - - db = new ODatabaseDocumentTx("memory:OTraverseStatementExecutionTest"); - db.create(); - - initBaseGraph(db); - } - - private static void initBaseGraph(ODatabaseDocument db) {} - - @AfterClass - public static void afterClass() { - db.close(); - } +public class OTraverseStatementExecutionTest extends BaseMemoryDatabase { @Test public void testPlainTraverse() { diff --git a/core/src/test/java/com/orientechnologies/orient/core/sql/functions/misc/OSQLFunctionIndexKeySizeTest.java b/core/src/test/java/com/orientechnologies/orient/core/sql/functions/misc/OSQLFunctionIndexKeySizeTest.java index 894b379e691..4750a5f0d66 100644 --- a/core/src/test/java/com/orientechnologies/orient/core/sql/functions/misc/OSQLFunctionIndexKeySizeTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/sql/functions/misc/OSQLFunctionIndexKeySizeTest.java @@ -1,6 +1,6 @@ package com.orientechnologies.orient.core.sql.functions.misc; -import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; +import com.orientechnologies.BaseMemoryDatabase; import com.orientechnologies.orient.core.metadata.schema.OClass; import com.orientechnologies.orient.core.metadata.schema.OType; import com.orientechnologies.orient.core.sql.executor.OResult; @@ -8,13 +8,10 @@ import org.junit.Assert; import org.junit.Test; -public class OSQLFunctionIndexKeySizeTest { +public class OSQLFunctionIndexKeySizeTest extends BaseMemoryDatabase { @Test public void test() { - ODatabaseDocumentTx db = - new ODatabaseDocumentTx("memory:" + OSQLFunctionIndexKeySizeTest.class.getSimpleName()); - db.create(); OClass clazz = db.getMetadata().getSchema().createClass("Test"); clazz.createProperty("name", OType.STRING); db.command("create index testindex on Test (name) notunique").close(); @@ -27,6 +24,5 @@ public void test() { Assert.assertEquals((Object) 2L, item.getProperty("foo")); Assert.assertFalse(rs.hasNext()); } - db.close(); } } diff --git a/core/src/test/java/com/orientechnologies/orient/core/sql/functions/sql/OCustomSQLFunctionsTest.java b/core/src/test/java/com/orientechnologies/orient/core/sql/functions/sql/OCustomSQLFunctionsTest.java index 2db9d28b289..7e864131606 100644 --- a/core/src/test/java/com/orientechnologies/orient/core/sql/functions/sql/OCustomSQLFunctionsTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/sql/functions/sql/OCustomSQLFunctionsTest.java @@ -3,29 +3,14 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; +import com.orientechnologies.BaseMemoryDatabase; import com.orientechnologies.orient.core.exception.OQueryParsingException; import com.orientechnologies.orient.core.record.impl.ODocument; import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery; import java.util.List; -import org.junit.AfterClass; -import org.junit.BeforeClass; import org.junit.Test; -public class OCustomSQLFunctionsTest { - - private static ODatabaseDocumentTx db; - - @BeforeClass - public static void beforeClass() { - db = new ODatabaseDocumentTx("memory:" + OCustomSQLFunctionsTest.class.getSimpleName()); - db.create(); - } - - @AfterClass - public static void afterClass() { - db.close(); - } +public class OCustomSQLFunctionsTest extends BaseMemoryDatabase { @Test public void testRandom() { diff --git a/core/src/test/java/com/orientechnologies/orient/core/sql/functions/sql/OFunctionSqlTest.java b/core/src/test/java/com/orientechnologies/orient/core/sql/functions/sql/OFunctionSqlTest.java index 6415d822d75..6904bf5d908 100755 --- a/core/src/test/java/com/orientechnologies/orient/core/sql/functions/sql/OFunctionSqlTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/sql/functions/sql/OFunctionSqlTest.java @@ -1,8 +1,7 @@ package com.orientechnologies.orient.core.sql.functions.sql; +import com.orientechnologies.BaseMemoryDatabase; import com.orientechnologies.orient.core.command.OBasicCommandContext; -import com.orientechnologies.orient.core.db.document.ODatabaseDocument; -import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; import com.orientechnologies.orient.core.metadata.function.OFunction; import com.orientechnologies.orient.core.record.impl.ODocument; import com.orientechnologies.orient.core.sql.query.OLegacyResultSet; @@ -11,14 +10,11 @@ import org.junit.Test; /** Created by Enrico Risa on 07/04/15. */ -public class OFunctionSqlTest { +public class OFunctionSqlTest extends BaseMemoryDatabase { @Test public void functionSqlWithParameters() { - ODatabaseDocument db = new ODatabaseDocumentTx("memory:functionSqlWithParameters"); - db.create(); - // ODatabaseRecordThreadLocal.instance().set(db); ODocument doc1 = new ODocument("Test"); doc1.field("name", "Enrico"); @@ -41,15 +37,11 @@ public void functionSqlWithParameters() { Object result = function.executeInContext(new OBasicCommandContext(), "Enrico"); Assert.assertEquals(((OLegacyResultSet) result).size(), 1); - db.drop(); } @Test public void functionSqlWithInnerFunctionJs() { - ODatabaseDocument db = new ODatabaseDocumentTx("memory:functionSqlWithInnerFunctionJs"); - db.create(); - // ODatabaseRecordThreadLocal.instance().set(db); ODocument doc1 = new ODocument("Test"); doc1.field("name", "Enrico"); @@ -84,6 +76,5 @@ public void functionSqlWithInnerFunctionJs() { Object result = function.executeInContext(new OBasicCommandContext(), "Enrico"); Assert.assertEquals(((OLegacyResultSet) result).size(), 1); - db.drop(); } } diff --git a/core/src/test/java/com/orientechnologies/orient/core/tx/DuplicateDictionaryIndexChangesTxTest.java b/core/src/test/java/com/orientechnologies/orient/core/tx/DuplicateDictionaryIndexChangesTxTest.java index d9949ae7d85..189b68fc02f 100644 --- a/core/src/test/java/com/orientechnologies/orient/core/tx/DuplicateDictionaryIndexChangesTxTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/tx/DuplicateDictionaryIndexChangesTxTest.java @@ -19,41 +19,23 @@ package com.orientechnologies.orient.core.tx; -import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; +import com.orientechnologies.BaseMemoryDatabase; import com.orientechnologies.orient.core.id.ORID; import com.orientechnologies.orient.core.index.OIndex; import com.orientechnologies.orient.core.metadata.schema.OClass; import com.orientechnologies.orient.core.metadata.schema.OType; import com.orientechnologies.orient.core.record.impl.ODocument; import java.util.stream.Stream; -import org.junit.AfterClass; import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; /** @author Sergey Sitnikov */ -public class DuplicateDictionaryIndexChangesTxTest { +public class DuplicateDictionaryIndexChangesTxTest extends BaseMemoryDatabase { - private static ODatabaseDocumentTx db; private OIndex index; - @BeforeClass - public static void before() { - db = - new ODatabaseDocumentTx( - "memory:" + DuplicateDictionaryIndexChangesTxTest.class.getSimpleName()); - } - - @AfterClass - public static void after() { - db.drop(); - } - - @Before - public void beforeMethod() { - if (!db.isClosed()) db.drop(); - db.create(); + public void beforeTest() { + super.beforeTest(); final OClass class_ = db.getMetadata().getSchema().createClass("Person"); index = class_ @@ -66,9 +48,12 @@ public void testDuplicateNullsOnCreate() { db.begin(); // saved persons will have null name - final ODocument person1 = db.newInstance("Person").save(); - final ODocument person2 = db.newInstance("Person").save(); - final ODocument person3 = db.newInstance("Person").save(); + final ODocument person1 = db.newInstance("Person"); + db.save(person1); + final ODocument person2 = db.newInstance("Person"); + db.save(person2); + final ODocument person3 = db.newInstance("Person"); + db.save(person3); // change some names to not null person1.field("name", "Name1").save(); @@ -90,9 +75,15 @@ public void testDuplicateNullsOnCreate() { @Test public void testDuplicateNullsOnUpdate() { db.begin(); - final ODocument person1 = db.newInstance("Person").field("name", (Object) null).save(); - final ODocument person2 = db.newInstance("Person").field("name", (Object) null).save(); - final ODocument person3 = db.newInstance("Person").field("name", (Object) null).save(); + final ODocument person1 = db.newInstance("Person"); + person1.field("name", (Object) null); + db.save(person1); + final ODocument person2 = db.newInstance("Person"); + person2.field("name", (Object) null); + db.save(person2); + final ODocument person3 = db.newInstance("Person"); + person3.field("name", (Object) null); + db.save(person3); db.commit(); // verify index state @@ -128,9 +119,15 @@ public void testDuplicateValuesOnCreate() { db.begin(); // saved persons will have same name - final ODocument person1 = db.newInstance("Person").field("name", "same").save(); - final ODocument person2 = db.newInstance("Person").field("name", "same").save(); - final ODocument person3 = db.newInstance("Person").field("name", "same").save(); + final ODocument person1 = db.newInstance("Person"); + person1.field("name", "same"); + db.save(person1); + final ODocument person2 = db.newInstance("Person"); + person2.field("name", "same"); + db.save(person2); + final ODocument person3 = db.newInstance("Person"); + person3.field("name", "same"); + person3.save(); // change names to unique person1.field("name", "Name1").save(); @@ -157,9 +154,15 @@ public void testDuplicateValuesOnCreate() { @Test public void testDuplicateValuesOnUpdate() { db.begin(); - final ODocument person1 = db.newInstance("Person").field("name", "Name1").save(); - final ODocument person2 = db.newInstance("Person").field("name", "Name2").save(); - final ODocument person3 = db.newInstance("Person").field("name", "Name3").save(); + final ODocument person1 = db.newInstance("Person"); + person1.field("name", "Name1"); + db.save(person1); + final ODocument person2 = db.newInstance("Person"); + person2.field("name", "Name2"); + db.save(person2); + final ODocument person3 = db.newInstance("Person"); + person3.field("name", "Name3"); + db.save(person3); db.commit(); // verify index state @@ -213,10 +216,18 @@ public void testDuplicateValuesOnCreateDelete() { db.begin(); // saved persons will have same name - final ODocument person1 = db.newInstance("Person").field("name", "same").save(); - final ODocument person2 = db.newInstance("Person").field("name", "same").save(); - final ODocument person3 = db.newInstance("Person").field("name", "same").save(); - final ODocument person4 = db.newInstance("Person").field("name", "same").save(); + final ODocument person1 = db.newInstance("Person"); + person1.field("name", "same"); + db.save(person1); + final ODocument person2 = db.newInstance("Person"); + person2.field("name", "same"); + db.save(person2); + final ODocument person3 = db.newInstance("Person"); + person3.field("name", "same"); + db.save(person3); + final ODocument person4 = db.newInstance("Person"); + person4.field("name", "same"); + db.save(person4); person1.delete(); person2.field("name", "Name2").save(); @@ -240,10 +251,18 @@ public void testDuplicateValuesOnCreateDelete() { @Test public void testDuplicateValuesOnUpdateDelete() { db.begin(); - final ODocument person1 = db.newInstance("Person").field("name", "Name1").save(); - final ODocument person2 = db.newInstance("Person").field("name", "Name2").save(); - final ODocument person3 = db.newInstance("Person").field("name", "Name3").save(); - final ODocument person4 = db.newInstance("Person").field("name", "Name4").save(); + final ODocument person1 = db.newInstance("Person"); + person1.field("name", "Name1"); + db.save(person1); + final ODocument person2 = db.newInstance("Person"); + person2.field("name", "Name2"); + db.save(person2); + final ODocument person3 = db.newInstance("Person"); + person3.field("name", "Name3"); + db.save(person3); + final ODocument person4 = db.newInstance("Person"); + person4.field("name", "Name4"); + db.save(person4); db.commit(); // verify index state diff --git a/core/src/test/java/com/orientechnologies/orient/core/tx/DuplicateNonUniqueIndexChangesTxTest.java b/core/src/test/java/com/orientechnologies/orient/core/tx/DuplicateNonUniqueIndexChangesTxTest.java index 8723a5c8bba..33162be0ad7 100644 --- a/core/src/test/java/com/orientechnologies/orient/core/tx/DuplicateNonUniqueIndexChangesTxTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/tx/DuplicateNonUniqueIndexChangesTxTest.java @@ -19,7 +19,7 @@ package com.orientechnologies.orient.core.tx; -import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; +import com.orientechnologies.BaseMemoryDatabase; import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.id.ORID; import com.orientechnologies.orient.core.index.OIndex; @@ -31,34 +31,16 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.junit.AfterClass; import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; /** @author Sergey Sitnikov */ -public class DuplicateNonUniqueIndexChangesTxTest { +public class DuplicateNonUniqueIndexChangesTxTest extends BaseMemoryDatabase { - private static ODatabaseDocumentTx db; private OIndex index; - @BeforeClass - public static void before() { - db = - new ODatabaseDocumentTx( - "memory:" + DuplicateNonUniqueIndexChangesTxTest.class.getSimpleName()); - } - - @AfterClass - public static void after() { - db.drop(); - } - - @Before - public void beforeMethod() { - if (!db.isClosed()) db.drop(); - db.create(); + public void beforeTest() { + super.beforeTest(); final OClass class_ = db.getMetadata().getSchema().createClass("Person"); index = class_ @@ -71,9 +53,12 @@ public void testDuplicateNullsOnCreate() { db.begin(); // saved persons will have null name - final ODocument person1 = db.newInstance("Person").save(); - final ODocument person2 = db.newInstance("Person").save(); - final ODocument person3 = db.newInstance("Person").save(); + final ODocument person1 = db.newInstance("Person"); + db.save(person1); + final ODocument person2 = db.newInstance("Person"); + db.save(person2); + final ODocument person3 = db.newInstance("Person"); + db.save(person3); // change some names person3.field("name", "Name3").save(); @@ -88,9 +73,15 @@ public void testDuplicateNullsOnCreate() { @Test public void testDuplicateNullsOnUpdate() { db.begin(); - final ODocument person1 = db.newInstance("Person").field("name", "Name1").save(); - final ODocument person2 = db.newInstance("Person").field("name", "Name2").save(); - final ODocument person3 = db.newInstance("Person").field("name", "Name3").save(); + final ODocument person1 = db.newInstance("Person"); + person1.field("name", "Name1"); + db.save(person1); + final ODocument person2 = db.newInstance("Person"); + person2.field("name", "Name2"); + db.save(person2); + final ODocument person3 = db.newInstance("Person"); + person3.field("name", "Name3"); + db.save(person3); db.commit(); // verify index state @@ -129,9 +120,15 @@ public void testDuplicateValuesOnCreate() { db.begin(); // saved persons will have same name - final ODocument person1 = db.newInstance("Person").field("name", "same").save(); - final ODocument person2 = db.newInstance("Person").field("name", "same").save(); - final ODocument person3 = db.newInstance("Person").field("name", "same").save(); + final ODocument person1 = db.newInstance("Person"); + person1.field("name", "same"); + db.save(person1); + final ODocument person2 = db.newInstance("Person"); + person2.field("name", "same"); + db.save(person2); + final ODocument person3 = db.newInstance("Person"); + person3.field("name", "same"); + db.save(person3); // change some names person2.field("name", "Name1").save(); @@ -149,9 +146,15 @@ public void testDuplicateValuesOnCreate() { @Test public void testDuplicateValuesOnUpdate() { db.begin(); - final ODocument person1 = db.newInstance("Person").field("name", "Name1").save(); - final ODocument person2 = db.newInstance("Person").field("name", "Name2").save(); - final ODocument person3 = db.newInstance("Person").field("name", "Name3").save(); + final ODocument person1 = db.newInstance("Person"); + person1.field("name", "Name1"); + db.save(person1); + final ODocument person2 = db.newInstance("Person"); + person2.field("name", "Name2"); + db.save(person2); + final ODocument person3 = db.newInstance("Person"); + person3.field("name", "Name3"); + db.save(person3); db.commit(); // verify index state @@ -186,10 +189,18 @@ public void testDuplicateValuesOnCreateDelete() { db.begin(); // saved persons will have same name - final ODocument person1 = db.newInstance("Person").field("name", "same").save(); - final ODocument person2 = db.newInstance("Person").field("name", "same").save(); - final ODocument person3 = db.newInstance("Person").field("name", "same").save(); - final ODocument person4 = db.newInstance("Person").field("name", "same").save(); + final ODocument person1 = db.newInstance("Person"); + person1.field("name", "same"); + db.save(person1); + final ODocument person2 = db.newInstance("Person"); + person2.field("name", "same"); + db.save(person2); + final ODocument person3 = db.newInstance("Person"); + person3.field("name", "same"); + db.save(person3); + final ODocument person4 = db.newInstance("Person"); + person4.field("name", "same"); + db.save(person4); person1.delete(); person2.field("name", "Name2").save(); @@ -208,10 +219,18 @@ public void testDuplicateValuesOnCreateDelete() { @Test public void testDuplicateValuesOnUpdateDelete() { db.begin(); - final ODocument person1 = db.newInstance("Person").field("name", "Name1").save(); - final ODocument person2 = db.newInstance("Person").field("name", "Name2").save(); - final ODocument person3 = db.newInstance("Person").field("name", "Name3").save(); - final ODocument person4 = db.newInstance("Person").field("name", "Name4").save(); + final ODocument person1 = db.newInstance("Person"); + person1.field("name", "Name1"); + db.save(person1); + final ODocument person2 = db.newInstance("Person"); + person2.field("name", "Name2"); + db.save(person2); + final ODocument person3 = db.newInstance("Person"); + person3.field("name", "Name3"); + db.save(person3); + final ODocument person4 = db.newInstance("Person"); + person4.field("name", "Name4"); + db.save(person4); db.commit(); // verify index state @@ -254,7 +273,10 @@ public void testManyManyUpdatesToTheSameKey() { db.begin(); for (int i = 0; i < OTransactionIndexChangesPerKey.SET_ADD_THRESHOLD * 2; ++i) { - db.newInstance("Person").field("name", "Name").field("serial", i).save(); + ODocument pers = db.newInstance("Person"); + pers.field("name", "Name"); + pers.field("serial", i); + db.save(pers); unseen.add(i); } db.commit(); diff --git a/core/src/test/java/com/orientechnologies/orient/core/tx/DuplicateUniqueIndexChangesTxTest.java b/core/src/test/java/com/orientechnologies/orient/core/tx/DuplicateUniqueIndexChangesTxTest.java index b5749f02da2..bbfb4f31f49 100644 --- a/core/src/test/java/com/orientechnologies/orient/core/tx/DuplicateUniqueIndexChangesTxTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/tx/DuplicateUniqueIndexChangesTxTest.java @@ -19,7 +19,7 @@ package com.orientechnologies.orient.core.tx; -import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; +import com.orientechnologies.BaseMemoryDatabase; import com.orientechnologies.orient.core.id.ORID; import com.orientechnologies.orient.core.index.OIndex; import com.orientechnologies.orient.core.metadata.schema.OClass; @@ -27,34 +27,16 @@ import com.orientechnologies.orient.core.record.impl.ODocument; import com.orientechnologies.orient.core.storage.ORecordDuplicatedException; import java.util.stream.Stream; -import org.junit.AfterClass; import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; /** @author Sergey Sitnikov */ -public class DuplicateUniqueIndexChangesTxTest { +public class DuplicateUniqueIndexChangesTxTest extends BaseMemoryDatabase { - private static ODatabaseDocumentTx db; private OIndex index; - @BeforeClass - public static void before() { - db = - new ODatabaseDocumentTx( - "memory:" + DuplicateUniqueIndexChangesTxTest.class.getSimpleName()); - } - - @AfterClass - public static void after() { - db.drop(); - } - - @Before - public void beforeMethod() { - if (!db.isClosed()) db.drop(); - db.create(); + public void beforeTest() { + super.beforeTest(); final OClass class_ = db.getMetadata().getSchema().createClass("Person"); index = class_ @@ -67,9 +49,12 @@ public void testDuplicateNullsOnCreate() { db.begin(); // saved persons will have null name - final ODocument person1 = db.newInstance("Person").save(); - final ODocument person2 = db.newInstance("Person").save(); - final ODocument person3 = db.newInstance("Person").save(); + final ODocument person1 = db.newInstance("Person"); + db.save(person1); + final ODocument person2 = db.newInstance("Person"); + db.save(person2); + final ODocument person3 = db.newInstance("Person"); + db.save(person3); // change names to unique person1.field("name", "Name1").save(); @@ -95,9 +80,15 @@ private ODocument fetchDocumentFromIndex(String o) { @Test public void testDuplicateNullsOnUpdate() { db.begin(); - final ODocument person1 = db.newInstance("Person").field("name", "Name1").save(); - final ODocument person2 = db.newInstance("Person").field("name", "Name2").save(); - final ODocument person3 = db.newInstance("Person").field("name", "Name3").save(); + final ODocument person1 = db.newInstance("Person"); + person1.field("name", "Name1"); + db.save(person1); + final ODocument person2 = db.newInstance("Person"); + person2.field("name", "Name2"); + db.save(person2); + final ODocument person3 = db.newInstance("Person"); + person3.field("name", "Name3"); + db.save(person3); db.commit(); // verify index state @@ -137,9 +128,15 @@ public void testDuplicateValuesOnCreate() { db.begin(); // saved persons will have same name - final ODocument person1 = db.newInstance("Person").field("name", "same").save(); - final ODocument person2 = db.newInstance("Person").field("name", "same").save(); - final ODocument person3 = db.newInstance("Person").field("name", "same").save(); + final ODocument person1 = db.newInstance("Person"); + person1.field("name", "same"); + db.save(person1); + final ODocument person2 = db.newInstance("Person"); + person2.field("name", "same"); + db.save(person2); + final ODocument person3 = db.newInstance("Person"); + person3.field("name", "same"); + db.save(person3); // change names to unique person1.field("name", "Name1").save(); @@ -159,9 +156,15 @@ public void testDuplicateValuesOnCreate() { @Test public void testDuplicateValuesOnUpdate() { db.begin(); - final ODocument person1 = db.newInstance("Person").field("name", "Name1").save(); - final ODocument person2 = db.newInstance("Person").field("name", "Name2").save(); - final ODocument person3 = db.newInstance("Person").field("name", "Name3").save(); + final ODocument person1 = db.newInstance("Person"); + person1.field("name", "Name1"); + db.save(person1); + final ODocument person2 = db.newInstance("Person"); + person2.field("name", "Name2"); + db.save(person2); + final ODocument person3 = db.newInstance("Person"); + person3.field("name", "Name3"); + db.save(person3); db.commit(); // verify index state @@ -196,10 +199,18 @@ public void testDuplicateValuesOnCreateDelete() { db.begin(); // saved persons will have same name - final ODocument person1 = db.newInstance("Person").field("name", "same").save(); - final ODocument person2 = db.newInstance("Person").field("name", "same").save(); - final ODocument person3 = db.newInstance("Person").field("name", "same").save(); - final ODocument person4 = db.newInstance("Person").field("name", "same").save(); + final ODocument person1 = db.newInstance("Person"); + person1.field("name", "same"); + db.save(person1); + final ODocument person2 = db.newInstance("Person"); + person2.field("name", "same"); + db.save(person2); + final ODocument person3 = db.newInstance("Person"); + person3.field("name", "same"); + db.save(person3); + final ODocument person4 = db.newInstance("Person"); + person4.field("name", "same"); + db.save(person4); person1.delete(); person2.field("name", "Name2").save(); @@ -216,10 +227,18 @@ public void testDuplicateValuesOnCreateDelete() { @Test public void testDuplicateValuesOnUpdateDelete() { db.begin(); - final ODocument person1 = db.newInstance("Person").field("name", "Name1").save(); - final ODocument person2 = db.newInstance("Person").field("name", "Name2").save(); - final ODocument person3 = db.newInstance("Person").field("name", "Name3").save(); - final ODocument person4 = db.newInstance("Person").field("name", "Name4").save(); + final ODocument person1 = db.newInstance("Person"); + person1.field("name", "Name1"); + db.save(person1); + final ODocument person2 = db.newInstance("Person"); + person2.field("name", "Name2"); + db.save(person2); + final ODocument person3 = db.newInstance("Person"); + person3.field("name", "Name3"); + db.save(person3); + final ODocument person4 = db.newInstance("Person"); + person4.field("name", "Name4"); + db.save(person4); db.commit(); // verify index state @@ -256,10 +275,16 @@ public void testDuplicateValuesOnUpdateDelete() { @Test(expected = ORecordDuplicatedException.class) public void testDuplicateCreateThrows() { db.begin(); - db.newInstance("Person").field("name", "Name1").save(); - db.newInstance("Person").save(); - db.newInstance("Person").save(); - db.newInstance("Person").field("name", "Name1").save(); + ODocument person1 = db.newInstance("Person"); + person1.field("name", "Name1"); + db.save(person1); + ODocument person2 = db.newInstance("Person"); + db.save(person2); + ODocument person3 = db.newInstance("Person"); + db.save(person3); + ODocument person4 = db.newInstance("Person"); + person4.field("name", "Name1"); + db.save(person4); // Assert.assertThrows(ORecordDuplicatedException.class, new Assert.ThrowingRunnable() { // @Override // public void run() throws Throwable { @@ -272,10 +297,18 @@ public void testDuplicateCreateThrows() { @Test(expected = ORecordDuplicatedException.class) public void testDuplicateUpdateThrows() { db.begin(); - final ODocument person1 = db.newInstance("Person").field("name", "Name1").save(); - final ODocument person2 = db.newInstance("Person").field("name", "Name2").save(); - final ODocument person3 = db.newInstance("Person").field("name", "Name3").save(); - final ODocument person4 = db.newInstance("Person").field("name", "Name4").save(); + final ODocument person1 = db.newInstance("Person"); + person1.field("name", "Name1"); + db.save(person1); + final ODocument person2 = db.newInstance("Person"); + person2.field("name", "Name2"); + db.save(person2); + final ODocument person3 = db.newInstance("Person"); + person3.field("name", "Name3"); + db.save(person3); + final ODocument person4 = db.newInstance("Person"); + person4.field("name", "Name4"); + db.save(person4); db.commit(); // verify index state