1 package org.simantics.db.tests.client;
3 import java.util.concurrent.atomic.AtomicInteger;
6 import org.simantics.db.exception.DatabaseException;
7 import org.simantics.db.testing.base.TestCommonNoVirtual;
8 import org.simantics.db.testing.common.Client;
9 import org.simantics.db.testing.common.ClientFactory;
10 import org.simantics.db.tests.common.ClientOperations;
11 import org.simantics.db.tests.common.Configuration;
13 public class RefreshTest5 extends TestCommonNoVirtual {
14 private static final int COUNT = Configuration.get().refreshLoopCount;
15 private static final int ADD_COUNT = Configuration.get().refreshAddCount;
17 AtomicInteger size = null;
18 AtomicInteger validate = null;
21 public void testRefresh5() throws DatabaseException {
24 for (int i=0; i<COUNT; ++i) {
28 void refreshTestAdd() throws DatabaseException {
29 AtomicInteger size = new AtomicInteger(0);
30 AtomicInteger validate = new AtomicInteger(0);
31 // ServerAddress serverAddress = getSessionContext().getAddress();
32 Client client1 = ClientFactory.create(getRandomString());
33 Client client2 = ClientFactory.create(getRandomString());
34 RefreshValidateThread t1 = null;
35 RefreshValidateThread t2 = null;
38 String name1 = ClientOperations.createOrderedSet(client1, size.get());
39 ClientOperations.validateOrderedSet(client1, name1, size.get());
40 ClientOperations.validateOrderedSet(client2, name1, size.get());
41 t1 = new RefreshValidateThread(client1, name1, size, validate);
43 t2 = new RefreshValidateThread(client1, name1, size, validate);
45 for (int i=0; i<ADD_COUNT; ++i) {
46 ClientOperations.adddElement(client1, name1, 1);
47 int oldSize = size.incrementAndGet();
48 while (validate.get() < oldSize*2 &&
49 null == t1.exception &&
50 null == t2.exception) {
51 if (null != t1.exception)
53 else if (null != t2.exception)
56 Thread.sleep(10); // milliseconds
57 } catch (InterruptedException e) {
62 } catch (Throwable t) {
69 } catch (InterruptedException e) {
76 if (null != t1 && null != t1.exception)
78 if (null != t2 && null != t2.exception)
82 class RefreshValidateThread extends Thread {
83 private Client client;
85 private int oldSize = 0;
86 private AtomicInteger size;
87 private AtomicInteger validate;
88 DatabaseException exception = null;
89 public RefreshValidateThread(Client client, String name, AtomicInteger size, AtomicInteger validate) {
90 super("RefreshValidateThread");
94 this.validate = validate;
99 while (!stop && size.get() <= oldSize && size.get() <= ADD_COUNT)
101 Thread.sleep(10); // milliseconds
102 } catch (InterruptedException e) {
105 oldSize = size.get();
107 ClientOperations.validateOrderedSet(client, name, oldSize);
108 } catch (DatabaseException e) {
112 validate.incrementAndGet();