Package org.drools.rule

Examples of org.drools.rule.TimeMachine


        Scenario sc = new Scenario();
        MockWorkingMemory wm = new MockWorkingMemory();
        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 );

        ExecutionTrace ext = new ExecutionTrace();
        ext.scenarioSimulatedDate = new Date( "10-Jul-1974" );
        sc.fixtures.add( ext );
        run = new ScenarioRunner( sc,
                                  null,
                                  wm );
        tm = run.workingMemory.getTimeMachine();

        long expected = ext.scenarioSimulatedDate.getTime();
        assertEquals( expected,
                      tm.getNow().getTimeInMillis() );
        Thread.sleep( 50 );
        assertEquals( expected,
                      tm.getNow().getTimeInMillis() );

    }
View Full Code Here


  private void applyTimeMachine(final InternalWorkingMemory wm,
      ExecutionTrace executionTrace) {
    if (executionTrace.scenarioSimulatedDate != null) {
      final Calendar now = Calendar.getInstance();
      now.setTimeInMillis(executionTrace.scenarioSimulatedDate.getTime());
      wm.setTimeMachine(new TimeMachine() {
        @Override
        public Calendar getNow() {
          return now;
        }
      });
    } else {
      //normal time.
      wm.setTimeMachine(new TimeMachine());
    }
  }
View Full Code Here

TOP

Related Classes of org.drools.rule.TimeMachine

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.