From a9dd54d60f46d09e38e3f2170190d078bcafc390 Mon Sep 17 00:00:00 2001 From: Tglman Date: Tue, 28 Nov 2023 14:12:31 +0100 Subject: [PATCH] refactor: removed old api from unit tests --- .../core/command/traverse/OTraverseTest.java | 24 +- .../core/db/hook/CheckHookCallCountTest.java | 165 ++++----- .../db/hook/HookChangeValidationTest.java | 329 ++++++++---------- .../core/db/hook/HookRegisterRemoveTest.java | 10 +- .../orient/core/db/hook/HookSaveTest.java | 28 +- .../record/DocumentJavaSerializationTest.java | 14 +- ...eGuessingWorkingWithSQLAndMultiValues.java | 19 +- .../ODocumentSchemafullSerializationTest.java | 5 +- .../ODocumentSchemalessSerializationTest.java | 8 +- .../core/record/impl/ODocumentTest.java | 10 +- .../ORecordSerializerBinaryDebugTest.java | 256 ++++++-------- 11 files changed, 374 insertions(+), 494 deletions(-) diff --git a/core/src/test/java/com/orientechnologies/orient/core/command/traverse/OTraverseTest.java b/core/src/test/java/com/orientechnologies/orient/core/command/traverse/OTraverseTest.java index 1b9351d1c6d..65a4423c0c9 100755 --- a/core/src/test/java/com/orientechnologies/orient/core/command/traverse/OTraverseTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/command/traverse/OTraverseTest.java @@ -1,44 +1,28 @@ package com.orientechnologies.orient.core.command.traverse; -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.db.record.OIdentifiable; import com.orientechnologies.orient.core.record.impl.ODocument; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.junit.After; import org.junit.Assert; -import org.junit.Before; import org.junit.Test; /** @author Artem Orobets (enisher-at-gmail.com) */ -public class OTraverseTest { +public class OTraverseTest extends BaseMemoryDatabase { - private ODatabaseDocument db; private ODocument rootDocument; private OTraverse traverse; - @Before - public void setUp() throws Exception { - db = new ODatabaseDocumentTx("memory:" + OTraverseTest.class.getSimpleName()); - if (db.exists()) { - db.open("admin", "admin"); - db.drop(); - } - - db.create(); + public void beforeTest() { + super.beforeTest(); rootDocument = new ODocument(); traverse = new OTraverse(); traverse.target(rootDocument).fields("*"); } - @After - public void tearDown() throws Exception { - db.drop(); - } - @Test public void testDepthTraverse() throws Exception { diff --git a/core/src/test/java/com/orientechnologies/orient/core/db/hook/CheckHookCallCountTest.java b/core/src/test/java/com/orientechnologies/orient/core/db/hook/CheckHookCallCountTest.java index fe92c9fc0ca..b41eec2902d 100755 --- a/core/src/test/java/com/orientechnologies/orient/core/db/hook/CheckHookCallCountTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/db/hook/CheckHookCallCountTest.java @@ -3,8 +3,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -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.hook.ODocumentHookAbstract; import com.orientechnologies.orient.core.metadata.schema.OClass; import com.orientechnologies.orient.core.metadata.schema.OSchema; @@ -15,7 +14,7 @@ import java.util.UUID; import org.junit.Test; -public class CheckHookCallCountTest { +public class CheckHookCallCountTest extends BaseMemoryDatabase { private final String CLASS_NAME = "Data"; private final String FIELD_ID = "ID"; private final String FIELD_STATUS = "STATUS"; @@ -23,98 +22,84 @@ public class CheckHookCallCountTest { @Test public void testMultipleCallHook() { - ODatabaseDocument db = - new ODatabaseDocumentTx("memory:" + CheckHookCallCountTest.class.getSimpleName()); - db.create(); - try { - OClass aClass = db.getMetadata().getSchema().createClass(CLASS_NAME); - aClass.createProperty(FIELD_ID, OType.STRING); - aClass.createProperty(FIELD_STATUS, OType.STRING); - aClass.createIndex("IDX", OClass.INDEX_TYPE.NOTUNIQUE, FIELD_ID); - TestHook hook = new TestHook(); - db.registerHook(hook); - - String id = UUID.randomUUID().toString(); - ODocument first = new ODocument(CLASS_NAME); - first.field(FIELD_ID, id); - first.field(FIELD_STATUS, STATUS); - db.save(first); - - db.query( - new OSQLSynchQuery( - "SELECT FROM " + CLASS_NAME + " WHERE " + FIELD_STATUS + " = '" + STATUS + "'")); - // assertEquals(hook.readCount, 1); //TODO - hook.readCount = 0; - db.query( - new OSQLSynchQuery( - "SELECT FROM " + CLASS_NAME + " WHERE " + FIELD_ID + " = '" + id + "'")); - // assertEquals(hook.readCount, 1); //TODO - } finally { - db.drop(); - } + OClass aClass = db.getMetadata().getSchema().createClass(CLASS_NAME); + aClass.createProperty(FIELD_ID, OType.STRING); + aClass.createProperty(FIELD_STATUS, OType.STRING); + aClass.createIndex("IDX", OClass.INDEX_TYPE.NOTUNIQUE, FIELD_ID); + TestHook hook = new TestHook(); + db.registerHook(hook); + + String id = UUID.randomUUID().toString(); + ODocument first = new ODocument(CLASS_NAME); + first.field(FIELD_ID, id); + first.field(FIELD_STATUS, STATUS); + db.save(first); + + db.query( + new OSQLSynchQuery( + "SELECT FROM " + CLASS_NAME + " WHERE " + FIELD_STATUS + " = '" + STATUS + "'")); + // assertEquals(hook.readCount, 1); //TODO + hook.readCount = 0; + db.query( + new OSQLSynchQuery( + "SELECT FROM " + CLASS_NAME + " WHERE " + FIELD_ID + " = '" + id + "'")); + // assertEquals(hook.readCount, 1); //TODO } @Test public void testInHook() throws Exception { - ODatabaseDocument db = - new ODatabaseDocumentTx("memory:" + CheckHookCallCountTest.class.getSimpleName()); - db.create(); - try { - OSchema schema = db.getMetadata().getSchema(); - OClass oClass = schema.createClass("TestInHook"); - oClass.createProperty("a", OType.INTEGER); - oClass.createProperty("b", OType.INTEGER); - oClass.createProperty("c", OType.INTEGER); - ODocument doc = new ODocument(oClass); - doc.field("a", 2); - doc.field("b", 2); - doc.save(); - doc.reload(); - assertEquals(Integer.valueOf(2), doc.field("a")); - assertEquals(Integer.valueOf(2), doc.field("b")); - assertNull(doc.field("c")); - db.registerHook( - new ODocumentHookAbstract(db) { - - { - setIncludeClasses("TestInHook"); - } - - @Override - public void onRecordAfterCreate(ODocument iDocument) { - onRecordAfterRead(iDocument); - } - - @Override - public void onRecordAfterRead(ODocument iDocument) { - String script = "select sum(a, b) as value from " + iDocument.getIdentity(); - List calculated = database.query(new OSQLSynchQuery(script)); - if (calculated != null && !calculated.isEmpty()) { - iDocument.field("c", calculated.get(0).field("value")); - } - } - - @Override - public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() { - return DISTRIBUTED_EXECUTION_MODE.SOURCE_NODE; + OSchema schema = db.getMetadata().getSchema(); + OClass oClass = schema.createClass("TestInHook"); + oClass.createProperty("a", OType.INTEGER); + oClass.createProperty("b", OType.INTEGER); + oClass.createProperty("c", OType.INTEGER); + ODocument doc = new ODocument(oClass); + doc.field("a", 2); + doc.field("b", 2); + doc.save(); + doc.reload(); + assertEquals(Integer.valueOf(2), doc.field("a")); + assertEquals(Integer.valueOf(2), doc.field("b")); + assertNull(doc.field("c")); + db.registerHook( + new ODocumentHookAbstract(db) { + + { + setIncludeClasses("TestInHook"); + } + + @Override + public void onRecordAfterCreate(ODocument iDocument) { + onRecordAfterRead(iDocument); + } + + @Override + public void onRecordAfterRead(ODocument iDocument) { + String script = "select sum(a, b) as value from " + iDocument.getIdentity(); + List calculated = database.query(new OSQLSynchQuery(script)); + if (calculated != null && !calculated.isEmpty()) { + iDocument.field("c", calculated.get(0).field("value")); } - }); - doc.reload(); - assertEquals(Integer.valueOf(2), doc.field("a")); - assertEquals(Integer.valueOf(2), doc.field("b")); - assertEquals(Integer.valueOf(4), doc.field("c")); - - doc = new ODocument(oClass); - doc.field("a", 3); - doc.field("b", 3); - doc.save(); // FAILING here: infinite recursion - - assertEquals(Integer.valueOf(3), doc.field("a")); - assertEquals(Integer.valueOf(3), doc.field("b")); - assertEquals(Integer.valueOf(6), doc.field("c")); - } finally { - db.drop(); - } + } + + @Override + public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() { + return DISTRIBUTED_EXECUTION_MODE.SOURCE_NODE; + } + }); + doc.reload(); + assertEquals(Integer.valueOf(2), doc.field("a")); + assertEquals(Integer.valueOf(2), doc.field("b")); + assertEquals(Integer.valueOf(4), doc.field("c")); + + doc = new ODocument(oClass); + doc.field("a", 3); + doc.field("b", 3); + doc.save(); // FAILING here: infinite recursion + + assertEquals(Integer.valueOf(3), doc.field("a")); + assertEquals(Integer.valueOf(3), doc.field("b")); + assertEquals(Integer.valueOf(6), doc.field("c")); } public class TestHook extends ODocumentHookAbstract { diff --git a/core/src/test/java/com/orientechnologies/orient/core/db/hook/HookChangeValidationTest.java b/core/src/test/java/com/orientechnologies/orient/core/db/hook/HookChangeValidationTest.java index 67b2120a4da..6ee4e51e391 100755 --- a/core/src/test/java/com/orientechnologies/orient/core/db/hook/HookChangeValidationTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/db/hook/HookChangeValidationTest.java @@ -2,8 +2,7 @@ import static org.junit.Assert.assertEquals; -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.OValidationException; import com.orientechnologies.orient.core.hook.ODocumentHookAbstract; import com.orientechnologies.orient.core.metadata.schema.OClass; @@ -13,211 +12,183 @@ import org.junit.Assert; import org.junit.Test; -public class HookChangeValidationTest { +public class HookChangeValidationTest extends BaseMemoryDatabase { @Test public void testHookCreateChange() { - ODatabaseDocument db = - new ODatabaseDocumentTx("memory:" + HookChangeValidationTest.class.getSimpleName()); - db.create(); + OSchema schema = db.getMetadata().getSchema(); + OClass classA = schema.createClass("TestClass"); + classA.createProperty("property1", OType.STRING).setNotNull(true); + classA.createProperty("property2", OType.STRING).setReadonly(true); + classA.createProperty("property3", OType.STRING).setMandatory(true); + db.registerHook( + new ODocumentHookAbstract() { + @Override + public RESULT onRecordBeforeCreate(ODocument doc) { + doc.removeField("property1"); + doc.removeField("property2"); + doc.removeField("property3"); + return RESULT.RECORD_CHANGED; + } + + @Override + public RESULT onRecordBeforeUpdate(ODocument doc) { + return RESULT.RECORD_NOT_CHANGED; + } + + @Override + public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() { + return DISTRIBUTED_EXECUTION_MODE.SOURCE_NODE; + } + }); + ODocument doc = new ODocument(classA); + doc.field("property1", "value1-create"); + doc.field("property2", "value2-create"); + doc.field("property3", "value3-create"); try { - OSchema schema = db.getMetadata().getSchema(); - OClass classA = schema.createClass("TestClass"); - classA.createProperty("property1", OType.STRING).setNotNull(true); - classA.createProperty("property2", OType.STRING).setReadonly(true); - classA.createProperty("property3", OType.STRING).setMandatory(true); - db.registerHook( - new ODocumentHookAbstract() { - @Override - public RESULT onRecordBeforeCreate(ODocument doc) { - doc.removeField("property1"); - doc.removeField("property2"); - doc.removeField("property3"); - return RESULT.RECORD_CHANGED; - } - - @Override - public RESULT onRecordBeforeUpdate(ODocument doc) { - return RESULT.RECORD_NOT_CHANGED; - } - - @Override - public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() { - return DISTRIBUTED_EXECUTION_MODE.SOURCE_NODE; - } - }); - ODocument doc = new ODocument(classA); - doc.field("property1", "value1-create"); - doc.field("property2", "value2-create"); - doc.field("property3", "value3-create"); - try { - doc.save(); - Assert.fail("The document save should fail for validation exception"); - } catch (OValidationException ex) { - - } - } finally { - db.drop(); + doc.save(); + Assert.fail("The document save should fail for validation exception"); + } catch (OValidationException ex) { + } } @Test public void testHookUpdateChange() { - ODatabaseDocument db = - new ODatabaseDocumentTx("memory:" + HookChangeValidationTest.class.getSimpleName()); - db.create(); + OSchema schema = db.getMetadata().getSchema(); + OClass classA = schema.createClass("TestClass"); + classA.createProperty("property1", OType.STRING).setNotNull(true); + classA.createProperty("property2", OType.STRING).setReadonly(true); + classA.createProperty("property3", OType.STRING).setMandatory(true); + db.registerHook( + new ODocumentHookAbstract() { + @Override + public RESULT onRecordBeforeCreate(ODocument doc) { + return RESULT.RECORD_NOT_CHANGED; + } + + @Override + public RESULT onRecordBeforeUpdate(ODocument doc) { + doc.removeField("property1"); + doc.removeField("property2"); + doc.removeField("property3"); + return RESULT.RECORD_CHANGED; + } + + @Override + public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() { + return DISTRIBUTED_EXECUTION_MODE.SOURCE_NODE; + } + }); + ODocument doc = new ODocument(classA); + doc.field("property1", "value1-create"); + doc.field("property2", "value2-create"); + doc.field("property3", "value3-create"); + doc.save(); + assertEquals("value1-create", doc.field("property1")); + assertEquals("value2-create", doc.field("property2")); + assertEquals("value3-create", doc.field("property3")); + + doc.field("property1", "value1-update"); + doc.field("property2", "value2-update"); try { - OSchema schema = db.getMetadata().getSchema(); - OClass classA = schema.createClass("TestClass"); - classA.createProperty("property1", OType.STRING).setNotNull(true); - classA.createProperty("property2", OType.STRING).setReadonly(true); - classA.createProperty("property3", OType.STRING).setMandatory(true); - db.registerHook( - new ODocumentHookAbstract() { - @Override - public RESULT onRecordBeforeCreate(ODocument doc) { - return RESULT.RECORD_NOT_CHANGED; - } - - @Override - public RESULT onRecordBeforeUpdate(ODocument doc) { - doc.removeField("property1"); - doc.removeField("property2"); - doc.removeField("property3"); - return RESULT.RECORD_CHANGED; - } - - @Override - public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() { - return DISTRIBUTED_EXECUTION_MODE.SOURCE_NODE; - } - }); - ODocument doc = new ODocument(classA); - doc.field("property1", "value1-create"); - doc.field("property2", "value2-create"); - doc.field("property3", "value3-create"); doc.save(); - assertEquals("value1-create", doc.field("property1")); - assertEquals("value2-create", doc.field("property2")); - assertEquals("value3-create", doc.field("property3")); - - doc.field("property1", "value1-update"); - doc.field("property2", "value2-update"); - try { - doc.save(); - Assert.fail("The document save should fail for validation exception"); - } catch (OValidationException ex) { - - } - } finally { - db.drop(); + Assert.fail("The document save should fail for validation exception"); + } catch (OValidationException ex) { + } } @Test public void testHookCreateChangeTx() { - ODatabaseDocument db = - new ODatabaseDocumentTx("memory:" + HookChangeValidationTest.class.getSimpleName()); - db.create(); + OSchema schema = db.getMetadata().getSchema(); + OClass classA = schema.createClass("TestClass"); + classA.createProperty("property1", OType.STRING).setNotNull(true); + classA.createProperty("property2", OType.STRING).setReadonly(true); + classA.createProperty("property3", OType.STRING).setMandatory(true); + db.registerHook( + new ODocumentHookAbstract() { + @Override + public RESULT onRecordBeforeCreate(ODocument doc) { + doc.removeField("property1"); + doc.removeField("property2"); + doc.removeField("property3"); + return RESULT.RECORD_CHANGED; + } + + @Override + public RESULT onRecordBeforeUpdate(ODocument doc) { + return RESULT.RECORD_NOT_CHANGED; + } + + @Override + public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() { + return DISTRIBUTED_EXECUTION_MODE.SOURCE_NODE; + } + }); + ODocument doc = new ODocument(classA); + doc.field("property1", "value1-create"); + doc.field("property2", "value2-create"); + doc.field("property3", "value3-create"); try { - OSchema schema = db.getMetadata().getSchema(); - OClass classA = schema.createClass("TestClass"); - classA.createProperty("property1", OType.STRING).setNotNull(true); - classA.createProperty("property2", OType.STRING).setReadonly(true); - classA.createProperty("property3", OType.STRING).setMandatory(true); - db.registerHook( - new ODocumentHookAbstract() { - @Override - public RESULT onRecordBeforeCreate(ODocument doc) { - doc.removeField("property1"); - doc.removeField("property2"); - doc.removeField("property3"); - return RESULT.RECORD_CHANGED; - } - - @Override - public RESULT onRecordBeforeUpdate(ODocument doc) { - return RESULT.RECORD_NOT_CHANGED; - } - - @Override - public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() { - return DISTRIBUTED_EXECUTION_MODE.SOURCE_NODE; - } - }); - ODocument doc = new ODocument(classA); - doc.field("property1", "value1-create"); - doc.field("property2", "value2-create"); - doc.field("property3", "value3-create"); - try { - db.begin(); - doc.save(); - db.commit(); - Assert.fail("The document save should fail for validation exception"); - } catch (OValidationException ex) { - - } - } finally { - db.drop(); + db.begin(); + doc.save(); + db.commit(); + Assert.fail("The document save should fail for validation exception"); + } catch (OValidationException ex) { + } } @Test public void testHookUpdateChangeTx() { - ODatabaseDocument db = - new ODatabaseDocumentTx("memory:" + HookChangeValidationTest.class.getSimpleName()); - db.create(); + OSchema schema = db.getMetadata().getSchema(); + OClass classA = schema.createClass("TestClass"); + classA.createProperty("property1", OType.STRING).setNotNull(true); + classA.createProperty("property2", OType.STRING).setReadonly(true); + classA.createProperty("property3", OType.STRING).setMandatory(true); + db.registerHook( + new ODocumentHookAbstract() { + @Override + public RESULT onRecordBeforeCreate(ODocument doc) { + return RESULT.RECORD_NOT_CHANGED; + } + + @Override + public RESULT onRecordBeforeUpdate(ODocument doc) { + doc.removeField("property1"); + doc.removeField("property2"); + doc.removeField("property3"); + return RESULT.RECORD_CHANGED; + } + + @Override + public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() { + return DISTRIBUTED_EXECUTION_MODE.SOURCE_NODE; + } + }); + ODocument doc = new ODocument(classA); + doc.field("property1", "value1-create"); + doc.field("property2", "value2-create"); + doc.field("property3", "value3-create"); + doc.save(); + assertEquals("value1-create", doc.field("property1")); + assertEquals("value2-create", doc.field("property2")); + assertEquals("value3-create", doc.field("property3")); + + doc.field("property1", "value1-update"); + doc.field("property2", "value2-update"); try { - OSchema schema = db.getMetadata().getSchema(); - OClass classA = schema.createClass("TestClass"); - classA.createProperty("property1", OType.STRING).setNotNull(true); - classA.createProperty("property2", OType.STRING).setReadonly(true); - classA.createProperty("property3", OType.STRING).setMandatory(true); - db.registerHook( - new ODocumentHookAbstract() { - @Override - public RESULT onRecordBeforeCreate(ODocument doc) { - return RESULT.RECORD_NOT_CHANGED; - } - - @Override - public RESULT onRecordBeforeUpdate(ODocument doc) { - doc.removeField("property1"); - doc.removeField("property2"); - doc.removeField("property3"); - return RESULT.RECORD_CHANGED; - } - - @Override - public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() { - return DISTRIBUTED_EXECUTION_MODE.SOURCE_NODE; - } - }); - ODocument doc = new ODocument(classA); - doc.field("property1", "value1-create"); - doc.field("property2", "value2-create"); - doc.field("property3", "value3-create"); + db.begin(); doc.save(); - assertEquals("value1-create", doc.field("property1")); - assertEquals("value2-create", doc.field("property2")); - assertEquals("value3-create", doc.field("property3")); - - doc.field("property1", "value1-update"); - doc.field("property2", "value2-update"); - try { - db.begin(); - doc.save(); - db.commit(); - Assert.fail("The document save should fail for validation exception"); - } catch (OValidationException ex) { - - } - } finally { - db.drop(); + db.commit(); + Assert.fail("The document save should fail for validation exception"); + } catch (OValidationException ex) { + } } } diff --git a/core/src/test/java/com/orientechnologies/orient/core/db/hook/HookRegisterRemoveTest.java b/core/src/test/java/com/orientechnologies/orient/core/db/hook/HookRegisterRemoveTest.java index 9e45f2d9532..4611087e049 100644 --- a/core/src/test/java/com/orientechnologies/orient/core/db/hook/HookRegisterRemoveTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/db/hook/HookRegisterRemoveTest.java @@ -2,22 +2,17 @@ import static org.junit.Assert.assertEquals; -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.hook.ORecordHook; import com.orientechnologies.orient.core.record.ORecord; import com.orientechnologies.orient.core.record.impl.ODocument; import java.util.concurrent.atomic.AtomicInteger; import org.junit.Test; -public class HookRegisterRemoveTest { +public class HookRegisterRemoveTest extends BaseMemoryDatabase { @Test public void addAndRemoveHookTest() { - - ODatabaseDocument db = - new ODatabaseDocumentTx("memory:" + HookRegisterRemoveTest.class.getSimpleName()); - db.create(); final AtomicInteger integer = new AtomicInteger(0); ORecordHook iHookImpl = new ORecordHook() { @@ -43,6 +38,5 @@ public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() { db.unregisterHook(iHookImpl); db.save(new ODocument(), db.getClusterNameById(db.getDefaultClusterId())); assertEquals(3, integer.get()); - db.drop(); } } diff --git a/core/src/test/java/com/orientechnologies/orient/core/db/hook/HookSaveTest.java b/core/src/test/java/com/orientechnologies/orient/core/db/hook/HookSaveTest.java index 02cd6b83486..d17d0a666c6 100644 --- a/core/src/test/java/com/orientechnologies/orient/core/db/hook/HookSaveTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/db/hook/HookSaveTest.java @@ -2,34 +2,18 @@ import static org.junit.Assert.assertNotNull; -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.hook.ORecordHook; import com.orientechnologies.orient.core.record.ORecord; import com.orientechnologies.orient.core.record.impl.ODocument; -import org.junit.After; -import org.junit.Before; import org.junit.Test; /** Created by tglman on 01/06/16. */ -public class HookSaveTest { - - private ODatabaseDocument database; - - @Before - public void before() { - database = new ODatabaseDocumentTx("memory:" + HookSaveTest.this.getClass().getSimpleName()); - database.create(); - } - - @After - public void after() { - database.drop(); - } +public class HookSaveTest extends BaseMemoryDatabase { @Test public void testCreatedLinkedInHook() { - database.registerHook( + db.registerHook( new ORecordHook() { @Override public void onUnregister() {} @@ -51,7 +35,7 @@ public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() { } }); - ODocument doc = database.save(new ODocument("test")); + ODocument doc = db.save(new ODocument("test")); ODocument newRef = doc.field("testNewLinkedRecord"); assertNotNull(newRef); assertNotNull(newRef.getIdentity().isPersistent()); @@ -59,7 +43,7 @@ public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() { @Test public void testCreatedBackLinkedInHook() { - database.registerHook( + db.registerHook( new ORecordHook() { @Override public void onUnregister() {} @@ -82,7 +66,7 @@ public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() { } }); - ODocument doc = database.save(new ODocument("test")); + ODocument doc = db.save(new ODocument("test")); ODocument newRef = doc.field("testNewLinkedRecord"); assertNotNull(newRef); assertNotNull(newRef.getIdentity().isPersistent()); diff --git a/core/src/test/java/com/orientechnologies/orient/core/db/record/DocumentJavaSerializationTest.java b/core/src/test/java/com/orientechnologies/orient/core/db/record/DocumentJavaSerializationTest.java index 959cf0686e2..ffe484c680c 100644 --- a/core/src/test/java/com/orientechnologies/orient/core/db/record/DocumentJavaSerializationTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/db/record/DocumentJavaSerializationTest.java @@ -3,7 +3,7 @@ import static org.junit.Assert.assertEquals; import com.orientechnologies.orient.core.config.OGlobalConfiguration; -import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; +import com.orientechnologies.orient.core.db.document.ODatabaseDocumentAbstract; import com.orientechnologies.orient.core.record.ORecordInternal; import com.orientechnologies.orient.core.record.impl.ODocument; import com.orientechnologies.orient.core.serialization.serializer.record.ORecordSerializer; @@ -26,13 +26,13 @@ public class DocumentJavaSerializationTest { @Before public void before() { this.previousSerializerConf = OGlobalConfiguration.DB_DOCUMENT_SERIALIZER.getValueAsString(); - previousSerializerInstance = ODatabaseDocumentTx.getDefaultSerializer(); + previousSerializerInstance = ODatabaseDocumentAbstract.getDefaultSerializer(); } @After public void after() { OGlobalConfiguration.DB_DOCUMENT_SERIALIZER.setValue(this.previousSerializerConf); - ODatabaseDocumentTx.setDefaultSerializer(previousSerializerInstance); + ODatabaseDocumentAbstract.setDefaultSerializer(previousSerializerInstance); } @Test @@ -54,7 +54,7 @@ public void testSimpleSerialization() throws IOException, ClassNotFoundException @Test public void testCsvBinarySerialization() throws IOException, ClassNotFoundException { OGlobalConfiguration.DB_DOCUMENT_SERIALIZER.setValue(ORecordSerializerSchemaAware2CSV.NAME); - ODatabaseDocumentTx.setDefaultSerializer( + ODatabaseDocumentAbstract.setDefaultSerializer( ORecordSerializerFactory.instance().getFormat(ORecordSerializerSchemaAware2CSV.NAME)); ODocument doc = new ODocument(); ORecordInternal.setRecordSerializer( @@ -66,7 +66,7 @@ public void testCsvBinarySerialization() throws IOException, ClassNotFoundExcept oos.writeObject(doc); OGlobalConfiguration.DB_DOCUMENT_SERIALIZER.setValue(ORecordSerializerBinary.NAME); - ODatabaseDocumentTx.setDefaultSerializer( + ODatabaseDocumentAbstract.setDefaultSerializer( ORecordSerializerFactory.instance().getFormat(ORecordSerializerBinary.NAME)); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); @@ -79,7 +79,7 @@ public void testCsvBinarySerialization() throws IOException, ClassNotFoundExcept @Test public void testBinaryCsvSerialization() throws IOException, ClassNotFoundException { OGlobalConfiguration.DB_DOCUMENT_SERIALIZER.setValue(ORecordSerializerBinary.NAME); - ODatabaseDocumentTx.setDefaultSerializer( + ODatabaseDocumentAbstract.setDefaultSerializer( ORecordSerializerFactory.instance().getFormat(ORecordSerializerBinary.NAME)); ODocument doc = new ODocument(); ORecordInternal.setRecordSerializer( @@ -91,7 +91,7 @@ public void testBinaryCsvSerialization() throws IOException, ClassNotFoundExcept oos.writeObject(doc); OGlobalConfiguration.DB_DOCUMENT_SERIALIZER.setValue(ORecordSerializerSchemaAware2CSV.NAME); - ODatabaseDocumentTx.setDefaultSerializer( + ODatabaseDocumentAbstract.setDefaultSerializer( ORecordSerializerFactory.instance().getFormat(ORecordSerializerSchemaAware2CSV.NAME)); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); diff --git a/core/src/test/java/com/orientechnologies/orient/core/db/record/TestTypeGuessingWorkingWithSQLAndMultiValues.java b/core/src/test/java/com/orientechnologies/orient/core/db/record/TestTypeGuessingWorkingWithSQLAndMultiValues.java index 98e9c29da51..e2920c168e8 100644 --- a/core/src/test/java/com/orientechnologies/orient/core/db/record/TestTypeGuessingWorkingWithSQLAndMultiValues.java +++ b/core/src/test/java/com/orientechnologies/orient/core/db/record/TestTypeGuessingWorkingWithSQLAndMultiValues.java @@ -1,26 +1,20 @@ package com.orientechnologies.orient.core.db.record; +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.record.impl.ODocument; import com.orientechnologies.orient.core.sql.OCommandSQL; import java.util.Collection; -import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; /** @author Luca Garulli (l.garulli--(at)--orientdb.com) */ -public class TestTypeGuessingWorkingWithSQLAndMultiValues { - - private ODatabaseDocumentTx db; +public class TestTypeGuessingWorkingWithSQLAndMultiValues extends BaseMemoryDatabase { @Before - public void create() { - db = - new ODatabaseDocumentTx( - "memory:" + TestTypeGuessingWorkingWithSQLAndMultiValues.class.getSimpleName()); - db.create(); + public void beforeTest() { + super.beforeTest(); db.command( new OCommandScript( @@ -70,9 +64,4 @@ public void testLinkedValue() { for (ODocument a : addresses) Assert.assertTrue(a.getClassName().equals("Address")); } - - @After - public void after() { - db.drop(); - } } diff --git a/core/src/test/java/com/orientechnologies/orient/core/record/impl/ODocumentSchemafullSerializationTest.java b/core/src/test/java/com/orientechnologies/orient/core/record/impl/ODocumentSchemafullSerializationTest.java index 6ed74b0c32c..b0225edc5f7 100755 --- a/core/src/test/java/com/orientechnologies/orient/core/record/impl/ODocumentSchemafullSerializationTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/record/impl/ODocumentSchemafullSerializationTest.java @@ -6,6 +6,7 @@ import com.orientechnologies.orient.core.config.OGlobalConfiguration; import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal; import com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal; +import com.orientechnologies.orient.core.db.document.ODatabaseDocumentAbstract; import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; import com.orientechnologies.orient.core.id.ORecordId; import com.orientechnologies.orient.core.metadata.schema.OClass; @@ -73,7 +74,7 @@ public ODocumentSchemafullSerializationTest(ORecordSerializer serializer) { @Before public void before() { - ODatabaseDocumentTx.setDefaultSerializer(serializer); + ODatabaseDocumentAbstract.setDefaultSerializer(serializer); databaseDocument = new ODatabaseDocumentTx("memory:" + name.getMethodName()).create(); // databaseDocument.getMetadata(). OSchema schema = databaseDocument.getMetadata().getSchema(); @@ -127,7 +128,7 @@ public void before() { @After public void after() { databaseDocument.drop(); - ODatabaseDocumentTx.setDefaultSerializer( + ODatabaseDocumentAbstract.setDefaultSerializer( ORecordSerializerFactory.instance() .getFormat(OGlobalConfiguration.DB_DOCUMENT_SERIALIZER.getValueAsString())); } diff --git a/core/src/test/java/com/orientechnologies/orient/core/record/impl/ODocumentSchemalessSerializationTest.java b/core/src/test/java/com/orientechnologies/orient/core/record/impl/ODocumentSchemalessSerializationTest.java index 8bc1f3bfd15..1ce24e068d1 100755 --- a/core/src/test/java/com/orientechnologies/orient/core/record/impl/ODocumentSchemalessSerializationTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/record/impl/ODocumentSchemalessSerializationTest.java @@ -5,7 +5,7 @@ import static org.junit.Assert.assertTrue; import com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal; -import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; +import com.orientechnologies.orient.core.db.document.ODatabaseDocumentAbstract; import com.orientechnologies.orient.core.id.ORecordId; import com.orientechnologies.orient.core.metadata.schema.OType; import com.orientechnologies.orient.core.serialization.serializer.record.ORecordSerializer; @@ -31,14 +31,14 @@ public class ODocumentSchemalessSerializationTest { @Before public void before() { serializer = new ORecordSerializerSchemaAware2CSV(); - defaultSerializer = ODatabaseDocumentTx.getDefaultSerializer(); - ODatabaseDocumentTx.setDefaultSerializer(serializer); + defaultSerializer = ODatabaseDocumentAbstract.getDefaultSerializer(); + ODatabaseDocumentAbstract.setDefaultSerializer(serializer); ODatabaseRecordThreadLocal.instance().remove(); } @After public void after() { - ODatabaseDocumentTx.setDefaultSerializer(defaultSerializer); + ODatabaseDocumentAbstract.setDefaultSerializer(defaultSerializer); } @Test diff --git a/core/src/test/java/com/orientechnologies/orient/core/record/impl/ODocumentTest.java b/core/src/test/java/com/orientechnologies/orient/core/record/impl/ODocumentTest.java index 28160256927..6b3fd95ef5f 100755 --- a/core/src/test/java/com/orientechnologies/orient/core/record/impl/ODocumentTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/record/impl/ODocumentTest.java @@ -10,7 +10,7 @@ import com.orientechnologies.orient.core.OCreateDatabaseUtil; import com.orientechnologies.orient.core.db.ODatabaseSession; import com.orientechnologies.orient.core.db.OrientDB; -import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; +import com.orientechnologies.orient.core.db.document.ODatabaseDocumentAbstract; import com.orientechnologies.orient.core.db.record.ridbag.ORidBag; import com.orientechnologies.orient.core.id.ORecordId; import com.orientechnologies.orient.core.metadata.schema.OClass; @@ -135,7 +135,7 @@ public void testKeepFieldTypeSerialization() throws Exception { assertEquals(doc.fieldType("link"), OType.LINK); assertEquals(doc.fieldType("string"), OType.STRING); assertEquals(doc.fieldType("binary"), OType.BINARY); - ORecordSerializer ser = ODatabaseDocumentTx.getDefaultSerializer(); + ORecordSerializer ser = ODatabaseDocumentAbstract.getDefaultSerializer(); byte[] bytes = ser.toStream(doc); doc = new ODocument(); ser.fromStream(bytes, doc, null); @@ -158,7 +158,7 @@ public void testKeepAutoFieldTypeSerialization() throws Exception { assertNull(doc.fieldType("link")); assertNull(doc.fieldType("string")); assertNull(doc.fieldType("binary")); - ORecordSerializer ser = ODatabaseDocumentTx.getDefaultSerializer(); + ORecordSerializer ser = ODatabaseDocumentAbstract.getDefaultSerializer(); byte[] bytes = ser.toStream(doc); doc = new ODocument(); ser.fromStream(bytes, doc, null); @@ -192,7 +192,7 @@ public void testKeepSchemafullFieldTypeSerialization() throws Exception { assertEquals(doc.fieldType("link"), OType.LINK); assertEquals(doc.fieldType("string"), OType.STRING); assertEquals(doc.fieldType("binary"), OType.BINARY); - ORecordSerializer ser = ODatabaseDocumentTx.getDefaultSerializer(); + ORecordSerializer ser = ODatabaseDocumentAbstract.getDefaultSerializer(); byte[] bytes = ser.toStream(doc); doc = new ODocument(); ser.fromStream(bytes, doc, null); @@ -213,7 +213,7 @@ public void testKeepSchemafullFieldTypeSerialization() throws Exception { public void testChangeTypeOnValueSet() throws Exception { ODocument doc = new ODocument(); doc.field("link", new ORecordId(1, 2)); - ORecordSerializer ser = ODatabaseDocumentTx.getDefaultSerializer(); + ORecordSerializer ser = ODatabaseDocumentAbstract.getDefaultSerializer(); byte[] bytes = ser.toStream(doc); doc = new ODocument(); ser.fromStream(bytes, doc, null); diff --git a/core/src/test/java/com/orientechnologies/orient/core/serialization/serializer/binary/impl/ORecordSerializerBinaryDebugTest.java b/core/src/test/java/com/orientechnologies/orient/core/serialization/serializer/binary/impl/ORecordSerializerBinaryDebugTest.java index ed21a6d2157..37719e0a0c2 100644 --- a/core/src/test/java/com/orientechnologies/orient/core/serialization/serializer/binary/impl/ORecordSerializerBinaryDebugTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/serialization/serializer/binary/impl/ORecordSerializerBinaryDebugTest.java @@ -3,9 +3,9 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import com.orientechnologies.BaseMemoryDatabase; 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.document.ODatabaseDocumentAbstract; import com.orientechnologies.orient.core.metadata.schema.OClass; import com.orientechnologies.orient.core.metadata.schema.OType; import com.orientechnologies.orient.core.record.impl.ODocument; @@ -17,171 +17,143 @@ import org.junit.Before; import org.junit.Test; -public class ORecordSerializerBinaryDebugTest { +public class ORecordSerializerBinaryDebugTest extends BaseMemoryDatabase { private ORecordSerializer previous; @Before public void before() { - previous = ODatabaseDocumentTx.getDefaultSerializer(); - ODatabaseDocumentTx.setDefaultSerializer(new ORecordSerializerBinary()); + previous = ODatabaseDocumentAbstract.getDefaultSerializer(); + ODatabaseDocumentAbstract.setDefaultSerializer(new ORecordSerializerBinary()); } @After public void after() { - ODatabaseDocumentTx.setDefaultSerializer(previous); + ODatabaseDocumentAbstract.setDefaultSerializer(previous); } @Test public void testSimpleDocumentDebug() { - ODatabaseDocument db = - new ODatabaseDocumentTx("memory:" + ORecordSerializerBinaryDebugTest.class.getSimpleName()); - db.create(); - try { - ODocument doc = new ODocument(); - doc.field("test", "test"); - doc.field("anInt", 2); - doc.field("anDouble", 2D); - - byte[] bytes = doc.toStream(); - - ORecordSerializerBinaryDebug debugger = new ORecordSerializerBinaryDebug(); - ORecordSerializationDebug debug = - debugger.deserializeDebug(bytes, (ODatabaseDocumentInternal) db); - - assertEquals(debug.properties.size(), 3); - assertEquals(debug.properties.get(0).name, "test"); - assertEquals(debug.properties.get(0).type, OType.STRING); - assertEquals(debug.properties.get(0).value, "test"); - - assertEquals(debug.properties.get(1).name, "anInt"); - assertEquals(debug.properties.get(1).type, OType.INTEGER); - assertEquals(debug.properties.get(1).value, 2); - - assertEquals(debug.properties.get(2).name, "anDouble"); - assertEquals(debug.properties.get(2).type, OType.DOUBLE); - assertEquals(debug.properties.get(2).value, 2D); - } finally { - db.drop(); - } + ODocument doc = new ODocument(); + doc.field("test", "test"); + doc.field("anInt", 2); + doc.field("anDouble", 2D); + + byte[] bytes = doc.toStream(); + + ORecordSerializerBinaryDebug debugger = new ORecordSerializerBinaryDebug(); + ORecordSerializationDebug debug = + debugger.deserializeDebug(bytes, (ODatabaseDocumentInternal) db); + + assertEquals(debug.properties.size(), 3); + assertEquals(debug.properties.get(0).name, "test"); + assertEquals(debug.properties.get(0).type, OType.STRING); + assertEquals(debug.properties.get(0).value, "test"); + + assertEquals(debug.properties.get(1).name, "anInt"); + assertEquals(debug.properties.get(1).type, OType.INTEGER); + assertEquals(debug.properties.get(1).value, 2); + + assertEquals(debug.properties.get(2).name, "anDouble"); + assertEquals(debug.properties.get(2).type, OType.DOUBLE); + assertEquals(debug.properties.get(2).value, 2D); } @Test public void testSchemaFullDocumentDebug() { - ODatabaseDocument db = - new ODatabaseDocumentTx("memory:" + ORecordSerializerBinaryDebugTest.class.getSimpleName()); - db.create(); - try { - OClass clazz = db.getMetadata().getSchema().createClass("some"); - clazz.createProperty("testP", OType.STRING); - clazz.createProperty("theInt", OType.INTEGER); - ODocument doc = new ODocument("some"); - doc.field("testP", "test"); - doc.field("theInt", 2); - doc.field("anDouble", 2D); - - byte[] bytes = doc.toStream(); - - ORecordSerializerBinaryDebug debugger = new ORecordSerializerBinaryDebug(); - ORecordSerializationDebug debug = - debugger.deserializeDebug(bytes, (ODatabaseDocumentInternal) db); - - assertEquals(debug.properties.size(), 3); - assertEquals(debug.properties.get(0).name, "testP"); - assertEquals(debug.properties.get(0).type, OType.STRING); - assertEquals(debug.properties.get(0).value, "test"); - - assertEquals(debug.properties.get(1).name, "theInt"); - assertEquals(debug.properties.get(1).type, OType.INTEGER); - assertEquals(debug.properties.get(1).value, 2); - - assertEquals(debug.properties.get(2).name, "anDouble"); - assertEquals(debug.properties.get(2).type, OType.DOUBLE); - assertEquals(debug.properties.get(2).value, 2D); - } finally { - db.drop(); - } + OClass clazz = db.getMetadata().getSchema().createClass("some"); + clazz.createProperty("testP", OType.STRING); + clazz.createProperty("theInt", OType.INTEGER); + ODocument doc = new ODocument("some"); + doc.field("testP", "test"); + doc.field("theInt", 2); + doc.field("anDouble", 2D); + + byte[] bytes = doc.toStream(); + + ORecordSerializerBinaryDebug debugger = new ORecordSerializerBinaryDebug(); + ORecordSerializationDebug debug = + debugger.deserializeDebug(bytes, (ODatabaseDocumentInternal) db); + + assertEquals(debug.properties.size(), 3); + assertEquals(debug.properties.get(0).name, "testP"); + assertEquals(debug.properties.get(0).type, OType.STRING); + assertEquals(debug.properties.get(0).value, "test"); + + assertEquals(debug.properties.get(1).name, "theInt"); + assertEquals(debug.properties.get(1).type, OType.INTEGER); + assertEquals(debug.properties.get(1).value, 2); + + assertEquals(debug.properties.get(2).name, "anDouble"); + assertEquals(debug.properties.get(2).type, OType.DOUBLE); + assertEquals(debug.properties.get(2).value, 2D); } @Test public void testSimpleBrokenDocumentDebug() { - ODatabaseDocument db = - new ODatabaseDocumentTx("memory:" + ORecordSerializerBinaryDebugTest.class.getSimpleName()); - db.create(); - try { - ODocument doc = new ODocument(); - doc.field("test", "test"); - doc.field("anInt", 2); - doc.field("anDouble", 2D); - - byte[] bytes = doc.toStream(); - byte[] brokenBytes = new byte[bytes.length - 10]; - System.arraycopy(bytes, 0, brokenBytes, 0, bytes.length - 10); - - ORecordSerializerBinaryDebug debugger = new ORecordSerializerBinaryDebug(); - ORecordSerializationDebug debug = - debugger.deserializeDebug(brokenBytes, (ODatabaseDocumentInternal) db); - - assertEquals(debug.properties.size(), 3); - assertEquals(debug.properties.get(0).name, "test"); - assertEquals(debug.properties.get(0).type, OType.STRING); - assertEquals(debug.properties.get(0).faildToRead, true); - assertNotNull(debug.properties.get(0).readingException); - - assertEquals(debug.properties.get(1).name, "anInt"); - assertEquals(debug.properties.get(1).type, OType.INTEGER); - assertEquals(debug.properties.get(1).faildToRead, true); - assertNotNull(debug.properties.get(1).readingException); - - assertEquals(debug.properties.get(2).name, "anDouble"); - assertEquals(debug.properties.get(2).type, OType.DOUBLE); - assertEquals(debug.properties.get(2).faildToRead, true); - assertNotNull(debug.properties.get(2).readingException); - } finally { - db.drop(); - } + ODocument doc = new ODocument(); + doc.field("test", "test"); + doc.field("anInt", 2); + doc.field("anDouble", 2D); + + byte[] bytes = doc.toStream(); + byte[] brokenBytes = new byte[bytes.length - 10]; + System.arraycopy(bytes, 0, brokenBytes, 0, bytes.length - 10); + + ORecordSerializerBinaryDebug debugger = new ORecordSerializerBinaryDebug(); + ORecordSerializationDebug debug = + debugger.deserializeDebug(brokenBytes, (ODatabaseDocumentInternal) db); + + assertEquals(debug.properties.size(), 3); + assertEquals(debug.properties.get(0).name, "test"); + assertEquals(debug.properties.get(0).type, OType.STRING); + assertEquals(debug.properties.get(0).faildToRead, true); + assertNotNull(debug.properties.get(0).readingException); + + assertEquals(debug.properties.get(1).name, "anInt"); + assertEquals(debug.properties.get(1).type, OType.INTEGER); + assertEquals(debug.properties.get(1).faildToRead, true); + assertNotNull(debug.properties.get(1).readingException); + + assertEquals(debug.properties.get(2).name, "anDouble"); + assertEquals(debug.properties.get(2).type, OType.DOUBLE); + assertEquals(debug.properties.get(2).faildToRead, true); + assertNotNull(debug.properties.get(2).readingException); } @Test public void testBrokenSchemaFullDocumentDebug() { - ODatabaseDocument db = - new ODatabaseDocumentTx("memory:" + ORecordSerializerBinaryDebugTest.class.getSimpleName()); - db.create(); - try { - OClass clazz = db.getMetadata().getSchema().createClass("some"); - clazz.createProperty("testP", OType.STRING); - clazz.createProperty("theInt", OType.INTEGER); - ODocument doc = new ODocument("some"); - doc.field("testP", "test"); - doc.field("theInt", 2); - doc.field("anDouble", 2D); - - byte[] bytes = doc.toStream(); - byte[] brokenBytes = new byte[bytes.length - 10]; - System.arraycopy(bytes, 0, brokenBytes, 0, bytes.length - 10); - - ORecordSerializerBinaryDebug debugger = new ORecordSerializerBinaryDebug(); - ORecordSerializationDebug debug = - debugger.deserializeDebug(brokenBytes, (ODatabaseDocumentInternal) db); - - assertEquals(debug.properties.size(), 3); - assertEquals(debug.properties.get(0).name, "testP"); - assertEquals(debug.properties.get(0).type, OType.STRING); - assertEquals(debug.properties.get(0).faildToRead, true); - assertNotNull(debug.properties.get(0).readingException); - - assertEquals(debug.properties.get(1).name, "theInt"); - assertEquals(debug.properties.get(1).type, OType.INTEGER); - assertEquals(debug.properties.get(1).faildToRead, true); - assertNotNull(debug.properties.get(1).readingException); - - assertEquals(debug.properties.get(2).name, "anDouble"); - assertEquals(debug.properties.get(2).type, OType.DOUBLE); - assertEquals(debug.properties.get(2).faildToRead, true); - assertNotNull(debug.properties.get(2).readingException); - } finally { - db.drop(); - } + OClass clazz = db.getMetadata().getSchema().createClass("some"); + clazz.createProperty("testP", OType.STRING); + clazz.createProperty("theInt", OType.INTEGER); + ODocument doc = new ODocument("some"); + doc.field("testP", "test"); + doc.field("theInt", 2); + doc.field("anDouble", 2D); + + byte[] bytes = doc.toStream(); + byte[] brokenBytes = new byte[bytes.length - 10]; + System.arraycopy(bytes, 0, brokenBytes, 0, bytes.length - 10); + + ORecordSerializerBinaryDebug debugger = new ORecordSerializerBinaryDebug(); + ORecordSerializationDebug debug = + debugger.deserializeDebug(brokenBytes, (ODatabaseDocumentInternal) db); + + assertEquals(debug.properties.size(), 3); + assertEquals(debug.properties.get(0).name, "testP"); + assertEquals(debug.properties.get(0).type, OType.STRING); + assertEquals(debug.properties.get(0).faildToRead, true); + assertNotNull(debug.properties.get(0).readingException); + + assertEquals(debug.properties.get(1).name, "theInt"); + assertEquals(debug.properties.get(1).type, OType.INTEGER); + assertEquals(debug.properties.get(1).faildToRead, true); + assertNotNull(debug.properties.get(1).readingException); + + assertEquals(debug.properties.get(2).name, "anDouble"); + assertEquals(debug.properties.get(2).type, OType.DOUBLE); + assertEquals(debug.properties.get(2).faildToRead, true); + assertNotNull(debug.properties.get(2).readingException); } }