]> gerrit.simantics Code Review - simantics/platform.git/blob - 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
1 package org.simantics.db.tests.client;
2
3 import org.junit.Test;
4 import org.simantics.db.exception.DatabaseException;
5 import org.simantics.db.service.LifecycleSupport;
6 import org.simantics.db.testing.annotation.Fails;
7 import org.simantics.db.testing.base.ExistingDatabaseTest;
8 import org.simantics.db.testing.common.Client;
9 import org.simantics.db.testing.common.ClientFactory;
10 import org.simantics.db.tests.common.Configuration;
11
12 public class CallTest extends ExistingDatabaseTest {
13     private static final int COUNT = Configuration.get().callLoopCount;
14     private static final int CALL_COUNT = Configuration.get().callCallCount;
15     private static final int N_THREADS = Configuration.get().callThreadCount;
16     private CallTestThread[] threads = new CallTestThread[N_THREADS];
17
18     @Test
19     @Fails
20     public void testCall() throws DatabaseException {
21         for (int i=0; i<COUNT; ++i) {
22             callTestImpl();
23         }
24         for (int i=0; i<N_THREADS; ++i)
25             threads[i] = null;
26     }
27     void callTestImpl() throws DatabaseException {
28         try {
29 //            ServerAddress serverAddress = getSessionContext().getAddress();
30             for (int i=0; i<N_THREADS; ++i) {
31                 threads[i] = new CallTestThread(i, ClientFactory.create(getRandomString()), CALL_COUNT);
32                 threads[i].start();
33             }
34         } finally {
35             try {
36                 for (int i=0; i<N_THREADS; ++i) {
37                     if (null != threads[i])
38                     threads[i].join();
39                 }
40             } catch (InterruptedException e) {
41                 e.printStackTrace();
42             }
43             DatabaseException ex = null;
44             for (int i=0; i<N_THREADS; ++i) {
45                 if (null != threads[i] && null != threads[i].client)
46                     try {
47                         threads[i].client.close();
48                     } catch (DatabaseException e) {
49                         ex = e;
50                     }
51             }
52             if (null != ex)
53                 throw ex;
54         }
55     }
56     class CallTestThread extends Thread {
57         Client client;
58         private final int size;
59         DatabaseException exception = null;
60         LifecycleSupport support;
61         public CallTestThread(int index, Client client, int size) {
62             super("CallTestThread " + ++index);
63             this.client = client;
64             this.size = size;
65             support = client.getSession().getService(LifecycleSupport.class);
66         }
67         @Override
68         public void run() {
69             for (int i=0; i<size; ++i) {
70                 try {
71                     support.ping();
72                 } catch (DatabaseException e) {
73                     exception = e;
74                     return;
75                 }
76             }
77         }
78         
79     }
80 }