Browse Source

RuntimeService sends Notification for run cycles.
Adapted testcases.

markus.muehlbrandt@itemis.de 13 years ago
parent
commit
de47a2dd7a
14 changed files with 372 additions and 226 deletions
  1. 1 1
      examples/org.yakindu.sct.generator.java.trafficlight/src-gen/org/yakindu/sct/runtime/java/NotificationType.java
  2. 3 1
      examples/org.yakindu.sct.generator.java.trafficlight/src-gen/org/yakindu/sct/runtime/java/RuntimeService.java
  3. 1 1
      plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/templates/NotificationType.xpt
  4. 3 1
      plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/templates/RuntimeService.xpt
  5. 1 1
      test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/NotificationType.java
  6. 3 1
      test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/RuntimeService.java
  7. 8 0
      test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/test_parallelregions/Test_ParallelRegionsCycleBasedStatemachine.java
  8. 3 3
      test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/test_transition/DefaultInterfaceImpl.java
  9. 5 3
      test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/test_transition/InterfaceA.java
  10. 14 4
      test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/test_transition/InterfaceAImpl.java
  11. 22 44
      test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/test_transition/Test_TransitionCycleBasedStatemachine.java
  12. 275 151
      test-plugins/org.yakindu.sct.generator.java.runtime.test/src/org/yakindu/sct/generator/java/runtime/test/StatemachinePerformanceTest.java
  13. 29 10
      test-plugins/org.yakindu.sct.generator.java.runtime.test/src/org/yakindu/sct/generator/java/runtime/test/TestExpressionEventBasedStatemachine.java
  14. 4 5
      test-plugins/org.yakindu.sct.generator.java.runtime.test/src/org/yakindu/sct/generator/java/runtime/test/TestInterfaceTestEventBasedStatemachine.java

+ 1 - 1
examples/org.yakindu.sct.generator.java.trafficlight/src-gen/org/yakindu/sct/runtime/java/NotificationType.java

@@ -11,5 +11,5 @@ Contributors:
 package org.yakindu.sct.runtime.java;
 
 public enum NotificationType {
-	EventNotification,
+	EventNotification, RuntimeCycleNotification
 }

+ 3 - 1
examples/org.yakindu.sct.generator.java.trafficlight/src-gen/org/yakindu/sct/runtime/java/RuntimeService.java

@@ -16,7 +16,7 @@ import java.util.Timer;
 import java.util.TimerTask;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
