[jboss-svn-commits] JBL Code SVN: r36097 - in labs/jbossrules/trunk: drools-core/src/main/java/org/drools/common and 6 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sun Nov 28 20:46:47 EST 2010


Author: mark.proctor at jboss.com
Date: 2010-11-28 20:46:45 -0500 (Sun, 28 Nov 2010)
New Revision: 36097

Removed:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/TimeMachine.java
Modified:
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/testframework/MockWorkingMemory.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/SharedWorkingMemoryContext.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Rule.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/time/impl/PseudoClockScheduler.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/rule/RuleTest.java
   labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/testframework/ScenarioRunner.java
   labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/testframework/MockWorkingMemory.java
   labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/testframework/ScenarioRunnerTest.java
Log:
JBRULES-2808 Remove TimeMachine so we have a unified clock structure

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/testframework/MockWorkingMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/testframework/MockWorkingMemory.java	2010-11-28 16:41:17 UTC (rev 36096)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/testframework/MockWorkingMemory.java	2010-11-29 01:46:45 UTC (rev 36097)
@@ -40,7 +40,6 @@
 import org.drools.reteoo.PartitionTaskManager;
 import org.drools.rule.EntryPoint;
 import org.drools.rule.Rule;
-import org.drools.rule.TimeMachine;
 import org.drools.runtime.Calendars;
 import org.drools.runtime.Channel;
 import org.drools.runtime.Environment;
@@ -64,20 +63,17 @@
                 
 	List<Object> facts = new ArrayList<Object>();
 	AgendaEventListener agendaEventListener;
-	TimeMachine timeMachine = new TimeMachine();
 	Map<String, Object> globals = new HashMap<String, Object>();
 
     public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
         facts   = (List<Object>)in.readObject();
         agendaEventListener   = (AgendaEventListener)in.readObject();
-        timeMachine   = (TimeMachine)in.readObject();
         globals   = (Map<String, Object>)in.readObject();
     }
 
     public void writeExternal(ObjectOutput out) throws IOException {
         out.writeObject(facts);
         out.writeObject(agendaEventListener);
-        out.writeObject(timeMachine);
         out.writeObject(globals);
     }
     
@@ -98,11 +94,6 @@
 		this.agendaEventListener = listener;
 	}
 
-	public void setTimeMachine(TimeMachine tm) {
-		this.timeMachine = tm;
-
-	}
-
     public void addLIANodePropagation(LIANodePropagation liaNodePropagation) {
         // TODO Auto-generated method stub
         
@@ -172,11 +163,7 @@
         // TODO Auto-generated method stub
         return null;
     }
-
-    public TimeMachine getTimeMachine() {
-		return this.timeMachine;
-    }
-
+    
     public TimerService getTimerService() {
         // TODO Auto-generated method stub
         return null;

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java	2010-11-28 16:41:17 UTC (rev 36096)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java	2010-11-29 01:46:45 UTC (rev 36097)
@@ -79,7 +79,6 @@
 import org.drools.rule.Declaration;
 import org.drools.rule.EntryPoint;
 import org.drools.rule.Rule;
-import org.drools.rule.TimeMachine;
 import org.drools.runtime.Calendars;
 import org.drools.runtime.Channel;
 import org.drools.runtime.Environment;
@@ -172,8 +171,6 @@
 
     private WorkItemManager                                      workItemManager;
 
-    private TimeMachine                                          timeMachine;
-
     private TimerService                                         timerService;
 
     protected Map<String, WorkingMemoryEntryPoint>               entryPoints;
@@ -326,7 +323,6 @@
         this.__ruleBaseEventListeners = new LinkedList();
         this.lock = new ReentrantLock();
         this.liaPropagations = Collections.EMPTY_LIST;
-        this.timeMachine = new TimeMachine();
 
         timerService = TimerServiceFactory.getTimerService( this.config );
 
@@ -1186,23 +1182,6 @@
         return result;
     }
 
