java.time.Clock#systemUTC ( )源码实例Demo

下面列出了java.time.Clock#systemUTC ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

private void startNewSnapshot() {
    cleanupTimedOutSnapshots();

    AtomicBoolean anyReplicatorDisconnected = new AtomicBoolean();
    topic.getReplicators().forEach((cluster, replicator) -> {
        if (!replicator.isConnected()) {
            anyReplicatorDisconnected.set(true);
        }
    });

    if (anyReplicatorDisconnected.get()) {
        // Do not attempt to create snapshot when some of the clusters are not reachable
        return;
    }

    pendingSnapshotsMetric.inc();
    ReplicatedSubscriptionsSnapshotBuilder builder = new ReplicatedSubscriptionsSnapshotBuilder(this,
            topic.getReplicators().keys(), topic.getBrokerService().pulsar().getConfiguration(), Clock.systemUTC());
    pendingSnapshots.put(builder.getSnapshotId(), builder);
    builder.start();

}
 
源代码2 项目: jdk8u-jdk   文件: TCKClock_System.java
public void test_equals() {
    Clock a = Clock.systemUTC();
    Clock b = Clock.systemUTC();
    assertEquals(a.equals(a), true);
    assertEquals(a.equals(b), true);
    assertEquals(b.equals(a), true);
    assertEquals(b.equals(b), true);

    Clock c = Clock.system(PARIS);
    Clock d = Clock.system(PARIS);
    assertEquals(c.equals(c), true);
    assertEquals(c.equals(d), true);
    assertEquals(d.equals(c), true);
    assertEquals(d.equals(d), true);

    assertEquals(a.equals(c), false);
    assertEquals(c.equals(a), false);

    assertEquals(a.equals(null), false);
    assertEquals(a.equals("other type"), false);
    assertEquals(a.equals(Clock.fixed(Instant.now(), ZoneOffset.UTC)), false);
}
 
源代码3 项目: vespa   文件: VespaModelFactory.java
/** Creates a factory for Vespa models for this version of the source */
@Inject
public VespaModelFactory(ComponentRegistry<ConfigModelPlugin> pluginRegistry,
                         ComponentRegistry<MlModelImporter> modelImporters,
                         Zone zone) {
    this.version = new Version(VespaVersion.major, VespaVersion.minor, VespaVersion.micro);
    List<ConfigModelBuilder> modelBuilders = new ArrayList<>();
    for (ConfigModelPlugin plugin : pluginRegistry.allComponents()) {
        if (plugin instanceof ConfigModelBuilder) {
            modelBuilders.add((ConfigModelBuilder) plugin);
        }
    }
    this.configModelRegistry = new MapConfigModelRegistry(modelBuilders);
    this.modelImporters = modelImporters.allComponents();
    this.zone = zone;

    this.clock = Clock.systemUTC();
}
 
源代码4 项目: openjdk-jdk8u-backup   文件: TCKClock_System.java
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();
}
 
源代码5 项目: aws-sdk-java-v2   文件: Aws4SignerRequestParams.java
private Clock resolveSigningClock(Aws4SignerParams signerParams) {
    if (signerParams.signingClockOverride().isPresent()) {
        return signerParams.signingClockOverride().get();
    }
    Clock baseClock = Clock.systemUTC();
    return signerParams.timeOffset()
            .map(offset -> Clock.offset(baseClock, Duration.ofSeconds(-offset)))
            .orElse(baseClock);
}
 
源代码6 项目: ja-micro   文件: KafkaSubscriberTest.java
@Test
public void subscriberLosesPartitionAssignment() {
    KafkaSubscriber<String> subscriber = new KafkaSubscriber<>(new MessageCallback(),
            "topic", "groupId", false,
            KafkaSubscriber.OffsetReset.Earliest, 1, 1, 1,
            5000, 5000, KafkaSubscriber.QueueType.OffsetBlocking, 1000);
    KafkaTopicInfo message1 = new KafkaTopicInfo("topic", 0, 1, null);
    KafkaTopicInfo message2 = new KafkaTopicInfo("topic", 0, 2, null);
    KafkaTopicInfo message3 = new KafkaTopicInfo("topic", 1, 1, null);
    KafkaTopicInfo message4 = new KafkaTopicInfo("topic", 1, 2, null);
    subscriber.consume(message1);
    subscriber.consume(message2);
    subscriber.consume(message3);
    subscriber.consume(message4);
    KafkaConsumer realConsumer = mock(KafkaConsumer.class);
    class ArgMatcher implements ArgumentMatcher<Map<TopicPartition, OffsetAndMetadata>> {
        @Override
        public boolean matches(Map<TopicPartition, OffsetAndMetadata> arg) {
            OffsetAndMetadata oam = arg.values().iterator().next();
            return oam.offset() == 3;
        }
    }
    doThrow(new CommitFailedException()).when(realConsumer).commitSync(argThat(new ArgMatcher()));
    subscriber.realConsumer = realConsumer;
    subscriber.offsetCommitter = new OffsetCommitter(realConsumer, Clock.systemUTC());
    subscriber.consumeMessages();
}
 
