Author: heiko.braun(a)jboss.com
Date: 2008-07-23 10:28:48 -0400 (Wed, 23 Jul 2008)
New Revision: 197
Added:
sam/trunk/modules/sim/src/test/resources/simulation/test.drl
Removed:
sam/trunk/modules/sim/src/test/resources/adapter/
sam/trunk/modules/sim/src/test/resources/database/
sam/trunk/modules/sim/src/test/resources/samples/esper-default-cfg.xml
sam/trunk/modules/sim/src/test/resources/samples/pattern/esper-cfg.xml
sam/trunk/modules/sim/src/test/resources/simulation/esper-cfg.xml
sam/trunk/modules/sim/src/test/resources/viz/
Modified:
sam/trunk/modules/sim/src/main/java/org/jboss/sam/simulation/EventSimulation.java
sam/trunk/modules/sim/src/test/java/org/jboss/test/sam/simulation/SimulationTestCase.java
Log:
Drools migration: Clean up broken tests
Modified:
sam/trunk/modules/sim/src/main/java/org/jboss/sam/simulation/EventSimulation.java
===================================================================
---
sam/trunk/modules/sim/src/main/java/org/jboss/sam/simulation/EventSimulation.java 2008-07-23
12:54:57 UTC (rev 196)
+++
sam/trunk/modules/sim/src/main/java/org/jboss/sam/simulation/EventSimulation.java 2008-07-23
14:28:48 UTC (rev 197)
@@ -21,22 +21,23 @@
*/
package org.jboss.sam.simulation;
-import org.javasim.*;
-import com.espertech.esper.client.UnmatchedListener;
-import com.espertech.esper.event.EventBean;
+import org.javasim.Scheduler;
+import org.javasim.SimulationException;
+import org.javasim.SimulationProcess;
import org.jboss.sam.EventProcessor;
import org.jboss.sam.EventProcessorFactory;
import org.jboss.sam.StreamInput;
-import org.jboss.sam.internal.esper.EsperRuntimeImpl;
+import org.jboss.sam.internal.stream.InVMDispatcher;
import org.jboss.sam.internal.stream.InVMStreamInput;
-import org.jboss.sam.internal.stream.InVMDispatcher;
-import org.javasim.Scheduler;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.UUID;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.io.IOException;
/**
* Simulations are created from global configuration,
@@ -49,7 +50,7 @@
* typed event messages. They need to be added to a simulation ({@link
#addSource(EventSourceEntity)})
* in order to emit events to the event processor.
* <p>
- *
+ *
* <b>Event sinks</b><br>
* {@link org.jboss.sam.simulation.EventSinkEntity}'s processes event messages that
have been forwarded
* from an event processor. They need to be added ({@link #addSink(EventSinkEntity)}) to
a simualtion
@@ -59,7 +60,7 @@
* <b>Shared context</b><br>
* The {@link org.jboss.sam.simulation.SimulationContext} is shared between all
simulation
* entities and acts as a blackboard where any entity can read and write simulation data
and configuration.
- *
+ *
* @author Heiko.Braun <heiko.braun(a)jboss.com>
*/
public class EventSimulation extends SimulationProcess
@@ -67,7 +68,7 @@
// simulation properties
private List<EventSinkEntity> eventSinks = new
ArrayList<EventSinkEntity>();
private List<EventSourceEntity> eventSources = new
ArrayList<EventSourceEntity>();
- private SimulationContext context;
+ private SimulationContext context;
private InVMDispatcher dispatcher;
// SAM properties
@@ -77,7 +78,7 @@
// Constants
public final static String TOTAL_SIM_TIME = "sam.total-sim-time";
public final static String NUM_UNMATCHED_EVENTS = "sam.unmatched-events";
-
+
private EventSimulation(Properties config, URL bootstrap)
{
// thread setup
@@ -94,23 +95,9 @@
// create a dispatcher used within event source
this.dispatcher = new InVMDispatcher(InVMDispatcher.DEFAULT_CHANNEL_NAME);
-
+
// register in/out with hub
this.eventProcessor.addInput(streamInput);
-
- ((EsperRuntimeImpl) eventProcessor).getUnderlying().getEPRuntime()
- .setUnmatchedListener(
- new UnmatchedListener()
- {
-
- public void update(EventBean event)
- {
- System.out.println("! Unmatched event: " + event);
- context.getMeasurement(NUM_UNMATCHED_EVENTS).increment();
- }
- }
- );
-
}
public EventSinkEntity addSink(EventSinkEntity sink)
@@ -126,7 +113,7 @@
{
source.setContext(this.context);
source.setDispatcher(this.dispatcher);
-
+
this.eventSources.add(source);
return source;
}
@@ -178,11 +165,11 @@
catch(SimulationException e)
{
e.printStackTrace();
- }
+ }
}
-
+
private void begin()
- {
+ {
for(EventSinkEntity sink : eventSinks)
{
sink.begin();
@@ -216,14 +203,14 @@
{
return context.getMeasurement(key);
}
-
+
public void run()
{
try
{
// wait for main thread
waitForMainSuspended();
-
+
// [HB] System.out.println("Running " + this);
// begin
@@ -246,7 +233,7 @@
{
e.printStackTrace();
System.exit(-1);
- }
+ }
}
@@ -271,11 +258,34 @@
{
return new EventSimulation(config,
Thread.currentThread().getContextClassLoader().getResource("samples/esper-default-cfg.xml")
- );
+ );
}
public static EventSimulation bootstrap(Properties config, URL bootstrap)
{
return new EventSimulation(config, bootstrap);
}
+
+ public static String getDRLFromResource(String resourceName)
+ {
+ try
+ {
+ URL url =
Thread.currentThread().getContextClassLoader().getResource(resourceName);
+ BufferedReader reader = new BufferedReader(
+ new InputStreamReader(url.openStream())
+ );
+ StringBuffer sb = new StringBuffer();
+ String line;
+ while((line = reader.readLine()) != null)
+ {
+ sb.append(line);
+ }
+
+ return sb.toString();
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException("Failed to load DRL", e);
+ }
+ }
}
Modified:
sam/trunk/modules/sim/src/test/java/org/jboss/test/sam/simulation/SimulationTestCase.java
===================================================================
---
sam/trunk/modules/sim/src/test/java/org/jboss/test/sam/simulation/SimulationTestCase.java 2008-07-23
12:54:57 UTC (rev 196)
+++
sam/trunk/modules/sim/src/test/java/org/jboss/test/sam/simulation/SimulationTestCase.java 2008-07-23
14:28:48 UTC (rev 197)
@@ -41,16 +41,13 @@
config.put(EventSimulation.TOTAL_SIM_TIME, 60.00);
// init
- EventSimulation simulation = EventSimulation.bootstrap(
- config,
-
Thread.currentThread().getContextClassLoader().getResource("simulation/esper-cfg.xml")
- );
+ EventSimulation simulation = EventSimulation.bootstrap(config);
// shared between all entities
SimulationContext context = simulation.getContext();
// create an event source and associate a message factory
- EventSourceEntity source = new EventSourceEntity("source-A", 0.10);
+ EventSourceEntity source = new EventSourceEntity("EventSource_A", 0.10);
source.setEventMessageFactory(
new EventMessageFactory()
{
@@ -62,7 +59,7 @@
);
// create an event sink and associate handler
- EventSinkEntity sink = new EventSinkEntity("sink-B");
+ EventSinkEntity sink = new EventSinkEntity("EventSink_B");
sink.setEventHandler(
new EventSinkHandler()
{
@@ -76,8 +73,11 @@
simulation.addSource(source);
simulation.addSink(sink);
+ // DRL
+ String epl = EventSimulation.getDRLFromResource("simulation/test.drl");
+
// forward single event messages
- simulation.bindStatement("select * from
org.jboss.test.sam.simulation.SensorEventMessage", sink);
+ simulation.bindStatement(epl, sink);
// start simulation
simulation.singleRun();
Deleted: sam/trunk/modules/sim/src/test/resources/samples/esper-default-cfg.xml
===================================================================
--- sam/trunk/modules/sim/src/test/resources/samples/esper-default-cfg.xml 2008-07-23
12:54:57 UTC (rev 196)
+++ sam/trunk/modules/sim/src/test/resources/samples/esper-default-cfg.xml 2008-07-23
14:28:48 UTC (rev 197)
@@ -1,71 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Sample configuration file.
--->
-<esper-configuration
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xmlns="http://www.espertech.com/schema/esper"
-
xsi:noNamespaceSchemaLocation="esper-configuration-2-0.xsd">
-
- <!--
- Sample engine settings
- -->
- <engine-settings>
- <defaults>
- <threading>
- <!--
- In multithreaded environments, this setting controls whether dispatches to
listeners
- preserve the ordering in which the statement processes events
- -->
- <listener-dispatch preserve-order="true"
timeout-msec="1000" locking="spin"/>
- <!--
- In multithreaded environments, this setting controls whether insert-into
streams
- preserve the order of events inserted into them by one or more statements,
- allowing statements that consume other statement's events to behave
deterministic.
- -->
- <insert-into-dispatch preserve-order="true"
timeout-msec="100" locking="spin"/>
- <!-- These settings define the resolution of the internal timer thread,
- and can disable the timer to indicate that the application supplies the
timer events
- -->
- <internal-timer enabled="true"
msec-resolution="100"/>
- </threading>
- <event-meta>
- <!--
- Lets configure the engine to use case-insensitive resolution for event
properties
- -->
- <class-property-resolution
style="distinct_case_insensitive"/>
- </event-meta>
- <view-resources>
- <!--
- Lets configure the engine to reuse views, which is the default but can
introduce additional locking
- -->
- <share-views enabled="true"/>
- </view-resources>
- <logging>
- <!--
- By default the engine does not generate logging through Log4j of the event
processing execution path.
- To get debug output, set this flag to true. This setting translates into a
static boolean flag
- and thus may apply to multiple engine instances within a given VM.
- -->
- <execution-path enabled="false" />
- </logging>
- <stream-selection>
- <!--
- By default the engine generates output for the insert stream only, and not
for the remove stream.
- To obtain output for remove stream only, or for insert stream and remove
stream,
- there are keywords "rstream" and "irstream" for use in
the select clause.
- This setting controls the default behavior, if no keyword is specified in
the select-clause by statements.
- -->
- <stream-selector value="irstream" />
- </stream-selection>
- <time-source>
- <!--
- By default the time source is System.currentTimeMillis.
- This sample configures the nano-second time call System.nanoTime() as the
time source,
- which Esper adjusts for wall clock time.
- -->
- <time-source-type value="nano" />
- </time-source>
- </defaults>
- </engine-settings>
-
-</esper-configuration>
Deleted: sam/trunk/modules/sim/src/test/resources/samples/pattern/esper-cfg.xml
===================================================================
--- sam/trunk/modules/sim/src/test/resources/samples/pattern/esper-cfg.xml 2008-07-23
12:54:57 UTC (rev 196)
+++ sam/trunk/modules/sim/src/test/resources/samples/pattern/esper-cfg.xml 2008-07-23
14:28:48 UTC (rev 197)
@@ -1,79 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Sample configuration file.
--->
-<esper-configuration
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xmlns="http://www.espertech.com/schema/esper"
-
xsi:noNamespaceSchemaLocation="esper-configuration-2-0.xsd">
-
- <!--
- Adds a Java package name of a package that Java event classes reside in.
- This setting allows an application to place all it's events into one or more Java
packages
- and then declare these packages.
- The engine attempts to resolve an event type alias to a Java class residing in each
declared package.
- -->
- <event-type-auto-alias
package-name="org.jboss.test.sam.samples.pattern"/>
-
- <!--
- Sample engine settings
- -->
- <engine-settings>
- <defaults>
- <threading>
- <!--
- In multithreaded environments, this setting controls whether dispatches to
listeners
- preserve the ordering in which the statement processes events
- -->
- <listener-dispatch preserve-order="true"
timeout-msec="1000" locking="spin"/>
- <!--
- In multithreaded environments, this setting controls whether insert-into
streams
- preserve the order of events inserted into them by one or more statements,
- allowing statements that consume other statement's events to behave
deterministic.
- -->
- <insert-into-dispatch preserve-order="true"
timeout-msec="100" locking="spin"/>
- <!-- These settings define the resolution of the internal timer thread,
- and can disable the timer to indicate that the application supplies the
timer events
- -->
- <internal-timer enabled="true"
msec-resolution="100"/>
- </threading>
- <event-meta>
- <!--
- Lets configure the engine to use case-insensitive resolution for event
properties
- -->
- <class-property-resolution
style="distinct_case_insensitive"/>
- </event-meta>
- <view-resources>
- <!--
- Lets configure the engine to reuse views, which is the default but can
introduce additional locking
- -->
- <share-views enabled="true"/>
- </view-resources>
- <logging>
- <!--
- By default the engine does not generate logging through Log4j of the event
processing execution path.
- To get debug output, set this flag to true. This setting translates into a
static boolean flag
- and thus may apply to multiple engine instances within a given VM.
- -->
- <execution-path enabled="false" />
- </logging>
- <stream-selection>
- <!--
- By default the engine generates output for the insert stream only, and not
for the remove stream.
- To obtain output for remove stream only, or for insert stream and remove
stream,
- there are keywords "rstream" and "irstream" for use in
the select clause.
- This setting controls the default behavior, if no keyword is specified in
the select-clause by statements.
- -->
- <stream-selector value="irstream" />
- </stream-selection>
- <time-source>
- <!--
- By default the time source is System.currentTimeMillis.
- This sample configures the nano-second time call System.nanoTime() as the
time source,
- which Esper adjusts for wall clock time.
- -->
- <time-source-type value="nano" />
- </time-source>
- </defaults>
- </engine-settings>
-
-</esper-configuration>
Deleted: sam/trunk/modules/sim/src/test/resources/simulation/esper-cfg.xml
===================================================================
--- sam/trunk/modules/sim/src/test/resources/simulation/esper-cfg.xml 2008-07-23 12:54:57
UTC (rev 196)
+++ sam/trunk/modules/sim/src/test/resources/simulation/esper-cfg.xml 2008-07-23 14:28:48
UTC (rev 197)
@@ -1,79 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Sample configuration file.
--->
-<esper-configuration
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xmlns="http://www.espertech.com/schema/esper"
-
xsi:noNamespaceSchemaLocation="esper-configuration-2-0.xsd">
-
- <!--
- Adds a Java package name of a package that Java event classes reside in.
- This setting allows an application to place all it's events into one or more Java
packages
- and then declare these packages.
- The engine attempts to resolve an event type alias to a Java class residing in each
declared package.
- -->
- <event-type-auto-alias package-name="org.jboss.test.sam.simulation"/>
-
- <!--
- Sample engine settings
- -->
- <engine-settings>
- <defaults>
- <threading>
- <!--
- In multithreaded environments, this setting controls whether dispatches to
listeners
- preserve the ordering in which the statement processes events
- -->
- <listener-dispatch preserve-order="true"
timeout-msec="1000" locking="spin"/>
- <!--
- In multithreaded environments, this setting controls whether insert-into
streams
- preserve the order of events inserted into them by one or more statements,
- allowing statements that consume other statement's events to behave
deterministic.
- -->
- <insert-into-dispatch preserve-order="true"
timeout-msec="100" locking="spin"/>
- <!-- These settings define the resolution of the internal timer thread,
- and can disable the timer to indicate that the application supplies the
timer events
- -->
- <internal-timer enabled="true"
msec-resolution="100"/>
- </threading>
- <event-meta>
- <!--
- Lets configure the engine to use case-insensitive resolution for event
properties
- -->
- <class-property-resolution
style="distinct_case_insensitive"/>
- </event-meta>
- <view-resources>
- <!--
- Lets configure the engine to reuse views, which is the default but can
introduce additional locking
- -->
- <share-views enabled="true"/>
- </view-resources>
- <logging>
- <!--
- By default the engine does not generate logging through Log4j of the event
processing execution path.
- To get debug output, set this flag to true. This setting translates into a
static boolean flag
- and thus may apply to multiple engine instances within a given VM.
- -->
- <execution-path enabled="false" />
- </logging>
- <stream-selection>
- <!--
- By default the engine generates output for the insert stream only, and not
for the remove stream.
- To obtain output for remove stream only, or for insert stream and remove
stream,
- there are keywords "rstream" and "irstream" for use in
the select clause.
- This setting controls the default behavior, if no keyword is specified in
the select-clause by statements.
- -->
- <stream-selector value="irstream" />
- </stream-selection>
- <time-source>
- <!--
- By default the time source is System.currentTimeMillis.
- This sample configures the nano-second time call System.nanoTime() as the
time source,
- which Esper adjusts for wall clock time.
- -->
- <time-source-type value="nano" />
- </time-source>
- </defaults>
- </engine-settings>
-
-</esper-configuration>
Added: sam/trunk/modules/sim/src/test/resources/simulation/test.drl
===================================================================
--- sam/trunk/modules/sim/src/test/resources/simulation/test.drl
(rev 0)
+++ sam/trunk/modules/sim/src/test/resources/simulation/test.drl 2008-07-23 14:28:48 UTC
(rev 197)
@@ -0,0 +1,12 @@
+package org.jboss.test.sam.drools;
+
+import org.jboss.test.sam.simulation.SensorEventMessage;
+
+global org.jboss.sam.internal.drools.DroolsAdapter Drools;
+
+rule "Pick all sensor event messages"
+when
+ $event: SensorEventMessage()
+then
+ Drools.getListener("EventSink_B").update($event);
+end