Example usage for java.time Duration ZERO

List of usage examples for java.time Duration ZERO

Introduction

In this page you can find the example usage for java.time Duration ZERO.

Prototype

Duration ZERO

To view the source code for java.time Duration ZERO.

Click Source Link

Document

Constant for a duration of zero.

Usage

From source file:org.janusgraph.diskstorage.configuration.backend.KCVSConfiguration.java

public void setMaxOperationWaitTime(Duration waitTime) {

    Preconditions.checkArgument(Duration.ZERO.compareTo(waitTime) < 0, "Wait time must be nonnegative: %s",
            waitTime);//from  w  ww. ja  v  a2s.  c o m
    this.maxOperationWaitTime = waitTime;
}

From source file:org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.java

public GraphDatabaseConfiguration(ReadConfiguration localConfig) {
    Preconditions.checkNotNull(localConfig);

    configurationAtOpen = localConfig;//from w w  w  .  j  a  v a 2s.co m

    BasicConfiguration localbc = new BasicConfiguration(ROOT_NS, localConfig,
            BasicConfiguration.Restriction.NONE);
    ModifiableConfiguration overwrite = new ModifiableConfiguration(ROOT_NS, new CommonsConfiguration(),
            BasicConfiguration.Restriction.NONE);

    //        KeyColumnValueStoreManager storeManager=null;
    final KeyColumnValueStoreManager storeManager = Backend.getStorageManager(localbc);
    final StoreFeatures storeFeatures = storeManager.getFeatures();
    KCVSConfiguration kcvsConfig = Backend.getStandaloneGlobalConfiguration(storeManager, localbc);
    ReadConfiguration globalConfig = null;

    //Copy over local config options
    localConfiguration = new ModifiableConfiguration(ROOT_NS, new CommonsConfiguration(),
            BasicConfiguration.Restriction.LOCAL);
    localConfiguration.setAll(getLocalSubset(localbc.getAll()));

    //Read out global configuration
    try {
        // If lock prefix is unspecified, specify it now
        if (!localbc.has(LOCK_LOCAL_MEDIATOR_GROUP)) {
            overwrite.set(LOCK_LOCAL_MEDIATOR_GROUP, storeManager.getName());
        }

        //Freeze global configuration if not already frozen!
        ModifiableConfiguration globalWrite = new ModifiableConfiguration(ROOT_NS, kcvsConfig,
                BasicConfiguration.Restriction.GLOBAL);
        if (!globalWrite.isFrozen()) {
            //Copy over global configurations
            globalWrite.setAll(getGlobalSubset(localbc.getAll()));

            //Write JanusGraph version
            Preconditions.checkArgument(!globalWrite.has(INITIAL_JANUSGRAPH_VERSION),
                    "Database has already been initialized but not frozen");
            globalWrite.set(INITIAL_JANUSGRAPH_VERSION, JanusGraphConstants.VERSION);

            /* If the configuration does not explicitly set a timestamp provider and
             * the storage backend both supports timestamps and has a preference for
             * a specific timestamp provider, then apply the backend's preference.
             */
            if (!localbc.has(TIMESTAMP_PROVIDER)) {
                StoreFeatures f = storeManager.getFeatures();
                TimestampProviders backendPreference = null;
                if (f.hasTimestamps() && null != (backendPreference = f.getPreferredTimestamps())) {
                    globalWrite.set(TIMESTAMP_PROVIDER, backendPreference);
                    log.info("Set timestamps to {} according to storage backend preference",
                            globalWrite.get(TIMESTAMP_PROVIDER));
                }
                globalWrite.set(TIMESTAMP_PROVIDER, TIMESTAMP_PROVIDER.getDefaultValue());
                log.info("Set default timestamp provider {}", globalWrite.get(TIMESTAMP_PROVIDER));
            } else {
                log.info("Using configured timestamp provider {}", localbc.get(TIMESTAMP_PROVIDER));
            }

            globalWrite.freezeConfiguration();
        } else {
            String version = globalWrite.get(INITIAL_JANUSGRAPH_VERSION);
            Preconditions.checkArgument(version != null, "JanusGraph version has not been initialized");
            if (!JanusGraphConstants.VERSION.equals(version)
                    && !JanusGraphConstants.COMPATIBLE_VERSIONS.contains(version)) {
                throw new JanusGraphException(
                        "StorageBackend version is incompatible with current JanusGraph version: storage="
                                + version + " vs. runtime=" + JanusGraphConstants.VERSION);
            }

            final boolean managedOverridesAllowed;

            if (localbc.has(ALLOW_STALE_CONFIG))
                managedOverridesAllowed = localbc.get(ALLOW_STALE_CONFIG);
            else if (globalWrite.has(ALLOW_STALE_CONFIG))
                managedOverridesAllowed = globalWrite.get(ALLOW_STALE_CONFIG);
            else
                managedOverridesAllowed = ALLOW_STALE_CONFIG.getDefaultValue();

            // Check for disagreement between local and backend values for GLOBAL(_OFFLINE) and FIXED options
            // The point of this check is to find edits to the local config which have no effect (and therefore likely indicate misconfiguration)
            Set<String> optionsWithDiscrepancies = Sets.newHashSet();
            for (Map.Entry<ConfigElement.PathIdentifier, Object> ent : getManagedSubset(localbc.getAll())
                    .entrySet()) {
                ConfigElement.PathIdentifier pid = ent.getKey();
                assert pid.element.isOption();
                ConfigOption<?> opt = (ConfigOption<?>) pid.element;
                Object localValue = ent.getValue();

                // Get the storage backend's setting and compare with localValue
                Object storeValue = globalWrite.get(opt, pid.umbrellaElements);

                // Most validation predicate impls disallow null, but we can't assume that here
                final boolean match;
                if (null != localValue && null != storeValue) {
                    match = localValue.equals(storeValue);
                } else if (null == localValue && null == storeValue) {
                    match = true;
                } else {
                    match = false;
                }

                // Log each option with value disagreement between local and backend configs
                if (!match) {
                    String fullOptionName = ConfigElement.getPath(pid.element, pid.umbrellaElements);
                    String template = "Local setting {}={} (Type: {}) is overridden by globally managed value ({}).  Use the {} interface instead of the local configuration to control this setting.";
                    Object replacements[] = new Object[] { fullOptionName, localValue, opt.getType(),
                            storeValue, ManagementSystem.class.getSimpleName() };
                    if (managedOverridesAllowed) { // Lower log severity when this is enabled
                        log.warn(template, replacements);
                    } else {
                        log.error(template, replacements);
                    }
                    optionsWithDiscrepancies.add(fullOptionName);
                }
            }

            if (0 < optionsWithDiscrepancies.size() && !managedOverridesAllowed) {
                String template = "Local settings present for one or more globally managed options: [%s].  These options are controlled through the %s interface; local settings have no effect.";
                throw new JanusGraphConfigurationException(
                        String.format(template, Joiner.on(", ").join(optionsWithDiscrepancies),
                                ManagementSystem.class.getSimpleName()));
            }
        }

        globalConfig = kcvsConfig.asReadConfiguration();
    } finally {
        kcvsConfig.close();
    }
    Configuration combinedConfig = new MixedConfiguration(ROOT_NS, globalConfig, localConfig);

    //Compute unique instance id
    this.uniqueGraphId = getOrGenerateUniqueInstanceId(combinedConfig);
    overwrite.set(UNIQUE_INSTANCE_ID, this.uniqueGraphId);

    //Default log configuration for system and tx log
    //TRANSACTION LOG: send_delay=0, ttl=2days and backend=default
    Preconditions.checkArgument(
            combinedConfig.get(LOG_BACKEND, TRANSACTION_LOG).equals(LOG_BACKEND.getDefaultValue()),
            "Must use default log backend for transaction log");
    Preconditions.checkArgument(
            !combinedConfig.has(LOG_SEND_DELAY, TRANSACTION_LOG)
                    || combinedConfig.get(LOG_SEND_DELAY, TRANSACTION_LOG).isZero(),
            "Send delay must be 0 for transaction log.");
    overwrite.set(LOG_SEND_DELAY, Duration.ZERO, TRANSACTION_LOG);
    if (!combinedConfig.has(LOG_STORE_TTL, TRANSACTION_LOG) && TTLKCVSManager.supportsAnyTTL(storeFeatures)) {
        overwrite.set(LOG_STORE_TTL, TRANSACTION_LOG_DEFAULT_TTL, TRANSACTION_LOG);
    }
    //SYSTEM MANAGEMENT LOG: backend=default and send_delay=0 and key_consistent=true and fixed-partitions=true
    Preconditions.checkArgument(
            combinedConfig.get(LOG_BACKEND, MANAGEMENT_LOG).equals(LOG_BACKEND.getDefaultValue()),
            "Must use default log backend for system log");
    Preconditions.checkArgument(
            !combinedConfig.has(LOG_SEND_DELAY, MANAGEMENT_LOG)
                    || combinedConfig.get(LOG_SEND_DELAY, MANAGEMENT_LOG).isZero(),
            "Send delay must be 0 for system log.");
    overwrite.set(LOG_SEND_DELAY, Duration.ZERO, MANAGEMENT_LOG);
    Preconditions.checkArgument(
            !combinedConfig.has(KCVSLog.LOG_KEY_CONSISTENT, MANAGEMENT_LOG)
                    || combinedConfig.get(KCVSLog.LOG_KEY_CONSISTENT, MANAGEMENT_LOG),
            "Management log must be configured to be key-consistent");
    overwrite.set(KCVSLog.LOG_KEY_CONSISTENT, true, MANAGEMENT_LOG);
    Preconditions.checkArgument(
            !combinedConfig.has(KCVSLogManager.LOG_FIXED_PARTITION, MANAGEMENT_LOG)
                    || combinedConfig.get(KCVSLogManager.LOG_FIXED_PARTITION, MANAGEMENT_LOG),
            "Fixed partitions must be enabled for management log");
    overwrite.set(KCVSLogManager.LOG_FIXED_PARTITION, true, MANAGEMENT_LOG);

    this.configuration = new MergedConfiguration(overwrite, combinedConfig);
    preLoadConfiguration();
}

