Examples of TimeMachine


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

Examples of org.drools.rule.TimeMachine

  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

Examples of org.sonar.api.batch.TimeMachine

  @Test
  public void includeCurrentMeasures() throws ParseException {
    TendencyAnalyser analyser = mock(TendencyAnalyser.class);
    TimeMachineQuery query = new TimeMachineQuery(null).setMetrics(CoreMetrics.LINES, CoreMetrics.COVERAGE);
    TimeMachine timeMachine = mock(TimeMachine.class);

    when(timeMachine.getMeasuresFields(query)).thenReturn(Arrays.<Object[]>asList(
      new Object[] {date("2009-12-01"), CoreMetrics.LINES, 1200.0},
      new Object[] {date("2009-12-01"), CoreMetrics.COVERAGE, 80.5},
      new Object[] {date("2009-12-02"), CoreMetrics.LINES, 1300.0},
      new Object[] {date("2009-12-02"), CoreMetrics.COVERAGE, 79.6},
      new Object[] {date("2009-12-15"), CoreMetrics.LINES, 1150.0}
View Full Code Here

Examples of org.sonar.api.batch.TimeMachine

  @Test
  public void noTendencyIfNoCurrentMeasures() throws ParseException {
    TendencyAnalyser analyser = mock(TendencyAnalyser.class);
    TimeMachineQuery query = new TimeMachineQuery(null).setMetrics(CoreMetrics.LINES, CoreMetrics.COVERAGE);
    TimeMachine timeMachine = mock(TimeMachine.class);

    when(timeMachine.getMeasuresFields(query)).thenReturn(Arrays.<Object[]>asList(
      new Object[] {date("2009-12-01"), CoreMetrics.LINES, 1200.0},
      new Object[] {date("2009-12-02"), CoreMetrics.LINES, 1300.0}
    ));

    DecoratorContext context = mock(DecoratorContext.class);
View Full Code Here

Examples of org.sonar.wsclient.services.TimeMachine

    }
    Object cells = utils.getField(json, "cells");
    if (cells == null) {
      throw new IllegalArgumentException("cells must be set");
    }
    return new TimeMachine(toColumns(cols), toCells(cells));
  }
View Full Code Here

Examples of org.sonar.wsclient.services.TimeMachine

public class TimeMachineUnmarshallerTest extends UnmarshallerTestCase {

  @Test
  public void test_to_model() throws Exception {
    TimeMachine timeMachine = new TimeMachineUnmarshaller().toModel(loadFile("/timemachine/timemachine.json"));

    // columns
    assertThat(timeMachine.getColumns().length).isEqualTo(2);
    assertThat(timeMachine.getColumns()[0].getIndex()).isEqualTo(0);
    assertThat(timeMachine.getColumns()[0].getMetricKey()).isEqualTo("ncloc");
    assertThat(timeMachine.getColumns()[1].getIndex()).isEqualTo(1);
    assertThat(timeMachine.getColumns()[1].getMetricKey()).isEqualTo("coverage");

    // values sorted by date
    assertThat(timeMachine.getCells().length).isEqualTo(3); // 3 days
    assertThat(getDayOfMonth(timeMachine.getCells()[0].getDate())).isEqualTo(19);
    assertThat(getDayOfMonth(timeMachine.getCells()[1].getDate())).isEqualTo(21);
    assertThat(getDayOfMonth(timeMachine.getCells()[2].getDate())).isEqualTo(25);

    assertThat(timeMachine.getCells()[0].getValues()).hasSize(2);
    assertThat((Double) timeMachine.getCells()[0].getValues()[0]).isEqualTo(21.0);
    assertThat((Double) timeMachine.getCells()[0].getValues()[1]).isEqualTo(80.0);
  }
View Full Code Here

Examples of org.sonar.wsclient.services.TimeMachine

    assertThat((Double) timeMachine.getCells()[0].getValues()[1]).isEqualTo(80.0);
  }

  @Test
  public void should_accept_null_values() throws Exception {
    TimeMachine timeMachine = new TimeMachineUnmarshaller().toModel(loadFile("/timemachine/null-values.json"));

    assertThat(timeMachine.getCells()[0].getValues().length).isEqualTo(2);
    assertThat(timeMachine.getCells()[0].getValues()[0]).isNull();
    assertThat((Double) timeMachine.getCells()[0].getValues()[1]).isEqualTo(80.0);

    assertThat((Double) timeMachine.getCells()[1].getValues()[0]).isEqualTo(29.0);
    assertThat(timeMachine.getCells()[1].getValues()[1]).isNull();
  }
View Full Code Here

Examples of org.sonar.wsclient.services.TimeMachine

    assertThat(timeMachine.getCells()[1].getValues()[1]).isNull();
  }

  @Test
  public void should_cast_values() throws Exception {
    TimeMachine timeMachine = new TimeMachineUnmarshaller().toModel(loadFile("/timemachine/typed-values.json"));

    assertThat(timeMachine.getCells()[0].getValues().length).isEqualTo(2);
    assertThat((String) timeMachine.getCells()[0].getValues()[0]).isEqualTo("Sonar way");
    assertThat((Double) timeMachine.getCells()[0].getValues()[1]).isEqualTo(80.0);
  }
View Full Code Here

Examples of time.TimeMachine

        }
    }

    private void createTime() {
        if (tm == null) {
            tm = new TimeMachine();
        }
        thisThread.start();
        tm.startTime();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.