Java Code Examples for java.time.Clock#systemUTC()

The following examples show how to use java.time.Clock#systemUTC() . 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: ReplicatedSubscriptionsController.java    From pulsar with Apache License 2.0 6 votes vote down vote up
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();

}
 
Example 2
Source File: VespaModelFactory.java    From vespa with Apache License 2.0 6 votes vote down vote up
/** 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();
}
 
Example 3
Source File: TCKClock_System.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example 4
Source File: KafkaSubscriberTest.java    From ja-micro with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 5
Source File: Aws4SignerRequestParams.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 6
Source File: TCKClock_System.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 7
Source File: TCKClock_System.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void test_systemUTC() {
    Clock test = Clock.systemUTC();
    assertEquals(test.getZone(), ZoneOffset.UTC);
    assertEquals(test, Clock.system(ZoneOffset.UTC));
}
 
Example 8
Source File: Trace.java    From vespa with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 9
Source File: RedundantDeltaTest.java    From emodb with Apache License 2.0 4 votes vote down vote up
@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());
}
 
Example 10
Source File: FunctionResultRouter.java    From pulsar with Apache License 2.0 4 votes vote down vote up
public FunctionResultRouter() {
    this(Math.abs(ThreadLocalRandom.current().nextInt()), Clock.systemUTC());
}
 
Example 11
Source File: DeployTester.java    From vespa with Apache License 2.0 4 votes vote down vote up
public static CountingModelFactory createHostedModelFactory(Version version) {
    return new CountingModelFactory(HostedConfigModelRegistry.create(), version, Clock.systemUTC(), Zone.defaultZone());
}
 
Example 12
Source File: MockDeployer.java    From vespa with Apache License 2.0 4 votes vote down vote up
/** Create a mock deployer which returns empty on every deploy request. */
@Inject
@SuppressWarnings("unused")
public MockDeployer() {
    this(null, Clock.systemUTC(), Map.of());
}
 
Example 13
Source File: SyslogDecoder.java    From datacollector with Apache License 2.0 4 votes vote down vote up
public SyslogDecoder(Charset charset) {
  this(charset, Clock.systemUTC());
}
 
Example 14
Source File: MetricUpdater.java    From vespa with Apache License 2.0 4 votes vote down vote up
public UpdaterTask(Metric metric, ContainerWatchdogMetrics containerWatchdogMetrics) {
    this.metric = metric;
    this.containerWatchdogMetrics = containerWatchdogMetrics;
    this.garbageCollectionMetrics = new GarbageCollectionMetrics(Clock.systemUTC());
    this.jrtMetrics = new JrtMetrics(metric);
}
 
Example 15
Source File: DefaultDatabusTest.java    From emodb with Apache License 2.0 4 votes vote down vote up
@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);
}
 
Example 16
Source File: IdGenerator.java    From time-id with Apache License 2.0 4 votes vote down vote up
/** Creates a new {@link IdGenerator}. */
public IdGenerator() {
  this(new SecureRandom(), Clock.systemUTC());
}
 
Example 17
Source File: BannedPlayerFilter.java    From triplea with GNU General Public License v3.0 4 votes vote down vote up
public static BannedPlayerFilter newBannedPlayerFilter(final Jdbi jdbi) {
  return new BannedPlayerFilter(jdbi.onDemand(UserBanDao.class), Clock.systemUTC());
}
 
Example 18
Source File: RunRecorder.java    From docker-compose-rule with Apache License 2.0 4 votes vote down vote up
public static RunRecorder defaults() {
    return new RunRecorder(Clock.systemUTC(), PostReportOnShutdown.reporter());
}
 
Example 19
Source File: CuratorCompletionWaiter.java    From vespa with Apache License 2.0 4 votes vote down vote up
public static Curator.CompletionWaiter create(Curator curator, Path barrierPath, String id) {
    return new CuratorCompletionWaiter(curator, barrierPath.getAbsolute(), id, Clock.systemUTC());
}
 
Example 20
Source File: ServiceRegistry.java    From vespa with Apache License 2.0 votes vote down vote up
default Clock clock() { return Clock.systemUTC(); }