源代码7 项目: vespa   文件: CuratorCompletionWaiter.java
public static Curator.CompletionWaiter create(Curator curator, Path barrierPath, String id) {
    return new CuratorCompletionWaiter(curator, barrierPath.getAbsolute(), id, Clock.systemUTC());
}
 
源代码8 项目: docker-compose-rule   文件: RunRecorder.java
public static RunRecorder defaults() {
    return new RunRecorder(Clock.systemUTC(), PostReportOnShutdown.reporter());
}
 
源代码9 项目: triplea   文件: BannedPlayerFilter.java
public static BannedPlayerFilter newBannedPlayerFilter(final Jdbi jdbi) {
  return new BannedPlayerFilter(jdbi.onDemand(UserBanDao.class), Clock.systemUTC());
}
 
源代码10 项目: time-id   文件: IdGenerator.java
/** Creates a new {@link IdGenerator}. */
public IdGenerator() {
  this(new SecureRandom(), Clock.systemUTC());
}
 
源代码11 项目: emodb   文件: DefaultDatabusTest.java
@Test
public void testDrainQueueForAllNonRedundantItemsInOnePeek() {

    Supplier<Condition> ignoreReEtl = Suppliers.ofInstance(
            Conditions.not(Conditions.mapBuilder().matches(UpdateRef.TAGS_NAME, Conditions.containsAny("re-etl")).build()));
    final List<String> actualIds = Lists.newArrayList();
    DedupEventStore dedupEventStore = mock(DedupEventStore.class);
    DatabusEventStore eventStore = new DatabusEventStore(mock(EventStore.class), dedupEventStore, Suppliers.ofInstance(true)) {
        @Override
        public boolean peek(String subscription, EventSink sink) {
            // The single peek will supply 3 redundant events followed by an empty queue return value
            for (int i = 0; i < 3; i++) {
                String id = "a" + i;
                actualIds.add(id);
                assertTrue(sink.remaining() > 0);
                EventSink.Status status = sink.accept(newEvent(id, "table", "key", TimeUUIDs.newUUID()));
                assertEquals(status, EventSink.Status.ACCEPTED_CONTINUE);
            }
            return false;
        }
    };
    Map<String, Object> content = entity("table", "key", ImmutableMap.of("rating", "5"));
    // Create a custom annotated content which returns all changes as not redundant
    DataProvider.AnnotatedContent annotatedContent = mock(DataProvider.AnnotatedContent.class);
    when(annotatedContent.getContent()).thenReturn(content);
    when(annotatedContent.isChangeDeltaRedundant(any(UUID.class))).thenReturn(false); // Items are not redundant.

    DefaultDatabus testDatabus = new DefaultDatabus(
            mock(LifeCycleRegistry.class), mock(DatabusEventWriterRegistry.class), new TestDataProvider().add(annotatedContent), mock(SubscriptionDAO.class),
            eventStore, mock(SubscriptionEvaluator.class), mock(JobService.class),
            mock(JobHandlerRegistry.class), mock(DatabusAuthorizer.class), "systemOwnerId", ignoreReEtl, MoreExecutors.sameThreadExecutor(),
            1, key -> 0, new MetricRegistry(), Clock.systemUTC());

    // Call the drainQueue method.
    testDatabus.drainQueueAsync("test-subscription");

    // no deletes should be happening.
    verifyZeroInteractions(dedupEventStore);

    // the entry should be removed from map.
    assertEquals(testDatabus.getDrainedSubscriptionsMap().size(), 0);
}
 
源代码12 项目: vespa   文件: MetricUpdater.java
public UpdaterTask(Metric metric, ContainerWatchdogMetrics containerWatchdogMetrics) {
    this.metric = metric;
    this.containerWatchdogMetrics = containerWatchdogMetrics;
    this.garbageCollectionMetrics = new GarbageCollectionMetrics(Clock.systemUTC());
    this.jrtMetrics = new JrtMetrics(metric);
}
 
源代码13 项目: datacollector   文件: SyslogDecoder.java
public SyslogDecoder(Charset charset) {
  this(charset, Clock.systemUTC());
}
 
源代码14 项目: openjdk-8   文件: TCKClock_System.java
public void test_systemUTC() {
    Clock test = Clock.systemUTC();
    assertEquals(test.getZone(), ZoneOffset.UTC);
    assertEquals(test, Clock.system(ZoneOffset.UTC));
}
 
源代码15 项目: vespa   文件: MockDeployer.java
/** Create a mock deployer which returns empty on every deploy request. */
@Inject
@SuppressWarnings("unused")
public MockDeployer() {
    this(null, Clock.systemUTC(), Map.of());
}
 
源代码16 项目: vespa   文件: DeployTester.java
public static CountingModelFactory createHostedModelFactory(Version version) {
    return new CountingModelFactory(HostedConfigModelRegistry.create(), version, Clock.systemUTC(), Zone.defaultZone());
}
 
源代码17 项目: pulsar   文件: FunctionResultRouter.java
public FunctionResultRouter() {
    this(Math.abs(ThreadLocalRandom.current().nextInt()), Clock.systemUTC());
}
 
