| 1 |
/* |
| 2 |
* Copyright (C) 2016 Brett Wooldridge |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
* you may not use this file except in compliance with the License. |
| 6 |
* You may obtain a copy of the License at |
| 7 |
* |
| 8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
* |
| 10 |
* Unless required by applicable law or agreed to in writing, software |
| 11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
* See the License for the specific language governing permissions and |
| 14 |
* limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
package com.zaxxer.hikari.util; |
| 18 |
|
| 19 |
import org.junit.Assert; |
| 20 |
import org.junit.Test; |
| 21 |
|
| 22 |
import static java.util.concurrent.TimeUnit.DAYS; |
| 23 |
import static java.util.concurrent.TimeUnit.HOURS; |
| 24 |
import static java.util.concurrent.TimeUnit.MICROSECONDS; |
| 25 |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
| 26 |
import static java.util.concurrent.TimeUnit.MINUTES; |
| 27 |
import static java.util.concurrent.TimeUnit.NANOSECONDS; |
| 28 |
import static java.util.concurrent.TimeUnit.SECONDS; |
| 29 |
|
| 30 |
/** |
| 31 |
* |
| 32 |
* @author Brett Wooldridge |
| 33 |
*/ |
| 34 |
public class ClockSourceTest |
| 35 |
{ |
| 36 |
@Test |
| 37 |
public void testClockSourceDisplay() |
| 38 |
{ |
| 39 |
ClockSource msSource = new ClockSource.MillisecondClockSource(); |
| 40 |
|
| 41 |
final long sTime = DAYS.toMillis(3) + HOURS.toMillis(9) + MINUTES.toMillis(24) + SECONDS.toMillis(18) + MILLISECONDS.toMillis(572); |
| 42 |
|
| 43 |
final long eTime = DAYS.toMillis(4) + HOURS.toMillis(9) + MINUTES.toMillis(55) + SECONDS.toMillis(23) + MILLISECONDS.toMillis(777); |
| 44 |
String ds1 = msSource.elapsedDisplayString0(sTime, eTime); |
| 45 |
Assert.assertEquals("1d31m5s205ms", ds1); |
| 46 |
|
| 47 |
final long eTime2 = DAYS.toMillis(3) + HOURS.toMillis(8) + MINUTES.toMillis(24) + SECONDS.toMillis(23) + MILLISECONDS.toMillis(777); |
| 48 |
String ds2 = msSource.elapsedDisplayString0(sTime, eTime2); |
| 49 |
Assert.assertEquals("-59m54s795ms", ds2); |
| 50 |
|
| 51 |
|
| 52 |
ClockSource nsSource = new ClockSource.NanosecondClockSource(); |
| 53 |
|
| 54 |
final long sTime2 = DAYS.toNanos(3) + HOURS.toNanos(9) + MINUTES.toNanos(24) + SECONDS.toNanos(18) + MILLISECONDS.toNanos(572) + MICROSECONDS.toNanos(324) + NANOSECONDS.toNanos(823); |
| 55 |
|
| 56 |
final long eTime3 = DAYS.toNanos(4) + HOURS.toNanos(19) + MINUTES.toNanos(55) + SECONDS.toNanos(23) + MILLISECONDS.toNanos(777) + MICROSECONDS.toNanos(0) + NANOSECONDS.toNanos(982); |
| 57 |
String ds3 = nsSource.elapsedDisplayString0(sTime2, eTime3); |
| 58 |
Assert.assertEquals("1d10h31m5s204ms676µs159ns", ds3); |
| 59 |
} |
| 60 |
} |