List of usage examples for org.joda.time DateTimeUtils setCurrentMillisFixed
public static final void setCurrentMillisFixed(long fixedMillis) throws SecurityException
From source file:br.com.caelum.timemachine.TimeMachine.java
License:Apache License
/** * Runs the given {@link Block} in the date and time given when constructing * the TimeMachine. A {@link DateTime} created inside the given code will * have always the same value, equal to the DateTime given when constructing * the TimeMachine.//from www.j a va2 s . c o m * * @param code * The code to be run in a different date and time * @return The result of running the given code */ public <T> T andExecute(Block<T> code) { MillisProvider provider = getCurrentTimeMillisProvider(); DateTimeUtils.setCurrentMillisFixed(somewhereInTime.getMillis()); try { return code.run(); } finally { DateTimeUtils.setCurrentMillisProvider(provider); } }
From source file:com.codereligion.cherry.junit.joda.TimeMachine.java
License:Apache License
/** * Goes to and stays at the specified time in millis. * * @param millis the milliseconds since epoch to go to and stay */// ww w . j a v a2 s .c o m public void goToAndStayAt(final long millis) { DateTimeUtils.setCurrentMillisFixed(millis); }
From source file:com.codereligion.cherry.junit.joda.TimeMachine.java
License:Apache License
/** * Goes to and stays at the specified {@link org.joda.time.DateTime}. * * @param dateTime the object which specifies the date and time to go to and stay *///from w w w. j a v a 2s .c o m public void goToAndStayAt(final DateTime dateTime) { checkArgument(dateTime != null, "dateTime must not be null."); DateTimeUtils.setCurrentMillisFixed(dateTime.getMillis()); }
From source file:com.facebook.util.TimeUtil.java
License:Apache License
/** * these methods affect only code that relies on DateTimeUtils.currentTimeMillis() * * NOTE: manipulation of {@link DateTimeUtils.currentTimeMillis()} is not thread safe * to begin with, so neither is this//w w w.ja v a 2 s. c o m */ public static void setNow(DateTime now) { DateTimeUtils.setCurrentMillisFixed(now.getMillis()); }
From source file:com.facebook.util.TimeUtil.java
License:Apache License
public static void advanceNow(Duration duration) { long now = DateTimeUtils.currentTimeMillis(); DateTimeUtils.setCurrentMillisFixed(now + duration.getMillis()); }
From source file:com.google.cloud.dataflow.sdk.testing.ResetDateTimeProvider.java
License:Apache License
public void setDateTimeFixed(long millis) { DateTimeUtils.setCurrentMillisFixed(millis); }
From source file:com.google.cloud.pubsub.FakeScheduledExecutorService.java
License:Open Source License
public FakeScheduledExecutorService() { DateTimeUtils.setCurrentMillisFixed(currentTime.getMillis()); }
From source file:com.google.cloud.pubsub.FakeScheduledExecutorService.java
License:Open Source License
/** * This will advance the reference time of the executor and execute (in the same thread) any * outstanding callable which execution time has passed. */// www .j a v a 2 s. c om public void advanceTime(Duration toAdvance) { currentTime.add(toAdvance); DateTimeUtils.setCurrentMillisFixed(currentTime.getMillis()); synchronized (pendingCallables) { while (!pendingCallables.isEmpty() && pendingCallables.peek().getScheduledTime().compareTo(currentTime) <= 0) { try { pendingCallables.poll().call(); if (shutdown.get() && pendingCallables.isEmpty()) { pendingCallables.notifyAll(); } } catch (Exception e) { // We ignore any callable exception, which should be set to the future but not relevant to // advanceTime. } } } }
From source file:divconq.hub.Clock.java
License:Open Source License
/** * If the framework time is configured to use an accelerated clock, this method gets * that accelerated clock going.//ww w . j a va2s . c o m * * @param or logger for the start up */ public void start(OperationResult or) { // we check our app schedule ever 1 (or so) system seconds this.slowclock = this.slowscheduler.scheduleAtFixedRate(new Runnable() { @Override public void run() { OperationContext.useHubContext(); int cycle = Clock.this.slowsysworkcycle; Clock.this.slowreporter.setStatus("Slow Sys starting cycle: " + cycle); for (ISystemWork work : Clock.this.slowsyswork) { try { int period = work.period(); if (period > 300) period = 300; // max allowed if (cycle % period == 0) { Clock.this.slowreporter.setStatus("before sys work: " + work.getClass()); work.run(Clock.this.slowreporter); Clock.this.slowreporter.setStatus("after sys work: " + work.getClass()); } } catch (Exception x) { System.out.println("sys scheduler error: " + x); } } Clock.this.slowreporter.setStatus("Slow Sys finished cycle: " + cycle); cycle++; if (cycle > 300) cycle = 1; Clock.this.slowsysworkcycle = cycle; } }, 1, 1, TimeUnit.SECONDS); // we check our app schedule ever 1 (or so) system seconds this.fastclock = this.fastscheduler.scheduleAtFixedRate(new Runnable() { @Override public void run() { OperationContext.useHubContext(); int cycle = Clock.this.fastsysworkcycle; Clock.this.fastreporter.setStatus("Fast Sys starting cycle: " + cycle); for (ISystemWork work : Clock.this.fastsyswork) { try { int period = work.period(); if (period > 300) period = 300; // max allowed if (cycle % period == 0) { Clock.this.fastreporter.setStatus("before sys work: " + work.getClass()); work.run(Clock.this.fastreporter); Clock.this.fastreporter.setStatus("after sys work: " + work.getClass()); } } catch (Exception x) { System.out.println("sys scheduler error: " + x); } } Clock.this.fastreporter.setStatus("Fast Sys finished cycle: " + cycle); cycle++; if (cycle > 300) cycle = 1; Clock.this.fastsysworkcycle = cycle; } }, 1, 1, TimeUnit.SECONDS); if (this.speed != 0) this.addFastSystemWorker(new ISystemWork() { @Override public int period() { return 1; } @Override public void run(SysReporter reporter) { reporter.setStatus("Before set date time"); DateTimeUtils .setCurrentMillisFixed(DateTimeUtils.currentTimeMillis() + (Clock.this.speed * 1000)); reporter.setStatus("After set date time"); } }); }
From source file:divconq.hub.Clock.java
License:Open Source License
/** * set framework's time to use a fixed time * //from ww w . j a v a 2s. c o m * @param time fixed time to use */ public void setAppClock(ReadableInstant time) { DateTimeUtils.setCurrentMillisFixed(time.getMillis()); }