From source file:org.janusgraph.StorageSetup.java

public static ModifiableConfiguration getInMemoryConfiguration() {
    return buildGraphConfiguration().set(STORAGE_BACKEND, "inmemory").set(IDAUTHORITY_WAIT, Duration.ZERO);
}

From source file:org.springframework.cloud.gateway.rsocket.server.GatewayRSocketTests.java

@Test
public void multipleFilters() {
    TestFilter filter1 = new TestFilter();
    TestFilter filter2 = new TestFilter();
    TestFilter filter3 = new TestFilter();

    Payload payload = new TestGatewayRSocket(registry, new TestRoutes(filter1, filter2, filter3))
            .requestResponse(incomingPayload).block(Duration.ZERO);

    assertThat(filter1.invoked()).isTrue();
    assertThat(filter2.invoked()).isTrue();
    assertThat(filter3.invoked()).isTrue();
    assertThat(payload).isNotNull();/*  ww  w . j a  va  2  s  . c  o m*/
}

From source file:org.springframework.cloud.gateway.rsocket.server.GatewayRSocketTests.java

@Test
public void zeroFilters() {
    Payload payload = new TestGatewayRSocket(registry, new TestRoutes()).requestResponse(incomingPayload)
            .block(Duration.ZERO);

    assertThat(payload).isNotNull();/* w  w w. j  a  v  a  2  s .c  om*/
}