源代码18 项目: emodb   文件: RedundantDeltaTest.java
@Test
public void testRedundantDeltas() throws Exception {
    InMemoryDataReaderDAO dataDao = new InMemoryDataReaderDAO();
    DefaultDataStore store = new DefaultDataStore(new DatabusEventWriterRegistry(), new InMemoryTableDAO(), dataDao, dataDao,
            new NullSlowQueryLog(), new DiscardingExecutorService(), new InMemoryHistoryStore(),
            Optional.<URI>absent(), new InMemoryCompactionControlSource(), Conditions.alwaysFalse(),
            new DiscardingAuditWriter(), new InMemoryMapStore<>(), new MetricRegistry(), Clock.systemUTC());

    TableOptions options = new TableOptionsBuilder().setPlacement("default").build();
    store.createTable(TABLE, options, Collections.<String, Object>emptyMap(), newAudit("create table"));

    UUID uuid0 = TimeUUIDs.newUUID();
    UUID uuid1 = TimeUUIDs.newUUID();
    UUID uuid2 = TimeUUIDs.newUUID();
    UUID uuid3 = TimeUUIDs.newUUID();
    UUID uuid4 = TimeUUIDs.newUUID();
    UUID uuid5 = TimeUUIDs.newUUID();
    UUID uuid6 = TimeUUIDs.newUUID();
    UUID uuid7 = TimeUUIDs.newUUID();

    store.update(TABLE, KEY, uuid1, Deltas.fromString("{\"name\":\"Bob\"}"), newAudit("submit"), WriteConsistency.STRONG);
    store.update(TABLE, KEY, uuid2, Deltas.fromString("{..,\"state\":\"APPROVED\"}"), newAudit("moderation"), WriteConsistency.STRONG);
    store.update(TABLE, KEY, uuid3, Deltas.fromString("{..,\"state\":\"APPROVED\"}"), newAudit("moderation"), WriteConsistency.STRONG);
    store.update(TABLE, KEY, uuid4, Deltas.fromString("{\"name\":\"Bob\"}"), newAudit("resubmit"), WriteConsistency.STRONG);
    store.update(TABLE, KEY, uuid5, Deltas.fromString("{\"name\":\"Tom\"}"), newAudit("resubmit"), WriteConsistency.STRONG);
    store.update(TABLE, KEY, uuid6, Deltas.fromString("{\"name\":\"Tom\"}"), newAudit("resubmit"), WriteConsistency.STRONG);
    store.update(TABLE, KEY, uuid7, Deltas.fromString("{\"name\":\"Tom\"}"), newAudit("resubmit"), WriteConsistency.STRONG);
    Map<String, String> expectedFinalState = ImmutableMap.of("name", "Tom");

    assertUnknownDelta(store, TABLE, KEY, uuid0);
    assertChange(store, TABLE, KEY, uuid1, expectedFinalState);
    assertChange(store, TABLE, KEY, uuid2, expectedFinalState);
    assertRedundantDelta(store, TABLE, KEY, uuid3);
    assertChange(store, TABLE, KEY, uuid4, expectedFinalState);
    assertChange(store, TABLE, KEY, uuid5, expectedFinalState);
    assertRedundantDelta(store, TABLE, KEY, uuid6);
    assertRedundantDelta(store, TABLE, KEY, uuid7);
    assertUnknownDelta(store, TABLE, KEY, TimeUUIDs.newUUID());

    // automatic compaction should be disabled in this test.  verify that using DiscardingExecutorService disabled it.
    assertEquals(Iterators.size(store.getTimeline(TABLE, KEY, true, false, null, null, false, 100, ReadConsistency.STRONG)), 7);

    // now compact and verify that all deltas are read normally
    dataDao.setFullConsistencyDelayMillis(0);
    store.compact(TABLE, KEY, null, ReadConsistency.STRONG, WriteConsistency.STRONG);
    assertChange(store, TABLE, KEY, uuid0, expectedFinalState);
    assertChange(store, TABLE, KEY, uuid1, expectedFinalState);
    assertChange(store, TABLE, KEY, uuid2, expectedFinalState);
    assertChange(store, TABLE, KEY, uuid3, expectedFinalState);
    assertChange(store, TABLE, KEY, uuid4, expectedFinalState);
    assertChange(store, TABLE, KEY, uuid5, expectedFinalState);
    assertRedundantDelta(store, TABLE, KEY, uuid6);
    assertRedundantDelta(store, TABLE, KEY, uuid7);
    dataDao.setFullConsistencyDelayMillis(Integer.MAX_VALUE);
    assertUnknownDelta(store, TABLE, KEY, TimeUUIDs.newUUID());
}
 
源代码19 项目: vespa   文件: Trace.java
public static Trace fromSlime(Inspector inspector) {
    int traceLevel = deserializeTraceLevel(inspector);
    Clock clock = Clock.systemUTC();
    SlimeTraceDeserializer deserializer = new SlimeTraceDeserializer(inspector.field(TRACE_TRACELOG));
    return new Trace(traceLevel, deserializer.deserialize(), clock);
}
 
源代码20 项目: vespa   文件: ServiceRegistry.java
default Clock clock() { return Clock.systemUTC(); }