-public class RuntimeService {
+public class RuntimeService extends NotificationSender {
 
 	private Timer timer = new Timer();
 
@@ -31,6 +31,8 @@ public class RuntimeService {
 			lock.readLock().lock();
 			for (IStatemachine statemachine : statemachineSet) {
 				statemachine.runCycle();
+				notifyListeners(new Notification<IStatemachine>(
+						NotificationType.RuntimeCycleNotification, statemachine));
 			}
 			lock.readLock().unlock();
 		}

+ 1 - 1
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/templates/NotificationType.xpt

@@ -18,7 +18,7 @@ Contributors:
 package «entry.getBasePackageName()»;
 
 public enum NotificationType {
-	EventNotification,
+	EventNotification, RuntimeCycleNotification
 }
 «ENDFILE-»
 «ENDIF-»

+ 3 - 1
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/templates/RuntimeService.xpt

@@ -23,7 +23,7 @@ import java.util.Timer;
 import java.util.TimerTask;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
-public class RuntimeService {
+public class RuntimeService extends NotificationSender {
 
 	private Timer timer = new Timer();
 
@@ -38,6 +38,8 @@ public class RuntimeService {
 			lock.readLock().lock();
 			for (IStatemachine statemachine : statemachineSet) {
 				statemachine.runCycle();
+				notifyListeners(new Notification<IStatemachine>(
+						NotificationType.RuntimeCycleNotification, statemachine));
 			}
 			lock.readLock().unlock();
 		}

+ 1 - 1
test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/NotificationType.java

@@ -11,5 +11,5 @@ Contributors:
 package org.yakindu.sct.runtime.java;
 
 public enum NotificationType {
-	EventNotification,
+	EventNotification, RuntimeCycleNotification
 }

+ 3 - 1
test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/RuntimeService.java

@@ -16,7 +16,7 @@ import java.util.Timer;
 import java.util.TimerTask;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
-public class RuntimeService {
+public class RuntimeService extends NotificationSender {
 
 	private Timer timer = new Timer();
 
@@ -31,6 +31,8 @@ public class RuntimeService {
 			lock.readLock().lock();
 			for (IStatemachine statemachine : statemachineSet) {
 				statemachine.runCycle();
+				notifyListeners(new Notification<IStatemachine>(
+						NotificationType.RuntimeCycleNotification, statemachine));
 			}
 			lock.readLock().unlock();
 		}

+ 8 - 0
test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/test_parallelregions/Test_ParallelRegionsCycleBasedStatemachine.java

@@ -83,6 +83,8 @@ public class Test_ParallelRegionsCycleBasedStatemachine
 		if (occuredEvents.contains(defaultInterface.getEventEvent1())) {
 			stateVector[0] = State.$NullState$;
 
+			defaultInterface.setVarHierarchy(2);
+
 			defaultInterface
 					.setVarHierarchy(defaultInterface.getVarHierarchy() + (3));
 
@@ -98,6 +100,8 @@ public class Test_ParallelRegionsCycleBasedStatemachine
 			if (occuredEvents.contains(defaultInterface.getEventEvent11())) {
 				stateVector[0] = State.$NullState$;
 
+				defaultInterface.setVarHierarchy(2);
+
 				defaultInterface.setVarHierarchy(defaultInterface
 						.getVarHierarchy() + (3));
 
@@ -125,6 +129,8 @@ public class Test_ParallelRegionsCycleBasedStatemachine
 				if (occuredEvents.contains(defaultInterface.getEventEvent12())) {
 					stateVector[0] = State.$NullState$;
 
+					defaultInterface.setVarHierarchy(2);
+
 					defaultInterface.setVarHierarchy(defaultInterface
 							.getVarHierarchy() + (3));
 
@@ -141,6 +147,8 @@ public class Test_ParallelRegionsCycleBasedStatemachine
 							.getEventEvent13())) {
 						stateVector[0] = State.$NullState$;
 
+						defaultInterface.setVarHierarchy(2);
+
 						defaultInterface.setVarHierarchy(defaultInterface
 								.getVarHierarchy() + (3));
 

+ 3 - 3
test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/test_transition/DefaultInterfaceImpl.java

@@ -20,11 +20,11 @@ public class DefaultInterfaceImpl extends NotificationSender
 			DefaultInterface {
 
 	private final ValuedEvent<Events, Boolean> EventEvent5 = new ValuedEvent<Events, Boolean>(
-			Events.Event5, 4, false);
+			Events.Event5, 5, false);
 	private final Event<Events> EventEvent6 = new Event<Events>(Events.Event6,
-			4);
+			5);
 	private final Event<Events> EventEvent7 = new Event<Events>(Events.Event7,
-			4);
+			5);
 
 	private Test_TransitionCycleBasedStatemachine statemachine;
 

+ 5 - 3
test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/test_transition/InterfaceA.java

@@ -16,7 +16,7 @@ import org.yakindu.sct.runtime.java.INotificationSender;
 public interface InterfaceA extends INotificationSender {
 
 	public enum Events {
-		Event1, Event2, Event3, Event4,
+		Event1, Event2, Event3, Event4, Event5,
 	}
 
 	public void raiseEvent1(int value);
@@ -24,8 +24,10 @@ public interface InterfaceA extends INotificationSender {
 	public void raiseEvent2();
 
 	public void raiseEvent3();
-	public boolean isRaisedEvent4();
 
-	public Event<Events> getEventEvent4();
+	public void raiseEvent4();
+	public boolean isRaisedEvent5();
+
+	public Event<Events> getEventEvent5();
 
 }

+ 14 - 4
test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/test_transition/InterfaceAImpl.java

@@ -25,6 +25,8 @@ public class InterfaceAImpl extends NotificationSender implements InterfaceA {
 			0);
 	private final Event<Events> EventEvent4 = new Event<Events>(Events.Event4,
 			0);
+	private final Event<Events> EventEvent5 = new Event<Events>(Events.Event5,
+			0);
 
 	private Test_TransitionCycleBasedStatemachine statemachine;
 
@@ -59,16 +61,24 @@ public class InterfaceAImpl extends NotificationSender implements InterfaceA {
 
 	public void raiseEvent4() {
 		statemachine.getOccuredEvents().add(EventEvent4);
-		statemachine.getOutEvents().add(EventEvent4);
-		notifyListeners(new EventNotification(EventEvent4));
 	}
 
 	public Event<Events> getEventEvent4() {
 		return EventEvent4;
 	}
 
-	public boolean isRaisedEvent4() {
-		return statemachine.getOutEvents().contains(EventEvent4);
+	public void raiseEvent5() {
+		statemachine.getOccuredEvents().add(EventEvent5);
+		statemachine.getOutEvents().add(EventEvent5);
+		notifyListeners(new EventNotification(EventEvent5));
+	}
+
+	public Event<Events> getEventEvent5() {
+		return EventEvent5;
+	}
+
+	public boolean isRaisedEvent5() {
+		return statemachine.getOutEvents().contains(EventEvent5);
 	}
 
 }

+ 22 - 44
test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/test_transition/Test_TransitionCycleBasedStatemachine.java

@@ -29,9 +29,9 @@ public class Test_TransitionCycleBasedStatemachine
 	}
 
 	private static final TimeEvent<TimeEvents> State1_time_event_0 = new TimeEvent<TimeEvents>(
-			TimeEvents.State1_time_event_0, 7, false);
+			TimeEvents.State1_time_event_0, 8, false);
 	private static final TimeEvent<TimeEvents> State1_time_event_1 = new TimeEvent<TimeEvents>(
-			TimeEvents.State1_time_event_1, 7, false);
+			TimeEvents.State1_time_event_1, 8, false);
 
 	public enum State {
 		State1, State2, $NullState$
@@ -53,7 +53,7 @@ public class Test_TransitionCycleBasedStatemachine
 	private long cycleStartTime;
 
 	public Test_TransitionCycleBasedStatemachine() {
-		occuredEvents = new EventVector<Event<? extends Enum<?>>>(9);
+		occuredEvents = new EventVector<Event<? extends Enum<?>>>(10);
 		outEvents = new HashSet<Event<? extends Enum<?>>>();
 		interfaceA = new InterfaceAImpl(this);
 		defaultInterface = new DefaultInterfaceImpl(this);
@@ -176,21 +176,17 @@ public class Test_TransitionCycleBasedStatemachine
 						stateVector[0] = State.State2;
 
 					} else {
-						if (occuredEvents.contains(defaultInterface
-								.getEventEvent6())) {
+						if (occuredEvents.contains(State1_time_event_0)) {
 							stateVector[0] = State.$NullState$;
 
 							getTimerService().resetTimer(State1_time_event_0);
 							getTimerService().resetTimer(State1_time_event_1);
 
-							defaultInterface.setVarI(15);
-
 							nextStateIndex = 0;
 							stateVector[0] = State.State2;
 
 						} else {
-							if (occuredEvents.contains(defaultInterface
-									.getEventEvent7())) {
+							if (occuredEvents.contains(State1_time_event_1)) {
 								stateVector[0] = State.$NullState$;
 
 								getTimerService().resetTimer(
@@ -198,14 +194,13 @@ public class Test_TransitionCycleBasedStatemachine
 								getTimerService().resetTimer(
 										State1_time_event_1);
 
-								defaultInterface.setVarJ((defaultInterface
-										.getVarI() * 9));
-
 								nextStateIndex = 0;
 								stateVector[0] = State.State2;
 
 							} else {
-								if (occuredEvents.contains(State1_time_event_0)) {
+								if ((occuredEvents.contains(interfaceA
+										.getEventEvent1()) && (interfaceA
+										.getEventEvent1().getValue() > 5))) {
 									stateVector[0] = State.$NullState$;
 
 									getTimerService().resetTimer(
@@ -213,40 +208,11 @@ public class Test_TransitionCycleBasedStatemachine
 									getTimerService().resetTimer(
 											State1_time_event_1);
 
+									defaultInterface.setVarI(1);
+
 									nextStateIndex = 0;
 									stateVector[0] = State.State2;
 
-								} else {
-									if (occuredEvents
-											.contains(State1_time_event_1)) {
-										stateVector[0] = State.$NullState$;
-
-										getTimerService().resetTimer(
-												State1_time_event_0);
-										getTimerService().resetTimer(
-												State1_time_event_1);
-
-										nextStateIndex = 0;
-										stateVector[0] = State.State2;
-
-									} else {
-										if ((occuredEvents.contains(interfaceA
-												.getEventEvent1()) && (interfaceA
-												.getEventEvent1().getValue() > 5))) {
-											stateVector[0] = State.$NullState$;
-
-											getTimerService().resetTimer(
-													State1_time_event_0);
-											getTimerService().resetTimer(
-													State1_time_event_1);
-
-											defaultInterface.setVarI(1);
-
-											nextStateIndex = 0;
-											stateVector[0] = State.State2;
-
-										}
-									}
 								}
 							}
 						}
@@ -256,6 +222,18 @@ public class Test_TransitionCycleBasedStatemachine
 		}
 	}
 	private void reactState2() {
+		if (occuredEvents.contains(defaultInterface.getEventEvent6())) {
+			stateVector[0] = State.$NullState$;
+
+			getTimerService().setTimer(State1_time_event_0, (10 * 1000),
+					cycleStartTime);
+			getTimerService()
+					.setTimer(State1_time_event_1, 100, cycleStartTime);
+
+			nextStateIndex = 0;
+			stateVector[0] = State.State1;
+
+		}
 	}
 	public void runCycle() {
 		cycleStartTime = System.currentTimeMillis();

+ 275 - 151
test-plugins/org.yakindu.sct.generator.java.runtime.test/src/org/yakindu/sct/generator/java/runtime/test/StatemachinePerformanceTest.java

@@ -10,117 +10,123 @@ import org.yakindu.sct.runtime.java.test_parallelregions.Test_ParallelRegionsCyc
 
 public class StatemachinePerformanceTest {
 
+	// @Test public void testPerformance_ParallelRegions() throws Exception{
+	//
+	// final Test_ParallelRegionsCycleBasedStatemachine sm_1 = new
+	// Test_ParallelRegionsCycleBasedStatemachine();
+	// final DefaultInterface di = sm_1.getDefaultInterface();
+	// sm_1.init();
+	// sm_1.enter();
+	//
+	// class TestRunnable implements Runnable {
+	// public boolean stop = false;
+	// public boolean stopped = false;
+	// public long cycles = 0;
+	//
+	// public void run() {
+	// while (!stop) {
+	//
+	// di.raiseEvent1();
+	// sm_1.runCycle();
+	// cycles ++;
+	// assertTrue(sm_1.isStateActive(Test_ParallelRegionsCycleBasedStatemachine.State.State3));
+	// assertTrue(sm_1.isStateActive(Test_ParallelRegionsCycleBasedStatemachine.State.State7));
+	//
+	// di.raiseEvent10();
+	// sm_1.runCycle();
+	// cycles ++;
+	// assertTrue(sm_1.isStateActive(Test_ParallelRegionsCycleBasedStatemachine.State.State1));
+	//
+	// di.raiseEvent12();
+	// sm_1.runCycle();
+	// cycles ++;
+	// assertTrue(sm_1.isStateActive(Test_ParallelRegionsCycleBasedStatemachine.State.State8));
+	//
+	// di.raiseEvent2();
+	// sm_1.runCycle();
+	// cycles ++;
+	//
+	// di.raiseEvent6();
+	// sm_1.runCycle();
+	// cycles ++;
+	//
+	// di.raiseEvent7();
+	// sm_1.runCycle();
+	// cycles ++;
+	// assertTrue(sm_1.isStateActive(Test_ParallelRegionsCycleBasedStatemachine.State.State1));
+	//
+	// }
+	// stopped = true;
+	// }
+	//
+	// };
+	//
+	// TestRunnable run = new TestRunnable();
+	// Thread thread = new Thread(run);
+	//
+	// System.out.println( ">>  " + run.cycles );
+	//
+	// long start = System.currentTimeMillis();
+	// thread.start();
+	// Thread.sleep(20000);
+	// run.stop = true;
+	// while (!run.stopped) { Thread.sleep(10); }
+	// long stop = System.currentTimeMillis();
+	//
+	// System.out.println( "executed " + run.cycles + " in " + (stop - start) +
+	// "ms .");
+	// }
+
+	@Test
+	public void testPerformance_ParallelRegions_() throws Exception {
 
-	
-//	@Test public void testPerformance_ParallelRegions() throws Exception{
-//		
-//		final Test_ParallelRegionsCycleBasedStatemachine sm_1 = new Test_ParallelRegionsCycleBasedStatemachine();
-//		final DefaultInterface di = sm_1.getDefaultInterface();
-//		sm_1.init();
-//		sm_1.enter();
-//
-//		class TestRunnable implements Runnable {
-//			public boolean stop = false;
-//			public boolean stopped = false;
-//			public long cycles = 0;
-//			
-//			public void run() {
-//				while (!stop) {
-//					
-//					di.raiseEvent1();
-//					sm_1.runCycle(); 
-//					cycles ++;
-//					assertTrue(sm_1.isStateActive(Test_ParallelRegionsCycleBasedStatemachine.State.State3));
-//					assertTrue(sm_1.isStateActive(Test_ParallelRegionsCycleBasedStatemachine.State.State7));
-//					
-//					di.raiseEvent10();
-//					sm_1.runCycle();
-//					cycles ++;
-//					assertTrue(sm_1.isStateActive(Test_ParallelRegionsCycleBasedStatemachine.State.State1));
-//
-//					di.raiseEvent12();
-//					sm_1.runCycle();
-//					cycles ++;
-//					assertTrue(sm_1.isStateActive(Test_ParallelRegionsCycleBasedStatemachine.State.State8));
-//
-//					di.raiseEvent2();
-//					sm_1.runCycle();
-//					cycles ++;
-//
-//					di.raiseEvent6();
-//					sm_1.runCycle();
-//					cycles ++;
-//
-//					di.raiseEvent7();
-//					sm_1.runCycle();
-//					cycles ++;
-//					assertTrue(sm_1.isStateActive(Test_ParallelRegionsCycleBasedStatemachine.State.State1));
-//
-//				}
-//				stopped = true;
-//			}
-//			
-//		};
-//		
-//		TestRunnable run = new TestRunnable();
-//		Thread thread = new Thread(run);
-//		
-//		System.out.println( ">>  " + run.cycles );
-//
-//		long start = System.currentTimeMillis();
-//		thread.start();
-//		Thread.sleep(20000);
-//		run.stop = true;
-//		while (!run.stopped) { Thread.sleep(10); }
-//		long stop = System.currentTimeMillis();
-//		
-//		System.out.println( "executed " + run.cycles + " in " + (stop - start) + "ms .");
-//	}
-	
-	
-	@Test public void testPerformance_ParallelRegions_() throws Exception{
-		
 		final Test_ParallelRegionsCycleBasedStatemachine sm_1 = new Test_ParallelRegionsCycleBasedStatemachine();
 		final DefaultInterface di = sm_1.getDefaultInterface();
 		sm_1.init();
 		sm_1.enter();
 
 		class CycleRunner extends SMRunner {
-			
+
 			public void runCycles() {
 
-					di.raiseEvent1();
-					sm_1.runCycle(); 
-					cycles ++;
-					assertTrue(sm_1.isStateActive(Test_ParallelRegionsCycleBasedStatemachine.State.State3));
-					assertTrue(sm_1.isStateActive(Test_ParallelRegionsCycleBasedStatemachine.State.State7));
-					
-					di.raiseEvent10();
-					sm_1.runCycle();
-					cycles ++;
-					assertTrue(sm_1.isStateActive(Test_ParallelRegionsCycleBasedStatemachine.State.State1));
-
-					di.raiseEvent12();
-					sm_1.runCycle();
-					cycles ++;
-					assertTrue(sm_1.isStateActive(Test_ParallelRegionsCycleBasedStatemachine.State.State8));
-
-					di.raiseEvent2();
-					sm_1.runCycle();
-					cycles ++;
-
-					di.raiseEvent6();
-					sm_1.runCycle();
-					cycles ++;
-
-					di.raiseEvent7();
-					sm_1.runCycle();
-					cycles ++;
-					assertTrue(sm_1.isStateActive(Test_ParallelRegionsCycleBasedStatemachine.State.State1));
+				di.raiseEvent1();
+				sm_1.runCycle();
+				cycles++;
+				assertTrue(sm_1
+						.isStateActive(Test_ParallelRegionsCycleBasedStatemachine.State.State3));
+				assertTrue(sm_1
+						.isStateActive(Test_ParallelRegionsCycleBasedStatemachine.State.State7));
+
+				di.raiseEvent10();
+				sm_1.runCycle();
+				cycles++;
+				assertTrue(sm_1
+						.isStateActive(Test_ParallelRegionsCycleBasedStatemachine.State.State1));
+
+				di.raiseEvent12();
+				sm_1.runCycle();
+				cycles++;
+				assertTrue(sm_1
+						.isStateActive(Test_ParallelRegionsCycleBasedStatemachine.State.State8));
+
+				di.raiseEvent2();
+				sm_1.runCycle();
+				cycles++;
+
+				di.raiseEvent6();
+				sm_1.runCycle();
+				cycles++;
+
+				di.raiseEvent7();
+				sm_1.runCycle();
+				cycles++;
+				assertTrue(sm_1
+						.isStateActive(Test_ParallelRegionsCycleBasedStatemachine.State.State1));
 			}
-			
-		};
-		
+
+		}
+		;
+
 		CycleRunner run = new CycleRunner();
 		run.test("ParallelRegions", 1);
 		run.test("ParallelRegions", 10);
@@ -129,52 +135,165 @@ public class StatemachinePerformanceTest {
 		run.test("ParallelRegions", 10000);
 	}
 
-	
-	@Test public void testPerformance_Hierarchy() throws Exception{
+//	@Test
+//	public void testPerformance_Mix() throws Exception {
+//
+//		final Test_HierarchyCycleBasedStatemachine sm = new Test_HierarchyCycleBasedStatemachine();
+//		final Test_ParallelRegionsCycleBasedStatemachine sm_1 = new Test_ParallelRegionsCycleBasedStatemachine();
+//		sm_1.init();
+//		sm_1.enter();
+//		final DefaultInterface di_1 = sm_1.getDefaultInterface();
+//
+//		sm.init();
+//		sm.enter();
+//		final org.yakindu.sct.runtime.java.test_hierarchy.DefaultInterface di = sm
+//				.getDefaultInterface();
+//
+//		class TestRunner extends SMRunner {
+//
+//			public void runCycles() {
+//
+//				di.raiseEvent1();
+//				sm.runCycle();
+//				cycles++;
+//				assertTrue(sm.isStateActive(State.State3));
+//
+//				di.raiseEvent2();
+//				sm.runCycle();
+//				cycles++;
+//				assertTrue(sm.isStateActive(State.State5));
+//
+//				di.raiseEvent3();
+//				sm.runCycle();
+//				cycles++;
+//				assertTrue(sm.isStateActive(State.State7));
+//
+//				di.raiseEvent4();
+//				sm.runCycle();
+//				assertTrue(sm.isStateActive(State.State8));
+//				cycles++;
+//
+//				di.raiseEvent5();
+//				sm.runCycle();
+//				assertTrue(sm.isStateActive(State.State7));
+//				cycles++;
+//
+//				di.raiseEvent6();
+//				sm.runCycle();
+//				cycles++;
+//				assertTrue(sm.isStateActive(State.State9));
+//
+//			}
+//
+//		}
+//		;
+//
+//		class CycleRunner extends SMRunner {
+//
+//			public void runCycles() {
+//
+//				di_1.raiseEvent1();
+//				sm_1.runCycle();
+//				cycles++;
+////				assertTrue(sm_1
+////						.isStateActive(Test_ParallelRegionsCycleBasedStatemachine.State.State3));
+////				assertTrue(sm_1
+////						.isStateActive(Test_ParallelRegionsCycleBasedStatemachine.State.State7));
+//
+//				di_1.raiseEvent10();
+//				sm_1.runCycle();
+//				cycles++;
+////				assertTrue(sm_1
+////						.isStateActive(Test_ParallelRegionsCycleBasedStatemachine.State.State1));
+//
+//				di_1.raiseEvent12();
+//				sm_1.runCycle();
+//				cycles++;
+////				assertTrue(sm_1
+////						.isStateActive(Test_ParallelRegionsCycleBasedStatemachine.State.State8));
+//
+//				di_1.raiseEvent2();
+//				sm_1.runCycle();
+//				cycles++;
+//
+//				di_1.raiseEvent6();
+//				sm_1.runCycle();
+//				cycles++;
+//
+//				di_1.raiseEvent7();
+//				sm_1.runCycle();
+//				cycles++;
+////				assertTrue(sm_1
+////						.isStateActive(Test_ParallelRegionsCycleBasedStatemachine.State.State1));
+//			}
+//
+//		}
+//		;
+//
+//		TestRunner runner = new TestRunner();
+//		CycleRunner runner_2 = new CycleRunner();
+//		
+//		runner.test("Test_Hierarchy..", 1);
+//		runner_2.test("ParallelRegions", 1);
+//		runner.test("Test_Hierarchy..", 10);
+//		runner_2.test("ParallelRegions", 10);
+//		runner.test("Test_Hierarchy..", 100);
+//		runner_2.test("ParallelRegions", 100);
+//		runner.test("Test_Hierarchy..", 1000);
+//		runner_2.test("ParallelRegions", 1000);
+//		runner.test("Test_Hierarchy..", 10000);
+//		runner_2.test("ParallelRegions", 10000);
+//	}
+
+	@Test
+	public void testPerformance_Hierarchy() throws Exception {
 
 		final Test_HierarchyCycleBasedStatemachine sm = new Test_HierarchyCycleBasedStatemachine();
+
 		sm.init();
 		sm.enter();
-		final org.yakindu.sct.runtime.java.test_hierarchy.DefaultInterface di = sm.getDefaultInterface();
-		
+		final org.yakindu.sct.runtime.java.test_hierarchy.DefaultInterface di = sm
+				.getDefaultInterface();
+
 		class TestRunner extends SMRunner {
 
 			public void runCycles() {
-					
-					di.raiseEvent1();
-					sm.runCycle(); 
-					cycles ++;
-					assertTrue(sm.isStateActive(State.State3));
-					
-					di.raiseEvent2();
-					sm.runCycle();
-					cycles ++;
-					assertTrue(sm.isStateActive(State.State5));
-
-					di.raiseEvent3();
-					sm.runCycle();
-					cycles ++;
-					assertTrue(sm.isStateActive(State.State7));
-
-					di.raiseEvent4();
-					sm.runCycle();
-					assertTrue(sm.isStateActive(State.State8));
-					cycles ++;
-
-					di.raiseEvent5();
-					sm.runCycle();
-					assertTrue(sm.isStateActive(State.State7));
-					cycles ++;
-
-					di.raiseEvent6();
-					sm.runCycle();
-					cycles ++;
-					assertTrue(sm.isStateActive(State.State9));
+
+				di.raiseEvent1();
+				sm.runCycle();
+				cycles++;
+				assertTrue(sm.isStateActive(State.State3));
+
+				di.raiseEvent2();
+				sm.runCycle();
+				cycles++;
+				assertTrue(sm.isStateActive(State.State5));
+
+				di.raiseEvent3();
+				sm.runCycle();
+				cycles++;
+				assertTrue(sm.isStateActive(State.State7));
+
+				di.raiseEvent4();
+				sm.runCycle();
+				assertTrue(sm.isStateActive(State.State8));
+				cycles++;
+
+				di.raiseEvent5();
+				sm.runCycle();
+				assertTrue(sm.isStateActive(State.State7));
+				cycles++;
+
+				di.raiseEvent6();
+				sm.runCycle();
+				cycles++;
+				assertTrue(sm.isStateActive(State.State9));
 
 			}
-			
-		};
-		
+
+		}
+		;
+
 		TestRunner runner = new TestRunner();
 		runner.test("Test_Hierarchy..", 1);
 		runner.test("Test_Hierarchy..", 10);
@@ -183,8 +302,6 @@ public class StatemachinePerformanceTest {
 		runner.test("Test_Hierarchy..", 10000);
 	}
 
-	
-	
 	static abstract class SMRunner implements Runnable {
 		public boolean stop;
 		public boolean started;
@@ -193,7 +310,6 @@ public class StatemachinePerformanceTest {
 		public long t_start;
 		public long t_stop;
 
-		
 		public void run() {
 			cycles = 0;
 			t_start = System.nanoTime();
@@ -203,32 +319,40 @@ public class StatemachinePerformanceTest {
 				started = true;
 				runCycles();
 			}
-			
+
 			stopped = true;
 			t_stop = System.nanoTime();
 		}
-		
+
 		public abstract void runCycles();
-		
+
 		public void test(String name, long millis) throws Exception {
 			Thread thread = new Thread(this);
 
-			System.out.print( "run " + name + " for " + millis + "ms > ");
+			System.out.print("run " + name + " for " + millis + "ms > ");
 
 			stop = false;
 			stopped = false;
 			started = false;
-	
+
 			thread.start();
-			while (!thread.isAlive() && started) { Thread.sleep(1); }
-			
+			while (!thread.isAlive() && started) {
+				Thread.sleep(1);
+			}
+
 			Thread.sleep(millis);
 			stop = true;
 
-			while (thread.isAlive()) { Thread.sleep(10); }
-			
+			while (thread.isAlive()) {
+				Thread.sleep(10);
+			}
+
 			long t = t_stop - t_start;
-			System.out.println( "processd " + cycles + " cycles in " + (t/1000000) + "." + (t%1000000) + "ms >> " + (t / cycles) + "ns/cycle >> " + ((long) ( ((double)cycles) / ((double) t / 1000000) )) + " cycles/ms" ) ;
+			System.out.println("processd " + cycles + " cycles in "
+					+ (t / 1000000) + "." + (t % 1000000) + "ms >> "
+					+ (t / cycles) + "ns/cycle >> "
+					+ ((long) (((double) cycles) / ((double) t / 1000000)))
+					+ " cycles/ms");
 
 		}
 	};

+ 29 - 10
test-plugins/org.yakindu.sct.generator.java.runtime.test/src/org/yakindu/sct/generator/java/runtime/test/TestExpressionEventBasedStatemachine.java

@@ -5,6 +5,9 @@ import static org.junit.Assert.assertEquals;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.yakindu.sct.runtime.java.INotificationListener;
+import org.yakindu.sct.runtime.java.Notification;
+import org.yakindu.sct.runtime.java.NotificationType;
 import org.yakindu.sct.runtime.java.RuntimeService;
 import org.yakindu.sct.runtime.java.test_expression.Test_ExpressionEventBasedStatemachine;
 
@@ -14,6 +17,8 @@ public class TestExpressionEventBasedStatemachine {
 
 	private RuntimeService runtimeService;
 
+	private boolean shouldWait;
+
 	// Minimal cycletime
 	private final long cyclePeriod = 1;
 
@@ -22,7 +27,16 @@ public class TestExpressionEventBasedStatemachine {
 		statemachine = new Test_ExpressionEventBasedStatemachine();
 		statemachine.init();
 		statemachine.enter();
+		shouldWait = true;
 		runtimeService = new RuntimeService(cyclePeriod);
+		runtimeService.addNotificationListener(new INotificationListener() {
+			public void notify(Notification<?> notification) {
+				if (notification.getNotificationType() == NotificationType.RuntimeCycleNotification
+						&& notification.getElement() == statemachine) {
+					shouldWait = false;
+				}
+			}
+		});
 		runtimeService.addStatemachine(statemachine);
 	}
 
@@ -31,15 +45,20 @@ public class TestExpressionEventBasedStatemachine {
 		runtimeService.removeStatemachine(statemachine);
 		runtimeService.cancel();
 		statemachine = null;
+		shouldWait = false;
 	}
 
-	private void sleep(long time) {
+	private void sleep() {
 
-		try {
-			Thread.sleep(time);
-		} catch (InterruptedException e) {
-			e.printStackTrace();
+		while (shouldWait) {
+			try {
+				Thread.sleep(1);
+			} catch (InterruptedException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
 		}
+		shouldWait = true;
 	}
 
 	@Test
@@ -48,7 +67,7 @@ public class TestExpressionEventBasedStatemachine {
 				.getDefaultInterface().getVarVar3(), Math.pow(10, -8));
 
 		statemachine.getDefaultInterface().raiseEvent1(0);
-		sleep(5);
+		sleep();
 		assertEquals("Other.Var1 value not set correct: ", false, statemachine
 				.getInterfaceOther().getVarVar1());
 		assertEquals("Default.Var2 value not set correct: ", 1, statemachine
@@ -62,7 +81,7 @@ public class TestExpressionEventBasedStatemachine {
 
 		// Trigger oncycle expression with event
 		statemachine.getDefaultInterface().raiseEvent3();
-		sleep(5);
+		sleep();
 		assertEquals("Other.Var1 value not set correct: ", false, statemachine
 				.getInterfaceOther().getVarVar1());
 		assertEquals("Default.Var2 value not set correct: ", 1, statemachine
@@ -76,7 +95,7 @@ public class TestExpressionEventBasedStatemachine {
 
 		// Trigger oncycle expression with event
 		statemachine.getDefaultInterface().raiseEvent3();
-		sleep(5);
+		sleep();
 		assertEquals("Other.Var1 value not set correct: ", false, statemachine
 				.getInterfaceOther().getVarVar1());
 		assertEquals("Default.Var2 value not set correct: ", 1, statemachine
@@ -89,14 +108,14 @@ public class TestExpressionEventBasedStatemachine {
 				.getDefaultInterface().getVarVar1());
 
 		statemachine.getDefaultInterface().raiseEvent1(0);
-		sleep(5);
+		sleep();
 		assertEquals("Default.Var5 value not set correct: ", true, statemachine
 				.getDefaultInterface().getVarVar5());
 		assertEquals("Other.Var3 value not set correct: ", 962.24, statemachine
 				.getDefaultInterface().getVarVar3(), Math.pow(10, -8));
 
 		statemachine.getDefaultInterface().raiseEvent1(0);
-		sleep(5);
+		sleep();
 		assertEquals("Other.Var3 value not set correct: ", 962.24, statemachine
 				.getDefaultInterface().getVarVar3(), Math.pow(10, -8));
 

+ 4 - 5
test-plugins/org.yakindu.sct.generator.java.runtime.test/src/org/yakindu/sct/generator/java/runtime/test/TestInterfaceTestEventBasedStatemachine.java

@@ -13,7 +13,6 @@ package org.yakindu.sct.generator.java.runtime.test;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
 import org.junit.After;
 import org.junit.Before;
@@ -130,7 +129,7 @@ public class TestInterfaceTestEventBasedStatemachine {
 				.getDefaultInterface().getEventEvent2().getValue().intValue());
 
 		statemachine.getDefaultInterface().raiseEvent1();
-		sleep(2);
+		sleep(5);
 		// Test if statemachine is back in State 1
 		assertTrue("Statemachine isn't in State: " + State.State1.name() + ".",
 				statemachine.isStateActive(State.State1));
@@ -143,7 +142,7 @@ public class TestInterfaceTestEventBasedStatemachine {
 	public void testStatemachineRunCycle_2() {
 		statemachine.getDefaultInterface().setVarVar2(-12.6);
 		statemachine.getDefaultInterface().raiseEvent1();
-		sleep(2);
+		sleep(5);
 		// Test if statemachine is still in State 1
 		assertTrue("Statemachine isn't in State: " + State.State1.name() + ".",
 				statemachine.isStateActive(State.State1));
@@ -170,7 +169,7 @@ public class TestInterfaceTestEventBasedStatemachine {
 	@Test
 	public void testStatemachineRunCycle_3() {
 		statemachine.getInterfaceOther().raiseEvent3();
-		sleep(2);
+		sleep(5);
 		// Test if state is changed to State3
 		assertTrue("Statemachine isn't in State: " + State.State3.name() + ".",
 				statemachine.isStateActive(State.State3));
@@ -178,7 +177,7 @@ public class TestInterfaceTestEventBasedStatemachine {
 		assertTrue("Event not raised: ", events[1]);
 
 		statemachine.getInterfaceOther().raiseEvent3();
-		sleep(2);
+		sleep(5);
 		// Test if statemachine is back in State 1
 		assertTrue("Statemachine isn't in State: " + State.State1.name() + ".",
 				statemachine.isStateActive(State.State1));