From source file:org.springframework.cloud.gateway.rsocket.socketacceptor.GatewaySocketAcceptorTests.java

@Test
public void multipleFilters() {
    TestFilter filter1 = new TestFilter();
    TestFilter filter2 = new TestFilter();
    TestFilter filter3 = new TestFilter();

    RSocket socket = new GatewaySocketAcceptor(this.factory, Arrays.asList(filter1, filter2, filter3),
            this.meterRegistry, this.properties).accept(this.setupPayload, this.sendingSocket)
                    .block(Duration.ZERO);

    assertThat(filter1.invoked()).isTrue();
    assertThat(filter2.invoked()).isTrue();
    assertThat(filter3.invoked()).isTrue();
    assertThat(socket).isNotNull();/*from  ww w  .ja  v a2  s . com*/
}

From source file:org.springframework.cloud.gateway.rsocket.socketacceptor.GatewaySocketAcceptorTests.java

@Test
public void zeroFilters() {
    RSocket socket = new GatewaySocketAcceptor(this.factory, Collections.emptyList(), this.meterRegistry,
            this.properties).accept(this.setupPayload, this.sendingSocket).block(Duration.ZERO);

    assertThat(socket).isNotNull();//  w  ww . j  av a2 s  .c o m
}

From source file:org.springframework.cloud.gateway.rsocket.socketacceptor.GatewaySocketAcceptorTests.java

