Skip to content

Commit

Permalink
refactor: removed deprecated APIs use from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tglman committed Oct 19, 2023
1 parent 91bc8f6 commit 52df826
Show file tree
Hide file tree
Showing 26 changed files with 584 additions and 1,179 deletions.
Original file line number Diff line number Diff line change
@@ -1,32 +1,20 @@
package com.orientechnologies.orient.core.db.record.impl;

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.ORecordInternal;
import com.orientechnologies.orient.core.record.impl.ODocument;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

/** Created by tglman on 01/10/15. */
public class DirtyManagerReferenceCleanTest {
public class DirtyManagerReferenceCleanTest extends BaseMemoryDatabase {

private ODatabaseDocument db;

@Before
public void before() {
db = new ODatabaseDocumentTx("memory:" + DirtyManagerReferenceCleanTest.class.getSimpleName());
db.create();
public void beforeTest() {
super.beforeTest();
db.getMetadata().getSchema().createClass("test");
}

@After
public void after() {
db.drop();
}

@Test
public void testReferDeletedDocument() {
ODocument doc = new ODocument();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package com.orientechnologies.orient.core.db.tool;

import com.orientechnologies.orient.core.OCreateDatabaseUtil;
import com.orientechnologies.BaseMemoryInternalDatabase;
import com.orientechnologies.orient.core.command.OCommandOutputListener;
import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal;
import com.orientechnologies.orient.core.db.ODatabaseSession;
import com.orientechnologies.orient.core.db.OrientDB;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.index.OIndex;
import com.orientechnologies.orient.core.record.impl.ODocument;
Expand All @@ -16,83 +13,72 @@
import org.junit.Test;

/** Created by luigidellaquila on 14/09/17. */
public class OCheckIndexToolTest {
public class OCheckIndexToolTest extends BaseMemoryInternalDatabase {
@Test
public void test() {
ODatabaseDocumentInternal db = new ODatabaseDocumentTx("memory:OCheckIndexToolTest");
db.create();
try {
db.command(new OCommandSQL("create class Foo")).execute();
db.command(new OCommandSQL("create property Foo.name STRING")).execute();
db.command(new OCommandSQL("create index Foo.name on Foo (name) NOTUNIQUE")).execute();
db.command(new OCommandSQL("create class Foo")).execute();
db.command(new OCommandSQL("create property Foo.name STRING")).execute();
db.command(new OCommandSQL("create index Foo.name on Foo (name) NOTUNIQUE")).execute();

ODocument doc = db.newInstance("Foo");
doc.field("name", "a");
doc.save();
ODocument doc = db.newInstance("Foo");
doc.field("name", "a");
doc.save();

ORID rid = doc.getIdentity();
ORID rid = doc.getIdentity();

int N_RECORDS = 100000;
for (int i = 0; i < N_RECORDS; i++) {
doc = db.newInstance("Foo");
doc.field("name", "x" + i);
doc.save();
}
int N_RECORDS = 100000;
for (int i = 0; i < N_RECORDS; i++) {
doc = db.newInstance("Foo");
doc.field("name", "x" + i);
doc.save();
}

OIndex idx = db.getMetadata().getIndexManagerInternal().getIndex(db, "Foo.name");
Object key = idx.getDefinition().createValue("a");
boolean a = idx.remove(key, rid);
OIndex idx = db.getMetadata().getIndexManagerInternal().getIndex(db, "Foo.name");
Object key = idx.getDefinition().createValue("a");
boolean a = idx.remove(key, rid);

List result = db.query(new OSQLSynchQuery<Object>("SELECT FROM Foo"));
Assert.assertEquals(N_RECORDS + 1, result.size());
List result = db.query(new OSQLSynchQuery<Object>("SELECT FROM Foo"));
Assert.assertEquals(N_RECORDS + 1, result.size());

OCheckIndexTool tool = new OCheckIndexTool();
tool.setDatabase(db);
tool.setVerbose(true);
tool.setOutputListener(
new OCommandOutputListener() {
@Override
public void onMessage(String iText) {
System.out.println(iText);
}
});
OCheckIndexTool tool = new OCheckIndexTool();
tool.setDatabase(db);
tool.setVerbose(true);
tool.setOutputListener(
new OCommandOutputListener() {
@Override
public void onMessage(String iText) {
System.out.println(iText);
}
});

tool.run();
Assert.assertEquals(1, tool.getTotalErrors());
} finally {
db.close();
}
tool.run();
Assert.assertEquals(1, tool.getTotalErrors());
}

@Test
public void testBugOnCollectionIndex() {
final OrientDB context =
OCreateDatabaseUtil.createDatabase("test", "embedded:", OCreateDatabaseUtil.TYPE_MEMORY);
try (ODatabaseSession db = context.open("test", "admin", "adminpwd")) {
db.command("create class testclass");
db.command("create property testclass.name string");
db.command("create property testclass.tags linklist");
db.command("alter property testclass.tags default '[]'");
db.command("create index testclass_tags_idx on testclass (tags) NOTUNIQUE_HASH_INDEX");
db.command("create class testclass");
db.command("create property testclass.name string");
db.command("create property testclass.tags linklist");
db.command("alter property testclass.tags default '[]'");
db.command("create index testclass_tags_idx on testclass (tags) NOTUNIQUE_HASH_INDEX");

db.command("insert into testclass set name = 'a',tags = [#5:0] ");
db.command("insert into testclass set name = 'b'");
db.command("insert into testclass set name = 'c' ");
db.command("insert into testclass set name = 'a',tags = [#5:0] ");
db.command("insert into testclass set name = 'b'");
db.command("insert into testclass set name = 'c' ");

final OCheckIndexTool tool = new OCheckIndexTool();
final OCheckIndexTool tool = new OCheckIndexTool();

tool.setDatabase((ODatabaseDocumentInternal) db);
tool.setVerbose(true);
tool.setOutputListener(
new OCommandOutputListener() {
@Override
public void onMessage(String iText) {
System.out.println(iText);
}
});
tool.run();
Assert.assertEquals(0, tool.getTotalErrors());
}
context.close();
tool.setDatabase((ODatabaseDocumentInternal) db);
tool.setVerbose(true);
tool.setOutputListener(
new OCommandOutputListener() {
@Override
public void onMessage(String iText) {
System.out.println(iText);
}
});
tool.run();
Assert.assertEquals(0, tool.getTotalErrors());
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
package com.orientechnologies.orient.core.index;

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.metadata.schema.OClass;
import com.orientechnologies.orient.core.metadata.schema.OSchema;
import com.orientechnologies.orient.core.metadata.schema.OType;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.executor.OResultSet;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class OCompositeIndexSQLInsertTest {
public class OCompositeIndexSQLInsertTest extends BaseMemoryDatabase {

public ODatabaseDocument db;

@Before
public void before() {
System.err.println("BEFORE THREAD: " + Thread.currentThread());
db = new ODatabaseDocumentTx("memory:" + OCompositeIndexSQLInsertTest.class.getSimpleName());
db.create();
public void beforeTest() {
super.beforeTest();
OSchema schema = db.getMetadata().getSchema();
OClass book = schema.createClass("Book");
book.createProperty("author", OType.STRING);
Expand All @@ -35,13 +27,6 @@ public void before() {
"indexignoresnulls", "NOTUNIQUE", null, indexOptions, new String[] {"nullKey1"});
}

@After
public void after() {
System.err.println("AFTER THREAD: " + Thread.currentThread());
db.activateOnCurrentThread();
db.drop();
}

@Test
public void testCompositeIndexWithRangeAndContains() {
final OSchema schema = db.getMetadata().getSchema();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,41 @@

import static org.junit.Assert.assertEquals;

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.record.OElement;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.OCommandSQL;
import com.orientechnologies.orient.core.sql.query.OLegacyResultSet;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/** @author Sergey Sitnikov */
public class TxNonUniqueIndexWithCollationTest {

private ODatabaseDocumentTx db;
public class TxNonUniqueIndexWithCollationTest extends BaseMemoryDatabase {

@Before
public void before() {
db = new ODatabaseDocumentTx("memory:TxNonUniqueIndexWithCollationTest");
db.create();
public void beforeTest() {
super.beforeTest();
db.getMetadata()
.getSchema()
.createClass("user")
.createProperty("name", OType.STRING)
.setCollate("ci")
.createIndex(OClass.INDEX_TYPE.NOTUNIQUE);

db.newInstance("user").field("name", "abc").save();
db.newInstance("user").field("name", "aby").save();
db.newInstance("user").field("name", "aby").save();
db.newInstance("user").field("name", "abz").save();
}

@After
public void after() {
db.drop();
OElement user = db.newElement("user");
user.setProperty("name", "abc");
db.save(user);
user = db.newElement("user");
user.setProperty("name", "aby");
db.save(user);
user = db.newElement("user");
user.setProperty("name", "aby");
db.save(user);
user = db.newElement("user");
user.setProperty("name", "abz");
db.save(user);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,38 @@

import static org.junit.Assert.assertEquals;

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.record.OElement;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.OCommandSQL;
import com.orientechnologies.orient.core.sql.query.OLegacyResultSet;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/** @author Sergey Sitnikov */
public class TxUniqueIndexWithCollationTest {
public class TxUniqueIndexWithCollationTest extends BaseMemoryDatabase {

private ODatabaseDocumentTx db;

@Before
public void before() {
db = new ODatabaseDocumentTx("memory:TxUniqueIndexWithCollationTest");
db.create();
public void beforeTest() {
super.beforeTest();
db.getMetadata()
.getSchema()
.createClass("user")
.createProperty("name", OType.STRING)
.setCollate("ci")
.createIndex(OClass.INDEX_TYPE.UNIQUE);

db.newInstance("user").field("name", "abc").save();
db.newInstance("user").field("name", "aby").save();
db.newInstance("user").field("name", "abz").save();
}
OElement one = db.newElement("user");
one.setProperty("name", "abc");
db.save(one);

OElement two = db.newElement("user");
two.setProperty("name", "aby");
db.save(two);

@After
public void after() {
db.drop();
OElement three = db.newElement("user");
three.setProperty("name", "abz");
db.save(three);
}

@Test
Expand Down
Loading

0 comments on commit 52df826

Please sign in to comment.