You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by tk...@apache.org on 2023/03/24 08:28:32 UTC
[ignite-3] branch main updated: IGNITE-19072 Refactoring of org.apache.ignite.internal.index.IndexManagerTest (#1833)
This is an automated email from the ASF dual-hosted git repository.
tkalkirill pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
The following commit(s) were added to refs/heads/main by this push:
new f2033eeda1 IGNITE-19072 Refactoring of org.apache.ignite.internal.index.IndexManagerTest (#1833)
f2033eeda1 is described below
commit f2033eeda139042d4cf99388cb7244f31bb61617
Author: Kirill Tkalenko <tk...@yandex.ru>
AuthorDate: Fri Mar 24 11:28:25 2023 +0300
IGNITE-19072 Refactoring of org.apache.ignite.internal.index.IndexManagerTest (#1833)
---
.../internal/catalog/CatalogServiceSelfTest.java | 8 +-
.../CompletableFutureExceptionMatcher.java | 70 ++++-
.../ignite/internal/index/IndexManagerTest.java | 290 +++++----------------
.../SchemaDistributedConfigurationModule.java | 8 +-
.../AbstractTableIndexValidatorTest.java | 66 -----
.../SchemaDistributedConfigurationModuleTest.java | 5 +-
.../configuration/TableValidatorImplTest.java | 46 +++-
.../index/IndexValidatorImplTest.java | 137 ++++++++++
.../TableDistributedConfigurationModule.java | 43 ---
.../TableDistributedConfigurationModuleTest.java | 73 ------
10 files changed, 316 insertions(+), 430 deletions(-)
diff --git a/modules/catalog/src/test/java/org/apache/ignite/internal/catalog/CatalogServiceSelfTest.java b/modules/catalog/src/test/java/org/apache/ignite/internal/catalog/CatalogServiceSelfTest.java
index 9046b44b0b..76dd235bea 100644
--- a/modules/catalog/src/test/java/org/apache/ignite/internal/catalog/CatalogServiceSelfTest.java
+++ b/modules/catalog/src/test/java/org/apache/ignite/internal/catalog/CatalogServiceSelfTest.java
@@ -18,6 +18,7 @@
package org.apache.ignite.internal.catalog;
import static org.apache.ignite.internal.testframework.matchers.CompletableFutureExceptionMatcher.willThrowFast;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willBe;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -34,7 +35,6 @@ import org.apache.ignite.internal.catalog.commands.DefaultValue;
import org.apache.ignite.internal.catalog.descriptors.SchemaDescriptor;
import org.apache.ignite.internal.catalog.descriptors.TableDescriptor;
import org.apache.ignite.internal.metastorage.MetaStorageManager;
-import org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher;
import org.apache.ignite.lang.TableAlreadyExistsException;
import org.apache.ignite.sql.ColumnType;
import org.junit.jupiter.api.Test;
@@ -93,7 +93,7 @@ public class CatalogServiceSelfTest {
CompletableFuture<?> fut = service.createTable(params);
- assertThat(fut, CompletableFutureMatcher.willBe(true));
+ assertThat(fut, willBe(true));
// Validate catalog version from the past.
SchemaDescriptor schema = service.schema(0);
@@ -143,8 +143,8 @@ public class CatalogServiceSelfTest {
.ifTableExists(true)
.build();
- assertThat(service.createTable(params), CompletableFutureMatcher.willBe(true));
- assertThat(service.createTable(params), CompletableFutureMatcher.willBe(false));
+ assertThat(service.createTable(params), willBe(true));
+ assertThat(service.createTable(params), willBe(false));
CompletableFuture<?> fut = service.createTable(
CreateTableParams.builder()
diff --git a/modules/core/src/testFixtures/java/org/apache/ignite/internal/testframework/matchers/CompletableFutureExceptionMatcher.java b/modules/core/src/testFixtures/java/org/apache/ignite/internal/testframework/matchers/CompletableFutureExceptionMatcher.java
index 931eb9c1ea..17152bbb8d 100644
--- a/modules/core/src/testFixtures/java/org/apache/ignite/internal/testframework/matchers/CompletableFutureExceptionMatcher.java
+++ b/modules/core/src/testFixtures/java/org/apache/ignite/internal/testframework/matchers/CompletableFutureExceptionMatcher.java
@@ -17,6 +17,7 @@
package org.apache.ignite.internal.testframework.matchers;
+import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
@@ -29,6 +30,7 @@ import java.util.concurrent.TimeoutException;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
+import org.jetbrains.annotations.Nullable;
/**
* {@link Matcher} that awaits for the given future to complete exceptionally and the forwards the exception to the nested matcher.
@@ -46,6 +48,8 @@ public class CompletableFutureExceptionMatcher extends TypeSafeMatcher<Completab
private final TimeUnit timeUnit;
+ private final @Nullable Matcher<String> errorMessageFragmentMatcher;
+
/**
* Constructor.
*
@@ -54,12 +58,20 @@ public class CompletableFutureExceptionMatcher extends TypeSafeMatcher<Completab
* or every exception in the stacktrace is explored.
* @param timeout Timeout value.
* @param timeUnit Timeout unit.
+ * @param errorMessageFragment Expected error message fragment, {@code null} if any message is expected.
*/
- private CompletableFutureExceptionMatcher(Matcher<? extends Exception> matcher, boolean inspectCause, int timeout, TimeUnit timeUnit) {
+ private CompletableFutureExceptionMatcher(
+ Matcher<? extends Exception> matcher,
+ boolean inspectCause,
+ int timeout,
+ TimeUnit timeUnit,
+ @Nullable String errorMessageFragment
+ ) {
this.matcher = matcher;
this.inspectCause = inspectCause;
this.timeout = timeout;
this.timeUnit = timeUnit;
+ this.errorMessageFragmentMatcher = errorMessageFragment == null ? null : containsString(errorMessageFragment);
}
@Override
@@ -71,13 +83,22 @@ public class CompletableFutureExceptionMatcher extends TypeSafeMatcher<Completab
} catch (Throwable e) {
Throwable unwrapped = unwrapThrowable(e);
- return inspectCause ? matchesWithCause(unwrapped) : matcher.matches(unwrapped);
+ return inspectCause ? matchesWithCause(unwrapped) : matchesException(unwrapped);
}
}
+ private boolean matchesException(Throwable throwable) {
+ return matcher.matches(throwable)
+ && (errorMessageFragmentMatcher == null || errorMessageFragmentMatcher.matches(throwable.getMessage()));
+ }
+
@Override
public void describeTo(Description description) {
description.appendText("a future that completes with an exception that ").appendDescriptionOf(matcher);
+
+ if (errorMessageFragmentMatcher != null) {
+ description.appendText(" and error message that contains ").appendDescriptionOf(errorMessageFragmentMatcher);
+ }
}
@Override
@@ -105,7 +126,7 @@ public class CompletableFutureExceptionMatcher extends TypeSafeMatcher<Completab
private boolean matchesWithCause(Throwable e) {
for (Throwable current = e; current != null; current = current.getCause()) {
- if (matcher.matches(current) || Arrays.stream(current.getSuppressed()).anyMatch(this::matchesWithCause)) {
+ if (matchesException(current) || Arrays.stream(current.getSuppressed()).anyMatch(this::matchesWithCause)) {
return true;
}
@@ -121,14 +142,28 @@ public class CompletableFutureExceptionMatcher extends TypeSafeMatcher<Completab
* Creates a matcher that matches a future that completes exceptionally and the exception matches the nested matcher.
*/
public static CompletableFutureExceptionMatcher willThrow(Matcher<? extends Exception> matcher) {
- return new CompletableFutureExceptionMatcher(matcher, false, TIMEOUT_SECONDS, TimeUnit.SECONDS);
+ return new CompletableFutureExceptionMatcher(matcher, false, TIMEOUT_SECONDS, TimeUnit.SECONDS, null);
}
/**
* Creates a matcher that matches a future that completes exceptionally and the exception matches the nested matcher.
*/
public static CompletableFutureExceptionMatcher willThrow(Matcher<? extends Exception> matcher, int timeout, TimeUnit timeUnit) {
- return new CompletableFutureExceptionMatcher(matcher, false, timeout, timeUnit);
+ return new CompletableFutureExceptionMatcher(matcher, false, timeout, timeUnit, null);
+ }
+
+ /**
+ * Creates a matcher that matches a future that completes exceptionally and the exception matches the nested matcher.
+ */
+ public static CompletableFutureExceptionMatcher willThrow(
+ Matcher<? extends Exception> matcher,
+ int timeout,
+ TimeUnit timeUnit,
+ String errorMessageFragment
+ ) {
+ assert errorMessageFragment != null;
+
+ return new CompletableFutureExceptionMatcher(matcher, false, timeout, timeUnit, errorMessageFragment);
}
/**
@@ -145,6 +180,18 @@ public class CompletableFutureExceptionMatcher extends TypeSafeMatcher<Completab
return willThrow(is(instanceOf(cls)), timeout, timeUnit);
}
+ /**
+ * Creates a matcher that matches a future that completes with an exception of the provided type.
+ */
+ public static CompletableFutureExceptionMatcher willThrow(
+ Class<? extends Exception> cls,
+ int timeout,
+ TimeUnit timeUnit,
+ String errorMessageFragment
+ ) {
+ return willThrow(is(instanceOf(cls)), timeout, timeUnit, errorMessageFragment);
+ }
+
/**
* Creates a matcher that matches a future that completes exceptionally and decently fast.
*
@@ -155,11 +202,22 @@ public class CompletableFutureExceptionMatcher extends TypeSafeMatcher<Completab
return willThrow(cls, 1, TimeUnit.SECONDS);
}
+ /**
+ * Creates a matcher that matches a future that completes exceptionally and decently fast.
+ *
+ * @param cls The class of cause throwable.
+ * @param errorMessageFragment Expected error message fragment.
+ * @return matcher.
+ */
+ public static CompletableFutureExceptionMatcher willThrowFast(Class<? extends Exception> cls, String errorMessageFragment) {
+ return willThrow(cls, 1, TimeUnit.SECONDS, errorMessageFragment);
+ }
+
/**
* Creates a matcher that matches a future that completes with an exception that has a given {@code cause} in the exception stacktrace.
*/
public static CompletableFutureExceptionMatcher willThrowWithCauseOrSuppressed(Class<? extends Exception> cause) {
- return new CompletableFutureExceptionMatcher(is(instanceOf(cause)), true, TIMEOUT_SECONDS, TimeUnit.SECONDS);
+ return new CompletableFutureExceptionMatcher(is(instanceOf(cause)), true, TIMEOUT_SECONDS, TimeUnit.SECONDS, null);
}
/**
diff --git a/modules/index/src/test/java/org/apache/ignite/internal/index/IndexManagerTest.java b/modules/index/src/test/java/org/apache/ignite/internal/index/IndexManagerTest.java
index 98b17fdc0f..a072fb3caa 100644
--- a/modules/index/src/test/java/org/apache/ignite/internal/index/IndexManagerTest.java
+++ b/modules/index/src/test/java/org/apache/ignite/internal/index/IndexManagerTest.java
@@ -17,17 +17,14 @@
package org.apache.ignite.internal.index;
-import static org.apache.ignite.configuration.annotation.ConfigurationType.DISTRIBUTED;
-import static org.apache.ignite.internal.testframework.IgniteTestUtils.assertThrowsWithCause;
-import static org.apache.ignite.internal.testframework.IgniteTestUtils.await;
+import static java.util.concurrent.CompletableFuture.completedFuture;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureExceptionMatcher.willThrowFast;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
import static org.apache.ignite.lang.IgniteStringFormatter.format;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.notNullValue;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
@@ -38,51 +35,27 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
-import java.util.Set;
import java.util.UUID;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.CompletionException;
-import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
-import org.apache.ignite.configuration.NamedConfigurationTree;
-import org.apache.ignite.configuration.validation.ConfigurationValidationException;
-import org.apache.ignite.internal.configuration.ConfigurationRegistry;
-import org.apache.ignite.internal.configuration.NamedListConfiguration;
-import org.apache.ignite.internal.configuration.storage.TestConfigurationStorage;
import org.apache.ignite.internal.configuration.testframework.ConfigurationExtension;
+import org.apache.ignite.internal.configuration.testframework.InjectConfiguration;
import org.apache.ignite.internal.configuration.tree.ConverterToMapVisitor;
import org.apache.ignite.internal.configuration.tree.TraversableTreeNode;
import org.apache.ignite.internal.index.event.IndexEvent;
import org.apache.ignite.internal.index.event.IndexEventParameters;
import org.apache.ignite.internal.schema.SchemaManager;
import org.apache.ignite.internal.schema.configuration.ExtendedTableChange;
-import org.apache.ignite.internal.schema.configuration.ExtendedTableConfigurationSchema;
-import org.apache.ignite.internal.schema.configuration.TableChange;
-import org.apache.ignite.internal.schema.configuration.TableConfiguration;
-import org.apache.ignite.internal.schema.configuration.TableValidatorImpl;
-import org.apache.ignite.internal.schema.configuration.TableView;
+import org.apache.ignite.internal.schema.configuration.ExtendedTableConfiguration;
import org.apache.ignite.internal.schema.configuration.TablesConfiguration;
-import org.apache.ignite.internal.schema.configuration.defaultvalue.ConstantValueDefaultConfigurationSchema;
-import org.apache.ignite.internal.schema.configuration.defaultvalue.FunctionCallDefaultConfigurationSchema;
-import org.apache.ignite.internal.schema.configuration.defaultvalue.NullValueDefaultConfigurationSchema;
-import org.apache.ignite.internal.schema.configuration.index.HashIndexChange;
-import org.apache.ignite.internal.schema.configuration.index.HashIndexConfigurationSchema;
-import org.apache.ignite.internal.schema.configuration.index.IndexValidatorImpl;
import org.apache.ignite.internal.schema.configuration.index.SortedIndexChange;
-import org.apache.ignite.internal.schema.configuration.index.SortedIndexConfigurationSchema;
-import org.apache.ignite.internal.schema.configuration.index.TableIndexConfiguration;
-import org.apache.ignite.internal.schema.configuration.storage.UnknownDataStorageConfigurationSchema;
import org.apache.ignite.internal.table.InternalTable;
import org.apache.ignite.internal.table.TableImpl;
import org.apache.ignite.internal.table.distributed.TableManager;
-import org.apache.ignite.internal.testframework.IgniteTestUtils;
import org.apache.ignite.internal.tx.impl.HeapLockManager;
-import org.apache.ignite.lang.ErrorGroups;
import org.apache.ignite.lang.IgniteInternalException;
import org.apache.ignite.lang.IndexNotFoundException;
-import org.apache.ignite.lang.TableNotFoundException;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito;
@@ -92,91 +65,55 @@ import org.mockito.Mockito;
*/
@ExtendWith(ConfigurationExtension.class)
public class IndexManagerTest {
- /** Configuration registry with one table for each test. */
- private static ConfigurationRegistry confRegistry;
-
- /** Tables configuration. */
- private static TablesConfiguration tablesConfig;
-
- /** Index manager. */
- private static IndexManager indexManager;
-
- /** Per test unique index name. */
- private static AtomicInteger index = new AtomicInteger();
-
- /**
- * Common components initialization.
- */
- @BeforeAll
- public static void setUp() throws Exception {
- confRegistry = new ConfigurationRegistry(
- List.of(TablesConfiguration.KEY),
- Set.of(IndexValidatorImpl.INSTANCE, TableValidatorImpl.INSTANCE),
- new TestConfigurationStorage(DISTRIBUTED),
- List.of(ExtendedTableConfigurationSchema.class),
- List.of(
- HashIndexConfigurationSchema.class,
- SortedIndexConfigurationSchema.class,
-
- UnknownDataStorageConfigurationSchema.class,
- ConstantValueDefaultConfigurationSchema.class,
- FunctionCallDefaultConfigurationSchema.class,
- NullValueDefaultConfigurationSchema.class
- )
- );
+ @InjectConfiguration(
+ "mock.tables.tName {"
+ + "columns.c1 {type.type: STRING}, "
+ + "columns.c2 {type.type: STRING}, "
+ + "primaryKey {columns: [c1], colocationColumns: [c1]}"
+ + "}"
+ )
+ private TablesConfiguration tablesConfig;
- confRegistry.start();
+ private IndexManager indexManager;
- tablesConfig = confRegistry.getConfiguration(TablesConfiguration.KEY);
-
- TableManager tableManagerMock = Mockito.mock(TableManager.class);
- Map<UUID, TableImpl> tables = Mockito.mock(Map.class);
+ @BeforeEach
+ public void setUp() {
+ TableManager tableManagerMock = mock(TableManager.class);
when(tableManagerMock.tableAsync(anyLong(), any(UUID.class))).thenAnswer(inv -> {
- InternalTable tbl = Mockito.mock(InternalTable.class);
+ InternalTable tbl = mock(InternalTable.class);
+
Mockito.doReturn(inv.getArgument(1)).when(tbl).tableId();
- return CompletableFuture.completedFuture(
- new TableImpl(tbl, new HeapLockManager(), () -> CompletableFuture.completedFuture(List.of())));
+
+ return completedFuture(new TableImpl(tbl, new HeapLockManager(), () -> completedFuture(List.of())));
});
SchemaManager schManager = mock(SchemaManager.class);
- when(schManager.schemaRegistry(anyLong(), any())).thenReturn(CompletableFuture.completedFuture(null));
+
+ when(schManager.schemaRegistry(anyLong(), any())).thenReturn(completedFuture(null));
indexManager = new IndexManager(tablesConfig, schManager, tableManagerMock);
indexManager.start();
- tablesConfig.tables().change(tableChange -> tableChange.create("tName", chg -> {
- chg.changeColumns(cols -> cols
- .create("c1", col -> col.changeType(t -> t.changeType("STRING")))
- .create("c2", col -> col.changeType(t -> t.changeType("STRING"))));
-
- chg.changePrimaryKey(pk -> pk.changeColumns("c1").changeColocationColumns("c1"));
-
- ((ExtendedTableChange) chg).changeAssignments((byte) 1).changeSchemaId(1);
- })).get();
+ assertThat(
+ tablesConfig.tables().get("tName")
+ .change(tableChange -> ((ExtendedTableChange) tableChange).changeSchemaId(1).changeAssignments((byte) 1)),
+ willCompleteSuccessfully()
+ );
}
- /**
- * Sweep all necessary.
- */
- @AfterAll
- public static void tearDown() throws Exception {
- confRegistry.stop();
+ @AfterEach
+ void tearDown() throws Exception {
+ if (indexManager != null) {
+ indexManager.stop();
+ }
}
@Test
void configurationChangedWhenCreateIsInvoked() {
- String indexName = "idx" + index.incrementAndGet();
-
- NamedConfigurationTree<TableConfiguration, TableView, TableChange> cfg0 = tablesConfig.tables();
+ String indexName = "idx";
- List<UUID> ids = ((NamedListConfiguration<TableConfiguration, ?, ?>) cfg0).internalIds();
-
- assertEquals(1, ids.size());
-
- UUID tableId = ids.get(0);
-
- indexManager.createIndexAsync("sName", indexName, "tName", true, indexChange -> {
+ assertThat(indexManager.createIndexAsync("sName", indexName, "tName", true, indexChange -> {
SortedIndexChange sortedIndexChange = indexChange.convert(SortedIndexChange.class);
sortedIndexChange.changeColumns(columns -> {
@@ -184,8 +121,8 @@ public class IndexManagerTest {
columns.create("c2", columnChange -> columnChange.changeAsc(false));
});
- sortedIndexChange.changeTableId(tableId);
- }).join();
+ sortedIndexChange.changeTableId(tableId());
+ }), willCompleteSuccessfully());
var expected = List.of(
Map.of(
@@ -202,182 +139,75 @@ public class IndexManagerTest {
"name", indexName,
"type", "SORTED",
"uniq", false,
- "tableId", tableId.toString()
+ "tableId", tableId().toString()
)
);
assertSameObjects(expected, toMap(tablesConfig.indexes().value()));
}
- @Test
- public void createIndexForNonExistingTable() {
- CompletionException completionException = assertThrows(
- CompletionException.class,
- () -> indexManager.createIndexAsync("sName", "idx", "tName_notExist", true, indexChange -> {/* doesn't matter */}).join()
- );
-
- assertTrue(IgniteTestUtils.hasCause(completionException, TableNotFoundException.class,
- "The table does not exist [name=\"sName\".\"tName_notExist\"]"));
- }
-
@Test
public void createIndexWithEmptyName() {
- CompletionException completionException = assertThrows(
- CompletionException.class,
- () -> indexManager.createIndexAsync("sName", "", "tName", true, indexChange -> {/* doesn't matter */}).join()
- );
-
- assertThat(completionException.getCause(), instanceOf(IgniteInternalException.class));
assertThat(
- ((IgniteInternalException) completionException.getCause()).code(),
- equalTo(ErrorGroups.Index.INVALID_INDEX_DEFINITION_ERR)
- );
- }
-
- @Test
- public void createIndexWithEmptyColumnList() {
- String indexTitle = "idx" + index.incrementAndGet();
-
- CompletionException completionException = assertThrows(
- CompletionException.class,
- () -> indexManager.createIndexAsync("sName", indexTitle, "tName", true,
- indexChange -> indexChange.convert(HashIndexChange.class).changeColumnNames()
- .changeTableId(UUID.randomUUID())).join()
- );
-
- assertTrue(IgniteTestUtils.hasCause(completionException, ConfigurationValidationException.class,
- "Index must include at least one column"));
- }
-
- @Test
- public void createIndexForNonExistingColumn() {
- String indexName = "idx" + index.incrementAndGet();
-
- CompletionException completionException = assertThrows(
- CompletionException.class,
- () -> indexManager.createIndexAsync("sName", indexName, "tName", true,
- indexChange ->
- indexChange.convert(HashIndexChange.class).changeColumnNames("nonExistingColumn")
- .changeTableId(UUID.randomUUID())).join()
+ indexManager.createIndexAsync("sName", "", "tName", true, indexChange -> {/* doesn't matter */}),
+ willThrowFast(IgniteInternalException.class, "Index name should be at least 1 character long")
);
-
- assertTrue(IgniteTestUtils.hasCause(completionException, ConfigurationValidationException.class,
- "Columns don't exist"));
}
@Test
public void dropNonExistingIndex() {
- CompletionException completionException = assertThrows(
- CompletionException.class,
- () -> indexManager.dropIndexAsync("sName", "nonExisting", true).join()
+ assertThat(
+ indexManager.dropIndexAsync("sName", "nonExisting", true),
+ willThrowFast(IndexNotFoundException.class, "Index does not exist [name=\"sName\".\"nonExisting\"]")
);
-
- assertTrue(IgniteTestUtils.hasCause(completionException, IndexNotFoundException.class,
- "Index does not exist [name=\"sName\".\"nonExisting\"]"));
}
@Test
@SuppressWarnings("ConstantConditions")
public void eventIsFiredWhenIndexCreated() {
- String indexName = "idx" + index.incrementAndGet();
+ String indexName = "idx";
AtomicReference<IndexEventParameters> holder = new AtomicReference<>();
indexManager.listen(IndexEvent.CREATE, (param, th) -> {
holder.set(param);
- return CompletableFuture.completedFuture(true);
+ return completedFuture(true);
});
indexManager.listen(IndexEvent.DROP, (param, th) -> {
holder.set(param);
- return CompletableFuture.completedFuture(true);
+ return completedFuture(true);
});
- indexManager.start();
-
- NamedConfigurationTree<TableConfiguration, TableView, TableChange> cfg0 = tablesConfig.tables();
-
- List<UUID> ids = ((NamedListConfiguration<TableConfiguration, ?, ?>) cfg0).internalIds();
-
- assertEquals(1, ids.size());
-
- UUID tableId = ids.get(0);
-
- indexManager.createIndexAsync("sName", indexName, "tName", true, indexChange -> {
+ assertThat(indexManager.createIndexAsync("sName", indexName, "tName", true, indexChange -> {
SortedIndexChange sortedIndexChange = indexChange.convert(SortedIndexChange.class);
sortedIndexChange.changeColumns(columns -> {
columns.create("c2", columnChange -> columnChange.changeAsc(true));
});
- sortedIndexChange.changeTableId(tableId);
- }).join();
+ sortedIndexChange.changeTableId(tableId());
+ }), willCompleteSuccessfully());
- ids = ((NamedListConfiguration<TableIndexConfiguration, ?, ?>) tablesConfig.indexes()).internalIds();
+ List<UUID> indexIds = tablesConfig.indexes().internalIds();
- assertEquals(1, ids.size());
+ assertThat(indexIds, hasSize(1));
- UUID indexId = ids.get(0);
+ UUID indexId = indexIds.get(0);
assertThat(holder.get(), notNullValue());
assertThat(holder.get().indexId(), equalTo(indexId));
- assertThat(holder.get().tableId(), equalTo(tableId));
+ assertThat(holder.get().tableId(), equalTo(tableId()));
assertThat(holder.get().indexDescriptor().name(), equalTo(indexName));
- indexManager.dropIndexAsync("sName", indexName, true).join();
+ assertThat(indexManager.dropIndexAsync("sName", indexName, true), willCompleteSuccessfully());
assertThat(holder.get(), notNullValue());
assertThat(holder.get().indexId(), equalTo(indexId));
}
- @SuppressWarnings("ThrowableNotThrown")
- @Test
- public void createIndexWithExistingTableName() {
- CompletableFuture<Boolean> createIdxFut = indexManager.createIndexAsync("sName", "tName", "tName", true, indexChange ->
- indexChange.convert(SortedIndexChange.class).changeColumns(columns ->
- columns.create("c2", columnChange -> columnChange.changeAsc(true))));
-
- assertThrowsWithCause(() -> await(createIdxFut), ConfigurationValidationException.class,
- "Table with the same name already exists.");
- }
-
- @SuppressWarnings("ThrowableNotThrown")
- @Test
- public void createTableWithExistingIndexName() {
- String indexName = "idx" + index.incrementAndGet();
-
- List<UUID> ids = ((NamedListConfiguration<TableConfiguration, ?, ?>) tablesConfig.tables()).internalIds();
- assertEquals(1, ids.size());
-
- UUID tableId = ids.get(0);
-
- boolean created = indexManager.createIndexAsync("sName", indexName, "tName", true, indexChange -> {
- SortedIndexChange sortedIndexChange = indexChange.convert(SortedIndexChange.class);
-
- sortedIndexChange.changeColumns(columns -> {
- columns.create("c2", columnChange -> columnChange.changeAsc(true));
- });
-
- sortedIndexChange.changeTableId(tableId);
- }).join();
-
- assertTrue(created);
-
- try {
- CompletableFuture<Void> createTblFut = tablesConfig.tables().change(tableChange -> tableChange.create(indexName, chg -> {
- chg.changeColumns(cols -> cols.create("c1", col -> col.changeType(t -> t.changeType("STRING"))))
- .changePrimaryKey(pk -> pk.changeColumns("c1").changeColocationColumns("c1"));
- }));
-
- assertThrowsWithCause(() -> await(createTblFut), ConfigurationValidationException.class,
- "Index with the same name already exists.");
- } finally {
- indexManager.dropIndexAsync("sName", indexName, true).join();
- }
- }
-
private static Object toMap(Object obj) {
assert obj instanceof TraversableTreeNode;
@@ -452,10 +282,14 @@ public class IndexManagerTest {
private final List<String> path = new ArrayList<>();
- public ObjectsNotEqualException(Object o1, Object o2) {
+ ObjectsNotEqualException(Object o1, Object o2) {
super(null, null, false, false);
this.o1 = o1;
this.o2 = o2;
}
}
+
+ private UUID tableId() {
+ return ((ExtendedTableConfiguration) tablesConfig.tables().get("tName")).id().value();
+ }
}
diff --git a/modules/schema/src/main/java/org/apache/ignite/internal/schema/configuration/SchemaDistributedConfigurationModule.java b/modules/schema/src/main/java/org/apache/ignite/internal/schema/configuration/SchemaDistributedConfigurationModule.java
index 7ca4907ce3..b0927b5bec 100644
--- a/modules/schema/src/main/java/org/apache/ignite/internal/schema/configuration/SchemaDistributedConfigurationModule.java
+++ b/modules/schema/src/main/java/org/apache/ignite/internal/schema/configuration/SchemaDistributedConfigurationModule.java
@@ -39,7 +39,6 @@ import org.apache.ignite.internal.schema.configuration.storage.UnknownDataStorag
*/
@AutoService(ConfigurationModule.class)
public class SchemaDistributedConfigurationModule implements ConfigurationModule {
- /** {@inheritDoc} */
@Override
public ConfigurationType type() {
return ConfigurationType.DISTRIBUTED;
@@ -50,7 +49,6 @@ public class SchemaDistributedConfigurationModule implements ConfigurationModule
return List.of(TablesConfiguration.KEY);
}
- /** {@inheritDoc} */
@Override
public Set<Validator<?, ?>> validators() {
return Set.of(
@@ -61,7 +59,6 @@ public class SchemaDistributedConfigurationModule implements ConfigurationModule
);
}
- /** {@inheritDoc} */
@Override
public Collection<Class<?>> polymorphicSchemaExtensions() {
return List.of(
@@ -73,4 +70,9 @@ public class SchemaDistributedConfigurationModule implements ConfigurationModule
SortedIndexConfigurationSchema.class
);
}
+
+ @Override
+ public Collection<Class<?>> internalSchemaExtensions() {
+ return List.of(ExtendedTableConfigurationSchema.class);
+ }
}
diff --git a/modules/schema/src/test/java/org/apache/ignite/internal/schema/configuration/AbstractTableIndexValidatorTest.java b/modules/schema/src/test/java/org/apache/ignite/internal/schema/configuration/AbstractTableIndexValidatorTest.java
deleted file mode 100644
index 03ef4606b6..0000000000
--- a/modules/schema/src/test/java/org/apache/ignite/internal/schema/configuration/AbstractTableIndexValidatorTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 org.apache.ignite.internal.schema.configuration;
-
-import org.apache.ignite.internal.configuration.testframework.ConfigurationExtension;
-import org.apache.ignite.internal.configuration.testframework.InjectConfiguration;
-import org.apache.ignite.internal.schema.configuration.index.HashIndexConfigurationSchema;
-import org.apache.ignite.internal.schema.configuration.index.SortedIndexConfigurationSchema;
-import org.apache.ignite.internal.schema.testutils.SchemaConfigurationConverter;
-import org.apache.ignite.internal.schema.testutils.builder.SchemaBuilders;
-import org.apache.ignite.internal.schema.testutils.builder.TableDefinitionBuilder;
-import org.apache.ignite.internal.schema.testutils.definition.ColumnType;
-import org.apache.ignite.internal.schema.testutils.definition.TableDefinition;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.extension.ExtendWith;
-
-/**
- * Base class for table and index validation tests.
- */
-@ExtendWith(ConfigurationExtension.class)
-public class AbstractTableIndexValidatorTest {
- /** Basic table configuration to mutate and then validate. */
- @InjectConfiguration(
- polymorphicExtensions = {
- HashIndexConfigurationSchema.class,
- SortedIndexConfigurationSchema.class,
- }
- )
- protected TablesConfiguration tablesCfg;
-
- @BeforeEach
- public void setup() throws Exception {
- final TableDefinitionBuilder builder = SchemaBuilders.tableBuilder("schema", "table");
-
- TableDefinition def = builder
- .columns(
- SchemaBuilders.column("id", ColumnType.INT32).build(),
- SchemaBuilders.column("affId", ColumnType.INT32).build(),
- SchemaBuilders.column("id2", ColumnType.string()).asNullable(true).build()
- )
-
- .withPrimaryKey(
- SchemaBuilders.primaryKey() // Declare index column in order.
- .withColumns("affId", "id")
- .withColocationColumns("affId")
- .build()
- ).build();
-
- tablesCfg.tables().change(c -> c.create("schema.table", tblChg -> SchemaConfigurationConverter.convert(def, tblChg))).get();
- }
-}
diff --git a/modules/schema/src/test/java/org/apache/ignite/internal/schema/configuration/SchemaDistributedConfigurationModuleTest.java b/modules/schema/src/test/java/org/apache/ignite/internal/schema/configuration/SchemaDistributedConfigurationModuleTest.java
index 0b527a8e6d..a61fd4d931 100644
--- a/modules/schema/src/test/java/org/apache/ignite/internal/schema/configuration/SchemaDistributedConfigurationModuleTest.java
+++ b/modules/schema/src/test/java/org/apache/ignite/internal/schema/configuration/SchemaDistributedConfigurationModuleTest.java
@@ -20,7 +20,6 @@ package org.apache.ignite.internal.schema.configuration;
import static com.github.npathai.hamcrestopt.OptionalMatchers.isPresent;
import static org.apache.ignite.configuration.annotation.ConfigurationType.DISTRIBUTED;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
@@ -55,8 +54,8 @@ class SchemaDistributedConfigurationModuleTest {
}
@Test
- void providesNoInternalSchemaExtensions() {
- assertThat(module.internalSchemaExtensions(), is(empty()));
+ void providesInternalSchemaExtensions() {
+ assertThat(module.internalSchemaExtensions(), hasItem(ExtendedTableConfigurationSchema.class));
}
@Test
diff --git a/modules/schema/src/test/java/org/apache/ignite/internal/schema/configuration/TableValidatorImplTest.java b/modules/schema/src/test/java/org/apache/ignite/internal/schema/configuration/TableValidatorImplTest.java
index a2d8aede54..d1bc77acee 100644
--- a/modules/schema/src/test/java/org/apache/ignite/internal/schema/configuration/TableValidatorImplTest.java
+++ b/modules/schema/src/test/java/org/apache/ignite/internal/schema/configuration/TableValidatorImplTest.java
@@ -17,24 +17,62 @@
package org.apache.ignite.internal.schema.configuration;
-import static org.apache.ignite.internal.configuration.validation.TestValidationUtil.mockValidationContext;
import static org.apache.ignite.internal.configuration.validation.TestValidationUtil.validate;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import org.apache.ignite.configuration.NamedListView;
import org.apache.ignite.configuration.validation.ValidationContext;
+import org.apache.ignite.internal.configuration.testframework.ConfigurationExtension;
+import org.apache.ignite.internal.configuration.testframework.InjectConfiguration;
+import org.apache.ignite.internal.schema.configuration.index.HashIndexChange;
+import org.jetbrains.annotations.Nullable;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
/**
* TableValidatorImplTest.
* TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
*/
-public class TableValidatorImplTest extends AbstractTableIndexValidatorTest {
+@ExtendWith(ConfigurationExtension.class)
+public class TableValidatorImplTest {
+ @InjectConfiguration(
+ "mock.tables.table {"
+ + "columns.id {type.type: INT32}, "
+ + "columns.affId {type.type: INT32}, "
+ + "columns.id2 {type.type: STRING}, "
+ + "primaryKey {columns: [affId, id], colocationColumns: [affId]}"
+ + "}"
+ )
+ private TablesConfiguration tablesCfg;
+
/** Tests that validator finds no issues in a simple valid configuration. */
@Test
public void testNoIssues() {
- ValidationContext<NamedListView<TableView>> ctx = mockValidationContext(null, tablesCfg.tables().value());
+ validate0((String[]) null);
+ }
+
+ @Test
+ void testCreateTableWithSameIndexName() {
+ assertThat(
+ tablesCfg.indexes().change(indexesChange ->
+ indexesChange.create("table", indexChange -> indexChange.convert(HashIndexChange.class))
+ ),
+ willCompleteSuccessfully()
+ );
+
+ validate0("Unable to create table. Index with the same name already exists.");
+ }
+
+ private void validate0(String @Nullable ... errorMessagePrefixes) {
+ ValidationContext<NamedListView<TableView>> validationContext = mock(ValidationContext.class);
+
+ when(validationContext.getNewValue()).then(invocation -> tablesCfg.tables().value());
+
+ when(validationContext.getNewRoot(TablesConfiguration.KEY)).then(invocation -> tablesCfg.value());
- validate(TableValidatorImpl.INSTANCE, mock(TableValidator.class), ctx);
+ validate(TableValidatorImpl.INSTANCE, mock(TableValidator.class), validationContext, errorMessagePrefixes);
}
}
diff --git a/modules/schema/src/test/java/org/apache/ignite/internal/schema/configuration/index/IndexValidatorImplTest.java b/modules/schema/src/test/java/org/apache/ignite/internal/schema/configuration/index/IndexValidatorImplTest.java
new file mode 100644
index 0000000000..5845335cb3
--- /dev/null
+++ b/modules/schema/src/test/java/org/apache/ignite/internal/schema/configuration/index/IndexValidatorImplTest.java
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.ignite.internal.schema.configuration.index;
+
+import static org.apache.ignite.internal.configuration.validation.TestValidationUtil.validate;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.UUID;
+import java.util.function.Consumer;
+import org.apache.ignite.configuration.NamedListView;
+import org.apache.ignite.configuration.validation.ValidationContext;
+import org.apache.ignite.internal.configuration.testframework.ConfigurationExtension;
+import org.apache.ignite.internal.configuration.testframework.InjectConfiguration;
+import org.apache.ignite.internal.schema.configuration.ExtendedTableConfiguration;
+import org.apache.ignite.internal.schema.configuration.TablesConfiguration;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * For {@link IndexValidatorImpl} testing.
+ */
+@ExtendWith(ConfigurationExtension.class)
+public class IndexValidatorImplTest {
+ @InjectConfiguration("mock.tables.fooTable {columns.column0 {type.type: STRING}}")
+ private TablesConfiguration tablesConfig;
+
+ @Test
+ void testMissingTable() {
+ createIndex("fooIndex", indexChange -> indexChange.convert(HashIndexChange.class));
+ createIndex("barIndex", indexChange -> indexChange.convert(SortedIndexChange.class));
+
+ validate0(
+ "Unable to create index [name=fooIndex]. Table not found.",
+ "Unable to create index [name=barIndex]. Table not found."
+ );
+ }
+
+ @Test
+ void testMissingColumns() {
+ createIndex("fooIndex", indexChange -> indexChange.convert(HashIndexChange.class).changeColumnNames().changeTableId(tableId()));
+ createIndex("barIndex", indexChange -> indexChange.convert(SortedIndexChange.class).changeTableId(tableId()));
+
+ validate0(
+ "Index must include at least one column",
+ "Index must include at least one column"
+ );
+ }
+
+ @Test
+ void testColumnsDoesNotExists() {
+ createIndex(
+ "fooIndex",
+ indexChange -> indexChange.convert(HashIndexChange.class)
+ .changeColumnNames("notExists0")
+ .changeTableId(tableId())
+ );
+
+ createIndex(
+ "barIndex",
+ indexChange -> indexChange.convert(SortedIndexChange.class)
+ .changeColumns(indexColumnsChange -> indexColumnsChange.create("notExists1", indexColumnChange -> {}))
+ .changeTableId(tableId())
+ );
+
+ validate0(
+ "Columns don't exist [columns=[notExists0]]",
+ "Columns don't exist [columns=[notExists1]]"
+ );
+ }
+
+ @Test
+ void testCreateIndexWithSameTableName() {
+ createIndex(
+ "fooTable",
+ indexChange -> indexChange.convert(HashIndexChange.class).changeColumnNames("column0").changeTableId(tableId())
+ );
+
+ validate0("Unable to create index. Table with the same name already exists.");
+ }
+
+ @Test
+ void testCorrectIndexes() {
+ createIndex(
+ "fooIndex",
+ indexChange -> indexChange.convert(HashIndexChange.class).changeColumnNames("column0").changeTableId(tableId())
+ );
+
+ createIndex(
+ "barIndex",
+ indexChange -> indexChange.convert(SortedIndexChange.class)
+ .changeColumns(indexColumnsChange -> indexColumnsChange.create("column0", indexColumnChange -> {}))
+ .changeTableId(tableId())
+ );
+
+ validate0((String[]) null);
+ }
+
+ private void validate0(String @Nullable ... errorMessagePrefixes) {
+ ValidationContext<NamedListView<TableIndexView>> validationContext = mock(ValidationContext.class);
+
+ when(validationContext.getNewValue()).then(invocation -> tablesConfig.indexes().value());
+
+ when(validationContext.getNewRoot(TablesConfiguration.KEY)).then(invocation -> tablesConfig.value());
+
+ validate(IndexValidatorImpl.INSTANCE, mock(IndexValidator.class), validationContext, errorMessagePrefixes);
+ }
+
+ private UUID tableId() {
+ return ((ExtendedTableConfiguration) tablesConfig.tables().get("fooTable")).id().value();
+ }
+
+ private void createIndex(String indexName, Consumer<TableIndexChange> indexChange) {
+ assertThat(
+ tablesConfig.indexes().change(indexesChange -> indexesChange.create(indexName, indexChange)),
+ willCompleteSuccessfully()
+ );
+ }
+}
diff --git a/modules/table/src/main/java/org/apache/ignite/internal/configuration/TableDistributedConfigurationModule.java b/modules/table/src/main/java/org/apache/ignite/internal/configuration/TableDistributedConfigurationModule.java
deleted file mode 100644
index 8ccc66164d..0000000000
--- a/modules/table/src/main/java/org/apache/ignite/internal/configuration/TableDistributedConfigurationModule.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 org.apache.ignite.internal.configuration;
-
-import com.google.auto.service.AutoService;
-import java.util.Collection;
-import java.util.List;
-import org.apache.ignite.configuration.ConfigurationModule;
-import org.apache.ignite.configuration.annotation.ConfigurationType;
-import org.apache.ignite.internal.schema.configuration.ExtendedTableConfigurationSchema;
-
-/**
- * {@link ConfigurationModule} for cluster-wide configuration provided by ignite-table.
- */
-@AutoService(ConfigurationModule.class)
-public class TableDistributedConfigurationModule implements ConfigurationModule {
- /** {@inheritDoc} */
- @Override
- public ConfigurationType type() {
- return ConfigurationType.DISTRIBUTED;
- }
-
- /** {@inheritDoc} */
- @Override
- public Collection<Class<?>> internalSchemaExtensions() {
- return List.of(ExtendedTableConfigurationSchema.class);
- }
-}
diff --git a/modules/table/src/test/java/org/apache/ignite/internal/configuration/TableDistributedConfigurationModuleTest.java b/modules/table/src/test/java/org/apache/ignite/internal/configuration/TableDistributedConfigurationModuleTest.java
deleted file mode 100644
index 120442981e..0000000000
--- a/modules/table/src/test/java/org/apache/ignite/internal/configuration/TableDistributedConfigurationModuleTest.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 org.apache.ignite.internal.configuration;
-
-import static com.github.npathai.hamcrestopt.OptionalMatchers.isPresent;
-import static org.apache.ignite.configuration.annotation.ConfigurationType.DISTRIBUTED;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.empty;
-import static org.hamcrest.Matchers.hasItem;
-import static org.hamcrest.Matchers.is;
-
-import java.util.Optional;
-import java.util.ServiceLoader;
-import org.apache.ignite.configuration.ConfigurationModule;
-import org.apache.ignite.internal.schema.configuration.ExtendedTableConfigurationSchema;
-import org.junit.jupiter.api.Test;
-
-/**
- * Tests for {@link TableDistributedConfigurationModule}.
- */
-class TableDistributedConfigurationModuleTest {
- private final TableDistributedConfigurationModule module = new TableDistributedConfigurationModule();
-
- @Test
- void typeIsDistributed() {
- assertThat(module.type(), is(DISTRIBUTED));
- }
-
- @Test
- void hasNoConfigurationRoots() {
- assertThat(module.rootKeys(), is(empty()));
- }
-
- @Test
- void providesNoValidators() {
- assertThat(module.validators(), is(empty()));
- }
-
- @Test
- void providesExternalTableConfigurationSchemaAsInternalExtension() {
- assertThat(module.internalSchemaExtensions(), hasItem(ExtendedTableConfigurationSchema.class));
- }
-
- @Test
- void providesNoPolymorphicSchemaExtensions() {
- assertThat(module.polymorphicSchemaExtensions(), is(empty()));
- }
-
- @Test
- void isLoadedByServiceLoader() {
- Optional<ConfigurationModule> maybeModule = ServiceLoader.load(ConfigurationModule.class).stream()
- .map(ServiceLoader.Provider::get)
- .filter(module -> module instanceof TableDistributedConfigurationModule)
- .findAny();
-
- assertThat(maybeModule, isPresent());
- }
-}