Copilot commented on code in PR #13191:
URL: https://github.com/apache/ignite/pull/13191#discussion_r3353802132


##########
modules/core/src/test/java/org/apache/ignite/configuration/IgniteConfigurationTest.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.configuration;
+
+import java.util.regex.Pattern;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.testframework.ListeningTestLogger;
+import org.apache.ignite.testframework.LogListener;
+import org.apache.ignite.testframework.junits.WithSystemProperty;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Assert;
+import org.junit.Test;
+
+import static org.apache.ignite.IgniteSystemProperties.IGNITE_QUIET;
+
+/**
+ * Test covers cases where Ignite configuration,
+ * or it's nested objects has default implementation of {@link 
Object#toString()}
+ */
+@WithSystemProperty(key = IGNITE_QUIET, value = "false")
+public class IgniteConfigurationTest extends GridCommonAbstractTest {
+    /** Error message to be prompted for ignite configuration */
+    private static final String ASSERTION_ERROR_MESSAGE =
+            "Ignite configuration log message contains objects with default 
toString implementation";
+
+    /** Error message to be prompted for node start log message */
+    private static final String NODE_START_ASSERTION_ERROR_MESSAGE =
+            "Node start log message contains objects with default toString 
implementation";
+
+    /** Pattern to check any object has default {@link Object#toString()} 
implementation */
+    private static final Pattern ERROR_PATTERN = 
Pattern.compile("^(?=.*IgniteConfiguration \\[)(?!.*@[a-fA-F0-9]+).*$");
+
+    /** Pattern to check any object has default {@link Object#toString()} 
implementation */
+    private static final Pattern NODE_START_ERROR_PATTERN = 
Pattern.compile("^(?=.*Node started with the following configuration 
\\[id=)(?!.*@[a-fA-F0-9]+).*$");
+
+    /** */
+    private final ListeningTestLogger listeningLog = new 
ListeningTestLogger(log);
+
+    /**
+     * Check ignite configuration log message contains no @ letters
+     * It's a common way to ensure all objects in prompt has {@link 
Object#toString()} overriden
+     */
+    @Test
+    public void testIgniteConfigurationPrompt() throws Exception {
+        LogListener igniteConfigurationLogListener = LogListener
+                .matches(ERROR_PATTERN)
+                .build();
+        LogListener nodeStartIgniteConfigurationLogListener = LogListener
+                .matches(NODE_START_ERROR_PATTERN)
+                .build();
+        listeningLog.registerListener(igniteConfigurationLogListener);
+        listeningLog.registerListener(nodeStartIgniteConfigurationLogListener);
+        try (IgniteEx ignored = startGrid(0)) {
+            Assert.assertTrue(ASSERTION_ERROR_MESSAGE, 
igniteConfigurationLogListener.check());
+            Assert.assertTrue(NODE_START_ASSERTION_ERROR_MESSAGE, 
nodeStartIgniteConfigurationLogListener.check(10_000));

Review Comment:
   The test currently only asserts that at least one configuration log line 
matches a regex that *doesn't* contain an identity-hash fragment 
(`@[0-9a-f]+`). If there are multiple relevant log lines, this can pass even 
when another configuration line still contains a default `Object#toString()` 
fragment. Add explicit negative checks (e.g., `atMost(0)`) for patterns that 
include `@[0-9a-f]+` within the targeted messages.



##########
modules/core/src/test/java/org/apache/ignite/configuration/IgniteConfigurationTest.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.configuration;
+
+import java.util.regex.Pattern;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.testframework.ListeningTestLogger;
+import org.apache.ignite.testframework.LogListener;
+import org.apache.ignite.testframework.junits.WithSystemProperty;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Assert;
+import org.junit.Test;
+
+import static org.apache.ignite.IgniteSystemProperties.IGNITE_QUIET;
+
+/**
+ * Test covers cases where Ignite configuration,
+ * or it's nested objects has default implementation of {@link 
Object#toString()}
+ */
+@WithSystemProperty(key = IGNITE_QUIET, value = "false")
+public class IgniteConfigurationTest extends GridCommonAbstractTest {
+    /** Error message to be prompted for ignite configuration */
+    private static final String ASSERTION_ERROR_MESSAGE =
+            "Ignite configuration log message contains objects with default 
toString implementation";
+
+    /** Error message to be prompted for node start log message */
+    private static final String NODE_START_ASSERTION_ERROR_MESSAGE =
+            "Node start log message contains objects with default toString 
implementation";
+
+    /** Pattern to check any object has default {@link Object#toString()} 
implementation */
+    private static final Pattern ERROR_PATTERN = 
Pattern.compile("^(?=.*IgniteConfiguration \\[)(?!.*@[a-fA-F0-9]+).*$");
+
+    /** Pattern to check any object has default {@link Object#toString()} 
implementation */
+    private static final Pattern NODE_START_ERROR_PATTERN = 
Pattern.compile("^(?=.*Node started with the following configuration 
\\[id=)(?!.*@[a-fA-F0-9]+).*$");
+
+    /** */
+    private final ListeningTestLogger listeningLog = new 
ListeningTestLogger(log);
+
+    /**
+     * Check ignite configuration log message contains no @ letters
+     * It's a common way to ensure all objects in prompt has {@link 
Object#toString()} overriden
+     */

Review Comment:
   Spelling/wording in this test comment is incorrect ("prompt", "overriden") 
and makes the intent harder to read. Please correct the wording while the test 
is being added.



##########
modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java:
##########
@@ -1153,7 +1154,10 @@ public void simulateNodeFailure() {
 
     /** {@inheritDoc} */
     @Override public String toString() {
-        return S.toString(TcpCommunicationSpi.class, this);
+        return "TcpCommunicationSpi [" +
+                "ctxInitLatch=" + ctxInitLatch.getCount() +
+                ", stopping=" + stopping +
+                "]";

Review Comment:
   This `toString()` now exposes internal runtime state (`ctxInitLatch` / 
`stopping`) rather than configuration. Since this string is intended for 
configuration logging, it should be stable and describe configuration (or be 
reduced to a simple class name like the other SPI changes), not mutable 
internal flags.



##########
modules/core/src/test/java/org/apache/ignite/configuration/IgniteConfigurationTest.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.configuration;
+
+import java.util.regex.Pattern;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.testframework.ListeningTestLogger;
+import org.apache.ignite.testframework.LogListener;
+import org.apache.ignite.testframework.junits.WithSystemProperty;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Assert;
+import org.junit.Test;
+
+import static org.apache.ignite.IgniteSystemProperties.IGNITE_QUIET;
+
+/**
+ * Test covers cases where Ignite configuration,
+ * or it's nested objects has default implementation of {@link 
Object#toString()}
+ */

Review Comment:
   Grammar in the class Javadoc is off ("or it's nested objects has"). This is 
newly added test documentation; please correct to avoid confusion.



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