Java Code Examples for org.joda.time.DateTimeUtils#setCurrentMillisFixed()

The following examples show how to use org.joda.time.DateTimeUtils#setCurrentMillisFixed() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WithUserPaginatedDAOTest.java    From mamute with Apache License 2.0 6 votes vote down vote up
@Test
public void should_return_only_questions_with_the_provided_user_ordered_by_date() {
	DateTimeUtils.setCurrentMillisFixed(new DateTime().minusMonths(2).getMillis());
	Question javaEEQuestion = javaEEQuestion();
	DateTimeUtils.setCurrentMillisSystem();
	
	DateTimeUtils.setCurrentMillisFixed(new DateTime().minusMonths(1).getMillis());
	Question androidQuestion = androidQuestion();
	DateTimeUtils.setCurrentMillisSystem();

	Question javaQuestion = javaQuestion();
	
	List<Question> perguntasDoAuthor = questionsWithUser.by(author, ByDate, 1);
	
	assertTrue(perguntasDoAuthor.contains(javaQuestion));
	assertTrue(perguntasDoAuthor.contains(javaEEQuestion));
	assertTrue(perguntasDoAuthor.contains(androidQuestion));
	assertEquals(javaQuestion, perguntasDoAuthor.get(0));
	assertEquals(androidQuestion, perguntasDoAuthor.get(1));
	assertEquals(javaEEQuestion, perguntasDoAuthor.get(2));
}
 
Example 2
Source File: RepairRunResourceTest.java    From cassandra-reaper with Apache License 2.0 5 votes vote down vote up
@Test
public void testTriggerNewRunAlreadyRunningRun() throws InterruptedException, ReaperException {
  DateTimeUtils.setCurrentMillisFixed(TIME_CREATE);
  RepairRunResource resource = new RepairRunResource(context);
  Response response = addDefaultRepairRun(resource);
  assertTrue(response.getEntity().toString(), response.getEntity() instanceof RepairRunStatus);
  RepairRunStatus repairRunStatus = (RepairRunStatus) response.getEntity();
  UUID runId = repairRunStatus.getId();

  DateTimeUtils.setCurrentMillisFixed(TIME_START);
  Optional<String> newState = Optional.of(RepairRun.RunState.RUNNING.toString());
  resource.modifyRunState(uriInfo, runId, newState);
  Thread.sleep(1000);
  response = resource.modifyRunState(uriInfo, runId, newState);
  assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());

  // Adding a second run that we'll try to set to RUNNING status
  RepairRunResource newResource = new RepairRunResource(context);
  Response newResponse = addDefaultRepairRun(newResource);
  RepairRunStatus newRepairRunStatus = (RepairRunStatus) newResponse.getEntity();
  UUID newRunId = newRepairRunStatus.getId();

  DateTimeUtils.setCurrentMillisFixed(TIME_START);
  Optional<String> newRunState = Optional.of(RepairRun.RunState.RUNNING.toString());
  response = resource.modifyRunState(uriInfo, newRunId, newRunState);
  // We expect it to fail as we cannot have 2 running runs for the same repair unit at once
  assertEquals(Response.Status.CONFLICT.getStatusCode(), response.getStatus());

}
 
Example 3
Source File: S3FileStoreTest.java    From Cheddar with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldGetURL() throws IOException {
    // Given
    final S3FileStore s3FileStore = new S3FileStore(bucketSchema);
    s3FileStore.initialize(mockAmazonS3Client);
    final int randomMillis = Randoms.randomInt(1000);
    DateTimeUtils.setCurrentMillisFixed(randomMillis);

    // When
    s3FileStore.publicUrlForFilePath(filePath);

    // Then
    verify(mockAmazonS3Client).generatePresignedUrl(bucketSchema + "-" + filePath.directory(), filePath.filename(),
            new Date(3600000 + randomMillis), HttpMethod.GET);
}
 
Example 4
Source File: TestDateTimeFormat.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
protected void setUp() throws Exception {
    DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
    originalDateTimeZone = DateTimeZone.getDefault();
    originalTimeZone = TimeZone.getDefault();
    originalLocale = Locale.getDefault();
    DateTimeZone.setDefault(LONDON);
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Locale.setDefault(Locale.UK);
}
 
Example 5
Source File: TimeBasedRetentionPolicyTest.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
@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();
  }

}
 
Example 6
Source File: TestISOPeriodFormat.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
protected void setUp() throws Exception {
    DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
    originalDateTimeZone = DateTimeZone.getDefault();
    originalTimeZone = TimeZone.getDefault();
    originalLocale = Locale.getDefault();
    DateTimeZone.setDefault(LONDON);
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Locale.setDefault(Locale.UK);
}
 
Example 7
Source File: TestDateTimeFormatter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
protected void setUp() throws Exception {
    DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
    originalDateTimeZone = DateTimeZone.getDefault();
    originalTimeZone = TimeZone.getDefault();
    originalLocale = Locale.getDefault();
    DateTimeZone.setDefault(LONDON);
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Locale.setDefault(Locale.UK);
    f = new DateTimeFormatterBuilder()
            .appendDayOfWeekShortText()
            .appendLiteral(' ')
            .append(ISODateTimeFormat.dateTimeNoMillis())
            .toFormatter();
    g = ISODateTimeFormat.dateTimeNoMillis();
}
 
Example 8
Source File: TestISODateTimeFormat.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
protected void setUp() throws Exception {
    DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
    originalDateTimeZone = DateTimeZone.getDefault();
    originalTimeZone = TimeZone.getDefault();
    originalLocale = Locale.getDefault();
    DateTimeZone.setDefault(LONDON);
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Locale.setDefault(Locale.UK);
}
 
