Search in sources :

Example 76 with ODatabaseDocumentTx

use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.

the class LocalCreateBinarySpeedTest method init.

@Override
public void init() {
    Orient.instance().getProfiler().startRecording();
    database = new ODatabaseDocumentTx(System.getProperty("url")).open("admin", "admin");
    record = new ORecordBytes();
    database.declareIntent(new OIntentMassiveInsert());
    database.begin(TXTYPE.NOTX);
    Random rnd = new Random();
    recordContent = new byte[RECORD_SIZE];
    for (int i = 0; i < RECORD_SIZE; ++i) recordContent[i] = (byte) rnd.nextInt(256);
}
Also used : Random(java.util.Random) ORecordBytes(com.orientechnologies.orient.core.record.impl.ORecordBytes) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OIntentMassiveInsert(com.orientechnologies.orient.core.intent.OIntentMassiveInsert)

Example 77 with ODatabaseDocumentTx

use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.

the class LocalCreateDocumentMultiThreadSpeedTest method init.

@Override
public void init() {
    mainDatabase = new ODatabaseDocumentTx(System.getProperty("url"));
    mainDatabase.setSerializer(new ORecordSerializerBinary());
    if (mainDatabase.exists()) {
        mainDatabase.open("admin", "admin");
        // else
        mainDatabase.drop();
    }
    mainDatabase.create();
    mainDatabase.set(ODatabase.ATTRIBUTES.MINIMUMCLUSTERS, 8);
    mainDatabase.getMetadata().getSchema().createClass("Account");
    // database.countClusterElements("Account");
    foundObjects = 0;
    System.out.println("\nTotal objects in Animal cluster before the test: " + foundObjects);
}
Also used : ORecordSerializerBinary(com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializerBinary) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)

Example 78 with ODatabaseDocumentTx

use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.

the class ODirtyManagerRidbagTest method before.

@BeforeMethod
public void before() {
    db = new ODatabaseDocumentTx("memory:" + ODirtyManagerRidbagTest.class.getSimpleName());
    db.create();
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 79 with ODatabaseDocumentTx

use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.

the class OSBTreeRidBagConcurrencyMultiRidBag method testConcurrency.

public void testConcurrency() throws Exception {
    ODatabaseDocumentTx db = new ODatabaseDocumentTx(URL);
    if (db.exists()) {
        db.open("admin", "admin");
        db.drop();
    }
    db.create();
    for (int i = 0; i < 100; i++) {
        ODocument document = new ODocument();
        ORidBag ridBag = new ORidBag();
        document.field("ridBag", ridBag);
        document.save();
        ridTreePerDocument.put(document.getIdentity(), new ConcurrentSkipListSet<ORID>());
        lastClusterPosition.set(document.getIdentity().getClusterPosition());
    }
    final List<Future<?>> futures = new ArrayList<Future<?>>();
    Random random = new Random();
    for (int i = 0; i < 5; i++) addDocExecutor.scheduleAtFixedRate(new DocumentAdder(), random.nextInt(250), 250, TimeUnit.MILLISECONDS);
    for (int i = 0; i < 5; i++) futures.add(threadExecutor.submit(new RidAdder(i)));
    for (int i = 0; i < 5; i++) futures.add(threadExecutor.submit(new RidDeleter(i)));
    latch.countDown();
    Thread.sleep(30 * 60000);
    addDocExecutor.shutdown();
    addDocExecutor.awaitTermination(30, TimeUnit.SECONDS);
    Thread.sleep(30 * 60000);
    cont = false;
    for (Future<?> future : futures) future.get();
    long amountOfRids = 0;
    for (ORID rid : ridTreePerDocument.keySet()) {
        ODocument document = db.load(rid);
        document.setLazyLoad(false);
        final ConcurrentSkipListSet<ORID> ridTree = ridTreePerDocument.get(rid);
        final ORidBag ridBag = document.field("ridBag");
        for (OIdentifiable identifiable : ridBag) Assert.assertTrue(ridTree.remove(identifiable.getIdentity()));
        Assert.assertTrue(ridTree.isEmpty());
        amountOfRids += ridBag.size();
    }
    System.out.println("Total  records added :  " + db.countClusterElements(db.getDefaultClusterId()));
    System.out.println("Total rids added : " + amountOfRids);
    db.drop();
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ArrayList(java.util.ArrayList) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) Random(java.util.Random) Future(java.util.concurrent.Future) ORID(com.orientechnologies.orient.core.id.ORID) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 80 with ODatabaseDocumentTx

use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.

the class ORestricetedUserCleanUpTest method testAutoCleanUserAfterDelate.

@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));
        OSecurity security = db.getMetadata().getSecurity();
        OUser auser = security.createUser("auser", "whereever", new String[] {});
        OUser reader = security.getUser("admin");
        ODocument doc = new ODocument("TestRecord");
        Set<OIdentifiable> users = new HashSet<OIdentifiable>();
        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);
        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();
        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();
    } finally {
        db.drop();
    }
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) HashSet(java.util.HashSet) Set(java.util.Set) ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)590 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)257 Test (org.testng.annotations.Test)182 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)120 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)81 Test (org.junit.Test)79 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)61 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)47 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)46 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)41 ORID (com.orientechnologies.orient.core.id.ORID)39 ORecordId (com.orientechnologies.orient.core.id.ORecordId)34 Before (org.junit.Before)34 File (java.io.File)33 OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)25 ArrayList (java.util.ArrayList)25 BeforeClass (org.testng.annotations.BeforeClass)23 BeforeMethod (org.testng.annotations.BeforeMethod)23 OStorage (com.orientechnologies.orient.core.storage.OStorage)21 List (java.util.List)20