|
|
@@ -8,12 +8,12 @@ package net.ranides.assira.events;
|
|
|
|
|
|
import java.util.LinkedList;
|
|
|
import java.util.List;
|
|
|
+import net.ranides.assira.collection.ArrayUtils;
|
|
|
import net.ranides.assira.collection.SetUtils;
|
|
|
import net.ranides.assira.collection.map.LazyMap;
|
|
|
import net.ranides.assira.time.TimeUtils;
|
|
|
import net.ranides.assira.trace.LoggerUtils;
|
|
|
import static org.junit.Assert.*;
|
|
|
-import org.junit.Ignore;
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
|
@@ -29,7 +29,7 @@ public class EventProactorTest {
|
|
|
}
|
|
|
|
|
|
private static class HitMap extends LazyMap<String, List<Integer>> {
|
|
|
- private int counter;
|
|
|
+ private int counter = 0;
|
|
|
|
|
|
@Override
|
|
|
public List<Integer> apply(String source) {
|
|
|
@@ -47,15 +47,14 @@ public class EventProactorTest {
|
|
|
@Override
|
|
|
public void handleEvent(T event) {
|
|
|
// "handleEvent" can be invoked by many threads - have to be thread-safe
|
|
|
- synchronized(this) {
|
|
|
- get( name ).add(counter++);
|
|
|
+ synchronized(HitMap.this) {
|
|
|
+ get(name).add(counter++);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
- @Ignore("unstable")
|
|
|
@Test
|
|
|
public void testPropagation() {
|
|
|
// @todo (assira) EventProactor: unstable test of
|
|
|
@@ -101,26 +100,26 @@ public class EventProactorTest {
|
|
|
unknown.dispose();
|
|
|
}
|
|
|
|
|
|
-// @Test
|
|
|
-// public void testStop() {
|
|
|
-// HitMap hits = new HitMap();
|
|
|
-// EventReactor unknown = EventReactor.newInstance("unknown", 32, 1000);
|
|
|
-// EventReactor main = EventReactor.newInstance("name", 32, 1000);
|
|
|
-//
|
|
|
-// main.addEventListener(Event.class, hits.new HitListener<Event>("global") );
|
|
|
-// main.addEventListener(CoreEvent.Shutdown.class, hits.new HitListener<CoreEvent.Shutdown>("shutdown") );
|
|
|
-// main.addEventListener(CoreEvent.Stop.class, hits.new HitListener<CoreEvent.Stop>("exit") );
|
|
|
-//
|
|
|
-// main.signalEvent(CoreEvent.stop(unknown) );
|
|
|
-// main.stop();
|
|
|
-//
|
|
|
-// assertEquals(SetUtils.asHashSet("global", "exit", "shutdown"), hits.keySet());
|
|
|
-// assertEquals(ArrayUtils.asList(0,2,4,6), hits.get("global"));
|
|
|
-// assertEquals(ArrayUtils.asList(1,3), hits.get("exit"));
|
|
|
-// assertEquals(ArrayUtils.asList(5), hits.get("shutdown"));
|
|
|
-//
|
|
|
-// unknown.dispose();
|
|
|
-// }
|
|
|
+ @Test
|
|
|
+ public void testStop() {
|
|
|
+ HitMap hits = new HitMap();
|
|
|
+ EventReactor unknown = EventReactor.newInstance("unknown", 32, 1000);
|
|
|
+ EventReactor main = EventReactor.newInstance("name", 32, 1000);
|
|
|
+
|
|
|
+ main.addEventListener(Event.class, hits.new HitListener<Event>("global") );
|
|
|
+ main.addEventListener(CoreEvent.Shutdown.class, hits.new HitListener<CoreEvent.Shutdown>("shutdown") );
|
|
|
+ main.addEventListener(CoreEvent.Stop.class, hits.new HitListener<CoreEvent.Stop>("exit") );
|
|
|
+
|
|
|
+ main.signalEvent(CoreEvent.stop(unknown) );
|
|
|
+ main.stop();
|
|
|
+
|
|
|
+ assertEquals(SetUtils.asHashSet("global", "exit", "shutdown"), hits.keySet());
|
|
|
+ assertEquals(ArrayUtils.asList(0,2,4,6), hits.get("global"));
|
|
|
+ assertEquals(ArrayUtils.asList(1,3), hits.get("exit"));
|
|
|
+ assertEquals(ArrayUtils.asList(5), hits.get("shutdown"));
|
|
|
+
|
|
|
+ unknown.dispose();
|
|
|
+ }
|
|
|
|
|
|
@SuppressWarnings("PMD")
|
|
|
class IOEvent implements Event { }
|