@Test public void now_Clock_allSecsInDay_utc() { for (int i = 0; i < (2 * 24 * 60 * 60); i++) { Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L); Clock clock = Clock.fixed(instant, ZoneOffset.UTC); ZonedDateTime test = ZonedDateTime.now(clock); assertEquals(test.getYear(), 1970); assertEquals(test.getMonth(), Month.JANUARY); assertEquals(test.getDayOfMonth(), (i < 24 * 60 * 60 ? 1 : 2)); assertEquals(test.getHour(), (i / (60 * 60)) % 24); assertEquals(test.getMinute(), (i / 60) % 60); assertEquals(test.getSecond(), i % 60); assertEquals(test.getNano(), 123456789); assertEquals(test.getOffset(), ZoneOffset.UTC); assertEquals(test.getZone(), ZoneOffset.UTC); } }
@Test public void givenMultipleCacheFilesInCacheDirectory_allReadInOrder() throws Exception { underlyingEventStore.write(stream_1, singletonList(event_1)); Position firstPosition = saveAllToCache(getCacheFile("cache_1.gz")); underlyingEventStore.write(stream_1, singletonList(event_1)); Position secondPosition = saveAllToCache(getCacheFile("cache_2.gz"), firstPosition); underlyingEventStore.write(stream_1, singletonList(event_1)); Position thirdPosition = saveAllToCache(getCacheFile("cache_3.gz"), secondPosition); CacheEventReader newCacheEventReader = new CacheEventReader(new JavaInMemoryEventStore(Clock.systemUTC()), CODEC, cacheDirectory, "cache"); List<ResolvedEvent> resolvedEvents = readAllFromEmpty(newCacheEventReader); assertThat(resolvedEvents.stream().map(ResolvedEvent::position).collect(toList()), contains(firstPosition, secondPosition, thirdPosition)); }
/** * Produce randomly generated records into the defined kafka namespace. * * @param numberOfRecords how many records to produce * @param topicName the namespace name to produce into. * @param partitionId the partition to produce into. * @return List of ProducedKafkaRecords. */ public List<ProducedKafkaRecord<byte[], byte[]>> produceRecords( final int numberOfRecords, final String topicName, final int partitionId ) { Map<byte[], byte[]> keysAndValues = new HashMap<>(); // Generate random & unique data for (int x = 0; x < numberOfRecords; x++) { // Construct key and value long timeStamp = Clock.systemUTC().millis(); String key = "key" + timeStamp; String value = "value" + timeStamp; // Add to map keysAndValues.put(key.getBytes(Charsets.UTF_8), value.getBytes(Charsets.UTF_8)); } return produceRecords(keysAndValues, topicName, partitionId); }
@Test public void now_Clock_allSecsInDay_offset() { for (int i = 0; i < (2 * 24 * 60 * 60); i++) { Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L); Clock clock = Clock.fixed(instant.minusSeconds(OFFSET_PONE.getTotalSeconds()), OFFSET_PONE); OffsetDateTime test = OffsetDateTime.now(clock); assertEquals(test.getYear(), 1970); assertEquals(test.getMonth(), Month.JANUARY); assertEquals(test.getDayOfMonth(), (i < 24 * 60 * 60) ? 1 : 2); assertEquals(test.getHour(), (i / (60 * 60)) % 24); assertEquals(test.getMinute(), (i / 60) % 60); assertEquals(test.getSecond(), i % 60); assertEquals(test.getNano(), 123456789); assertEquals(test.getOffset(), OFFSET_PONE); } }
public static void testClock() throws InterruptedException { //时钟提供给我们用于访问某个特定 时区的 瞬时时间、日期 和 时间的。 Clock c1 = Clock.systemUTC(); //系统默认UTC时钟(当前瞬时时间 System.currentTimeMillis()) System.out.println(c1.millis()); //每次调用将返回当前瞬时时间(UTC) Clock c2 = Clock.systemDefaultZone(); //系统默认时区时钟(当前瞬时时间) Clock c31 = Clock.system(ZoneId.of("Europe/Paris")); //巴黎时区 System.out.println(c31.millis()); //每次调用将返回当前瞬时时间(UTC) Clock c32 = Clock.system(ZoneId.of("Asia/Shanghai"));//上海时区 System.out.println(c32.millis());//每次调用将返回当前瞬时时间(UTC) Clock c4 = Clock.fixed(Instant.now(), ZoneId.of("Asia/Shanghai"));//固定上海时区时钟 System.out.println(c4.millis()); Thread.sleep(1000); System.out.println(c4.millis()); //不变 即时钟时钟在那一个点不动 Clock c5 = Clock.offset(c1, Duration.ofSeconds(2)); //相对于系统默认时钟两秒的时钟 System.out.println(c1.millis()); System.out.println(c5.millis()); }
public void test__equals() { Clock a = Clock.tick(Clock.system(PARIS), Duration.ofMillis(500)); Clock b = Clock.tick(Clock.system(PARIS), Duration.ofMillis(500)); assertEquals(a.equals(a), true); assertEquals(a.equals(b), true); assertEquals(b.equals(a), true); assertEquals(b.equals(b), true); Clock c = Clock.tick(Clock.system(MOSCOW), Duration.ofMillis(500)); assertEquals(a.equals(c), false); Clock d = Clock.tick(Clock.system(PARIS), Duration.ofMillis(499)); assertEquals(a.equals(d), false); assertEquals(a.equals(null), false); assertEquals(a.equals("other type"), false); assertEquals(a.equals(Clock.systemUTC()), false); }
public void test_millis() { Clock system = Clock.systemUTC(); assertEquals(system.getZone(), ZoneOffset.UTC); for (int i = 0; i < 10000; i++) { // assume can eventually get these within 10 milliseconds long instant = system.millis(); long systemMillis = System.currentTimeMillis(); if (systemMillis - instant < 10) { return; // success } } fail(); }
@Test public void now() { MonthDay expected = MonthDay.now(Clock.systemDefaultZone()); MonthDay test = MonthDay.now(); for (int i = 0; i < 100; i++) { if (expected.equals(test)) { return; } expected = MonthDay.now(Clock.systemDefaultZone()); test = MonthDay.now(); } assertEquals(test, expected); }
@Override public void registerExtenderCallbacks(IBurpExtenderCallbacks callbacks) { this.callbacks = callbacks; this.helpers = callbacks.getHelpers(); callbacks.setExtensionName("ProxyHistoryWebUI"); try { // ONLY THIS PATTERN WORK FINE. ?? ClassLoader.loadClass() NOT WORK... X( Class.forName("org.h2.Driver"); appContext = new AppContext(Clock.systemDefaultZone()); appContext.setConsoleOutputWriter(new PrintWriter(callbacks.getStdout(), true)); appContext.setConsoleErrorWriter(new PrintWriter(callbacks.getStderr(), true)); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { demoPanel = new DemoPanel(appContext); callbacks.customizeUiComponent(demoPanel); callbacks.addSuiteTab(BurpExtender.this); // register ourselves as an HTTP listener callbacks.registerProxyListener(BurpExtender.this); } }); } catch (Exception e) { callbacks.printError(Throwables.getStackTraceAsString(e)); e.printStackTrace(); } }
private void initSystemComponents(final SystemComponents systemComponents) { client = systemComponents.client(); pluginConfig = systemComponents.pluginConfig(); infoStrategy = systemComponents.infoStrategy(); clientUtil = systemComponents.clientUtil(); zorro = new Zorro(pluginConfig); clock = Clock.systemDefaultZone(); }
@Bean public Clock systemClock() { return Clock.systemDefaultZone(); }
@Test public void test_MinguoChronology_dateNow() { ZoneId zoneId_paris = ZoneId.of("Europe/Paris"); Clock clock = Clock.system(zoneId_paris); Chronology chrono = Chronology.of("Minguo"); assertEquals(chrono.dateNow(), MinguoChronology.INSTANCE.dateNow()); assertEquals(chrono.dateNow(zoneId_paris), MinguoChronology.INSTANCE.dateNow(zoneId_paris)); assertEquals(chrono.dateNow(clock), MinguoChronology.INSTANCE.dateNow(clock)); }
public void test_tickSeconds_ZoneId() throws Exception { Clock test = Clock.tickSeconds(PARIS); assertEquals(test.getZone(), PARIS); assertEquals(test.instant().getNano(), 0); Thread.sleep(100); assertEquals(test.instant().getNano(), 0); }
@Test public void test() throws NoSuchMethodException, SecurityException, SQLException { PropertyMapperManager mapper = new PropertyMapperManager(); LocalDateTime localDateTime = LocalDateTime.now(); OffsetDateTime offsetDateTime = OffsetDateTime.of(localDateTime, OffsetDateTime.now().getOffset()); ZonedDateTime zonedDateTime = ZonedDateTime.of(localDateTime, Clock.systemDefaultZone().getZone()); java.sql.Timestamp timestamp = java.sql.Timestamp.valueOf(localDateTime); LocalDate localDate = localDateTime.toLocalDate(); java.sql.Date date = java.sql.Date.valueOf(localDate); LocalTime localTime = localDateTime.toLocalTime(); java.sql.Time time = new java.sql.Time(toTime(localTime)); OffsetTime offsetTime = offsetDateTime.toOffsetTime(); assertThat(mapper.getValue(JavaType.of(LocalDateTime.class), newResultSet("getTimestamp", timestamp), 1), is(localDateTime)); assertThat(mapper.getValue(JavaType.of(OffsetDateTime.class), newResultSet("getTimestamp", timestamp), 1), is(offsetDateTime)); assertThat(mapper.getValue(JavaType.of(ZonedDateTime.class), newResultSet("getTimestamp", timestamp), 1), is(zonedDateTime)); assertThat(mapper.getValue(JavaType.of(LocalDate.class), newResultSet("getDate", date), 1), is(localDate)); assertThat(mapper.getValue(JavaType.of(LocalTime.class), newResultSet("getTime", time), 1), is(localTime)); assertThat(mapper.getValue(JavaType.of(OffsetTime.class), newResultSet("getTime", time), 1), is(offsetTime)); assertThat(mapper.getValue(JavaType.of(LocalDateTime.class), newResultSet("getTimestamp", null), 1), is(nullValue())); assertThat(mapper.getValue(JavaType.of(OffsetDateTime.class), newResultSet("getTimestamp", null), 1), is(nullValue())); assertThat(mapper.getValue(JavaType.of(ZonedDateTime.class), newResultSet("getTimestamp", null), 1), is(nullValue())); assertThat(mapper.getValue(JavaType.of(LocalDate.class), newResultSet("getDate", null), 1), is(nullValue())); assertThat(mapper.getValue(JavaType.of(LocalTime.class), newResultSet("getTime", null), 1), is(nullValue())); assertThat(mapper.getValue(JavaType.of(OffsetTime.class), newResultSet("getTime", null), 1), is(nullValue())); }
@Test public void now_ZoneId() { ZoneId zone = ZoneId.of("UTC+01:02:03"); ZonedDateTime expected = ZonedDateTime.now(Clock.system(zone)); ZonedDateTime test = ZonedDateTime.now(zone); for (int i = 0; i < 100; i++) { if (expected.equals(test)) { return; } expected = ZonedDateTime.now(Clock.system(zone)); test = ZonedDateTime.now(zone); } assertEquals(test.truncatedTo(ChronoUnit.SECONDS), expected.truncatedTo(ChronoUnit.SECONDS)); }
@Test public void test_mockInstantClock_withZone() { ZoneId london = ZoneId.of("Europe/London"); Clock changed = MOCK_INSTANT.withZone(london); assertEquals(MOCK_INSTANT.instant(), INSTANT); assertEquals(MOCK_INSTANT.millis(), INSTANT.toEpochMilli()); assertEquals(changed.getZone(), london); }
public void test_hashCode() { Clock a = Clock.tick(Clock.system(PARIS), Duration.ofMillis(500)); Clock b = Clock.tick(Clock.system(PARIS), Duration.ofMillis(500)); assertEquals(a.hashCode(), a.hashCode()); assertEquals(a.hashCode(), b.hashCode()); Clock c = Clock.tick(Clock.system(MOSCOW), Duration.ofMillis(500)); assertEquals(a.hashCode() == c.hashCode(), false); Clock d = Clock.tick(Clock.system(PARIS), Duration.ofMillis(499)); assertEquals(a.hashCode() == d.hashCode(), false); }
/** * Constructor. * @param namespace - the namespace this tuple came from. * @param partition - the partition this tuple came from. * @param offset - the offset this tuple came from. * @param srcVirtualSpoutId - the VirtualSpout's identifier this tuple came from. */ public MessageId(final String namespace, final int partition, final long offset, final VirtualSpoutIdentifier srcVirtualSpoutId) { this.namespace = namespace; this.partition = partition; this.offset = offset; this.srcVirtualSpoutId = srcVirtualSpoutId; this.timestamp = Clock.systemUTC().millis(); }
@Test public void now_Clock_allSecsInDay_utc() { for (int i = 0; i < (2 * 24 * 60 * 60); i++) { Instant expected = Instant.ofEpochSecond(i).plusNanos(123456789L); Clock clock = Clock.fixed(expected, ZoneOffset.UTC); Instant test = Instant.now(clock); assertEquals(test, expected); } }
@Test public void now() { Instant expected = Instant.now(Clock.systemUTC()); Instant test = Instant.now(); long diff = Math.abs(test.toEpochMilli() - expected.toEpochMilli()); assertTrue(diff < 100); // less than 0.1 secs }
public void test_hashCode() { Clock a = Clock.system(ZoneOffset.UTC); Clock b = Clock.system(ZoneOffset.UTC); assertEquals(a.hashCode(), a.hashCode()); assertEquals(a.hashCode(), b.hashCode()); Clock c = Clock.system(PARIS); assertEquals(a.hashCode() == c.hashCode(), false); }
@Test public void now_Clock_allSecsInDay_utc() { for (int i = 0; i < (2 * 24 * 60 * 60); i++) { Instant instant = Instant.ofEpochSecond(i); Clock clock = Clock.fixed(instant, ZoneOffset.UTC); LocalDate test = LocalDate.now(clock); assertEquals(test.getYear(), 1970); assertEquals(test.getMonth(), Month.JANUARY); assertEquals(test.getDayOfMonth(), (i < 24 * 60 * 60 ? 1 : 2)); } }
ExpirationBasedCache() { _cache = new ConcurrentHashMap<>(); _clock = Clock.systemUTC(); Timer timer = new Timer("cacheExpiration", true); timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { expireCacheEntries(); }} , 60, 60); }
@Override protected org.apache.tinkerpop.gremlin.structure.Vertex complete(GraphTraversal traversal) { long startTime = Clock.systemUTC().millis(); try { return (org.apache.tinkerpop.gremlin.structure.Vertex) super.complete(traversal); } finally { if (log.isDebugEnabled()) { long endTime = Clock.systemUTC().millis(); log.debug("Executing '{} vertex' traversal {} in {}ms", should().label(), show(traversal), endTime - startTime); } } }
@Test public void now() { Year expected = Year.now(Clock.systemDefaultZone()); Year test = Year.now(); for (int i = 0; i < 100; i++) { if (expected.equals(test)) { return; } expected = Year.now(Clock.systemDefaultZone()); test = Year.now(); } assertEquals(test, expected); }
@Test public void now_Clock_min() { Clock clock = Clock.fixed(Instant.MIN, ZoneOffset.UTC); LocalTime test = LocalTime.now(clock); assertEquals(test.getHour(), 0); assertEquals(test.getMinute(), 0); assertEquals(test.getSecond(), 0); assertEquals(test.getNano(), 0); }
OfflineDevicesJobImpl( Clock clock, DeviceService deviceService, PushNotificationService pushNotificationService ) { if (clock == null || deviceService == null || pushNotificationService == null) { throw new IllegalArgumentException("Clock, device service nor push notification service can be null."); } this.clock = clock; this.deviceService = deviceService; this.pushNotificationService = pushNotificationService; this.offlineDevices = new ConcurrentHashMap<>(deviceService.getOfflineDevices()); }
@Test public void givenReadingFromEmptyStorePosition_readsFromTheCache() throws Exception { underlyingEventStore.write(stream_1, singletonList(event_1)); saveAllToCache(getCacheFile("cache.gz")); assertThat(readAllFromEmpty(cacheEventReader), hasSize(1)); CacheEventReader newCacheEventReader = new CacheEventReader(new JavaInMemoryEventStore(Clock.systemUTC()), CODEC, cacheDirectory, "cache"); assertThat(readAllFromEmpty(newCacheEventReader), hasSize(1)); assertThat(readAllFromEmpty(newCacheEventReader), equalTo(readAllToList(underlyingEventStore))); }
/** * Tests the constructor sets things appropriately. */ @Test public void testConstructor() { // Define inputs final MessageBus messageBus = new MessageBus(new FifoBuffer()); final Map<VirtualSpoutIdentifier, Queue<MessageId>> ackQueue = Maps.newConcurrentMap(); final Map<VirtualSpoutIdentifier, Queue<MessageId>> failQueue = Maps.newConcurrentMap(); final Clock clock = Clock.systemUTC(); // Define some config params final long consumerStateFlushInterval = 200L; // Create our spout delegate final DelegateSpout spout = mock(DelegateSpout.class); // Create config final Map<String, Object> topologyConfig = getDefaultConfig(consumerStateFlushInterval); // Create instance. SpoutRunner spoutRunner = new SpoutRunner( spout, messageBus, clock, topologyConfig ); // Call getters and validate! assertEquals("Clock instance is what we expect", clock, spoutRunner.getClock()); assertEquals("TopologyConfig looks legit", topologyConfig, spoutRunner.getTopologyConfig()); assertEquals( "getConsumerStateFlushIntervalMs() returns right value", consumerStateFlushInterval, spoutRunner.getConsumerStateFlushIntervalMs() ); assertNotNull("StartTime is null", spoutRunner.getStartTime()); assertNotEquals("StartTime is not zero", 0, spoutRunner.getStartTime()); assertEquals("Spout delegate got set", spout, spoutRunner.getSpout()); }
@Test public void now_Clock_allSecsInDay() { for (int i = 0; i < (2 * 24 * 60 * 60); i++) { Instant instant = Instant.ofEpochSecond(i, 8); Clock clock = Clock.fixed(instant, ZoneOffset.UTC); LocalTime test = LocalTime.now(clock); assertEquals(test.getHour(), (i / (60 * 60)) % 24); assertEquals(test.getMinute(), (i / 60) % 60); assertEquals(test.getSecond(), i % 60); assertEquals(test.getNano(), 8); } }
protected BigInteger calculateHashRate(Predicate<BlockHeaderElement> countCondition, Duration period) { if (hasBestBlock()) { Instant upto = Clock.systemUTC().instant(); Instant from = upto.minus(period); return this.hashRate(getHeaderElement(blockStore.getBestBlock().getHash()), countCondition, b -> checkBlockTimeRange(b, from, upto)); } return BigInteger.ZERO; }
@Test public void test_ThaiBuddhistChronology_dateNow() { ZoneId zoneId_paris = ZoneId.of("Europe/Paris"); Clock clock = Clock.system(zoneId_paris); Chronology chrono = Chronology.of("ThaiBuddhist"); assertEquals(chrono.dateNow(), ThaiBuddhistChronology.INSTANCE.dateNow()); assertEquals(chrono.dateNow(zoneId_paris), ThaiBuddhistChronology.INSTANCE.dateNow(zoneId_paris)); assertEquals(chrono.dateNow(clock), ThaiBuddhistChronology.INSTANCE.dateNow(clock)); }
@Test public void getCurrentUtcTime_ShouldReturnTimeInUtc() throws Exception { subject = new JGroupsTaskStateImpl(Clock.fixed(Instant.parse("2017-01-01T13:30:00Z"), ZoneOffset.UTC)); ZonedDateTime time = subject.getCurrentUtcTime(); assertThat(time.getHour()).isEqualTo(13); assertThat(time.getMinute()).isEqualTo(30); assertThat(time.getOffset()).isEqualByComparingTo(ZoneOffset.UTC); }
@Test public void now_Clock_allSecsInDay() { for (int i = 0; i < (2 * 24 * 60 * 60); i++) { Instant instant = Instant.ofEpochSecond(i, 8); Clock clock = Clock.fixed(instant, ZoneOffset.UTC); OffsetTime test = OffsetTime.now(clock); assertEquals(test.getHour(), (i / (60 * 60)) % 24); assertEquals(test.getMinute(), (i / 60) % 60); assertEquals(test.getSecond(), i % 60); assertEquals(test.getNano(), 8); assertEquals(test.getOffset(), ZoneOffset.UTC); } }
@Test(expectedExceptions=NullPointerException.class) public void now_Clock_nullClock() { LocalTime.now((Clock) null); }
public DateServiceImpl() { this.clock = Clock.system(ZoneId.of("UTC")); }
@Test(expectedExceptions = NullPointerException.class) public void test_fixed_InstantZoneId_nullInstant() { Clock.fixed(null, PARIS); }