@Test
public void shortcircuitFilter() {

    TestFilter filter1 = new TestFilter();
    ShortcircuitingFilter filter2 = new ShortcircuitingFilter();
    TestFilter filter3 = new TestFilter();

    RSocket socket = new GatewaySocketAcceptor(this.factory, Arrays.asList(filter1, filter2, filter3),
            this.meterRegistry, this.properties).accept(this.setupPayload, this.sendingSocket)
                    .block(Duration.ZERO);

    assertThat(filter1.invoked()).isTrue();
    assertThat(filter2.invoked()).isTrue();
    assertThat(filter3.invoked()).isFalse();
    assertThat(socket).isNull();/*  w w w.j a va 2s. com*/
}

From source file:org.springframework.data.redis.connection.lettuce.LettuceConnectionFactoryTests.java

@Test // DATAREDIS-667
public void factoryCreatesPooledConnections() {

    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();

    LettuceClientConfiguration configuration = LettucePoolingClientConfiguration.builder()
            .poolConfig(poolConfig).clientResources(LettuceTestClientResources.getSharedClientResources())
            .shutdownTimeout(Duration.ZERO).build();

    LettuceConnectionFactory factory = new LettuceConnectionFactory(new RedisStandaloneConfiguration(),
            configuration);/* w  w  w.  j  av a2s  .co  m*/
    factory.setShareNativeConnection(false);
    factory.afterPropertiesSet();

    ConnectionFactoryTracker.add(factory);

    RedisConnection initial = factory.getConnection();
    Object initialNativeConnection = initial.getNativeConnection();

    initial.close();

    RedisConnection subsequent = factory.getConnection();
    Object subsequentNativeConnection = subsequent.getNativeConnection();

    subsequent.close();

    assertThat(initialNativeConnection, is(subsequentNativeConnection));

    factory.destroy();
}

From source file:org.springframework.web.server.handler.FilteringWebHandlerTests.java

@Test
public void multipleFilters() throws Exception {

    TestFilter filter1 = new TestFilter();
    TestFilter filter2 = new TestFilter();
    TestFilter filter3 = new TestFilter();
    StubWebHandler targetHandler = new StubWebHandler();

    new FilteringWebHandler(targetHandler, Arrays.asList(filter1, filter2, filter3))
            .handle(MockServerWebExchange.from(MockServerHttpRequest.get("/"))).block(Duration.ZERO);

    assertTrue(filter1.invoked());//from   w w w .  j a  v  a 2  s.  c  o  m
    assertTrue(filter2.invoked());
    assertTrue(filter3.invoked());
    assertTrue(targetHandler.invoked());
}