ibessonov commented on code in PR #3614:
URL: https://github.com/apache/ignite-3/pull/3614#discussion_r1570178024


##########
modules/rest/src/integrationTest/java/org/apache/ignite/internal/rest/recovery/ItDisasterRecoveryControllerTest.java:
##########
@@ -0,0 +1,169 @@
+/*
+ * 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.rest.recovery;
+
+import static java.util.stream.Collectors.toList;
+import static java.util.stream.IntStream.range;
+import static 
org.apache.ignite.internal.TestDefaultProfilesNames.DEFAULT_AIPERSIST_PROFILE_NAME;
+import static 
org.apache.ignite.internal.catalog.commands.CatalogUtils.DEFAULT_PARTITION_COUNT;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import io.micronaut.http.HttpResponse;
+import io.micronaut.http.HttpStatus;
+import io.micronaut.http.client.HttpClient;
+import io.micronaut.http.client.annotation.Client;
+import io.micronaut.http.client.exceptions.HttpClientResponseException;
+import io.micronaut.test.extensions.junit5.annotation.MicronautTest;
+import jakarta.inject.Inject;
+import java.util.List;
+import org.apache.ignite.internal.Cluster;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import 
org.apache.ignite.internal.rest.api.recovery.GlobalPartitionStateResponse;
+import 
org.apache.ignite.internal.rest.api.recovery.GlobalPartitionStatesResponse;
+import 
org.apache.ignite.internal.rest.api.recovery.LocalPartitionStateResponse;
+import 
org.apache.ignite.internal.rest.api.recovery.LocalPartitionStatesResponse;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test for disaster recovery REST commands.
+ */
+@MicronautTest
+public class ItDisasterRecoveryControllerTest extends 
ClusterPerTestIntegrationTest {
+    private static final String NODE_URL = "http://localhost:"; + 
Cluster.BASE_HTTP_PORT;
+
+    @Inject
+    @Client(NODE_URL + "/management/v1/recovery/")
+    HttpClient client;
+
+    @Override
+    protected int initialNodes() {
+        return 1;
+    }
+
+    @Test
+    void testLocalPartitionStates() {
+        executeSql("CREATE TABLE foo (id INT PRIMARY KEY, val INT)");
+        var response = client.toBlocking().exchange("/state/local/", 
LocalPartitionStatesResponse.class);
+
+        assertEquals(HttpStatus.OK, response.status());
+
+        LocalPartitionStatesResponse body = response.body();
+        assertEquals(DEFAULT_PARTITION_COUNT, body.states().size());
+
+        List<Integer> partitionIds = 
body.states().stream().map(LocalPartitionStateResponse::partitionId).collect(toList());
+        assertEquals(range(0, 
DEFAULT_PARTITION_COUNT).boxed().collect(toList()), partitionIds);
+    }
+
+    @Test
+    void testLocalPartitionStatesByZoneMissingZone() {
+        HttpClientResponseException thrown = assertThrows(
+                HttpClientResponseException.class,
+                () -> client.toBlocking().exchange("/state/local/foo/", 
LocalPartitionStatesResponse.class)
+        );
+
+        assertEquals(HttpStatus.BAD_REQUEST, thrown.getResponse().status());
+    }
+
+    @Test
+    void testLocalPartitionStatesByZone() {
+        executeSql("CREATE TABLE def (id INT PRIMARY KEY, val INT)");
+
+        executeSql("CREATE ZONE foo WITH partitions=1, storage_profiles='" + 
DEFAULT_AIPERSIST_PROFILE_NAME + "'");
+        executeSql("CREATE TABLE foo (id INT PRIMARY KEY, val INT) WITH 
PRIMARY_ZONE = 'FOO'");
+
+        var response = client.toBlocking().exchange("/state/local/Default/", 
LocalPartitionStatesResponse.class);
+
+        assertEquals(HttpStatus.OK, response.status());
+        assertEquals(DEFAULT_PARTITION_COUNT, response.body().states().size());
+
+        response = client.toBlocking().exchange("/state/local/FOO/", 
LocalPartitionStatesResponse.class);
+
+        assertEquals(HttpStatus.OK, response.status());
+        assertEquals(1, response.body().states().size());
+    }
+
+    @Test
+    void testLocalPartitionStatesByZoneJson() {
+        executeSql("CREATE ZONE foo WITH partitions=1, storage_profiles='" + 
DEFAULT_AIPERSIST_PROFILE_NAME + "'");
+        executeSql("CREATE TABLE foo (id INT PRIMARY KEY, val INT) WITH 
PRIMARY_ZONE = 'FOO'");
+
+        HttpResponse<String> response = 
client.toBlocking().exchange("/state/local/FOO/", String.class);
+
+        assertEquals(
+                
"{'states':[{'partitionId':0,'tableName':'FOO','nodeName':'idrct_tlpsbzj_0','state':'HEALTHY'}]}".replace('\'',
 '"'),

Review Comment:
   I believe that this is not the only test that does so. Your concern is fair, 
but this is the order according to HashMap, as far as I understand, and it is 
pretty stable across all versions of all libraries, there's no way it'll get 
changed. Anyway, should I just remove the test for string representation and 
check all individual properties in another test? Maybe that would be better



-- 
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