X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=tests%2Forg.simantics.db.tests%2Fsrc%2Forg%2Fsimantics%2Fdb%2Ftests%2Fregression%2Fbugs%2FSimanticsBug1659Test1.java;fp=tests%2Forg.simantics.db.tests%2Fsrc%2Forg%2Fsimantics%2Fdb%2Ftests%2Fregression%2Fbugs%2FSimanticsBug1659Test1.java;h=768ebf73a8256dbb5629bd0acc432a6139edfca8;hb=67fd62f9c742337ec80eef658192db198a0efaac;hp=0000000000000000000000000000000000000000;hpb=cde82ba81327d5515fdca362f7f4c70f5103ae80;p=simantics%2Fplatform.git diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/SimanticsBug1659Test1.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/SimanticsBug1659Test1.java new file mode 100644 index 000000000..768ebf73a --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/SimanticsBug1659Test1.java @@ -0,0 +1,204 @@ +package org.simantics.db.tests.regression.bugs; + +import org.junit.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.primitiverequest.PossibleObject; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.SyncListener; +import org.simantics.db.service.ClusterControl; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.db.testing.common.TestBase; +import org.simantics.db.tests.common.Configuration; +import org.simantics.layer0.Layer0; +import org.simantics.utils.DataContainer; + +public class SimanticsBug1659Test1 extends ExistingDatabaseTest { + static int LOOP_COUNT = Configuration.get().i1659LoopCount; + static int RESOURCE_COUNT = 1000; + static boolean DEBUG = false; + static boolean DEBUG_LISTENER = false; + // Use transient listener. + static boolean USE_LISTENER = true; + // Use asynchronous listener. + static boolean USE_LISTENER2 = true; + // Use synchronous listener + static boolean USE_LISTENER3 = true; + Session session; + Resource testRoot; + Resource type; + DataContainer loopCount = new DataContainer(); + DataContainer listenerCount = new DataContainer(); + + @Test + public void testSimanticsBug16591() + throws DatabaseException { + session = getSession(); + session.syncRequest(new Init()); + loopCount.set(-1); + listenerCount.set(0); + int oldCount = 0; + for (int i=0; i() { + + @Override + public void execute(ReadGraph graph, Resource resource) throws DatabaseException { + if (DEBUG_LISTENER) + System.out.println("change " + resource); + } + + @Override + public void exception(ReadGraph graph, Throwable t) + throws DatabaseException { + t.printStackTrace(); + fail("Listener got exception: " + t); + } + + @Override + public boolean isDisposed() { + if (DEBUG_LISTENER) + System.out.println("Asked if disposed."); + return true; + } + }); + if (USE_LISTENER2) { + g.forPossibleObject(rr, l0.InstanceOf, new Listener(loopCount, listenerCount)); + } + if (USE_LISTENER3) { + g.syncRequest(new PossibleObject(rr, l0.InstanceOf), new Listener(loopCount, listenerCount)); + } + } + } + } + } + class Listener implements SyncListener { + final DataContainer loopCount; + final DataContainer listenerCount; + final int me; + boolean disposed = false; + Listener(DataContainer loopCount, DataContainer listenerCount) { + this.loopCount = loopCount; + this.listenerCount = listenerCount; + int value = this.listenerCount.get() + 1; + this.listenerCount.set(value); + this.me = loopCount.get(); + } + @Override + public void execute(ReadGraph graph, Resource resource) throws DatabaseException { + if (DEBUG_LISTENER) + System.out.println("change " + resource); + } + + @Override + public void exception(ReadGraph graph, Throwable t) + throws DatabaseException { + t.printStackTrace(); + fail("Listener got exception: " + t); + } + + @Override + public boolean isDisposed() { + if (DEBUG_LISTENER) + System.out.println("Asked if disposed."); + if (disposed) + return true; + disposed = loopCount.get() != me; + if (disposed) { + int value = this.listenerCount.get() - 1; + this.listenerCount.set(value); + } + return disposed; + } + + } + class Delete extends WriteRequest { + @Override + public void perform(WriteGraph g) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(g); + for (Resource r : g.getObjects(testRoot, l0.ConsistsOf)) { + if (DEBUG) + System.out.println("Deny resource " + r); + g.deny(testRoot, l0.ConsistsOf, r); + } + } + } +}