From 9ea2187c75135a55a1ed79cdec9cf4a6919663b0 Mon Sep 17 00:00:00 2001 From: lvca Date: Tue, 1 Dec 2015 20:50:08 +0100 Subject: [PATCH] Added one more index for async - remote - 3 nodes --- .../asynch/AsyncIndexRemoteTest.java | 108 ++++++++++++++++++ .../asynch/BareBoneBase3ServerTest.java | 90 +++++++++++++++ .../distributed/asynch/BareBonesServer.java | 6 +- .../resources/asynch-dserver-config-2.xml | 69 +++++++++++ 4 files changed, 271 insertions(+), 2 deletions(-) create mode 100644 distributed/src/test/java/com/orientechnologies/orient/server/distributed/asynch/AsyncIndexRemoteTest.java create mode 100644 distributed/src/test/java/com/orientechnologies/orient/server/distributed/asynch/BareBoneBase3ServerTest.java create mode 100755 distributed/src/test/resources/asynch-dserver-config-2.xml diff --git a/distributed/src/test/java/com/orientechnologies/orient/server/distributed/asynch/AsyncIndexRemoteTest.java b/distributed/src/test/java/com/orientechnologies/orient/server/distributed/asynch/AsyncIndexRemoteTest.java new file mode 100644 index 00000000000..0700655d765 --- /dev/null +++ b/distributed/src/test/java/com/orientechnologies/orient/server/distributed/asynch/AsyncIndexRemoteTest.java @@ -0,0 +1,108 @@ +package com.orientechnologies.orient.server.distributed.asynch; + +import junit.framework.Assert; + +import com.orientechnologies.common.log.OLogManager; +import com.orientechnologies.orient.core.sql.OCommandSQL; +import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery; +import com.orientechnologies.orient.core.storage.ORecordDuplicatedException; +import com.tinkerpop.blueprints.impls.orient.OrientBaseGraph; +import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx; +import com.tinkerpop.blueprints.impls.orient.OrientVertex; + +public class AsyncIndexRemoteTest extends BareBoneBase3ServerTest { + + @Override + protected String getDatabaseName() { + return "AsyncIndexTest"; + } + + protected void dbClient1() { + OrientBaseGraph graph = new OrientGraphNoTx(getRemoteURL()); + try { + graph.command(new OCommandSQL("create class SMS")).execute(); + graph.command(new OCommandSQL("create property SMS.type string")).execute(); + graph.command(new OCommandSQL("create property SMS.lang string")).execute(); + graph.command(new OCommandSQL("create property SMS.source integer")).execute(); + graph.command(new OCommandSQL("create property SMS.content string")).execute(); + graph.command(new OCommandSQL("alter property SMS.lang min 2")).execute(); + graph.command(new OCommandSQL("alter property SMS.lang max 2")).execute(); + graph.command(new OCommandSQL("create index sms_keys ON SMS (type, lang) unique")).execute(); + + graph.command(new OCommandSQL("insert into sms (type, lang, source, content) values ( 'notify', 'en', 1, 'This is a test')")) + .execute(); + try { + graph + .command(new OCommandSQL("insert into sms (type, lang, source, content) values ( 'notify', 'en', 1, 'This is a test')")) + .execute(); + Assert.fail("violated unique index was not raised"); + } catch (ORecordDuplicatedException e) { + } + + final Iterable result = graph.command(new OSQLSynchQuery("select count(*) from SMS")).execute(); + + Assert.assertEquals(1, ((Number) result.iterator().next().getProperty("count")).intValue()); + + } catch (Throwable e) { + if (exceptionInThread == null) { + exceptionInThread = e; + } + } finally { + OLogManager.instance().info(this, "Shutting down db1"); + graph.shutdown(); + } + + // CHECK ON THE 2ND NODE + OrientBaseGraph graph2 = new OrientGraphNoTx(getRemoteURL2()); + try { + try { + graph2 + .command(new OCommandSQL("insert into sms (type, lang, source, content) values ( 'notify', 'en', 1, 'This is a test')")) + .execute(); + Assert.fail("violated unique index was not raised"); + } catch (ORecordDuplicatedException e) { + } + + final Iterable result = graph2.command(new OSQLSynchQuery("select count(*) from SMS")).execute(); + + Assert.assertEquals(1, ((Number) result.iterator().next().getProperty("count")).intValue()); + + } catch (Throwable e) { + if (exceptionInThread == null) { + exceptionInThread = e; + } + } finally { + OLogManager.instance().info(this, "Shutting down db2"); + graph2.shutdown(); + } + + // CHECK ON THE 2ND NODE + OrientBaseGraph graph3 = new OrientGraphNoTx(getRemoteURL3()); + try { + try { + graph3 + .command(new OCommandSQL("insert into sms (type, lang, source, content) values ( 'notify', 'en', 1, 'This is a test')")) + .execute(); + Assert.fail("violated unique index was not raised"); + } catch (ORecordDuplicatedException e) { + } + + final Iterable result = graph3.command(new OSQLSynchQuery("select count(*) from SMS")).execute(); + + Assert.assertEquals(1, ((Number) result.iterator().next().getProperty("count")).intValue()); + + } catch (Throwable e) { + if (exceptionInThread == null) { + exceptionInThread = e; + } + } finally { + OLogManager.instance().info(this, "Shutting down db3"); + graph3.shutdown(); + } + } + + @Override + protected void dbClient2() { + + } +} diff --git a/distributed/src/test/java/com/orientechnologies/orient/server/distributed/asynch/BareBoneBase3ServerTest.java b/distributed/src/test/java/com/orientechnologies/orient/server/distributed/asynch/BareBoneBase3ServerTest.java new file mode 100644 index 00000000000..295bb8ce890 --- /dev/null +++ b/distributed/src/test/java/com/orientechnologies/orient/server/distributed/asynch/BareBoneBase3ServerTest.java @@ -0,0 +1,90 @@ +package com.orientechnologies.orient.server.distributed.asynch; + +import com.orientechnologies.common.io.OFileUtils; +import com.orientechnologies.orient.core.Orient; +import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; + +import java.io.File; + +public abstract class BareBoneBase3ServerTest extends BareBoneBase2ServerTest { + + protected static final String DB3_DIR = "target/db3"; + + protected String getLocalURL3() { + return "plocal:" + DB3_DIR + "/databases/" + getDatabaseName(); + } + + protected String getRemoteURL3() { + return "remote:localhost:2426/" + getDatabaseName(); + } + + public void setUp() { + System.out.println("SETUP TEST"); + super.setUp(); + OFileUtils.deleteRecursively(new File(DB3_DIR)); + } + + @Override + protected void tearDown() throws Exception { + System.out.println("TEAR DOWN"); + + super.tearDown(); + + new ODatabaseDocumentTx(getLocalURL3()).open("admin", "admin").drop(); + OFileUtils.deleteRecursively(new File(DB3_DIR)); + } + + public void testReplication() throws Throwable { + Orient.setRegisterDatabaseByPath(true); + + final BareBonesServer[] servers = new BareBonesServer[3]; + Thread dbServer1 = new Thread() { + @Override + public void run() { + servers[0] = dbServer(DB1_DIR, getLocalURL(), "asynch-dserver-config-0.xml"); + } + }; + dbServer1.start(); + dbServer1.join(); + + Thread dbServer2 = new Thread() { + @Override + public void run() { + servers[1] = dbServer(DB2_DIR, getLocalURL2(), "asynch-dserver-config-1.xml"); + } + }; + dbServer2.start(); + dbServer2.join(); + + Thread dbServer3 = new Thread() { + @Override + public void run() { + servers[2] = dbServer(DB3_DIR, getLocalURL3(), "asynch-dserver-config-2.xml"); + } + }; + dbServer3.start(); + dbServer3.join(); + + Thread dbClient1 = new Thread() { + @Override + public void run() { + dbClient1(); + } + }; + dbClient1.start(); + + Thread dbClient2 = new Thread() { + @Override + public void run() { + dbClient2(); + } + }; + dbClient2.start(); + + dbClient1.join(); + dbClient2.join(); + + endTest(servers); + } + +} diff --git a/distributed/src/test/java/com/orientechnologies/orient/server/distributed/asynch/BareBonesServer.java b/distributed/src/test/java/com/orientechnologies/orient/server/distributed/asynch/BareBonesServer.java index 89b4b9b7d36..dc58124b348 100755 --- a/distributed/src/test/java/com/orientechnologies/orient/server/distributed/asynch/BareBonesServer.java +++ b/distributed/src/test/java/com/orientechnologies/orient/server/distributed/asynch/BareBonesServer.java @@ -22,8 +22,10 @@ public void createDB(String orientUrl) { graph.executeOutsideTx(new OCallable() { @Override public Object call(OrientBaseGraph g) { - g.createEdgeType("edgetype"); - g.createVertexType("vertextype"); + if (g.getEdgeType("edgetype") == null) + g.createEdgeType("edgetype"); + if (g.getVertexType("vertextype") == null) + g.createVertexType("vertextype"); return null; } }); diff --git a/distributed/src/test/resources/asynch-dserver-config-2.xml b/distributed/src/test/resources/asynch-dserver-config-2.xml new file mode 100755 index 00000000000..cbacd539da0 --- /dev/null +++ b/distributed/src/test/resources/asynch-dserver-config-2.xml @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +