Refine search
@Test public void toDaysHoursMinutesSeconds_daysAndHoursAndMinutesAndSeconds_returnsDaysAndHoursAndMinutesAndSecondsString() throws Exception { assertThat(toDaysHoursMinutesSeconds( DAYS.toMillis(1) + HOURS.toMillis(1) + MINUTES.toMillis(1) + SECONDS.toMillis(1))) .isEqualTo("1 day 1 hour 1 minute 1 second"); assertThat(toDaysHoursMinutesSeconds( DAYS.toMillis(1) + HOURS.toMillis(5) + MINUTES.toMillis(15) + SECONDS.toMillis(45))) .isEqualTo("1 day 5 hours 15 minutes 45 seconds"); assertThat(toDaysHoursMinutesSeconds( DAYS.toMillis(2) + HOURS.toMillis(1) + MINUTES.toMillis(30) + SECONDS.toMillis(1))) .isEqualTo("2 days 1 hour 30 minutes 1 second"); }
@Test public void test() throws Exception { startDefaultMaster("--service-registry=" + registryAddress); verify(registrar, timeout((int) SECONDS.toMillis(LONG_WAIT_SECONDS))) .register(registrationCaptor.capture()); final ServiceRegistration registration = registrationCaptor.getValue(); final ServiceRegistration.Endpoint endpoint = getOnlyElement(registration.getEndpoints()); assertEquals("http", endpoint.getProtocol()); assertEquals("helios", endpoint.getName()); assertEquals(masterPort(), endpoint.getPort()); } }
@Test(timeout = 30000) public void testSimpleOneLessAsync() { long t = System.currentTimeMillis(); for (int i = 2; i < 50; i++) { if (System.currentTimeMillis() - t > TimeUnit.SECONDS.toMillis(9)) { break; } TestObserver<Integer> to = new TestObserver<Integer>(); List<Observable<Integer>> sourceList = new ArrayList<Observable<Integer>>(i); Set<Integer> expected = new HashSet<Integer>(i); for (int j = 1; j <= i; j++) { sourceList.add(Observable.just(j).subscribeOn(Schedulers.io())); expected.add(j); } Observable.merge(sourceList, i - 1).subscribe(to); to.awaitTerminalEvent(1, TimeUnit.SECONDS); to.assertNoErrors(); Set<Integer> actual = new HashSet<Integer>(to.values()); assertEquals(expected, actual); } }
@Test public void testDeserializationWithDefaults() throws Exception { String json = "{}"; HttpServerInventoryViewConfig config = TestHelper.makeJsonMapper().readValue(json, HttpServerInventoryViewConfig.class); Assert.assertEquals(TimeUnit.MINUTES.toMillis(4), config.getServerTimeout()); Assert.assertEquals(TimeUnit.MINUTES.toMillis(1), config.getServerUnstabilityTimeout()); Assert.assertEquals(5, config.getNumThreads()); }
@Test public void testConvertsOtherTimeUnitsToMillisForWaiter() throws InterruptedException { long timeoutMicros = 1000; try { future.get(timeoutMicros, TimeUnit.MICROSECONDS); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e); } catch (TimeoutException e) { // Expected. } verify(waiter, atLeastOnce()) .waitForTimeout(eq(future), eq(TimeUnit.MICROSECONDS.toMillis(timeoutMicros))); }
/** * Tests the {@link CommonUtils#convertMsToClockTime(long)} method. */ @Test public void convertMsToClockTime() { assertEquals("0 day(s), 0 hour(s), 0 minute(s), and 0 second(s)", CommonUtils.convertMsToClockTime(10)); assertEquals("0 day(s), 0 hour(s), 0 minute(s), and 1 second(s)", CommonUtils.convertMsToClockTime(TimeUnit.SECONDS.toMillis(1))); assertEquals("0 day(s), 0 hour(s), 1 minute(s), and 0 second(s)", CommonUtils.convertMsToClockTime(TimeUnit.MINUTES.toMillis(1))); assertEquals("0 day(s), 0 hour(s), 1 minute(s), and 30 second(s)", CommonUtils.convertMsToClockTime(TimeUnit.MINUTES.toMillis(1) + TimeUnit.SECONDS.toMillis(30))); assertEquals("0 day(s), 1 hour(s), 0 minute(s), and 0 second(s)", CommonUtils.convertMsToClockTime(TimeUnit.HOURS.toMillis(1))); long time = TimeUnit.DAYS.toMillis(1) + TimeUnit.HOURS.toMillis(4) + TimeUnit.MINUTES.toMillis(10) + TimeUnit.SECONDS.toMillis(45); String out = CommonUtils.convertMsToClockTime(time); assertEquals("1 day(s), 4 hour(s), 10 minute(s), and 45 second(s)", out); }
@Test public void toDaysHoursMinutesSeconds_minutesAndSeconds_returnsMinutesAndSecondsString() throws Exception { assertThat(toDaysHoursMinutesSeconds(MINUTES.toMillis(1) + SECONDS.toMillis(1))) .isEqualTo("1 minute 1 second"); assertThat(toDaysHoursMinutesSeconds(MINUTES.toMillis(1) + SECONDS.toMillis(30))) .isEqualTo("1 minute 30 seconds"); assertThat(toDaysHoursMinutesSeconds(MINUTES.toMillis(2) + SECONDS.toMillis(1))) .isEqualTo("2 minutes 1 second"); assertThat(toDaysHoursMinutesSeconds(MINUTES.toMillis(2) + SECONDS.toMillis(15))) .isEqualTo("2 minutes 15 seconds"); }
@Test public void testDeserializationWithNonDefaults() throws Exception { String json = "{\n" + " \"serverTimeout\": \"PT2M\",\n" + " \"serverUnstabilityTimeout\": \"PT3M\",\n" + " \"numThreads\": 7\n" + "}"; HttpServerInventoryViewConfig config = TestHelper.makeJsonMapper().readValue(json, HttpServerInventoryViewConfig.class); Assert.assertEquals(TimeUnit.MINUTES.toMillis(2), config.getServerTimeout()); Assert.assertEquals(TimeUnit.MINUTES.toMillis(3), config.getServerUnstabilityTimeout()); Assert.assertEquals(7, config.getNumThreads()); } }
@Test public void toDaysHoursMinutesSeconds_hoursAndMinutes_returnsHoursAndMinutesAndSecondsString() throws Exception { assertThat(toDaysHoursMinutesSeconds(HOURS.toMillis(1) + MINUTES.toMillis(1))) .isEqualTo("1 hour 1 minute 0 seconds"); assertThat(toDaysHoursMinutesSeconds(HOURS.toMillis(1) + MINUTES.toMillis(2))) .isEqualTo("1 hour 2 minutes 0 seconds"); }
@Test(timeout = 10000) public void testSimpleOneLessAsync() { long t = System.currentTimeMillis(); for (int i = 2; i < 50; i++) { if (System.currentTimeMillis() - t > TimeUnit.SECONDS.toMillis(9)) { break; } TestSubscriber<Integer> ts = new TestSubscriber<Integer>(); List<Flowable<Integer>> sourceList = new ArrayList<Flowable<Integer>>(i); Set<Integer> expected = new HashSet<Integer>(i); for (int j = 1; j <= i; j++) { sourceList.add(Flowable.just(j).subscribeOn(Schedulers.io())); expected.add(j); } Flowable.merge(sourceList, i - 1).subscribe(ts); ts.awaitTerminalEvent(1, TimeUnit.SECONDS); ts.assertNoErrors(); Set<Integer> actual = new HashSet<Integer>(ts.values()); assertEquals(expected, actual); } }
@Test public void toDaysHoursMinutesSeconds_hoursAndSeconds_returnsHoursAndSecondsString() throws Exception { assertThat(toDaysHoursMinutesSeconds(HOURS.toMillis(1) + SECONDS.toMillis(1))) .isEqualTo("1 hour 1 second"); assertThat(toDaysHoursMinutesSeconds(HOURS.toMillis(1) + SECONDS.toMillis(15))) .isEqualTo("1 hour 15 seconds"); }
@Test public void test() { doInHibernate( this::sessionFactory, session -> { Event event = new Event(); event.id = 1L; event.timeValue = new Time( 1000 ); event.timestampValue = new Timestamp( 45678 ); session.persist( event ); } ); doInHibernate( this::sessionFactory, session -> { Event event = session.find( Event.class, 1L ); assertEquals(1000, event.timeValue.getTime() % TimeUnit.DAYS.toMillis( 1 )); assertEquals(45678, event.timestampValue.getTime() % TimeUnit.DAYS.toMillis( 1 )); } ); }
@Test public void toDaysHoursMinutesSeconds_seconds_returnsSecondsString() throws Exception { assertThat(toDaysHoursMinutesSeconds(SECONDS.toMillis(0))).isEqualTo("0 seconds"); assertThat(toDaysHoursMinutesSeconds(SECONDS.toMillis(1))).isEqualTo("1 second"); assertThat(toDaysHoursMinutesSeconds(SECONDS.toMillis(2))).isEqualTo("2 seconds"); assertThat(toDaysHoursMinutesSeconds(SECONDS.toMillis(45))).isEqualTo("45 seconds"); }
@Test//(timeout = 100000) public void concatMapRangeAsyncLoopIssue2876() { final long durationSeconds = 2; final long startTime = System.currentTimeMillis(); for (int i = 0;; i++) { //only run this for a max of ten seconds if (System.currentTimeMillis() - startTime > TimeUnit.SECONDS.toMillis(durationSeconds)) { return; } if (i % 1000 == 0) { System.out.println("concatMapRangeAsyncLoop > " + i); } TestObserver<Integer> to = new TestObserver<Integer>(); Observable.range(0, 1000) .concatMap(new Function<Integer, Observable<Integer>>() { @Override public Observable<Integer> apply(Integer t) { return Observable.fromIterable(Arrays.asList(t)); } }) .observeOn(Schedulers.computation()).subscribe(to); to.awaitTerminalEvent(2500, TimeUnit.MILLISECONDS); to.assertTerminated(); to.assertNoErrors(); assertEquals(1000, to.valueCount()); assertEquals((Integer)999, to.values().get(999)); } }
@Test public void toDaysHoursMinutesSeconds_milliseconds_returnsSecondsString() throws Exception { assertThat(toDaysHoursMinutesSeconds(MILLISECONDS.toMillis(0))).isEqualTo("0 seconds"); assertThat(toDaysHoursMinutesSeconds(MILLISECONDS.toMillis(999))).isEqualTo("0 seconds"); assertThat(toDaysHoursMinutesSeconds(MILLISECONDS.toMillis(1000))).isEqualTo("1 second"); assertThat(toDaysHoursMinutesSeconds(MILLISECONDS.toMillis(1999))).isEqualTo("1 second"); }
@Test public void testFormatLong_goingBackInTime() { final long now = System.currentTimeMillis(); final long start = now - TimeUnit.HOURS.toMillis(25); final long end = now + TimeUnit.HOURS.toMillis(25); for (final FixedFormat format : FixedFormat.values()) { if (format.getPattern().endsWith("n")) { continue; // cannot compile precise timestamp formats with SimpleDateFormat } final SimpleDateFormat simpleDF = new SimpleDateFormat(format.getPattern(), Locale.getDefault()); final FixedDateFormat customTF = new FixedDateFormat(format, TimeZone.getDefault()); for (long time = end; time > start; time -= 12345) { final String actual = customTF.format(time); final String expected = simpleDF.format(new Date(time)); assertEquals(format + "(" + format.getPattern() + ")" + "/" + time, expected, actual); } } }
@Test public void testFormatLong() { final long now = System.currentTimeMillis(); final long start = now - TimeUnit.HOURS.toMillis(25); final long end = now + TimeUnit.HOURS.toMillis(25); for (final FixedFormat format : FixedFormat.values()) { if (format.getPattern().endsWith("n")) { continue; // cannot compile precise timestamp formats with SimpleDateFormat } final SimpleDateFormat simpleDF = new SimpleDateFormat(format.getPattern(), Locale.getDefault()); final FixedDateFormat customTF = new FixedDateFormat(format, TimeZone.getDefault()); for (long time = start; time < end; time += 12345) { final String actual = customTF.format(time); final String expected = simpleDF.format(new Date(time)); assertEquals(format + "(" + format.getPattern() + ")" + "/" + time, expected, actual); } } }