Ignore:
Timestamp:
07/04/13 20:29:50 (11 years ago)
Author:
psniegowski
Message:

HIGHLIGHTS:

  • cleanup Instance management
    • extract Instance interface
    • extract Instance common algorithms to InstanceUtils?
  • fix closing issues: Ctrl+C or window close button

properly shutdown whole program

by Java Framsticks framework

  • fix parsing and printing of all request types
  • hide exception passing in special handle method of closures
    • substantially improve readability of closures
    • basically enable use of exception in asynchronous closures

(thrown exception is transported back to the caller)

  • implement call request on both sides

CHANGELOG:
Further improve calling.

Improve instance calling.

Calling is working on both sides.

Improve exception handling in testing.

Waiters do not supercede other apllication exception being thrown.

Finished parsing and printing of all request types (with tests).

Move implementation and tests of request parsing to Request.

Add tests for Requests.

Improve waits in asynchronours tests.

Extract more algorithms to InstanceUtils?.

Extract Instance.resolve to InstanceUtils?.

Improve naming.

Improve passing exception in InstanceClient?.

Hide calling of passed functor in StateCallback?.

Hide Exception passing in asynchronous closures.

Hide exception passing in Future.

Make ResponseCallback? an abstract class.

Make Future an abstract class.

Minor change.

Move getPath to Path.to()

Move bindAccess to InstanceUtils?.

Extract common things to InstanceUtils?.

Fix synchronization bug in Connection.

Move resolve to InstanceUtils?.

Allow names of Joinable to be dynamic.

Add support for set request server side.

More fixes in communication.

Fix issues with parsing in connection.

Cut new line characters when reading.

More improvements.

Migrate closures to FramsticksException?.

Several changes.

Extract resolveAndFetch to InstanceUtils? algorithms.

Test resolving and fetching.

More fixes with function signature deduction.

Do not print default values in SimpleAbstractAccess?.

Add test of FramsClass? printing.

Improve FramsticksException? messages.

Add explicit dispatcher synchronization feature.

Rework assertions in tests.

Previous solution was not generic enough.

Allow addition of joinables to collection after start.

Extract SimulatorInstance? from RemoteInstance?.

Remove PrivateJoinableCollection?.

Improve connections.

Move shutdown hook to inside the Monitor.

It should work in TestNG tests, but it seems that
hooks are not called.

In ServerTest? client connects to testing server.

Move socket initialization to receiver thread.