Example 9
Source File: TestISOChronology.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
protected void setUp() throws Exception {
    DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
    originalDateTimeZone = DateTimeZone.getDefault();
    originalTimeZone = TimeZone.getDefault();
    originalLocale = Locale.getDefault();
    DateTimeZone.setDefault(LONDON);
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Locale.setDefault(Locale.UK);
}
 
Example 10
Source File: TestPeriodFormatterBuilder.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
protected void setUp() throws Exception {
    DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
    originalDateTimeZone = DateTimeZone.getDefault();
    originalTimeZone = TimeZone.getDefault();
    originalLocale = Locale.getDefault();
    DateTimeZone.setDefault(LONDON);
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Locale.setDefault(Locale.UK);
    
    builder = new PeriodFormatterBuilder();
}
 
Example 11
Source File: TestPeriodFormatter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
protected void setUp() throws Exception {
    DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
    originalDateTimeZone = DateTimeZone.getDefault();
    originalTimeZone = TimeZone.getDefault();
    originalLocale = Locale.getDefault();
    DateTimeZone.setDefault(LONDON);
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Locale.setDefault(Locale.UK);
    f = ISOPeriodFormat.standard();
}
 
Example 12
Source File: TestEthiopicChronology.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
protected void setUp() throws Exception {
    DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
    originalDateTimeZone = DateTimeZone.getDefault();
    originalTimeZone = TimeZone.getDefault();
    originalLocale = Locale.getDefault();
    DateTimeZone.setDefault(LONDON);
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Locale.setDefault(Locale.UK);
}
 
Example 13
Source File: TestEthiopicChronology.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
protected void setUp() throws Exception {
    DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
    originalDateTimeZone = DateTimeZone.getDefault();
    originalTimeZone = TimeZone.getDefault();
    originalLocale = Locale.getDefault();
    DateTimeZone.setDefault(LONDON);
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Locale.setDefault(Locale.UK);
}
 
Example 14
Source File: TestNullConverter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
protected void setUp() throws Exception {
    DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
    originalDateTimeZone = DateTimeZone.getDefault();
    originalTimeZone = TimeZone.getDefault();
    originalLocale = Locale.getDefault();
    DateTimeZone.setDefault(DateTimeZone.forID("Europe/London"));
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Locale.setDefault(Locale.UK);
    
    ISO = ISOChronology.getInstance();
    JULIAN = JulianChronology.getInstance();
}
 
Example 15
Source File: LegacyInputFormatTest.java    From hdfs2cass with Apache License 2.0 5 votes vote down vote up
@Test
public void testParseValid() throws Exception {

  DateTimeUtils.setCurrentMillisFixed(42l);

  String v1 = "HdfsToCassandra\t1\tkey\tcolName\tvalue";
  LegacyInputFormat r1 = LegacyInputFormat.parse(v1);
  assertEquals("key", r1.getRowkey());
  assertEquals("colName", r1.getColname());
  assertEquals("value", r1.getColval());
  assertEquals(42l, r1.getTimestamp());
  assertEquals(0, r1.getTtl());

  String v2 = "HdfsToCassandra\t2\tkey\tcolName\t23\tvalue";
  r1 = LegacyInputFormat.parse(v2);
  assertEquals("key", r1.getRowkey());
  assertEquals("colName", r1.getColname());
  assertEquals("value", r1.getColval());
  assertEquals(23l, r1.getTimestamp());
  assertEquals(0, r1.getTtl());

  String v3 = "HdfsToCassandra\t3\tkey\tcolName\t23\t666\tvalue";
  r1 = LegacyInputFormat.parse(v3);
  assertEquals("key", r1.getRowkey());
  assertEquals("colName", r1.getColname());
  assertEquals("value", r1.getColval());
  assertEquals(23l, r1.getTimestamp());
  assertEquals(666, r1.getTtl());
}
 
Example 16
Source File: TestGJChronology.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
protected void setUp() throws Exception {
    DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
    originalDateTimeZone = DateTimeZone.getDefault();
    originalTimeZone = TimeZone.getDefault();
    originalLocale = Locale.getDefault();
    DateTimeZone.setDefault(LONDON);
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Locale.setDefault(Locale.UK);
}
 
Example 17
Source File: DateRangePartitionFilterGeneratorTest.java    From incubator-gobblin with Apache License 2.0 4 votes vote down vote up
@BeforeMethod
public void setUp()
    throws Exception {
  DateTimeUtils.setCurrentMillisFixed(new DateTime(2016,3,15,10,15).getMillis());
}
 
Example 18
Source File: LookbackPartitionFilterGeneratorTest.java    From incubator-gobblin with Apache License 2.0 4 votes vote down vote up
@BeforeMethod
public void setUp()
    throws Exception {
  DateTimeUtils.setCurrentMillisFixed(new DateTime(2016,3,15,10,15).getMillis());
}
 
Example 19
Source File: AbstractElasticSearchSinkTest.java    From ingestion with Apache License 2.0 4 votes vote down vote up
@Before
public void setFixedJodaTime() {
  DateTimeUtils.setCurrentMillisFixed(FIXED_TIME_MILLIS);
}
 
Example 20
Source File: StageTest.java    From gocd with Apache License 2.0 4 votes vote down vote up
private void freezeTime(Long millis) {
    DateTimeUtils.setCurrentMillisFixed(millis);
}