@Test public void firstConfigInvalidShouldResolveToDefault() { CassandraKeyValueServiceRuntimeConfig returnedConfig = new CassandraAtlasDbFactory() .preprocessKvsRuntimeConfig(() -> Optional.of(INVALID_CKVS_RUNTIME_CONFIG)) .get(); assertEquals("First invalid config should resolve to default", DEFAULT_CKVS_RUNTIME_CONFIG, returnedConfig); }
@VisibleForTesting Supplier<CassandraKeyValueServiceRuntimeConfig> preprocessKvsRuntimeConfig( Supplier<Optional<KeyValueServiceRuntimeConfig>> runtimeConfig) { return () -> { Optional<KeyValueServiceRuntimeConfig> configOptional = runtimeConfig.get(); return configOptional.map(config -> { if (!(config instanceof CassandraKeyValueServiceRuntimeConfig)) { log.error("Invalid KeyValueServiceRuntimeConfig. Expected a KeyValueServiceRuntimeConfig of type" + " CassandraKeyValueServiceRuntimeConfig, found %s." + " Using latest valid CassandraKeyValueServiceRuntimeConfig.", config.getClass()); return latestValidRuntimeConfig; } latestValidRuntimeConfig = (CassandraKeyValueServiceRuntimeConfig) config; return latestValidRuntimeConfig; }).orElseGet(CassandraKeyValueServiceRuntimeConfig::getDefault); }; }
CassandraAtlasDbFactory implements AtlasDbFactory { @VisibleForTesting Supplier<CassandraKeyValueServiceRuntimeConfig> preprocessKvsRuntimeConfig( Supplier<Optional<KeyValueServiceRuntimeConfig>> runtimeConfig) { return () -> { Optional<KeyValueServiceRuntimeConfig> configOptional = runtimeConfig.get(); return configOptional.map(config -> { if (!(config instanceof CassandraKeyValueServiceRuntimeConfig)) { log.error("Invalid KeyValueServiceRuntimeConfig. Expected a KeyValueServiceRuntimeConfig of type" + " CassandraKeyValueServiceRuntimeConfig, found %s." + " Using latest valid CassandraKeyValueServiceRuntimeConfig.", config.getClass()); return latestValidRuntimeConfig; } latestValidRuntimeConfig = (CassandraKeyValueServiceRuntimeConfig) config; return latestValidRuntimeConfig; }).orElseGet(CassandraKeyValueServiceRuntimeConfig::getDefault); }; } }
CassandraAtlasDbFactory implements AtlasDbFactory { @VisibleForTesting Supplier<CassandraKeyValueServiceRuntimeConfig> preprocessKvsRuntimeConfig( Supplier<Optional<KeyValueServiceRuntimeConfig>> runtimeConfig) { return () -> { Optional<KeyValueServiceRuntimeConfig> configOptional = runtimeConfig.get(); return configOptional.map(config -> { if (!(config instanceof CassandraKeyValueServiceRuntimeConfig)) { log.error("Invalid KeyValueServiceRuntimeConfig. Expected a KeyValueServiceRuntimeConfig of type" + " CassandraKeyValueServiceRuntimeConfig, found %s." + " Using latest valid CassandraKeyValueServiceRuntimeConfig.", config.getClass()); return latestValidRuntimeConfig; } latestValidRuntimeConfig = (CassandraKeyValueServiceRuntimeConfig) config; return latestValidRuntimeConfig; }).orElseGet(CassandraKeyValueServiceRuntimeConfig::getDefault); }; }  }
CassandraAtlasDbFactory implements AtlasDbFactory { @VisibleForTesting Supplier<CassandraKeyValueServiceRuntimeConfig> preprocessKvsRuntimeConfig( Supplier<Optional<KeyValueServiceRuntimeConfig>> runtimeConfig) { return () -> { Optional<KeyValueServiceRuntimeConfig> configOptional = runtimeConfig.get(); return configOptional.map(config -> { if (!(config instanceof CassandraKeyValueServiceRuntimeConfig)) { log.error("Invalid KeyValueServiceRuntimeConfig. Expected a KeyValueServiceRuntimeConfig of type" + " CassandraKeyValueServiceRuntimeConfig, found %s." + " Using latest valid CassandraKeyValueServiceRuntimeConfig.", config.getClass()); return latestValidRuntimeConfig; } latestValidRuntimeConfig = (CassandraKeyValueServiceRuntimeConfig) config; return latestValidRuntimeConfig; }).orElseGet(CassandraKeyValueServiceRuntimeConfig::getDefault); }; }  @Override KeyValueService createRawKeyValueService(
            MetricsManager metricsManager,
            KeyValueServiceConfig config,
            Supplier<Optional<KeyValueServiceRuntimeConfig>> runtimeConfig,
            Optional<LeaderConfig> unused,
            Optional<String> namespace,
            LongSupplier freshTimestampSource,
            boolean initializeAsync); @Override ManagedTimestampService createManagedTimestampService(
            KeyValueService rawKvs,
            Optional<TableReference> timestampTable,
            boolean initializeAsync); @Override String getType(); @Override TimestampStoreInvalidator createTimestampStoreInvalidator(KeyValueService rawKvs); }
CassandraAtlasDbFactory implements AtlasDbFactory { @VisibleForTesting Supplier<CassandraKeyValueServiceRuntimeConfig> preprocessKvsRuntimeConfig( Supplier<Optional<KeyValueServiceRuntimeConfig>> runtimeConfig) { return () -> { Optional<KeyValueServiceRuntimeConfig> configOptional = runtimeConfig.get(); return configOptional.map(config -> { if (!(config instanceof CassandraKeyValueServiceRuntimeConfig)) { log.error("Invalid KeyValueServiceRuntimeConfig. Expected a KeyValueServiceRuntimeConfig of type" + " CassandraKeyValueServiceRuntimeConfig, found %s." + " Using latest valid CassandraKeyValueServiceRuntimeConfig.", config.getClass()); return latestValidRuntimeConfig; } latestValidRuntimeConfig = (CassandraKeyValueServiceRuntimeConfig) config; return latestValidRuntimeConfig; }).orElseGet(CassandraKeyValueServiceRuntimeConfig::getDefault); }; }  @Override KeyValueService createRawKeyValueService(
            MetricsManager metricsManager,
            KeyValueServiceConfig config,
            Supplier<Optional<KeyValueServiceRuntimeConfig>> runtimeConfig,
            Optional<LeaderConfig> unused,
            Optional<String> namespace,
            LongSupplier freshTimestampSource,
            boolean initializeAsync); @Override ManagedTimestampService createManagedTimestampService(
            KeyValueService rawKvs,
            Optional<TableReference> timestampTable,
            boolean initializeAsync); @Override String getType(); @Override TimestampStoreInvalidator createTimestampStoreInvalidator(KeyValueService rawKvs);  }