Add proper closing on Ctrl+C (don't use signals).

Fix bugs with server accepting connections.

Merge Entity into Joinable.

Reworking ServerInstance?.

Extract more algorithm to InstanceUtils?.

Extract some common functionality from AbstractInstance?.

Functions were placed in InstanceUtils?.

Hide registry of Instance.

Use ValueParam? in Instance interface.

Minor change.

Extract Instance interface.

Old Instance is now AbstractInstance?.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • java/main/src/test/java/com/framsticks/test/TestConfiguration.java

    r90 r96  
    11package com.framsticks.test;
    22
     3import java.util.HashSet;
    34import java.util.LinkedList;
    45import java.util.List;
     6import java.util.Set;
    57
    68import org.apache.log4j.Logger;
     
    810import org.testng.annotations.*;
    911
     12import com.framsticks.util.FramsticksException;
    1013import com.framsticks.util.dispatching.Dispatcher;
    11 import com.framsticks.util.dispatching.RunAt;
     14import com.framsticks.util.dispatching.Dispatching;
     15import com.framsticks.util.dispatching.Dispatching.Waiter;
     16import com.framsticks.util.dispatching.ExceptionHandler;
     17import com.framsticks.util.dispatching.ExceptionResultHandler;
     18
     19import static org.fest.assertions.Assertions.*;
    1220
    1321public class TestConfiguration {
     
    2129        }
    2230
    23         private final List<AsyncAssert<?>> asyncAssertions = new LinkedList<AsyncAssert<?>>();
     31        private final List<AssertionError> asyncAssertions = new LinkedList<>();
    2432
    25         public class AsyncAssert<C> extends RunAt<C> {
    26                 final RunAt<? extends C> runnable;
    27                 boolean done = false;
    28                 AssertionError assertion;
     33        public ExceptionHandler createExceptionHandler() {
     34                return new ExceptionHandler() {
     35                        @Override
     36                        public boolean handle(Dispatcher<?> dispatcher, Throwable throwable) {
     37                                AssertionError ae;
     38                                if (AssertionError.class.isInstance(throwable)) {
     39                                        ae = AssertionError.class.cast(throwable);
     40                                } else {
     41                                        ae = new AssertionError();
     42                                        ae.initCause(throwable);
     43                                }
     44                                synchronized (asyncAssertions) {
     45                                        asyncAssertions.add(ae);
     46                                }
     47                                return true;
     48                        }
     49                };
     50        }
    2951
    30                 /**
    31                  * @param runnable
    32                  */
    33                 public AsyncAssert(RunAt<? extends C> runnable) {
    34                         this.runnable = runnable;
    35                 }
    36 
    37                 @Override
    38                 public void run() {
     52        @AfterMethod
     53        public void waitForWaiters() {
     54                for (Waiter w : waiters) {
    3955                        try {
    40                                 runnable.run();
    41                         } catch (AssertionError e) {
    42                                 assertion = e;
    43                         }
    44                         synchronized (this) {
    45                                 done = true;
    46                                 this.notifyAll();
     56                                w.waitFor();
     57                        } catch (FramsticksException e) {
     58                                AssertionError ae = new AssertionError();
     59                                ae.initCause(e);
     60                                asyncAssertions.add(ae);
    4761                        }
    4862                }
    4963        }
    5064
    51         public <C> void assertDispatch(Dispatcher<C> dispatcher, RunAt<? extends C> runnable) {
    52                 AsyncAssert<C> assertion = new AsyncAssert<C>(runnable);
     65        @AfterMethod(timeOut = 1000, dependsOnMethods = "waitForWaiters")
     66        public void processAsyncAssertions() {
    5367                synchronized (asyncAssertions) {
    54                         asyncAssertions.add(assertion);
    55                 }
    56                 dispatcher.dispatch(assertion);
    57         }
    58 
    59         @BeforeMethod
    60         public void clearAsyncAsserts() {
    61                 synchronized (asyncAssertions) {
    62                         asyncAssertions.clear();
     68                        if (asyncAssertions.isEmpty()) {
     69                                return;
     70                        }
     71                        AssertionError a = asyncAssertions.get(0);
     72                        asyncAssertions.remove(0);
     73                        throw a;
    6374                }
    6475        }
    6576
    66         @AfterMethod(timeOut = 5000)
    67         public void waitForAsyncAsserts() {
    68                 while (true) {
    69                         AsyncAssert<?> assertion;
    70                         synchronized (asyncAssertions) {
    71                                 if (asyncAssertions.isEmpty()) {
    72                                         return;
    73                                 }
    74                                 assertion = asyncAssertions.get(0);
    75                                 asyncAssertions.remove(0);
     77        final Set<Waiter> waiters = new HashSet<>();
     78
     79        @BeforeMethod
     80        public void clearWaiters() {
     81                waiters.clear();
     82        }
     83
     84        protected Dispatching.Waiter produceWaiter(double timeOut) {
     85                Waiter waiter = new Waiter(timeOut);
     86                waiters.add(waiter);
     87                return waiter;
     88        }
     89
     90        public static ExceptionResultHandler failOnException() {
     91                return new ExceptionResultHandler() {
     92                        @Override
     93                        public void handle(FramsticksException e) {
     94                                assertThat(e).isNull();
    7695                        }
    77                         synchronized (assertion) {
    78                                 while (!assertion.done) {
    79                                         try {
    80                                                 assertion.wait();
    81                                         } catch (InterruptedException ignored) {
    82                                         }
    83                                 }
    84                                 if (assertion.assertion != null) {
    85                                         throw assertion.assertion;
    86                                 }
    87                         }
    88                 }
     96                };
     97
    8998        }
    9099}
Note: See TracChangeset for help on using the changeset viewer.