rpuch commented on code in PR #2448:
URL: https://github.com/apache/ignite-3/pull/2448#discussion_r1294422759


##########
modules/catalog/src/testFixtures/java/org/apache/ignite/internal/catalog/CatalogTestUtils.java:
##########
@@ -0,0 +1,117 @@
+/*
+ * 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.catalog;
+
+import static 
org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import org.apache.ignite.internal.catalog.storage.UpdateLogImpl;
+import org.apache.ignite.internal.hlc.HybridClock;
+import org.apache.ignite.internal.metastorage.MetaStorageManager;
+import 
org.apache.ignite.internal.metastorage.impl.StandaloneMetaStorageManager;
+import 
org.apache.ignite.internal.metastorage.server.SimpleInMemoryKeyValueStorage;
+import org.apache.ignite.internal.vault.VaultManager;
+import org.apache.ignite.internal.vault.inmemory.InMemoryVaultService;
+
+/**
+ * Utilities for working with the catalog in tests.
+ */
+public class CatalogTestUtils {
+    /**
+     * Creates a test implementation of {@link CatalogManager}.
+     *
+     * <p>NOTE: Uses {@link CatalogManagerImpl} under the hood and creates the 
internals he needs, may change in the future.

Review Comment:
   ```suggestion
        * <p>NOTE: Uses {@link CatalogManagerImpl} under the hood and creates 
the internals it needs, may change in the future.
   ```



##########
modules/distribution-zones/src/test/java/org/apache/ignite/internal/distributionzones/BaseDistributionZoneManagerTest.java:
##########
@@ -177,6 +188,14 @@ protected void createZone(
             @Nullable Integer dataNodesAutoAdjustScaleDown,
             @Nullable String filter
     ) {
+        DistributionZonesTestUtil.createZone(

Review Comment:
   These two calls to `createZone()` look almost identically, it's hard to 
distinguish them. Would it make sense to rename both methods to make them look 
like `createZoneInCatalog()` and `createZoneInManager()`?



##########
modules/distribution-zones/src/main/java/org/apache/ignite/internal/distributionzones/rebalance/DistributionZoneRebalanceEngine.java:
##########
@@ -168,30 +138,34 @@ public CompletableFuture<Void> onUpdate(WatchEvent evt) {
 
                     int zoneId = 
extractZoneId(evt.entryEvent().newEntry().key());
 
-                    DistributionZoneView zoneConfig;
+                    // It is safe to get the latest version of the catalog as 
we are in the metastore thread.
+                    int catalogVersion = catalogService.latestCatalogVersion();
 
-                    try {
-                        zoneConfig = getZoneById(zonesConfiguration, 
zoneId).value();
-                    } catch (DistributionZoneNotFoundException e) {
-                        //The zone was removed.
-                        return completedFuture(null);
-                    }
+                    // TODO: IGNITE-20114 Should be get from the catalog 
directly
+                    // CatalogZoneDescriptor zoneDescriptor = 
catalogService.zone(zoneId, catalogVersion);
+
+                    String zoneName = 
distributionZoneManager.getZoneName(zoneId);
+
+                    assert zoneName != null : zoneId;
+
+                    CatalogZoneDescriptor zoneDescriptor = 
catalogService.zones(catalogVersion).stream()

Review Comment:
   Doesn't `zone(String, int)` exist on `CatalogService` to get a zone by name 
at a version? For getting a table, there is such a method, how about adding it 
for zones as well?



##########
modules/distribution-zones/src/main/java/org/apache/ignite/internal/distributionzones/rebalance/DistributionZoneRebalanceEngine.java:
##########
@@ -203,23 +177,27 @@ public CompletableFuture<Void> onUpdate(WatchEvent evt) {
                         // This set is used to deduplicate exceptions (if 
there is an exception from upstream, for instance,
                         // when reading from MetaStorage, it will be 
encountered by every partition future) to avoid noise
                         // in the logs.
-                        Set<Throwable> exceptions = newSetFromMap(new 
ConcurrentHashMap<>());
+                        Set<Throwable> exceptions = 
ConcurrentHashMap.newKeySet();

Review Comment:
   ```suggestion
                           Set<Throwable> unwrappedCauses = 
ConcurrentHashMap.newKeySet();
   ```



##########
modules/catalog/src/testFixtures/java/org/apache/ignite/internal/catalog/CatalogTestUtils.java:
##########
@@ -0,0 +1,117 @@
+/*
+ * 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.catalog;
+
+import static 
org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import org.apache.ignite.internal.catalog.storage.UpdateLogImpl;
+import org.apache.ignite.internal.hlc.HybridClock;
+import org.apache.ignite.internal.metastorage.MetaStorageManager;
+import 
org.apache.ignite.internal.metastorage.impl.StandaloneMetaStorageManager;
+import 
org.apache.ignite.internal.metastorage.server.SimpleInMemoryKeyValueStorage;
+import org.apache.ignite.internal.vault.VaultManager;
+import org.apache.ignite.internal.vault.inmemory.InMemoryVaultService;
+
+/**
+ * Utilities for working with the catalog in tests.
+ */
+public class CatalogTestUtils {
+    /**
+     * Creates a test implementation of {@link CatalogManager}.
+     *
+     * <p>NOTE: Uses {@link CatalogManagerImpl} under the hood and creates the 
internals he needs, may change in the future.
+     *
+     * @param nodeName Node name.
+     * @param clock Hybrid clock.
+     */
+    public static CatalogManager createTestCatalogManager(String nodeName, 
HybridClock clock) {
+        var vault = new VaultManager(new InMemoryVaultService());
+
+        var metastore = StandaloneMetaStorageManager.create(vault, new 
SimpleInMemoryKeyValueStorage(nodeName));
+
+        var clockWaiter = new ClockWaiter(nodeName, clock);
+
+        return new CatalogManagerImpl(new UpdateLogImpl(metastore), 
clockWaiter) {
+            @Override
+            public void start() {
+                vault.start();
+                metastore.start();
+                clockWaiter.start();
+
+                super.start();
+
+                assertThat(metastore.deployWatches(), 
willCompleteSuccessfully());
+            }
+
+            @Override
+            public void beforeNodeStop() {
+                super.beforeNodeStop();
+
+                clockWaiter.beforeNodeStop();
+                metastore.beforeNodeStop();
+                vault.beforeNodeStop();
+            }
+
+            @Override
+            public void stop() throws Exception {
+                super.stop();
+
+                clockWaiter.stop();
+                metastore.stop();
+                vault.stop();
+            }
+        };
+    }
+
+    /**
+     * Creates a test implementation of {@link CatalogManager}.
+     *
+     * <p>NOTE: Uses {@link CatalogManagerImpl} under the hood and creates the 
internals he needs, may change in the future.

Review Comment:
   ```suggestion
        * <p>NOTE: Uses {@link CatalogManagerImpl} under the hood and creates 
the internals it needs, may change in the future.
   ```



##########
modules/table/src/testFixtures/java/org/apache/ignite/internal/table/TableTestUtils.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * 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.table;
+
+import static 
org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import java.util.List;
+import org.apache.ignite.internal.catalog.CatalogManager;
+import org.apache.ignite.internal.catalog.CatalogService;
+import org.apache.ignite.internal.catalog.commands.ColumnParams;
+import org.apache.ignite.internal.catalog.commands.CreateTableParams;
+import org.apache.ignite.internal.catalog.descriptors.CatalogTableDescriptor;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Utils to manage tables inside tests.
+ */
+public class TableTestUtils {
+    /**
+     * Creates table in the catalog.
+     *
+     * @param catalogManager Catalog manager.
+     * @param schemaName Schema name.
+     * @param zoneName Zone name.
+     * @param tableName Table name.
+     * @param columns Table columns.
+     * @param pkColumns Primary key columns.
+     */
+    public static void createTable(
+            CatalogManager catalogManager,
+            String schemaName,
+            String zoneName,
+            String tableName,
+            List<ColumnParams> columns,
+            List<String> pkColumns
+    ) {
+        CreateTableParams.Builder builder = CreateTableParams.builder()
+                .schemaName(schemaName)
+                .zone(zoneName)
+                .tableName(tableName)
+                .columns(columns)
+                .primaryKeyColumns(pkColumns);
+
+        assertThat(catalogManager.createTable(builder.build()), 
willCompleteSuccessfully());
+    }
+
+    /**
+     * Returns table ID form catalog, {@code null} if table is absent.
+     *
+     * @param catalogService Catalog service.
+     * @param tableName Table name.
+     * @param timestamp Timestamp.
+     */
+    public static @Nullable Integer getTableId(CatalogService catalogService, 
String tableName, long timestamp) {
+        CatalogTableDescriptor table = catalogService.table(tableName, 
timestamp);
+
+        return table == null ? null : table.id();
+    }
+
+    /**
+     * Returns table ID form catalog.

Review Comment:
   ```suggestion
        * Returns table ID from catalog.
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to