Test for autotx in case of lightweight edges
package com.orientechnologies.orient.core.sql;
-import com.orientechnologies.orient.core.db.ODatabaseSession;
-import com.orientechnologies.orient.core.db.ODatabaseType;
-import com.orientechnologies.orient.core.db.OrientDB;
-import com.orientechnologies.orient.core.db.OrientDBConfig;
+import com.orientechnologies.orient.core.db.*;
+import com.orientechnologies.orient.core.exception.OConcurrentModificationException;
import com.orientechnologies.orient.core.sql.executor.OResultSet;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import java.util.concurrent.CountDownLatch;
+import java.util.stream.IntStream;
+
import static org.junit.Assert.assertEquals;
public class CreateLightWeightEdgesSQLTest {
@@ -34,6 +35,59 @@ public class CreateLightWeightEdgesSQLTest {
}
}
+ @Test
+ public void mtTest() throws InterruptedException {
+
+ ODatabasePool pool = new ODatabasePool(orientDB, CreateLightWeightEdgesSQLTest.class.getSimpleName(), "admin", "admin");
+
+ ODatabaseSession session = pool.acquire();
+
+ session.command("ALTER DATABASE CUSTOM useLightweightEdges = true");
+ session.command("create vertex v set id = 1 ");
+ session.command("create vertex v set id = 2 ");
+
+ session.close();
+
+ CountDownLatch latch = new CountDownLatch(10);
+
+ IntStream.range(0, 10).forEach((i) -> {
+ new Thread(() -> {
+
+ ODatabaseSession session1 = pool.acquire();
+
+ try {
+ for (int j = 0; j < 100; j++) {
+
+
+ try {
+ session1.command("create edge e from (select from v where id=1) to (select from v where id=2) ");
+ } catch (OConcurrentModificationException e) {
+
+ }
+ }
+ } finally {
+ latch.countDown();
+ }
+
+ }).start();
+ });
+
+ latch.await();
+
+ session = pool.acquire();
+ try (OResultSet res = session.query("select sum(out().size()) as size from V where id = 1");
+ OResultSet res1 = session.query("select sum(in().size()) as size from V where id = 2")) {
+
+ Integer s1 = res.stream().findFirst().get().getProperty("size");
+ Integer s2 = res1.stream().findFirst().get().getProperty("size");
+ assertEquals(s1, s2);
+
+ } finally {
+ pool.close();
+ }
+
+ }
+
@After
public void after() {
orientDB.close();