-    /**
-     * The time machine tells you what time it is.
-     */
-    public TimeMachine getTimeMachine() {
-        return timeMachine;
-    }
-
-    /**
-     * The time machine defaults to returning the current time when asked.
-     * However, you can use tell it to go back in time.
-     * 
-     * @param timeMachine
-     */
-    public void setTimeMachine(TimeMachine timeMachine) {
-        this.timeMachine = timeMachine;
-    }
-
     public WorkingMemoryEntryPoint getWorkingMemoryEntryPoint(String name) {
         WorkingMemoryEntryPoint wmEntryPoint = this.entryPoints.get( name );
         return wmEntryPoint;

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java	2010-11-28 16:41:17 UTC (rev 36096)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java	2010-11-29 01:46:45 UTC (rev 36097)
@@ -31,7 +31,6 @@
 import org.drools.reteoo.PartitionTaskManager;
 import org.drools.rule.EntryPoint;
 import org.drools.rule.Rule;
-import org.drools.rule.TimeMachine;
 import org.drools.runtime.Calendars;
 import org.drools.runtime.Channel;
 import org.drools.runtime.ExitPoint;
@@ -105,10 +104,6 @@
     public boolean isSequential();
 
     public void addLIANodePropagation(LIANodePropagation liaNodePropagation);
-
-	public TimeMachine getTimeMachine();
-
-	public void setTimeMachine(TimeMachine tm);    
     
     public ObjectTypeConfigurationRegistry getObjectTypeConfigurationRegistry();
     

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/SharedWorkingMemoryContext.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/SharedWorkingMemoryContext.java	2010-11-28 16:41:17 UTC (rev 36096)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/SharedWorkingMemoryContext.java	2010-11-29 01:46:45 UTC (rev 36097)
@@ -23,7 +23,6 @@
 import org.drools.event.AgendaEventSupport;
 import org.drools.event.WorkingMemoryEventSupport;
 import org.drools.process.instance.WorkItemManager;
-import org.drools.rule.TimeMachine;
 import org.drools.spi.FactHandleFactory;
 import org.drools.spi.GlobalResolver;
 
@@ -46,8 +45,6 @@
 
     private WorkItemManager                     workItemManager;
 
-    private TimeMachine                         timeMachine;
-
     public SharedWorkingMemoryContext(FactHandleFactory handleFactory) {
         this.handleFactory = handleFactory;
 
@@ -56,8 +53,6 @@
         this.workingMemoryEventSupport = new WorkingMemoryEventSupport();
         this.agendaEventSupport = new AgendaEventSupport();
         this.__ruleBaseEventListeners = new LinkedList();
-
-        timeMachine = new TimeMachine();
     }
 
     public WorkItemManager getWorkItemManager() {
@@ -68,14 +63,6 @@
         this.workItemManager = workItemManager;
     }
 
-    public TimeMachine getTimeMachine() {
-        return timeMachine;
-    }
-
-    public void setTimeMachine(TimeMachine timeMachine) {
-        this.timeMachine = timeMachine;
-    }
-
     public FactHandleFactory getHandleFactory() {
         return handleFactory;
     }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java	2010-11-28 16:41:17 UTC (rev 36096)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java	2010-11-29 01:46:45 UTC (rev 36097)
@@ -160,8 +160,7 @@
                                 final PropagationContext context,
                                 final InternalWorkingMemory workingMemory) {
         //check if the rule is effective
-        if ( !this.rule.isEffective( workingMemory.getTimeMachine(),
-                                     tuple,
+        if ( !this.rule.isEffective( tuple,
                                      workingMemory ) ) {
             return;
         }
@@ -291,8 +290,7 @@
                                 PropagationContext context,
                                 InternalWorkingMemory workingMemory) {
         //check if the rule is effective
-        if ( !this.rule.isEffective( workingMemory.getTimeMachine(),
-                                     leftTuple,
+        if ( !this.rule.isEffective( leftTuple,
                                      workingMemory ) ) {
             return;
         }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Rule.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Rule.java	2010-11-28 16:41:17 UTC (rev 36096)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Rule.java	2010-11-29 01:46:45 UTC (rev 36097)
@@ -23,6 +23,7 @@
 import java.util.Calendar;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -367,8 +368,7 @@
      *
      * This uses the dateEffective, dateExpires and enabled flag to decide this.
      */
-    public boolean isEffective(TimeMachine tm,
-                               Tuple tuple,
+    public boolean isEffective(Tuple tuple,
                                WorkingMemory workingMemory) {
         if ( !this.enabled.getValue( tuple,
                                      this,
@@ -377,8 +377,9 @@
         }
         if ( this.dateEffective == null && this.dateExpires == null ) {
             return true;
-        } else {
-            final Calendar now = tm.getNow();
+        } else {            
+            Calendar now = Calendar.getInstance();
+            now.setTimeInMillis( workingMemory.getSessionClock().getCurrentTime() );
 
             if ( this.dateEffective != null && this.dateExpires != null ) {
                 return (now.after( this.dateEffective ) && now.before( this.dateExpires ));

Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/TimeMachine.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/TimeMachine.java	2010-11-28 16:41:17 UTC (rev 36096)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/TimeMachine.java	2010-11-29 01:46:45 UTC (rev 36097)
@@ -1,45 +0,0 @@
-/**
- * Copyright 2010 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.drools.rule;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Calendar;
-
-/**
- * This class allows the time for "now" to be defined outside of the Rule.
- * Mainly for external testing tools (testing of rules, not drools).
- *
- * @author Michael Neale
- */
-public class TimeMachine implements Externalizable {
-
-    private static final long serialVersionUID = 510l;
-
-    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-    }
-
-    public void writeExternal(ObjectOutput out) throws IOException {
-    }
-
-	public Calendar getNow() {
-		return Calendar.getInstance();
-	}
-
-}

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/time/impl/PseudoClockScheduler.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/time/impl/PseudoClockScheduler.java	2010-11-28 16:41:17 UTC (rev 36096)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/time/impl/PseudoClockScheduler.java	2010-11-29 01:46:45 UTC (rev 36097)
@@ -131,7 +131,7 @@
         return this.timer;
     }
 
-    public synchronized void setStartupTime(int i) {
+    public synchronized void setStartupTime(long i) {
         this.timer = i;
     }
 

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/rule/RuleTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/rule/RuleTest.java	2010-11-28 16:41:17 UTC (rev 36096)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/rule/RuleTest.java	2010-11-29 01:46:45 UTC (rev 36097)
@@ -17,10 +17,16 @@
 package org.drools.rule;
 
 import java.util.Calendar;
+import java.util.concurrent.TimeUnit;
 
 import junit.framework.TestCase;
 
+import org.drools.ClockType;
+import org.drools.SessionConfiguration;
+import org.drools.WorkingMemory;
 import org.drools.base.EnabledBoolean;
+import org.drools.reteoo.ReteooRuleBase;
+import org.drools.time.impl.PseudoClockScheduler;
 
 /**
  * @author Michael Neale
@@ -28,16 +34,18 @@
 public class RuleTest extends TestCase {
 
     public void testDateEffective() {
+        WorkingMemory wm = new ReteooRuleBase("x").newStatefulSession();
+
         final Rule rule = new Rule( "myrule" );
 
-        assertTrue( rule.isEffective(new TimeMachine(), null, null ) );
+        assertTrue( rule.isEffective(null, wm ) );
 
         final Calendar earlier = Calendar.getInstance();
         earlier.setTimeInMillis( 10 );
 
         rule.setDateEffective( earlier );
 
-        assertTrue( rule.isEffective(new TimeMachine(), null, null ) );
+        assertTrue( rule.isEffective(null, wm ) );
 
         final Calendar later = Calendar.getInstance();
         later.setTimeInMillis( later.getTimeInMillis() + 100000000 );
@@ -45,31 +53,35 @@
         assertTrue( later.after( Calendar.getInstance() ) );
 
         rule.setDateEffective( later );
-        assertFalse( rule.isEffective(new TimeMachine(), null, null ) );
+        assertFalse( rule.isEffective(null, wm ) );
 
     }
 
     public void testDateExpires() throws Exception {
+        WorkingMemory wm = new ReteooRuleBase("x").newStatefulSession();
+        
         final Rule rule = new Rule( "myrule" );
 
-        assertTrue( rule.isEffective(new TimeMachine(), null, null ) );
+        assertTrue( rule.isEffective(null, wm ) );
 
         final Calendar earlier = Calendar.getInstance();
         earlier.setTimeInMillis( 10 );
 
         rule.setDateExpires( earlier );
 
-        assertFalse( rule.isEffective(new TimeMachine(), null, null ) );
+        assertFalse( rule.isEffective(null, wm ) );
 
         final Calendar later = Calendar.getInstance();
         later.setTimeInMillis( later.getTimeInMillis() + 100000000 );
 
         rule.setDateExpires( later );
-        assertTrue( rule.isEffective(new TimeMachine(), null, null ) );
+        assertTrue( rule.isEffective(null, wm ) );
 
     }
 
     public void testDateEffectiveExpires() {
+        WorkingMemory wm = new ReteooRuleBase("x").newStatefulSession();
+        
         final Rule rule = new Rule( "myrule" );
 
         final Calendar past = Calendar.getInstance();
@@ -81,52 +93,57 @@
         rule.setDateEffective( past );
         rule.setDateExpires( future );
 
-        assertTrue( rule.isEffective(new TimeMachine(), null, null ) );
+        assertTrue( rule.isEffective(null, wm ) );
 
         rule.setDateExpires( past );
-        assertFalse( rule.isEffective(new TimeMachine(), null, null ) );
+        assertFalse( rule.isEffective(null, wm ) );
 
         rule.setDateExpires( future );
         rule.setDateEffective( future );
 
 
 
-        assertFalse( rule.isEffective(new TimeMachine(), null, null ) );
+        assertFalse( rule.isEffective(null, wm ) );
 
     }
 
     public void testRuleEnabled() {
+        WorkingMemory wm = new ReteooRuleBase("x").newStatefulSession();
+        
         final Rule rule = new Rule( "myrule" );
         rule.setEnabled( EnabledBoolean.ENABLED_FALSE );
-        assertFalse( rule.isEffective(new TimeMachine(), null, null ) );
+        assertFalse( rule.isEffective( null, wm ) );
 
         final Calendar past = Calendar.getInstance();
         past.setTimeInMillis( 10 );
 
         rule.setDateEffective( past );
-        assertFalse( rule.isEffective(new TimeMachine(), null, null ) );
+        assertFalse( rule.isEffective( null, wm ) );
         rule.setEnabled( EnabledBoolean.ENABLED_TRUE );
 
-        assertTrue( rule.isEffective(new TimeMachine(), null, null ) );
+        assertTrue( rule.isEffective( null, wm ) );
     }
 
     public void testTimeMachine() {
+        SessionConfiguration conf = new SessionConfiguration();
+        conf.setClockType( ClockType.PSEUDO_CLOCK );
+        WorkingMemory wm = new ReteooRuleBase("x").newStatefulSession(conf, null);
+        
+        final Calendar future = Calendar.getInstance();
+        ((PseudoClockScheduler)wm.getSessionClock()).setStartupTime( future.getTimeInMillis() );        
+        
         final Rule rule = new Rule( "myrule" );
         rule.setEnabled( EnabledBoolean.ENABLED_TRUE );
-        assertTrue( rule.isEffective(new TimeMachine(), null, null ) );
+        assertTrue( rule.isEffective(null, wm ) );
 
-        final Calendar future = Calendar.getInstance();
+        
         future.setTimeInMillis( future.getTimeInMillis() + 100000000 );
         rule.setDateEffective(future);
-        assertFalse( rule.isEffective(new TimeMachine(), null, null ) );
+        assertFalse( rule.isEffective(null, wm ) );
 
-        assertTrue(rule.isEffective(new TimeMachine() {
-        	public Calendar getNow() {
-        		Calendar loveYouLongTime = Calendar.getInstance();
-        		loveYouLongTime.setTimeInMillis(future.getTimeInMillis() + 1000000000000L);
-        		return loveYouLongTime;
-        	}
-        }, null, null ));
+        ((PseudoClockScheduler)wm.getSessionClock()).advanceTime( 1000000000000L, TimeUnit.MILLISECONDS );
+        
+        assertTrue(rule.isEffective(null, wm ));
     }
 
 }

Modified: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/testframework/ScenarioRunner.java
===================================================================
--- labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/testframework/ScenarioRunner.java	2010-11-28 16:41:17 UTC (rev 36096)
+++ labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/testframework/ScenarioRunner.java	2010-11-29 01:46:45 UTC (rev 36097)
@@ -26,6 +26,7 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.TimeUnit;
 
 import org.drools.FactHandle;
 import org.drools.RuleBase;
@@ -48,7 +49,7 @@
 import org.drools.ide.common.client.modeldriven.testing.VerifyRuleFired;
 import org.drools.ide.common.server.util.ScenarioXMLPersistence;
 import org.drools.rule.Package;
-import org.drools.rule.TimeMachine;
+import org.drools.time.impl.PseudoClockScheduler;
 import org.mvel2.MVEL;
 
 /**
@@ -254,19 +255,15 @@
 
     private void applyTimeMachine(final InternalWorkingMemory wm,
                                   ExecutionTrace executionTrace) {
+        long targetTime = 0;
         if ( executionTrace.getScenarioSimulatedDate() != null ) {
-            final Calendar now = Calendar.getInstance();
-            now.setTimeInMillis( executionTrace.getScenarioSimulatedDate().getTime() );
-            wm.setTimeMachine( new TimeMachine() {
-                @Override
-                public Calendar getNow() {
-                    return now;
-                }
-            } );
+            targetTime = executionTrace.getScenarioSimulatedDate().getTime();            
         } else {
-            //normal time.
-            wm.setTimeMachine( new TimeMachine() );
+            targetTime = new Date().getTime();
         }
+        
+        long currentTime = wm.getSessionClock().getCurrentTime();        
+        ((PseudoClockScheduler)wm.getSessionClock()).advanceTime( targetTime - currentTime, TimeUnit.MILLISECONDS );        
     }
 
     void verify(VerifyRuleFired assertion,

Modified: labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/testframework/MockWorkingMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/testframework/MockWorkingMemory.java	2010-11-28 16:41:17 UTC (rev 36096)
+++ labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/testframework/MockWorkingMemory.java	2010-11-29 01:46:45 UTC (rev 36097)
@@ -59,7 +59,6 @@
 import org.drools.reteoo.PartitionTaskManager;
 import org.drools.rule.EntryPoint;
 import org.drools.rule.Rule;
-import org.drools.rule.TimeMachine;
 import org.drools.runtime.Calendars;
 import org.drools.runtime.Channel;
 import org.drools.runtime.Environment;
@@ -76,26 +75,25 @@
 import org.drools.spi.PropagationContext;
 import org.drools.time.SessionClock;
 import org.drools.time.TimerService;
+import org.drools.time.impl.JDKTimerService;
 import org.drools.type.DateFormats;
 
 public class MockWorkingMemory implements InternalWorkingMemory {
                 
 	List<Object> facts = new ArrayList<Object>();
 	AgendaEventListener agendaEventListener;
-	TimeMachine timeMachine = new TimeMachine();
 	Map<String, Object> globals = new HashMap<String, Object>();
+	private SessionClock clock = new JDKTimerService();
 
     public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
         facts   = (List<Object>)in.readObject();
         agendaEventListener   = (AgendaEventListener)in.readObject();
-        timeMachine   = (TimeMachine)in.readObject();
         globals   = (Map<String, Object>)in.readObject();
     }
 
     public void writeExternal(ObjectOutput out) throws IOException {
         out.writeObject(facts);
-        out.writeObject(agendaEventListener);
-        out.writeObject(timeMachine);
+        out.writeObject(agendaEventListener);        
         out.writeObject(globals);
     }
     
@@ -116,11 +114,6 @@
 		this.agendaEventListener = listener;
 	}
 
-	public void setTimeMachine(TimeMachine tm) {
-		this.timeMachine = tm;
-
-	}
-
     public void addLIANodePropagation(LIANodePropagation liaNodePropagation) {
         // TODO Auto-generated method stub
         
@@ -196,10 +189,6 @@
         return null;
     }
 
-    public TimeMachine getTimeMachine() {
-		return this.timeMachine;
-    }
-
     public TimerService getTimerService() {
         // TODO Auto-generated method stub
         return null;
@@ -220,13 +209,6 @@
         
     }
 
-    public void removeLogicalDependencies(Activation activation,
-                                          PropagationContext context,
-                                          Rule rule) throws FactException {
-        // TODO Auto-generated method stub
-        
-    }
-
     public void removeProcessInstance(ProcessInstance processInstance) {
         // TODO Auto-generated method stub
         
@@ -359,10 +341,13 @@
     }
 
     public SessionClock getSessionClock() {
-        // TODO Auto-generated method stub
-        return null;
+        return this.clock;
     }
 
+    public void setSessionClock(SessionClock clock) {
+        this.clock = clock;
+    }
+    
     public SignalManager getSignalManager() {
         // TODO Auto-generated method stub
         return null;

Modified: labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/testframework/ScenarioRunnerTest.java
===================================================================
--- labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/testframework/ScenarioRunnerTest.java	2010-11-28 16:41:17 UTC (rev 36096)
+++ labs/jbossrules/trunk/drools-ide-common/src/test/java/org/drools/testframework/ScenarioRunnerTest.java	2010-11-29 01:46:45 UTC (rev 36097)
@@ -50,7 +50,7 @@
 import org.drools.ide.common.client.modeldriven.testing.VerifyField;
 import org.drools.ide.common.client.modeldriven.testing.VerifyRuleFired;
 import org.drools.ide.common.server.util.ScenarioXMLPersistence;
-import org.drools.rule.TimeMachine;
+import org.drools.time.impl.PseudoClockScheduler;
 
 public class ScenarioRunnerTest extends RuleUnit {
 
@@ -862,32 +862,30 @@
     public void testSimulatedDate() throws Exception {
         Scenario sc = new Scenario();
         MockWorkingMemory wm = new MockWorkingMemory();
+        PseudoClockScheduler clock = new PseudoClockScheduler();
+        long time = new Date().getTime();
+        clock.setStartupTime( time );
+        clock.setSession( wm );
+        wm.setSessionClock( clock );        
         ScenarioRunner run = new ScenarioRunner( sc,
                                                  null,
                                                  wm );
-        TimeMachine tm = run.workingMemory.getTimeMachine();
 
-        // love you
-        long time = tm.getNow().getTimeInMillis();
-
-        Thread.sleep( 100 );
-        long future = tm.getNow().getTimeInMillis();
-        assertTrue( future > time );
-
+        assertEquals( time, wm.getSessionClock().getCurrentTime() );
+        
         ExecutionTrace ext = new ExecutionTrace();
         ext.setScenarioSimulatedDate( new Date( "10-Jul-1974" ) );
         sc.fixtures.add( ext );
         run = new ScenarioRunner( sc,
                                   null,
                                   wm );
-        tm = run.workingMemory.getTimeMachine();
 
         long expected = ext.getScenarioSimulatedDate().getTime();
         assertEquals( expected,
-                      tm.getNow().getTimeInMillis() );
-        Thread.sleep( 50 );
-        assertEquals( expected,
-                      tm.getNow().getTimeInMillis() );
+                      wm.getSessionClock().getCurrentTime() );
+//        Thread.sleep( 50 );
+//        assertEquals( expected,
+//                      tm.getNow().getTimeInMillis() );
 
     }
 



More information about the jboss-svn-commits mailing list