From 9d9b6af14d5c3f9ff4cdcc72b3f488e2d2c563c8 Mon Sep 17 00:00:00 2001 From: Dimitris Rempapis Date: Fri, 3 Jan 2025 14:51:08 +0200 Subject: [PATCH 01/10] unmute tests --- muted-tests.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/muted-tests.yml b/muted-tests.yml index ec47ec92bbac6..3e104e8a5b0bf 100644 --- a/muted-tests.yml +++ b/muted-tests.yml @@ -163,12 +163,6 @@ tests: - class: org.elasticsearch.xpack.ml.integration.RegressionIT method: testTwoJobsWithSameRandomizeSeedUseSameTrainingSet issue: https://github.com/elastic/elasticsearch/issues/117805 -- class: org.elasticsearch.upgrades.QueryBuilderBWCIT - method: testQueryBuilderBWC {cluster=UPGRADED} - issue: https://github.com/elastic/elasticsearch/issues/116990 -- class: org.elasticsearch.xpack.restart.QueryBuilderBWCIT - method: testQueryBuilderBWC {p0=UPGRADED} - issue: https://github.com/elastic/elasticsearch/issues/116989 - class: org.elasticsearch.xpack.remotecluster.CrossClusterEsqlRCS2UnavailableRemotesIT method: testEsqlRcs2UnavailableRemoteScenarios issue: https://github.com/elastic/elasticsearch/issues/117419 From 02ddf8205360b818ba18beba96dc457a6843e70e Mon Sep 17 00:00:00 2001 From: Dimitris Rempapis Date: Fri, 3 Jan 2025 14:53:03 +0200 Subject: [PATCH 02/10] revert --- muted-tests.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/muted-tests.yml b/muted-tests.yml index 3e104e8a5b0bf..ec47ec92bbac6 100644 --- a/muted-tests.yml +++ b/muted-tests.yml @@ -163,6 +163,12 @@ tests: - class: org.elasticsearch.xpack.ml.integration.RegressionIT method: testTwoJobsWithSameRandomizeSeedUseSameTrainingSet issue: https://github.com/elastic/elasticsearch/issues/117805 +- class: org.elasticsearch.upgrades.QueryBuilderBWCIT + method: testQueryBuilderBWC {cluster=UPGRADED} + issue: https://github.com/elastic/elasticsearch/issues/116990 +- class: org.elasticsearch.xpack.restart.QueryBuilderBWCIT + method: testQueryBuilderBWC {p0=UPGRADED} + issue: https://github.com/elastic/elasticsearch/issues/116989 - class: org.elasticsearch.xpack.remotecluster.CrossClusterEsqlRCS2UnavailableRemotesIT method: testEsqlRcs2UnavailableRemoteScenarios issue: https://github.com/elastic/elasticsearch/issues/117419 From 936e62397780794cd980a216583165191a825965 Mon Sep 17 00:00:00 2001 From: Dimitris Rempapis Date: Fri, 17 Jan 2025 13:02:03 +0200 Subject: [PATCH 03/10] add PoC test --- .../datastreams/DataStreamsSnapshotsIT.java | 2 +- ...toreTemplateWithMatchOnlyTextMapperIT.java | 91 +++++++++++++++++++ 2 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/RestoreTemplateWithMatchOnlyTextMapperIT.java diff --git a/modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/DataStreamsSnapshotsIT.java b/modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/DataStreamsSnapshotsIT.java index 0ae7504bb9d7f..2dbad5e35f61b 100644 --- a/modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/DataStreamsSnapshotsIT.java +++ b/modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/DataStreamsSnapshotsIT.java @@ -1086,7 +1086,7 @@ public void testPartialRestoreSnapshotThatIncludesDataStream() { .prepareRestoreSnapshot(TEST_REQUEST_TIMEOUT, REPO, snapshot) .setIndices(indexWithoutDataStream) .setWaitForCompletion(true) - .setRestoreGlobalState(false) + .setRestoreGlobalState(true) .get() .getRestoreInfo(); assertThat(restoreInfo.failedShards(), is(0)); diff --git a/modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/RestoreTemplateWithMatchOnlyTextMapperIT.java b/modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/RestoreTemplateWithMatchOnlyTextMapperIT.java new file mode 100644 index 0000000000000..9b9d8460c5f79 --- /dev/null +++ b/modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/RestoreTemplateWithMatchOnlyTextMapperIT.java @@ -0,0 +1,91 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the "Elastic License + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +package org.elasticsearch.datastreams; + +import org.elasticsearch.action.admin.indices.template.put.TransportPutComposableIndexTemplateAction; +import org.elasticsearch.client.internal.Client; +import org.elasticsearch.cluster.metadata.ComposableIndexTemplate; +import org.elasticsearch.cluster.metadata.Template; +import org.elasticsearch.common.compress.CompressedXContent; +import org.elasticsearch.core.TimeValue; +import org.elasticsearch.index.mapper.extras.MapperExtrasPlugin; +import org.elasticsearch.plugins.Plugin; +import org.elasticsearch.snapshots.AbstractSnapshotIntegTestCase; +import org.elasticsearch.snapshots.RestoreInfo; +import org.elasticsearch.snapshots.mockstore.MockRepository; +import org.junit.Before; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.Collection; +import java.util.List; + +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; +import static org.hamcrest.Matchers.is; + +public class RestoreTemplateWithMatchOnlyTextMapperIT extends AbstractSnapshotIntegTestCase { + public static final String REPO = "repo"; + public static final String SNAPSHOT = "snap"; + private Client client; + + @Override + protected Collection> nodePlugins() { + return List.of(MockRepository.Plugin.class, MapperExtrasPlugin.class); + } + + @Before + public void setup() { + client = client(); + Path location = randomRepoPath(); + createRepository(REPO, "fs", location); + } + + public void test() throws IOException { + TransportPutComposableIndexTemplateAction.Request request = new TransportPutComposableIndexTemplateAction.Request("t1"); + request.indexTemplate( + ComposableIndexTemplate.builder() + .indexPatterns(List.of("test-index-*")) + .template(new Template(null, CompressedXContent.fromJSON(""" + { + "properties": { + "@timestamp": { + "type": "date", + "format": "date_optional_time||epoch_millis" + }, + "message": { + "type": "match_only_text" + }, + "flag": { + "type": "boolean" + } + } + }"""), null)) + .dataStreamTemplate(new ComposableIndexTemplate.DataStreamTemplate()) + .build() + ); + client().execute(TransportPutComposableIndexTemplateAction.TYPE, request).actionGet(); + + final String snapshot = "test-snapshot"; + final String indexWithoutDataStream = "test-idx-no-ds"; + createIndexWithContent(indexWithoutDataStream); + createFullSnapshot(REPO, snapshot); + assertAcked(client.admin().indices().prepareDelete(indexWithoutDataStream)); + RestoreInfo restoreInfo = client.admin() + .cluster() + .prepareRestoreSnapshot(TimeValue.THIRTY_SECONDS, REPO, snapshot) + .setIndices(indexWithoutDataStream) + .setWaitForCompletion(true) + .setRestoreGlobalState(false) + .get() + .getRestoreInfo(); + assertThat(restoreInfo.failedShards(), is(0)); + assertThat(restoreInfo.successfulShards(), is(1)); + } +} From d7070bc896cd53b2115bf5d12f9cc198f4a55a86 Mon Sep 17 00:00:00 2001 From: Dimitris Rempapis Date: Fri, 17 Jan 2025 13:46:40 +0200 Subject: [PATCH 04/10] update --- ...toreTemplateWithMatchOnlyTextMapperIT.java | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/RestoreTemplateWithMatchOnlyTextMapperIT.java b/modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/RestoreTemplateWithMatchOnlyTextMapperIT.java index 9b9d8460c5f79..91d166476f29f 100644 --- a/modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/RestoreTemplateWithMatchOnlyTextMapperIT.java +++ b/modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/RestoreTemplateWithMatchOnlyTextMapperIT.java @@ -54,18 +54,20 @@ public void test() throws IOException { .indexPatterns(List.of("test-index-*")) .template(new Template(null, CompressedXContent.fromJSON(""" { - "properties": { - "@timestamp": { - "type": "date", - "format": "date_optional_time||epoch_millis" - }, - "message": { - "type": "match_only_text" - }, - "flag": { - "type": "boolean" - } - } + "_doc": { + "properties": { + "@timestamp": { + "format": "date_optional_time||epoch_millis", + "type": "date" + }, + "flag": { + "type": "boolean" + }, + "message": { + "type": "match_only_text" + } + } + } }"""), null)) .dataStreamTemplate(new ComposableIndexTemplate.DataStreamTemplate()) .build() @@ -82,7 +84,7 @@ public void test() throws IOException { .prepareRestoreSnapshot(TimeValue.THIRTY_SECONDS, REPO, snapshot) .setIndices(indexWithoutDataStream) .setWaitForCompletion(true) - .setRestoreGlobalState(false) + .setRestoreGlobalState(true) .get() .getRestoreInfo(); assertThat(restoreInfo.failedShards(), is(0)); From b3532c1f7f43b9d1ca4940bee7e84417e270ac82 Mon Sep 17 00:00:00 2001 From: Dimitris Rempapis Date: Fri, 17 Jan 2025 16:38:35 +0200 Subject: [PATCH 05/10] Address test failure --- .../datastreams/DataStreamsSnapshotsIT.java | 14 +-- ...toreTemplateWithMatchOnlyTextMapperIT.java | 93 ------------------- .../elasticsearch/test/ESIntegTestCase.java | 26 +++++- 3 files changed, 25 insertions(+), 108 deletions(-) delete mode 100644 modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/RestoreTemplateWithMatchOnlyTextMapperIT.java diff --git a/modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/DataStreamsSnapshotsIT.java b/modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/DataStreamsSnapshotsIT.java index 2dbad5e35f61b..908a7fb8801b0 100644 --- a/modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/DataStreamsSnapshotsIT.java +++ b/modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/DataStreamsSnapshotsIT.java @@ -1095,11 +1095,8 @@ public void testPartialRestoreSnapshotThatIncludesDataStream() { /** * This test is a copy of the {@link #testPartialRestoreSnapshotThatIncludesDataStream()} the only difference - * is that one include the global state and one doesn't. In general this shouldn't matter that's why it used to be - * a random parameter of the test, but because of #107515 it fails when we include the global state. Keep them - * separate until this is fixed. + * is that one include the global state and one doesn't. */ - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/107515") public void testPartialRestoreSnapshotThatIncludesDataStreamWithGlobalState() { final String snapshot = "test-snapshot"; final String indexWithoutDataStream = "test-idx-no-ds"; @@ -1264,11 +1261,8 @@ public void testExcludeDSFromSnapshotWhenExcludingAnyOfItsIndices() { /** * This test is a copy of the {@link #testExcludeDSFromSnapshotWhenExcludingAnyOfItsIndices()} ()} the only difference - * is that one include the global state and one doesn't. In general this shouldn't matter that's why it used to be - * a random parameter of the test, but because of #107515 it fails when we include the global state. Keep them - * separate until this is fixed. + * is that one include the global state and one doesn't. */ - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/107515") public void testExcludeDSFromSnapshotWhenExcludingItsIndicesWithGlobalState() { final String snapshot = "test-snapshot"; final String indexWithoutDataStream = "test-idx-no-ds"; @@ -1434,10 +1428,6 @@ public void testWarningHeaderAbsentOnRestoreWithTemplates() throws Exception { } - /** - * This test is muted as it's awaiting the same fix as {@link #testPartialRestoreSnapshotThatIncludesDataStreamWithGlobalState()} - */ - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/107515") public void testWarningHeaderOnRestoreTemplateFromSnapshot() throws Exception { String datastreamName = "ds"; diff --git a/modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/RestoreTemplateWithMatchOnlyTextMapperIT.java b/modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/RestoreTemplateWithMatchOnlyTextMapperIT.java deleted file mode 100644 index 91d166476f29f..0000000000000 --- a/modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/RestoreTemplateWithMatchOnlyTextMapperIT.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the "Elastic License - * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side - * Public License v 1"; you may not use this file except in compliance with, at - * your election, the "Elastic License 2.0", the "GNU Affero General Public - * License v3.0 only", or the "Server Side Public License, v 1". - */ - -package org.elasticsearch.datastreams; - -import org.elasticsearch.action.admin.indices.template.put.TransportPutComposableIndexTemplateAction; -import org.elasticsearch.client.internal.Client; -import org.elasticsearch.cluster.metadata.ComposableIndexTemplate; -import org.elasticsearch.cluster.metadata.Template; -import org.elasticsearch.common.compress.CompressedXContent; -import org.elasticsearch.core.TimeValue; -import org.elasticsearch.index.mapper.extras.MapperExtrasPlugin; -import org.elasticsearch.plugins.Plugin; -import org.elasticsearch.snapshots.AbstractSnapshotIntegTestCase; -import org.elasticsearch.snapshots.RestoreInfo; -import org.elasticsearch.snapshots.mockstore.MockRepository; -import org.junit.Before; - -import java.io.IOException; -import java.nio.file.Path; -import java.util.Collection; -import java.util.List; - -import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; -import static org.hamcrest.Matchers.is; - -public class RestoreTemplateWithMatchOnlyTextMapperIT extends AbstractSnapshotIntegTestCase { - public static final String REPO = "repo"; - public static final String SNAPSHOT = "snap"; - private Client client; - - @Override - protected Collection> nodePlugins() { - return List.of(MockRepository.Plugin.class, MapperExtrasPlugin.class); - } - - @Before - public void setup() { - client = client(); - Path location = randomRepoPath(); - createRepository(REPO, "fs", location); - } - - public void test() throws IOException { - TransportPutComposableIndexTemplateAction.Request request = new TransportPutComposableIndexTemplateAction.Request("t1"); - request.indexTemplate( - ComposableIndexTemplate.builder() - .indexPatterns(List.of("test-index-*")) - .template(new Template(null, CompressedXContent.fromJSON(""" - { - "_doc": { - "properties": { - "@timestamp": { - "format": "date_optional_time||epoch_millis", - "type": "date" - }, - "flag": { - "type": "boolean" - }, - "message": { - "type": "match_only_text" - } - } - } - }"""), null)) - .dataStreamTemplate(new ComposableIndexTemplate.DataStreamTemplate()) - .build() - ); - client().execute(TransportPutComposableIndexTemplateAction.TYPE, request).actionGet(); - - final String snapshot = "test-snapshot"; - final String indexWithoutDataStream = "test-idx-no-ds"; - createIndexWithContent(indexWithoutDataStream); - createFullSnapshot(REPO, snapshot); - assertAcked(client.admin().indices().prepareDelete(indexWithoutDataStream)); - RestoreInfo restoreInfo = client.admin() - .cluster() - .prepareRestoreSnapshot(TimeValue.THIRTY_SECONDS, REPO, snapshot) - .setIndices(indexWithoutDataStream) - .setWaitForCompletion(true) - .setRestoreGlobalState(true) - .get() - .getRestoreInfo(); - assertThat(restoreInfo.failedShards(), is(0)); - assertThat(restoreInfo.successfulShards(), is(1)); - } -} diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java index bdfc0a693f7f4..fd61b377bfe92 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java @@ -185,6 +185,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; import java.util.IdentityHashMap; import java.util.List; @@ -1243,7 +1244,6 @@ protected final void doEnsureClusterStateConsistency(NamedWriteableRegistry name namedWriteableRegistry ); Map masterStateMap = convertToMap(masterClusterState); - int masterClusterStateSize = ClusterState.Builder.toBytes(masterClusterState).length; String masterId = masterClusterState.nodes().getMasterNodeId(); for (SubscribableListener localStateListener : localStates) { localStateListener.andThenAccept(localClusterStateResponse -> { @@ -1255,7 +1255,6 @@ protected final void doEnsureClusterStateConsistency(NamedWriteableRegistry name namedWriteableRegistry ); final Map localStateMap = convertToMap(localClusterState); - final int localClusterStateSize = ClusterState.Builder.toBytes(localClusterState).length; // Check that the non-master node has the same version of the cluster state as the master and // that the master node matches the master (otherwise there is no requirement for the cluster state to // match) @@ -1269,7 +1268,8 @@ protected final void doEnsureClusterStateConsistency(NamedWriteableRegistry name ); // We cannot compare serialization bytes since serialization order of maps is not guaranteed // but we can compare serialization sizes - they should be the same - assertEquals("cluster state size does not match", masterClusterStateSize, localClusterStateSize); + assertTrue("cluster states must be equal", equal(masterClusterState.toString(), localClusterState.toString())); + // Compare JSON serialization assertNull( "cluster state JSON serialization does not match", @@ -1291,6 +1291,26 @@ protected final void doEnsureClusterStateConsistency(NamedWriteableRegistry name safeGet(future); } + private static boolean equal(String str1, String str2) { + if (str1.length() != str2.length()) return false; + + Map charCount = new HashMap<>(); + str1.chars() + .mapToObj(c -> (char) c) + .forEach(c -> charCount.put(c, charCount.getOrDefault(c, 0) + 1)); + + str2.chars() + .mapToObj(c -> (char) c) + .forEach(c -> { + charCount.put(c, charCount.getOrDefault(c, 0) - 1); + if (charCount.get(c) == 0) { + charCount.remove(c); + } + }); + + return charCount.isEmpty(); + } + protected void ensureClusterStateCanBeReadByNodeTool() throws IOException { if (cluster() != null && cluster().size() > 0) { final Client masterClient = client(); From 52d483ee2cd158baaa2530f3dff965de9aacbb3c Mon Sep 17 00:00:00 2001 From: Dimitris Rempapis Date: Fri, 17 Jan 2025 16:50:45 +0200 Subject: [PATCH 06/10] Update pr --- .../org/elasticsearch/datastreams/DataStreamsSnapshotsIT.java | 2 +- .../src/main/java/org/elasticsearch/test/ESIntegTestCase.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/DataStreamsSnapshotsIT.java b/modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/DataStreamsSnapshotsIT.java index 908a7fb8801b0..e8a6aa6042317 100644 --- a/modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/DataStreamsSnapshotsIT.java +++ b/modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/DataStreamsSnapshotsIT.java @@ -1086,7 +1086,7 @@ public void testPartialRestoreSnapshotThatIncludesDataStream() { .prepareRestoreSnapshot(TEST_REQUEST_TIMEOUT, REPO, snapshot) .setIndices(indexWithoutDataStream) .setWaitForCompletion(true) - .setRestoreGlobalState(true) + .setRestoreGlobalState(false) .get() .getRestoreInfo(); assertThat(restoreInfo.failedShards(), is(0)); diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java index fd61b377bfe92..36392d9b4b5ce 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java @@ -1267,7 +1267,7 @@ protected final void doEnsureClusterStateConsistency(NamedWriteableRegistry name localClusterState.stateUUID() ); // We cannot compare serialization bytes since serialization order of maps is not guaranteed - // but we can compare serialization sizes - they should be the same + // but we can compare if the Strings are identical by "counting" the characters assertTrue("cluster states must be equal", equal(masterClusterState.toString(), localClusterState.toString())); // Compare JSON serialization From 6714b42dcef040a4642ccf199d49f73887f22c10 Mon Sep 17 00:00:00 2001 From: Dimitris Rempapis Date: Fri, 17 Jan 2025 16:53:20 +0200 Subject: [PATCH 07/10] Update docs/changelog/120392.yaml --- docs/changelog/120392.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 docs/changelog/120392.yaml diff --git a/docs/changelog/120392.yaml b/docs/changelog/120392.yaml new file mode 100644 index 0000000000000..69587b4d48241 --- /dev/null +++ b/docs/changelog/120392.yaml @@ -0,0 +1,6 @@ +pr: 120392 +summary: Test/107515 restore template with match only text mapper it fail +area: Search +type: bug +issues: + - 107515 From ff6291fe02f62658388bcb6a605cf5a3b97cd28e Mon Sep 17 00:00:00 2001 From: elasticsearchmachine Date: Fri, 17 Jan 2025 14:59:06 +0000 Subject: [PATCH 08/10] [CI] Auto commit changes from spotless --- .../elasticsearch/test/ESIntegTestCase.java | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java index 36392d9b4b5ce..9b930d9767299 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java @@ -1268,7 +1268,10 @@ protected final void doEnsureClusterStateConsistency(NamedWriteableRegistry name ); // We cannot compare serialization bytes since serialization order of maps is not guaranteed // but we can compare if the Strings are identical by "counting" the characters - assertTrue("cluster states must be equal", equal(masterClusterState.toString(), localClusterState.toString())); + assertTrue( + "cluster states must be equal", + equal(masterClusterState.toString(), localClusterState.toString()) + ); // Compare JSON serialization assertNull( @@ -1295,18 +1298,14 @@ private static boolean equal(String str1, String str2) { if (str1.length() != str2.length()) return false; Map charCount = new HashMap<>(); - str1.chars() - .mapToObj(c -> (char) c) - .forEach(c -> charCount.put(c, charCount.getOrDefault(c, 0) + 1)); - - str2.chars() - .mapToObj(c -> (char) c) - .forEach(c -> { - charCount.put(c, charCount.getOrDefault(c, 0) - 1); - if (charCount.get(c) == 0) { - charCount.remove(c); - } - }); + str1.chars().mapToObj(c -> (char) c).forEach(c -> charCount.put(c, charCount.getOrDefault(c, 0) + 1)); + + str2.chars().mapToObj(c -> (char) c).forEach(c -> { + charCount.put(c, charCount.getOrDefault(c, 0) - 1); + if (charCount.get(c) == 0) { + charCount.remove(c); + } + }); return charCount.isEmpty(); } From 728717fc1b2d83eb0a855f1c96acebed7931e274 Mon Sep 17 00:00:00 2001 From: Dimitris Rempapis Date: Fri, 24 Jan 2025 14:05:48 +0200 Subject: [PATCH 09/10] update after review --- .../elasticsearch/test/ESIntegTestCase.java | 26 +++---------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java index 9b930d9767299..e746c1aebed31 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java @@ -185,7 +185,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; import java.util.IdentityHashMap; import java.util.List; @@ -1266,12 +1265,9 @@ protected final void doEnsureClusterStateConsistency(NamedWriteableRegistry name masterClusterState.stateUUID(), localClusterState.stateUUID() ); - // We cannot compare serialization bytes since serialization order of maps is not guaranteed - // but we can compare if the Strings are identical by "counting" the characters - assertTrue( - "cluster states must be equal", - equal(masterClusterState.toString(), localClusterState.toString()) - ); + + // Compare the steMaps for equality. + assertNull(XContentTestUtils.differenceBetweenMapsIgnoringArrayOrder(masterStateMap, localStateMap)); // Compare JSON serialization assertNull( @@ -1294,22 +1290,6 @@ protected final void doEnsureClusterStateConsistency(NamedWriteableRegistry name safeGet(future); } - private static boolean equal(String str1, String str2) { - if (str1.length() != str2.length()) return false; - - Map charCount = new HashMap<>(); - str1.chars().mapToObj(c -> (char) c).forEach(c -> charCount.put(c, charCount.getOrDefault(c, 0) + 1)); - - str2.chars().mapToObj(c -> (char) c).forEach(c -> { - charCount.put(c, charCount.getOrDefault(c, 0) - 1); - if (charCount.get(c) == 0) { - charCount.remove(c); - } - }); - - return charCount.isEmpty(); - } - protected void ensureClusterStateCanBeReadByNodeTool() throws IOException { if (cluster() != null && cluster().size() > 0) { final Client masterClient = client(); From 2c64d7cf97c42151f5ecf82c3c7ecf45297bdefb Mon Sep 17 00:00:00 2001 From: Dimitris Rempapis Date: Fri, 24 Jan 2025 14:07:40 +0200 Subject: [PATCH 10/10] update --- .../src/main/java/org/elasticsearch/test/ESIntegTestCase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java index e746c1aebed31..bb259cb9b9788 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java @@ -1266,7 +1266,7 @@ protected final void doEnsureClusterStateConsistency(NamedWriteableRegistry name localClusterState.stateUUID() ); - // Compare the steMaps for equality. + // Compare the stateMaps for equality. assertNull(XContentTestUtils.differenceBetweenMapsIgnoringArrayOrder(masterStateMap, localStateMap)); // Compare JSON serialization