Synchronize Join PseudoState state machine listener
- Synchronize JoinPseudoState's JoinTracker.stateChanged(State<S, E>, State<S, E>) method for playing nice with concurrent region execution. Should fix #93. - Tuning test which relates to #76. What comes for the tests, there was this concurrency issue and also problem in tests itself. - Polish JoinPseudoState.
This commit is contained in:
@@ -156,6 +156,8 @@ public class TasksTests {
|
||||
|
||||
static class TestListener extends StateMachineListenerAdapter<States, Events> {
|
||||
|
||||
final Object lock = new Object();
|
||||
|
||||
volatile CountDownLatch stateChangedLatch = new CountDownLatch(1);
|
||||
volatile CountDownLatch stateEnteredLatch = new CountDownLatch(2);
|
||||
volatile CountDownLatch stateExitedLatch = new CountDownLatch(0);
|
||||
@@ -167,26 +169,34 @@ public class TasksTests {
|
||||
|
||||
@Override
|
||||
public void stateChanged(State<States, Events> from, State<States, Events> to) {
|
||||
stateChangedCount++;
|
||||
stateChangedLatch.countDown();
|
||||
synchronized (lock) {
|
||||
stateChangedCount++;
|
||||
stateChangedLatch.countDown();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stateEntered(State<States, Events> state) {
|
||||
statesEntered.add(state);
|
||||
stateEnteredLatch.countDown();
|
||||
synchronized (lock) {
|
||||
statesEntered.add(state);
|
||||
stateEnteredLatch.countDown();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stateExited(State<States, Events> state) {
|
||||
statesExited.add(state);
|
||||
stateExitedLatch.countDown();
|
||||
synchronized (lock) {
|
||||
statesExited.add(state);
|
||||
stateExitedLatch.countDown();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transitionEnded(Transition<States, Events> transition) {
|
||||
transitionCount++;
|
||||
transitionLatch.countDown();
|
||||
synchronized (lock) {
|
||||
transitionCount++;
|
||||
transitionLatch.countDown();
|
||||
}
|
||||
}
|
||||
|
||||
public void reset(int c1, int c2, int c3) {
|
||||
@@ -194,14 +204,16 @@ public class TasksTests {
|
||||
}
|
||||
|
||||
public void reset(int c1, int c2, int c3, int c4) {
|
||||
stateChangedLatch = new CountDownLatch(c1);
|
||||
stateEnteredLatch = new CountDownLatch(c2);
|
||||
stateExitedLatch = new CountDownLatch(c3);
|
||||
transitionLatch = new CountDownLatch(c4);
|
||||
stateChangedCount = 0;
|
||||
transitionCount = 0;
|
||||
statesEntered.clear();
|
||||
statesExited.clear();
|
||||
synchronized (lock) {
|
||||
stateChangedLatch = new CountDownLatch(c1);
|
||||
stateEnteredLatch = new CountDownLatch(c2);
|
||||
stateExitedLatch = new CountDownLatch(c3);
|
||||
transitionLatch = new CountDownLatch(c4);
|
||||
stateChangedCount = 0;
|
||||
transitionCount = 0;
|
||||
statesEntered.clear();
|
||||
statesExited.clear();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user