下面列出了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();
}
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);
}
/** 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();
}
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();
}
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);
}
@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();
}
public static Curator.CompletionWaiter create(Curator curator, Path barrierPath, String id) {
return new CuratorCompletionWaiter(curator, barrierPath.getAbsolute(), id, Clock.systemUTC());
}
public static RunRecorder defaults() {
return new RunRecorder(Clock.systemUTC(), PostReportOnShutdown.reporter());
}
public static BannedPlayerFilter newBannedPlayerFilter(final Jdbi jdbi) {
return new BannedPlayerFilter(jdbi.onDemand(UserBanDao.class), Clock.systemUTC());
}
/** Creates a new {@link IdGenerator}. */
public IdGenerator() {
this(new SecureRandom(), Clock.systemUTC());
}
@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);
}
public UpdaterTask(Metric metric, ContainerWatchdogMetrics containerWatchdogMetrics) {
this.metric = metric;
this.containerWatchdogMetrics = containerWatchdogMetrics;
this.garbageCollectionMetrics = new GarbageCollectionMetrics(Clock.systemUTC());
this.jrtMetrics = new JrtMetrics(metric);
}
public SyslogDecoder(Charset charset) {
this(charset, Clock.systemUTC());
}
public void test_systemUTC() {
Clock test = Clock.systemUTC();
assertEquals(test.getZone(), ZoneOffset.UTC);
assertEquals(test, Clock.system(ZoneOffset.UTC));
}
/** Create a mock deployer which returns empty on every deploy request. */
@Inject
@SuppressWarnings("unused")
public MockDeployer() {
this(null, Clock.systemUTC(), Map.of());
}
public static CountingModelFactory createHostedModelFactory(Version version) {
return new CountingModelFactory(HostedConfigModelRegistry.create(), version, Clock.systemUTC(), Zone.defaultZone());
}
public FunctionResultRouter() {
this(Math.abs(ThreadLocalRandom.current().nextInt()), Clock.systemUTC());
}
@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());
}
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);
}
default Clock clock() { return Clock.systemUTC(); }