source: java/main/src/test/java/com/framsticks/test/TestConfiguration.java @ 105

Last change on this file since 105 was 105, checked in by psniegowski, 11 years ago

HIGHLIGHTS:

  • import refactorization: move Tree, Path, etc.

from core to structure package

  • initial serialization implementation
  • improve PrimeExperiment? test
  • many organizational changes and convenience improvements

CHANGELOG:
Make registry in AbstractTree? final.

Move most classes from core to structure package.

Minor changes.

Switch names of Future and FutureHandler?.

Rename ExceptionResultHandler? to ExceptionHandler?.

Rename ExceptionHandler? to ExceptionDispatcherHandler?.

Fix bug in ParamCandidate? cache.

Add missing synchronization to the BufferedDispatcher?.

Develop @Serialized support.

Rework serialization further.

Add serialization/deserialization interface to ValueParam?.

Move getStorageType and isNumeric from Param down to params hierarchy.

Minor changes.

Improve param type induction.

Add TestSerializedClass? for testing new serialization.

Add info files gor GenePool? and Population.

Add standard.expt exemplary netfile.

Add type name field to PropertiesObject?.

Use PropertiesObject? for PropertiesAccess? instead of ordinary map.

Hide getFramsClass is several more places.

More unification accross FramsClass?, Access and Path.

Add ParamCollection?.

Simplify interface for getting params from FramsClass?, Access
or Path.

Make Access.call() interface variadic.

Add arguments(args) convenience wrapper around new Object[] {args}.

Upgrade to apache.commons.lang version 3.1

Minor improvement with Response constructors.

Develop proper result printing in ClientAtServer?.

Add experimentNetsave to PrimeExperiment?.

File size: 2.6 KB
Line 
1package com.framsticks.test;
2
3import java.util.HashSet;
4import java.util.LinkedList;
5import java.util.List;
6import java.util.Set;
7
8import org.apache.logging.log4j.Logger;
9import org.apache.logging.log4j.LogManager;
10import org.testng.annotations.*;
11
12import com.framsticks.util.ExceptionHandler;
13import com.framsticks.util.FramsticksException;
14import com.framsticks.util.dispatching.Dispatcher;
15import com.framsticks.util.dispatching.Dispatching;
16import com.framsticks.util.dispatching.Dispatching.Waiter;
17import com.framsticks.util.dispatching.ExceptionDispatcherHandler;
18
19// import static org.fest.assertions.Assertions.*;
20
21public class TestConfiguration {
22
23        private static final Logger log = LogManager.getLogger(TestConfiguration.class);
24
25        @BeforeClass
26        public void setUpConfiguration() {
27                log.info("testing {}", this.getClass());
28        }
29
30        private final List<AssertionError> asyncAssertions = new LinkedList<>();
31
32        public static AssertionError wrapInAssertion(Throwable throwable) {
33                if (throwable instanceof AssertionError) {
34                        return (AssertionError) throwable;
35                }
36
37                AssertionError ae = new AssertionError();
38                ae.initCause(throwable);
39                return ae;
40        }
41
42        public void addAsyncAssertion(Throwable throwable) {
43                synchronized (asyncAssertions) {
44                        asyncAssertions.add(wrapInAssertion(throwable));
45                }
46        }
47
48        public ExceptionDispatcherHandler createExceptionHandler() {
49                return new ExceptionDispatcherHandler() {
50                        @Override
51                        public boolean handle(Dispatcher<?> dispatcher, Throwable throwable) {
52                                addAsyncAssertion(throwable);
53                                return true;
54                        }
55                };
56        }
57
58        @AfterMethod
59        public void waitForWaiters() {
60                for (Waiter w : waiters) {
61                        try {
62                                w.waitFor();
63                        } catch (FramsticksException e) {
64                                AssertionError ae = new AssertionError();
65                                ae.initCause(e);
66                                asyncAssertions.add(ae);
67                        }
68                }
69        }
70
71        @AfterMethod(timeOut = 1000, dependsOnMethods = "waitForWaiters")
72        public void processAsyncAssertions() {
73                synchronized (asyncAssertions) {
74                        if (asyncAssertions.isEmpty()) {
75                                return;
76                        }
77                        AssertionError a = asyncAssertions.get(0);
78                        asyncAssertions.remove(0);
79                        throw a;
80                }
81        }
82
83        final Set<Waiter> waiters = new HashSet<>();
84
85        @BeforeMethod
86        public void clearWaiters() {
87                synchronized (waiters) {
88                        waiters.clear();
89                }
90        }
91
92        protected Dispatching.Waiter produceWaiter(double timeOut) {
93                Waiter waiter = new Waiter(timeOut, failOnException);
94                synchronized (waiters) {
95                        waiters.add(waiter);
96                }
97                return waiter;
98        }
99
100        public final ExceptionHandler failOnException = new ExceptionHandler() {
101                @Override
102                public void handle(FramsticksException e) {
103                        log.error("passing exception as assertion in {}", TestConfiguration.this.getClass(), e);
104                        addAsyncAssertion(e);
105                }
106        };
107}
Note: See TracBrowser for help on using the repository browser.