]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - tests/org.simantics.db.tests/src/org/simantics/db/tests/client/CallTest.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / client / CallTest.java
diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/CallTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/client/CallTest.java
new file mode 100644 (file)
index 0000000..7da5cfe
--- /dev/null
@@ -0,0 +1,80 @@
+package org.simantics.db.tests.client;
+
+import org.junit.Test;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.service.LifecycleSupport;
+import org.simantics.db.testing.annotation.Fails;
+import org.simantics.db.testing.base.ExistingDatabaseTest;
+import org.simantics.db.testing.common.Client;
+import org.simantics.db.testing.common.ClientFactory;
+import org.simantics.db.tests.common.Configuration;
+
+public class CallTest extends ExistingDatabaseTest {
+    private static final int COUNT = Configuration.get().callLoopCount;
+    private static final int CALL_COUNT = Configuration.get().callCallCount;
+    private static final int N_THREADS = Configuration.get().callThreadCount;
+    private CallTestThread[] threads = new CallTestThread[N_THREADS];
+
+    @Test
+    @Fails
+    public void testCall() throws DatabaseException {
+        for (int i=0; i<COUNT; ++i) {
+            callTestImpl();
+        }
+        for (int i=0; i<N_THREADS; ++i)
+            threads[i] = null;
+    }
+    void callTestImpl() throws DatabaseException {
+        try {
+//            ServerAddress serverAddress = getSessionContext().getAddress();
+            for (int i=0; i<N_THREADS; ++i) {
+                threads[i] = new CallTestThread(i, ClientFactory.create(getRandomString()), CALL_COUNT);
+                threads[i].start();
+            }
+        } finally {
+            try {
+                for (int i=0; i<N_THREADS; ++i) {
+                    if (null != threads[i])
+                    threads[i].join();
+                }
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
+            DatabaseException ex = null;
+            for (int i=0; i<N_THREADS; ++i) {
+                if (null != threads[i] && null != threads[i].client)
+                    try {
+                        threads[i].client.close();
+                    } catch (DatabaseException e) {
+                        ex = e;
+                    }
+            }
+            if (null != ex)
+                throw ex;
+        }
+    }
+    class CallTestThread extends Thread {
+        Client client;
+        private final int size;
+        DatabaseException exception = null;
+        LifecycleSupport support;
+        public CallTestThread(int index, Client client, int size) {
+            super("CallTestThread " + ++index);
+            this.client = client;
+            this.size = size;
+            support = client.getSession().getService(LifecycleSupport.class);
+        }
+        @Override
+        public void run() {
+            for (int i=0; i<size; ++i) {
+                try {
+                    support.ping();
+                } catch (DatabaseException e) {
+                    exception = e;
+                    return;
+                }
+            }
+        }
+        
+    }
+}