From 7ff57ce2532bc74aec3c8b5246b73decad4a381b Mon Sep 17 00:00:00 2001 From: Dain Sundstrom Date: Sun, 3 Jul 2022 12:28:26 -0700 Subject: [PATCH] Add DynamicCatalogManager Move support for dynamically adding catalogs from StaticCatalogManager to new DynamicCatalogManager. This is only used in testing and moving this feature makes future enhancements simpler. --- .../trino/connector/CatalogManagerConfig.java | 41 +++++ .../trino/connector/CatalogManagerModule.java | 30 +--- .../connector/ConnectorServicesProvider.java | 2 + .../CoordinatorDynamicCatalogManager.java | 154 ++++++++++++++++++ .../DynamicCatalogManagerModule.java | 49 ++++++ .../trino/connector/StaticCatalogManager.java | 18 +- .../connector/StaticCatalogManagerModule.java | 53 ++++++ .../io/trino/metadata/CatalogManager.java | 10 ++ .../src/main/java/io/trino/server/Server.java | 3 +- .../server/testing/TestingTrinoServer.java | 6 +- .../io/trino/testing/LocalQueryRunner.java | 7 +- .../connector/TestCatalogManagerConfig.java | 47 ++++++ 12 files changed, 373 insertions(+), 47 deletions(-) create mode 100644 core/trino-main/src/main/java/io/trino/connector/CatalogManagerConfig.java create mode 100644 core/trino-main/src/main/java/io/trino/connector/CoordinatorDynamicCatalogManager.java create mode 100644 core/trino-main/src/main/java/io/trino/connector/DynamicCatalogManagerModule.java create mode 100644 core/trino-main/src/main/java/io/trino/connector/StaticCatalogManagerModule.java create mode 100644 core/trino-main/src/test/java/io/trino/connector/TestCatalogManagerConfig.java diff --git a/core/trino-main/src/main/java/io/trino/connector/CatalogManagerConfig.java b/core/trino-main/src/main/java/io/trino/connector/CatalogManagerConfig.java new file mode 100644 index 0000000000000..be06b32491999 --- /dev/null +++ b/core/trino-main/src/main/java/io/trino/connector/CatalogManagerConfig.java @@ -0,0 +1,41 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.trino.connector; + +import io.airlift.configuration.Config; + +import javax.validation.constraints.NotNull; + +public class CatalogManagerConfig +{ + public enum CatalogMangerKind + { + STATIC, DYNAMIC + } + + private CatalogMangerKind catalogMangerKind = CatalogMangerKind.STATIC; + + @NotNull + public CatalogMangerKind getCatalogMangerKind() + { + return catalogMangerKind; + } + + @Config("catalog.management") + public CatalogManagerConfig setCatalogMangerKind(CatalogMangerKind catalogMangerKind) + { + this.catalogMangerKind = catalogMangerKind; + return this; + } +} diff --git a/core/trino-main/src/main/java/io/trino/connector/CatalogManagerModule.java b/core/trino-main/src/main/java/io/trino/connector/CatalogManagerModule.java index e2ba132c4c800..e75233e9cefd0 100644 --- a/core/trino-main/src/main/java/io/trino/connector/CatalogManagerModule.java +++ b/core/trino-main/src/main/java/io/trino/connector/CatalogManagerModule.java @@ -16,12 +16,6 @@ import com.google.inject.Binder; import com.google.inject.Scopes; import io.airlift.configuration.AbstractConfigurationAwareModule; -import io.trino.connector.system.GlobalSystemConnector; -import io.trino.metadata.CatalogManager; - -import javax.inject.Inject; - -import static io.airlift.configuration.ConfigBinder.configBinder; public class CatalogManagerModule extends AbstractConfigurationAwareModule @@ -32,27 +26,13 @@ protected void setup(Binder binder) binder.bind(DefaultCatalogFactory.class).in(Scopes.SINGLETON); binder.bind(LazyCatalogFactory.class).in(Scopes.SINGLETON); binder.bind(CatalogFactory.class).to(LazyCatalogFactory.class).in(Scopes.SINGLETON); - binder.bind(LazyRegister.class).asEagerSingleton(); - configBinder(binder).bindConfig(StaticCatalogManagerConfig.class); - binder.bind(StaticCatalogManager.class).in(Scopes.SINGLETON); - binder.bind(ConnectorServicesProvider.class).to(StaticCatalogManager.class).in(Scopes.SINGLETON); - binder.bind(CatalogManager.class).to(StaticCatalogManager.class).in(Scopes.SINGLETON); + CatalogManagerConfig config = buildConfigObject(CatalogManagerConfig.class); + switch (config.getCatalogMangerKind()) { + case STATIC -> install(new StaticCatalogManagerModule()); + case DYNAMIC -> install(new DynamicCatalogManagerModule()); + } install(new CatalogServiceProviderModule()); } - - private static class LazyRegister - { - @Inject - public LazyRegister( - DefaultCatalogFactory defaultCatalogFactory, - LazyCatalogFactory lazyCatalogFactory, - StaticCatalogManager catalogManager, - GlobalSystemConnector globalSystemConnector) - { - lazyCatalogFactory.setCatalogFactory(defaultCatalogFactory); - catalogManager.registerGlobalSystemConnector(globalSystemConnector); - } - } } diff --git a/core/trino-main/src/main/java/io/trino/connector/ConnectorServicesProvider.java b/core/trino-main/src/main/java/io/trino/connector/ConnectorServicesProvider.java index 2af91fa60211f..10bcb81c9a8b4 100644 --- a/core/trino-main/src/main/java/io/trino/connector/ConnectorServicesProvider.java +++ b/core/trino-main/src/main/java/io/trino/connector/ConnectorServicesProvider.java @@ -15,5 +15,7 @@ public interface ConnectorServicesProvider { + void loadInitialCatalogs(); + ConnectorServices getConnectorServices(CatalogHandle catalogHandle); } diff --git a/core/trino-main/src/main/java/io/trino/connector/CoordinatorDynamicCatalogManager.java b/core/trino-main/src/main/java/io/trino/connector/CoordinatorDynamicCatalogManager.java new file mode 100644 index 0000000000000..4b5481f5ab0a6 --- /dev/null +++ b/core/trino-main/src/main/java/io/trino/connector/CoordinatorDynamicCatalogManager.java @@ -0,0 +1,154 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.trino.connector; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; +import io.trino.connector.system.GlobalSystemConnector; +import io.trino.metadata.Catalog; +import io.trino.metadata.CatalogManager; +import io.trino.spi.TrinoException; + +import javax.annotation.PreDestroy; +import javax.annotation.concurrent.GuardedBy; +import javax.annotation.concurrent.ThreadSafe; +import javax.inject.Inject; + +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkState; +import static io.trino.connector.CatalogHandle.createRootCatalogHandle; +import static io.trino.spi.StandardErrorCode.ALREADY_EXISTS; +import static java.lang.String.format; +import static java.util.Objects.requireNonNull; + +@ThreadSafe +public class CoordinatorDynamicCatalogManager + implements CatalogManager, ConnectorServicesProvider +{ + private final CatalogFactory catalogFactory; + + private final Lock catalogsUpdateLock = new ReentrantLock(); + private final ConcurrentMap catalogs = new ConcurrentHashMap<>(); + + @GuardedBy("catalogsUpdateLock") + private boolean stopped; + + @Inject + public CoordinatorDynamicCatalogManager(CatalogFactory catalogFactory) + { + this.catalogFactory = requireNonNull(catalogFactory, "catalogFactory is null"); + } + + @PreDestroy + public void stop() + { + List catalogs; + + catalogsUpdateLock.lock(); + try { + if (stopped) { + return; + } + stopped = true; + + catalogs = ImmutableList.copyOf(this.catalogs.values()); + this.catalogs.clear(); + } + finally { + catalogsUpdateLock.unlock(); + } + + for (CatalogConnector connector : catalogs) { + connector.shutdown(); + } + } + + @Override + public void loadInitialCatalogs() {} + + @Override + public Set getCatalogNames() + { + return ImmutableSet.copyOf(catalogs.keySet()); + } + + @Override + public Optional getCatalog(String catalogName) + { + return Optional.ofNullable(catalogs.get(catalogName)) + .map(CatalogConnector::getCatalog); + } + + @Override + public ConnectorServices getConnectorServices(CatalogHandle catalogHandle) + { + CatalogConnector catalogConnector = catalogs.get(catalogHandle.getCatalogName()); + checkArgument(catalogConnector != null, "No catalog '%s'", catalogHandle.getCatalogName()); + return catalogConnector.getMaterializedConnector(catalogHandle.getType()); + } + + @Override + public CatalogHandle createCatalog(String catalogName, String connectorName, Map properties) + { + requireNonNull(catalogName, "catalogName is null"); + requireNonNull(connectorName, "connectorName is null"); + requireNonNull(properties, "properties is null"); + + catalogsUpdateLock.lock(); + try { + checkState(!stopped, "ConnectorManager is stopped"); + + if (catalogs.containsKey(catalogName)) { + throw new TrinoException(ALREADY_EXISTS, format("Catalog '%s' already exists", catalogName)); + } + + CatalogProperties catalogProperties = new CatalogProperties(createRootCatalogHandle(catalogName), connectorName, properties); + CatalogConnector catalog = catalogFactory.createCatalog(catalogProperties); + catalogs.put(catalogName, catalog); + return catalog.getCatalogHandle(); + } + finally { + catalogsUpdateLock.unlock(); + } + } + + public void registerGlobalSystemConnector(GlobalSystemConnector connector) + { + requireNonNull(connector, "connector is null"); + + catalogsUpdateLock.lock(); + try { + if (stopped) { + return; + } + + CatalogConnector catalog = catalogFactory.createCatalog(GlobalSystemConnector.CATALOG_HANDLE, GlobalSystemConnector.NAME, connector); + if (catalogs.putIfAbsent(GlobalSystemConnector.NAME, catalog) != null) { + throw new IllegalStateException("Global system catalog already registered"); + } + } + finally { + catalogsUpdateLock.unlock(); + } + } +} diff --git a/core/trino-main/src/main/java/io/trino/connector/DynamicCatalogManagerModule.java b/core/trino-main/src/main/java/io/trino/connector/DynamicCatalogManagerModule.java new file mode 100644 index 0000000000000..db421f1b9fb56 --- /dev/null +++ b/core/trino-main/src/main/java/io/trino/connector/DynamicCatalogManagerModule.java @@ -0,0 +1,49 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.trino.connector; + +import com.google.inject.Binder; +import com.google.inject.Scopes; +import io.airlift.configuration.AbstractConfigurationAwareModule; +import io.trino.connector.system.GlobalSystemConnector; +import io.trino.metadata.CatalogManager; + +import javax.inject.Inject; + +public class DynamicCatalogManagerModule + extends AbstractConfigurationAwareModule +{ + @Override + protected void setup(Binder binder) + { + binder.bind(CoordinatorDynamicCatalogManager.class).in(Scopes.SINGLETON); + binder.bind(ConnectorServicesProvider.class).to(CoordinatorDynamicCatalogManager.class).in(Scopes.SINGLETON); + binder.bind(CatalogManager.class).to(CoordinatorDynamicCatalogManager.class).in(Scopes.SINGLETON); + binder.bind(CoordinatorLazyRegister.class).asEagerSingleton(); + } + + private static class CoordinatorLazyRegister + { + @Inject + public CoordinatorLazyRegister( + DefaultCatalogFactory defaultCatalogFactory, + LazyCatalogFactory lazyCatalogFactory, + CoordinatorDynamicCatalogManager catalogManager, + GlobalSystemConnector globalSystemConnector) + { + lazyCatalogFactory.setCatalogFactory(defaultCatalogFactory); + catalogManager.registerGlobalSystemConnector(globalSystemConnector); + } + } +} diff --git a/core/trino-main/src/main/java/io/trino/connector/StaticCatalogManager.java b/core/trino-main/src/main/java/io/trino/connector/StaticCatalogManager.java index 34a2ea990b9fb..7a583ca8e6777 100644 --- a/core/trino-main/src/main/java/io/trino/connector/StaticCatalogManager.java +++ b/core/trino-main/src/main/java/io/trino/connector/StaticCatalogManager.java @@ -13,7 +13,6 @@ */ package io.trino.connector; -import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -22,6 +21,7 @@ import io.trino.connector.system.GlobalSystemConnector; import io.trino.metadata.Catalog; import io.trino.metadata.CatalogManager; +import io.trino.spi.TrinoException; import javax.annotation.PreDestroy; import javax.annotation.concurrent.ThreadSafe; @@ -46,6 +46,7 @@ import static com.google.common.collect.ImmutableList.toImmutableList; import static io.airlift.configuration.ConfigurationLoader.loadPropertiesFrom; import static io.trino.connector.CatalogHandle.createRootCatalogHandle; +import static io.trino.spi.StandardErrorCode.NOT_SUPPORTED; import static java.util.Objects.requireNonNull; @ThreadSafe @@ -123,6 +124,7 @@ public void stop() catalogs.clear(); } + @Override public void loadInitialCatalogs() { if (!state.compareAndSet(State.CREATED, State.INITIALIZED)) { @@ -169,19 +171,9 @@ public void registerGlobalSystemConnector(GlobalSystemConnector connector) } } - @VisibleForTesting + @Override public CatalogHandle createCatalog(String catalogName, String connectorName, Map properties) { - requireNonNull(catalogName, "catalogName is null"); - requireNonNull(connectorName, "connectorName is null"); - requireNonNull(properties, "properties is null"); - - checkState(state.get() != State.STOPPED, "Catalog manager is stopped"); - - CatalogConnector catalog = catalogFactory.createCatalog(new CatalogProperties(createRootCatalogHandle(catalogName), connectorName, properties)); - if (catalogs.putIfAbsent(catalogName, catalog) != null) { - throw new IllegalStateException(String.format("Catalog '%s' already exists", catalogName)); - } - return catalog.getCatalogHandle(); + throw new TrinoException(NOT_SUPPORTED, "Create catalog is not supported by the static catalog manager"); } } diff --git a/core/trino-main/src/main/java/io/trino/connector/StaticCatalogManagerModule.java b/core/trino-main/src/main/java/io/trino/connector/StaticCatalogManagerModule.java new file mode 100644 index 0000000000000..52755be568b38 --- /dev/null +++ b/core/trino-main/src/main/java/io/trino/connector/StaticCatalogManagerModule.java @@ -0,0 +1,53 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.trino.connector; + +import com.google.inject.Binder; +import com.google.inject.Module; +import com.google.inject.Scopes; +import io.trino.connector.system.GlobalSystemConnector; +import io.trino.metadata.CatalogManager; + +import javax.inject.Inject; + +import static io.airlift.configuration.ConfigBinder.configBinder; + +public class StaticCatalogManagerModule + implements Module +{ + @Override + public void configure(Binder binder) + { + configBinder(binder).bindConfig(StaticCatalogManagerConfig.class); + binder.bind(StaticCatalogManager.class).in(Scopes.SINGLETON); + binder.bind(ConnectorServicesProvider.class).to(StaticCatalogManager.class).in(Scopes.SINGLETON); + binder.bind(CatalogManager.class).to(StaticCatalogManager.class).in(Scopes.SINGLETON); + + binder.bind(LazyRegister.class).asEagerSingleton(); + } + + private static class LazyRegister + { + @Inject + public LazyRegister( + DefaultCatalogFactory defaultCatalogFactory, + LazyCatalogFactory lazyCatalogFactory, + StaticCatalogManager catalogManager, + GlobalSystemConnector globalSystemConnector) + { + lazyCatalogFactory.setCatalogFactory(defaultCatalogFactory); + catalogManager.registerGlobalSystemConnector(globalSystemConnector); + } + } +} diff --git a/core/trino-main/src/main/java/io/trino/metadata/CatalogManager.java b/core/trino-main/src/main/java/io/trino/metadata/CatalogManager.java index e6dfb5636abc5..cc8c8e75d2a7e 100644 --- a/core/trino-main/src/main/java/io/trino/metadata/CatalogManager.java +++ b/core/trino-main/src/main/java/io/trino/metadata/CatalogManager.java @@ -14,7 +14,9 @@ package io.trino.metadata; import com.google.common.collect.ImmutableSet; +import io.trino.connector.CatalogHandle; +import java.util.Map; import java.util.Optional; import java.util.Set; @@ -33,9 +35,17 @@ public Optional getCatalog(String catalogName) { return Optional.empty(); } + + @Override + public CatalogHandle createCatalog(String catalogName, String connectorName, Map properties) + { + throw new UnsupportedOperationException(); + } }; Set getCatalogNames(); Optional getCatalog(String catalogName); + + CatalogHandle createCatalog(String catalogName, String connectorName, Map properties); } diff --git a/core/trino-main/src/main/java/io/trino/server/Server.java b/core/trino-main/src/main/java/io/trino/server/Server.java index 4574cd5142e95..0753ba44cd5d6 100644 --- a/core/trino-main/src/main/java/io/trino/server/Server.java +++ b/core/trino-main/src/main/java/io/trino/server/Server.java @@ -42,7 +42,6 @@ import io.trino.connector.CatalogManagerModule; import io.trino.connector.ConnectorServices; import io.trino.connector.ConnectorServicesProvider; -import io.trino.connector.StaticCatalogManager; import io.trino.eventlistener.EventListenerManager; import io.trino.eventlistener.EventListenerModule; import io.trino.exchange.ExchangeManagerModule; @@ -134,7 +133,7 @@ private void doStart(String trinoVersion) injector.getInstance(PluginManager.class).loadPlugins(); - injector.getInstance(StaticCatalogManager.class).loadInitialCatalogs(); + injector.getInstance(ConnectorServicesProvider.class).loadInitialCatalogs(); // Connector event listeners are only supported for statically loaded catalogs // TODO: remove connector event listeners or add support for dynamic loading from connector diff --git a/core/trino-main/src/main/java/io/trino/server/testing/TestingTrinoServer.java b/core/trino-main/src/main/java/io/trino/server/testing/TestingTrinoServer.java index bdad2e2420f93..3fe2c9562f422 100644 --- a/core/trino-main/src/main/java/io/trino/server/testing/TestingTrinoServer.java +++ b/core/trino-main/src/main/java/io/trino/server/testing/TestingTrinoServer.java @@ -41,7 +41,6 @@ import io.trino.connector.CatalogHandle; import io.trino.connector.CatalogManagerModule; import io.trino.connector.ConnectorServicesProvider; -import io.trino.connector.StaticCatalogManager; import io.trino.cost.StatsCalculator; import io.trino.dispatcher.DispatchManager; import io.trino.eventlistener.EventListenerConfig; @@ -152,7 +151,7 @@ public static Builder builder() private final boolean preserveData; private final LifeCycleManager lifeCycleManager; private final PluginManager pluginManager; - private final StaticCatalogManager catalogManager; + private final CatalogManager catalogManager; private final TestingHttpServer server; private final TransactionManager transactionManager; private final Metadata metadata; @@ -237,6 +236,7 @@ private TestingTrinoServer( ImmutableMap.Builder serverProperties = ImmutableMap.builder() .putAll(properties) .put("coordinator", String.valueOf(coordinator)) + .put("catalog.management", "dynamic") .put("task.concurrency", "4") .put("task.max-worker-threads", "4") .put("exchange.client-threads", "4") @@ -309,7 +309,7 @@ private TestingTrinoServer( pluginManager = injector.getInstance(PluginManager.class); - catalogManager = injector.getInstance(StaticCatalogManager.class); + catalogManager = injector.getInstance(CatalogManager.class); server = injector.getInstance(TestingHttpServer.class); transactionManager = injector.getInstance(TransactionManager.class); diff --git a/core/trino-main/src/main/java/io/trino/testing/LocalQueryRunner.java b/core/trino-main/src/main/java/io/trino/testing/LocalQueryRunner.java index cf146511af2cc..489a31ca405c5 100644 --- a/core/trino-main/src/main/java/io/trino/testing/LocalQueryRunner.java +++ b/core/trino-main/src/main/java/io/trino/testing/LocalQueryRunner.java @@ -27,10 +27,9 @@ import io.trino.connector.CatalogHandle; import io.trino.connector.CatalogServiceProviderModule; import io.trino.connector.ConnectorServicesProvider; +import io.trino.connector.CoordinatorDynamicCatalogManager; import io.trino.connector.DefaultCatalogFactory; import io.trino.connector.LazyCatalogFactory; -import io.trino.connector.StaticCatalogManager; -import io.trino.connector.StaticCatalogManagerConfig; import io.trino.connector.system.AnalyzePropertiesSystemTable; import io.trino.connector.system.CatalogSystemTable; import io.trino.connector.system.ColumnPropertiesSystemTable; @@ -291,7 +290,7 @@ public class LocalQueryRunner private final JoinFilterFunctionCompiler joinFilterFunctionCompiler; private final JoinCompiler joinCompiler; private final CatalogFactory catalogFactory; - private final StaticCatalogManager catalogManager; + private final CoordinatorDynamicCatalogManager catalogManager; private final PluginManager pluginManager; private final ExchangeManagerRegistry exchangeManagerRegistry; @@ -351,7 +350,7 @@ private LocalQueryRunner( this.optimizerConfig = new OptimizerConfig(); LazyCatalogFactory catalogFactory = new LazyCatalogFactory(); this.catalogFactory = catalogFactory; - this.catalogManager = new StaticCatalogManager(catalogFactory, new StaticCatalogManagerConfig()); + this.catalogManager = new CoordinatorDynamicCatalogManager(catalogFactory); this.transactionManager = InMemoryTransactionManager.create( new TransactionManagerConfig().setIdleTimeout(new Duration(1, TimeUnit.DAYS)), yieldExecutor, diff --git a/core/trino-main/src/test/java/io/trino/connector/TestCatalogManagerConfig.java b/core/trino-main/src/test/java/io/trino/connector/TestCatalogManagerConfig.java new file mode 100644 index 0000000000000..d72bfe10a7bd1 --- /dev/null +++ b/core/trino-main/src/test/java/io/trino/connector/TestCatalogManagerConfig.java @@ -0,0 +1,47 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.trino.connector; + +import com.google.common.collect.ImmutableMap; +import io.trino.connector.CatalogManagerConfig.CatalogMangerKind; +import org.testng.annotations.Test; + +import java.util.Map; + +import static io.airlift.configuration.testing.ConfigAssertions.assertFullMapping; +import static io.airlift.configuration.testing.ConfigAssertions.assertRecordedDefaults; +import static io.airlift.configuration.testing.ConfigAssertions.recordDefaults; + +public class TestCatalogManagerConfig +{ + @Test + public void testDefaults() + { + assertRecordedDefaults(recordDefaults(CatalogManagerConfig.class) + .setCatalogMangerKind(CatalogMangerKind.STATIC)); + } + + @Test + public void testExplicitPropertyMappings() + { + Map properties = ImmutableMap.builder() + .put("catalog.management", "dynamic") + .buildOrThrow(); + + CatalogManagerConfig expected = new CatalogManagerConfig() + .setCatalogMangerKind(CatalogMangerKind.DYNAMIC); + + assertFullMapping(properties, expected); + } +}