Copilot commented on code in PR #7246:
URL: https://github.com/apache/ignite-3/pull/7246#discussion_r2626064119


##########
modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItThinClientDdlQueriesTrackerTest.java:
##########
@@ -0,0 +1,116 @@
+/*
+ * 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.runner.app.client;
+
+import static org.apache.ignite.internal.TestWrappers.unwrapIgniteImpl;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.await;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.sameInstance;
+
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.client.handler.ClientInboundMessageHandler;
+import 
org.apache.ignite.internal.configuration.SuggestionsClusterExtensionConfiguration;
+import org.apache.ignite.internal.lang.IgniteStringFormatter;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * End-to-end tests to validate the behavior of the DDL queries suggestion 
handler.
+ */
+public class ItThinClientDdlQueriesTrackerTest extends 
ItAbstractThinClientTest {
+    @Override
+    protected int nodes() {
+        return 1;
+    }
+
+    @AfterEach
+    void dropTable() {
+        server(0).sql().executeScript("DROP TABLE t");

Review Comment:
   The cleanup method should handle cases where the table doesn't exist. If a 
test fails before creating the table or during table creation, this method will 
fail during cleanup, which can mask the real test failure. Consider adding 
error handling or checking if the table exists before dropping it, similar to 
the pattern used in ItThinClientSqlTest.dropAllTables() which checks if tables 
exist before dropping them.
   ```suggestion
           server(0).sql().executeScript("DROP TABLE IF EXISTS t");
   ```



##########
modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItThinClientDdlQueriesTrackerTest.java:
##########
@@ -0,0 +1,116 @@
+/*
+ * 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.runner.app.client;
+
+import static org.apache.ignite.internal.TestWrappers.unwrapIgniteImpl;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.await;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.sameInstance;
+
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.client.handler.ClientInboundMessageHandler;
+import 
org.apache.ignite.internal.configuration.SuggestionsClusterExtensionConfiguration;
+import org.apache.ignite.internal.lang.IgniteStringFormatter;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * End-to-end tests to validate the behavior of the DDL queries suggestion 
handler.
+ */
+public class ItThinClientDdlQueriesTrackerTest extends 
ItAbstractThinClientTest {
+    @Override
+    protected int nodes() {
+        return 1;
+    }
+
+    @AfterEach
+    void dropTable() {
+        server(0).sql().executeScript("DROP TABLE t");
+    }
+
+    @Test
+    void ddlIsTrackedByConnection() {
+        server(0).sql().executeScript("CREATE TABLE t(id INT PRIMARY KEY)");
+
+        IgniteClient client1 = client();
+        ClientInboundMessageHandler handler1 = 
unwrapIgniteImpl(server(0)).clientInboundMessageHandler();
+
+        // The handler "test reference" is updated after a new connection is 
established.
+        IgniteClient client2 = 
IgniteClient.builder().addresses(getClientAddresses().toArray(new 
String[0])).build();
+        ClientInboundMessageHandler handler2 = 
unwrapIgniteImpl(server(0)).clientInboundMessageHandler();
+
+        assertThat(handler1, not(sameInstance(handler2)));
+
+        addColumn(client1, 0);
+        addColumn(client1, 1);
+
+        assertThat(handler1.ddlQueriesInRow(), is(2));
+        assertThat(handler2.ddlQueriesInRow(), is(0));
+
+        addColumn(client2, 2);
+
+        assertThat(handler1.ddlQueriesInRow(), is(2));
+        assertThat(handler2.ddlQueriesInRow(), is(1));
+    }
+
+    @Test
+    void disableSuggestion() {
+        server(0).sql().executeScript("CREATE TABLE t(id INT PRIMARY KEY)");
+
+        SuggestionsClusterExtensionConfiguration config = 
unwrapIgniteImpl(server(0)).clusterConfiguration()
+                
.getConfiguration(SuggestionsClusterExtensionConfiguration.KEY);
+
+        { // Suggestion is enabled by default
+            ClientInboundMessageHandler handler = 
unwrapIgniteImpl(server(0)).clientInboundMessageHandler();
+
+            addColumn(client(), 0);
+            assertThat(handler.ddlQueriesInRow(), is(1));
+        }
+
+        { // Disable suggestion
+            await(config.suggestions().change(c -> c.changeEnabled(false)));
+
+            // The handler "test reference" is updated after a new connection 
is established.
+            IgniteClient client = 
IgniteClient.builder().addresses(getClientAddresses().toArray(new 
String[0])).build();

Review Comment:
   The manually created client is not closed, which may result in a resource 
leak. Consider using a try-with-resources statement or explicitly closing the 
client in an @AfterEach method.



##########
modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItThinClientDdlQueriesTrackerTest.java:
##########
@@ -0,0 +1,116 @@
+/*
+ * 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.runner.app.client;
+
+import static org.apache.ignite.internal.TestWrappers.unwrapIgniteImpl;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.await;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.sameInstance;
+
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.client.handler.ClientInboundMessageHandler;
+import 
org.apache.ignite.internal.configuration.SuggestionsClusterExtensionConfiguration;
+import org.apache.ignite.internal.lang.IgniteStringFormatter;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * End-to-end tests to validate the behavior of the DDL queries suggestion 
handler.
+ */
+public class ItThinClientDdlQueriesTrackerTest extends 
ItAbstractThinClientTest {
+    @Override
+    protected int nodes() {
+        return 1;
+    }
+
+    @AfterEach
+    void dropTable() {
+        server(0).sql().executeScript("DROP TABLE t");
+    }
+
+    @Test
+    void ddlIsTrackedByConnection() {
+        server(0).sql().executeScript("CREATE TABLE t(id INT PRIMARY KEY)");
+
+        IgniteClient client1 = client();
+        ClientInboundMessageHandler handler1 = 
unwrapIgniteImpl(server(0)).clientInboundMessageHandler();
+
+        // The handler "test reference" is updated after a new connection is 
established.
+        IgniteClient client2 = 
IgniteClient.builder().addresses(getClientAddresses().toArray(new 
String[0])).build();

Review Comment:
   The manually created client (client2) is not closed, which may result in a 
resource leak. Consider using a try-with-resources statement or explicitly 
closing the client in an @AfterEach method. The same issue exists on lines 91 
and 102 where additional clients are created but never closed.



##########
modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItThinClientDdlQueriesTrackerTest.java:
##########
@@ -0,0 +1,116 @@
+/*
+ * 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.runner.app.client;
+
+import static org.apache.ignite.internal.TestWrappers.unwrapIgniteImpl;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.await;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.sameInstance;
+
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.client.handler.ClientInboundMessageHandler;
+import 
org.apache.ignite.internal.configuration.SuggestionsClusterExtensionConfiguration;
+import org.apache.ignite.internal.lang.IgniteStringFormatter;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * End-to-end tests to validate the behavior of the DDL queries suggestion 
handler.
+ */
+public class ItThinClientDdlQueriesTrackerTest extends 
ItAbstractThinClientTest {
+    @Override
+    protected int nodes() {
+        return 1;
+    }
+
+    @AfterEach
+    void dropTable() {
+        server(0).sql().executeScript("DROP TABLE t");
+    }
+
+    @Test
+    void ddlIsTrackedByConnection() {
+        server(0).sql().executeScript("CREATE TABLE t(id INT PRIMARY KEY)");
+
+        IgniteClient client1 = client();
+        ClientInboundMessageHandler handler1 = 
unwrapIgniteImpl(server(0)).clientInboundMessageHandler();
+
+        // The handler "test reference" is updated after a new connection is 
established.
+        IgniteClient client2 = 
IgniteClient.builder().addresses(getClientAddresses().toArray(new 
String[0])).build();
+        ClientInboundMessageHandler handler2 = 
unwrapIgniteImpl(server(0)).clientInboundMessageHandler();
+
+        assertThat(handler1, not(sameInstance(handler2)));
+
+        addColumn(client1, 0);
+        addColumn(client1, 1);
+
+        assertThat(handler1.ddlQueriesInRow(), is(2));
+        assertThat(handler2.ddlQueriesInRow(), is(0));
+
+        addColumn(client2, 2);
+
+        assertThat(handler1.ddlQueriesInRow(), is(2));
+        assertThat(handler2.ddlQueriesInRow(), is(1));
+    }
+
+    @Test
+    void disableSuggestion() {
+        server(0).sql().executeScript("CREATE TABLE t(id INT PRIMARY KEY)");
+
+        SuggestionsClusterExtensionConfiguration config = 
unwrapIgniteImpl(server(0)).clusterConfiguration()
+                
.getConfiguration(SuggestionsClusterExtensionConfiguration.KEY);
+
+        { // Suggestion is enabled by default
+            ClientInboundMessageHandler handler = 
unwrapIgniteImpl(server(0)).clientInboundMessageHandler();
+
+            addColumn(client(), 0);
+            assertThat(handler.ddlQueriesInRow(), is(1));
+        }
+
+        { // Disable suggestion
+            await(config.suggestions().change(c -> c.changeEnabled(false)));
+
+            // The handler "test reference" is updated after a new connection 
is established.
+            IgniteClient client = 
IgniteClient.builder().addresses(getClientAddresses().toArray(new 
String[0])).build();
+            ClientInboundMessageHandler handler = 
unwrapIgniteImpl(server(0)).clientInboundMessageHandler();
+
+            addColumn(client, 1);
+            addColumn(client, 2);
+            assertThat(handler.ddlQueriesInRow(), is(-1));
+        }
+
+        { // Enable suggestion
+            await(config.suggestions().change(c -> c.changeEnabled(true)));
+
+            IgniteClient client = 
IgniteClient.builder().addresses(getClientAddresses().toArray(new 
String[0])).build();

Review Comment:
   The manually created client is not closed, which may result in a resource 
leak. Consider using a try-with-resources statement or explicitly closing the 
client in an @AfterEach method.



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