private void freezeTime(Long millis) { DateTimeUtils.setCurrentMillisFixed(millis); }
@BeforeMethod public void setUp() throws Exception { DateTimeUtils.setCurrentMillisFixed(new DateTime(2016,3,15,10,15).getMillis()); }
@Test public void updateExecutionsUpdateCallFails() throws Exception { mockUpdateCallFails(); when(this.executorLoader.fetchExecutor(anyInt())).thenReturn(this.activeExecutor); DateTimeUtils.setCurrentMillisFixed(System.currentTimeMillis()); for (int i = 0; i < this.updater.numErrorsBeforeUnresponsiveEmail; i++) { this.updater.updateExecutions(); DateTimeUtils.setCurrentMillisFixed( DateTimeUtils.currentTimeMillis() + this.updater.errorThreshold + 1L); } verify(this.mailAlerter).alertOnFailedUpdate( this.activeExecutor, Collections.singletonList(this.execution), API_CALL_EXCEPTION); verifyZeroInteractions(this.executionFinalizer); }
/** * Should finalize execution if executor doesn't exist in the DB. */ @Test public void updateExecutionsUpdateCallFailsExecutorDoesntExist() throws Exception { mockUpdateCallFails(); when(this.executorLoader.fetchExecutor(anyInt())).thenReturn(null); DateTimeUtils.setCurrentMillisFixed(System.currentTimeMillis()); this.updater.updateExecutions(); verify(this.executionFinalizer).finalizeFlow( this.execution, "Not running on the assigned executor (any more)", null); }
/** * Shouldn't finalize executions if executor's existence can't be checked. */ @Test public void updateExecutionsUpdateCallFailsExecutorCheckThrows() throws Exception { mockUpdateCallFails(); when(this.executorLoader.fetchExecutor(anyInt())) .thenThrow(new ExecutorManagerException("Mocked fetchExecutor failure")); DateTimeUtils.setCurrentMillisFixed(System.currentTimeMillis()); this.updater.updateExecutions(); verifyZeroInteractions(this.executionFinalizer); }
DateTimeUtils.setCurrentMillisFixed(new DateTime(2015, 7, 15, 10, 0).withZone(DateTimeZone.UTC).getMillis());
DateTimeUtils.setCurrentMillisFixed(new DateTime(2015, 7, 15, 10, 0).getMillis());
}}; DateTimeUtils.setCurrentMillisFixed(1000L);
@Test public void testISORetentionDuration() throws Exception { DateTimeUtils.setCurrentMillisFixed(new DateTime(2016, 2, 11, 10, 0, 0, 0).getMillis()); try { // 20 Days verify("P20D", ImmutableList.of(WithDate(new DateTime(2016, 1, 5, 10, 0, 0, 0)), WithDate(new DateTime(2016, 1, 6, 10, 0, 0, 0))), ImmutableList.of(WithDate(new DateTime(2016, 2, 10, 10, 0, 0, 0)), WithDate(new DateTime(2016, 2, 11, 10, 0, 0, 0)))); // 2 Months verify("P2M", ImmutableList.of(WithDate(new DateTime(2015, 12, 5, 10, 0, 0, 0)), WithDate(new DateTime(2015, 11, 5, 10, 0, 0, 0))), ImmutableList.of(WithDate(new DateTime(2016, 2, 10, 10, 0, 0, 0)), WithDate(new DateTime(2016, 1, 10, 10, 0, 0, 0)))); // 2 Years verify("P2Y", ImmutableList.of(WithDate(new DateTime(2014, 1, 5, 10, 0, 0, 0)), WithDate(new DateTime(2013, 1, 5, 10, 0, 0, 0))), ImmutableList.of(WithDate(new DateTime(2016, 2, 10, 10, 0, 0, 0)), WithDate(new DateTime(2015, 2, 10, 10, 0, 0, 0)))); // 20 Hours verify("PT20H", ImmutableList.of(WithDate(new DateTime(2016, 2, 10, 11, 0, 0, 0)), WithDate(new DateTime(2016, 2, 9, 11, 0, 0, 0))), ImmutableList.of(WithDate(new DateTime(2016, 2, 11, 8, 0, 0, 0)), WithDate(new DateTime(2016, 2, 11, 9, 0, 0, 0)))); } finally { // Restore time DateTimeUtils.setCurrentMillisSystem(); } }
@Before public void setUp() throws Exception { // Init zone info Context context = InstrumentationRegistry.getContext(); JodaTimeAndroid.init(context); // Force the system into 24-hour time for tests ContentResolver cr = context.getContentResolver(); mOldTime1224Setting = Settings.System.getString(cr, Settings.System.TIME_12_24); Settings.System.putString(cr, Settings.System.TIME_12_24, "24"); // Force all tests to be in the US locale; that way we can test output in consistent manner Application app = (Application) InstrumentationRegistry.getContext().getApplicationContext(); Resources res = app.getBaseContext().getResources(); Configuration config = res.getConfiguration(); Locale.setDefault(Locale.US); config.locale = Locale.US; res.updateConfiguration(config, res.getDisplayMetrics()); // Force the default timezone mDefaultJodaTz = DateTimeZone.forID("America/New_York"); mOldDefaultJodaTz = DateTimeZone.getDefault(); DateTimeZone.setDefault(mDefaultJodaTz); // ...And for the system as well mDefaultSystemTz = TimeZone.getTimeZone("America/Chicago"); mOldDefaultSystemTz = TimeZone.getDefault(); TimeZone.setDefault(mDefaultSystemTz); // Force current "now" time, so all tests can be consistent mNow = new DateTime(YEAR, MONTH_OF_YEAR, DAY_OF_MONTH, HOUR_OF_DAY, MINUTE_OF_HOUR, SECOND_OF_MINUTE, MILLIS_OF_SECOND, mDefaultJodaTz); DateTimeUtils.setCurrentMillisFixed(mNow.getMillis()); }
/** * This test manipulates global states (time) in org.joda.time.DateTimeUtils . Thus this test can * run in parallel with tests that do the same. */ @Test public void periodTimerTest() { // get a new timechecker, start from now, repeat every minute. should // evaluate to false now, and true a minute later. final long baseTimeInMilliSeconds = 1000; final ReadablePeriod period = Utils.parsePeriodString("10s"); DateTimeUtils.setCurrentMillisFixed(baseTimeInMilliSeconds); final BasicTimeChecker timeChecker = new BasicTimeChecker("BasicTimeChecket_1", baseTimeInMilliSeconds, DateTimeZone.UTC, true, true, period, null); final Condition cond = getCondition(timeChecker); assertFalse(cond.isMet()); DateTimeUtils.setCurrentMillisFixed(baseTimeInMilliSeconds + 11 * 1000); assertTrue(cond.isMet()); cond.resetCheckers(); assertFalse(cond.isMet()); DateTimeUtils.setCurrentMillisFixed(baseTimeInMilliSeconds + 22 * 1000); assertTrue(cond.isMet()); DateTimeUtils.setCurrentMillisSystem(); }
/** * 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 */ public static void setNow(DateTime now) { DateTimeUtils.setCurrentMillisFixed(now.getMillis()); }
@Before public void setUp() throws Exception { this.defaultTz = TimeZone.getDefault(); assertNotNull(this.defaultTz); // EEST TimeZone.setDefault(TimeZone.getTimeZone("Europe/Helsinki")); DateTimeUtils.setCurrentMillisFixed(FIXED_CURRENT_TIME_MILLIS); this.mailCreator = new DefaultMailCreator(); this.executor = new Executor(1, "executor1-host", 1234, true); this.flow = new Flow("mail-creator-test"); this.project = new Project(1, "test-project"); this.options = new ExecutionOptions(); this.message = new EmailMessage("localhost", EmailMessageCreator.DEFAULT_SMTP_PORT, "", "", null); this.azkabanName = "unit-tests"; this.scheme = "http"; this.clientHostname = "localhost"; this.clientPortNumber = "8081"; final Node failedNode = new Node("test-job"); failedNode.setType("noop"); this.flow.addNode(failedNode); this.executableFlow = new ExecutableFlow(this.project, this.flow); this.executableFlow.setExecutionOptions(this.options); this.executableFlow.setStartTime(START_TIME_MILLIS); this.options.setFailureEmails(ImmutableList.of("test@example.com")); this.options.setSuccessEmails(ImmutableList.of("test@example.com")); }
public static void advanceNow(Duration duration) { long now = DateTimeUtils.currentTimeMillis(); DateTimeUtils.setCurrentMillisFixed(now + duration.getMillis()); } }
@BeforeMethod(alwaysRun = true) public void setUp() throws Exception { now = new DateTime("2010-01-01T00:00:00"); DateTimeUtils.setCurrentMillisFixed(now.getMillis()); }
private void advanceNowSeconds(int seconds) { DateTimeUtils.setCurrentMillisFixed( DateTimeUtils.currentTimeMillis() + seconds * 1000 ); } }
private void setNow(ReadableDateTime value) { DateTimeUtils.setCurrentMillisFixed(value.getMillis()); now = new DateTime(value); } }
private void advanceNowSeconds(int seconds) { DateTime updatedNow = new DateTime(now.plusSeconds(seconds)); DateTimeUtils.setCurrentMillisFixed(updatedNow.getMillis()); now = updatedNow; } }
@BeforeMethod(alwaysRun = true) public void setUp() throws Exception { DateTimeUtils.setCurrentMillisFixed(new DateTime("2010-01-01").getMillis()); eventCounter = new CompositeSum(Duration.standardSeconds(60)); rate = new EventRateImpl(eventCounter, Duration.standardSeconds(60)); }
@Test(groups = "fast") public void testEvictionListener() throws Exception { // add a value to the cache Assert.assertEquals(cache.get(KEY), value1); Assert.assertEquals(producer.getCalledCount(), 1); DateTimeUtils.setCurrentMillisFixed(30); cache.prune(); // key is removed from the cache Assert.assertEquals(cache.size(), 0); // and this will execute the eviction callback mockExecutor.drain(); Assert.assertEquals(evicted.size(), 1); }