From 8eca5c2e9129ed8a4f907052183f868523d9df7a Mon Sep 17 00:00:00 2001 From: Joe Gallo Date: Tue, 8 Apr 2025 09:46:35 -0400 Subject: [PATCH 1/3] Conserve precious characters --- .../ingest/common/RemoveProcessorTests.java | 89 ++++++------------- 1 file changed, 28 insertions(+), 61 deletions(-) diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/RemoveProcessorTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/RemoveProcessorTests.java index b18a7ff26e30e..8b6e0b9b8bcdb 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/RemoveProcessorTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/RemoveProcessorTests.java @@ -16,11 +16,12 @@ import org.elasticsearch.script.TemplateScript; import org.elasticsearch.test.ESTestCase; -import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; +import static org.elasticsearch.ingest.common.RemoveProcessor.shouldKeep; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; @@ -76,24 +77,19 @@ public void testKeepFields() throws Exception { source.put("age", 55); source.put("address", address); - IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), source); - - List fieldsToKeep = List.of( - new TestTemplateService.MockTemplateScript.Factory("name"), - new TestTemplateService.MockTemplateScript.Factory("address.street") - ); - - Processor processor = new RemoveProcessor(randomAlphaOfLength(10), null, new ArrayList<>(), fieldsToKeep, false); - processor.execute(ingestDocument); - assertTrue(ingestDocument.hasField("name")); - assertTrue(ingestDocument.hasField("address")); - assertTrue(ingestDocument.hasField("address.street")); - assertFalse(ingestDocument.hasField("age")); - assertFalse(ingestDocument.hasField("address.number")); - assertTrue(ingestDocument.hasField("_index")); - assertTrue(ingestDocument.hasField("_version")); - assertTrue(ingestDocument.hasField("_id")); - assertTrue(ingestDocument.hasField("_version_type")); + IngestDocument document = RandomDocumentPicks.randomIngestDocument(random(), source); + + Processor processor = new RemoveProcessor(null, null, List.of(), templates("name", "address.street"), false); + processor.execute(document); + assertTrue(document.hasField("name")); + assertTrue(document.hasField("address")); + assertTrue(document.hasField("address.street")); + assertFalse(document.hasField("age")); + assertFalse(document.hasField("address.number")); + assertTrue(document.hasField("_index")); + assertTrue(document.hasField("_version")); + assertTrue(document.hasField("_id")); + assertTrue(document.hasField("_version_type")); } public void testShouldKeep(String a, String b) { @@ -105,57 +101,28 @@ public void testShouldKeep(String a, String b) { source.put("name", "eric clapton"); source.put("address", address); - IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), source); + IngestDocument document = RandomDocumentPicks.randomIngestDocument(random(), source); - assertTrue(RemoveProcessor.shouldKeep("name", List.of(new TestTemplateService.MockTemplateScript.Factory("name")), ingestDocument)); + assertTrue(shouldKeep("name", templates("name"), document)); - assertTrue(RemoveProcessor.shouldKeep("age", List.of(new TestTemplateService.MockTemplateScript.Factory("age")), ingestDocument)); + assertTrue(shouldKeep("age", templates("age"), document)); - assertFalse(RemoveProcessor.shouldKeep("name", List.of(new TestTemplateService.MockTemplateScript.Factory("age")), ingestDocument)); + assertFalse(shouldKeep("name", templates("age"), document)); - assertTrue( - RemoveProcessor.shouldKeep( - "address", - List.of(new TestTemplateService.MockTemplateScript.Factory("address.street")), - ingestDocument - ) - ); + assertTrue(shouldKeep("address", templates("address.street"), document)); - assertTrue( - RemoveProcessor.shouldKeep( - "address", - List.of(new TestTemplateService.MockTemplateScript.Factory("address.number")), - ingestDocument - ) - ); + assertTrue(shouldKeep("address", templates("address.number"), document)); - assertTrue( - RemoveProcessor.shouldKeep( - "address.street", - List.of(new TestTemplateService.MockTemplateScript.Factory("address")), - ingestDocument - ) - ); + assertTrue(shouldKeep("address.street", templates("address"), document)); - assertTrue( - RemoveProcessor.shouldKeep( - "address.number", - List.of(new TestTemplateService.MockTemplateScript.Factory("address")), - ingestDocument - ) - ); + assertTrue(shouldKeep("address.number", templates("address"), document)); - assertTrue( - RemoveProcessor.shouldKeep("address", List.of(new TestTemplateService.MockTemplateScript.Factory("address")), ingestDocument) - ); + assertTrue(shouldKeep("address", templates("address"), document)); - assertFalse( - RemoveProcessor.shouldKeep( - "address.street", - List.of(new TestTemplateService.MockTemplateScript.Factory("address.number")), - ingestDocument - ) - ); + assertFalse(shouldKeep("address.street", templates("address.number"), document)); } + private static List templates(String... fields) { + return Arrays.stream(fields).map(f -> (TemplateScript.Factory) new TestTemplateService.MockTemplateScript.Factory(f)).toList(); + } } From e67568de57ce431989f9596add67dd17f7fbbb8e Mon Sep 17 00:00:00 2001 From: Joe Gallo Date: Tue, 8 Apr 2025 09:48:31 -0400 Subject: [PATCH 2/3] Whitespace --- .../ingest/common/RemoveProcessorTests.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/RemoveProcessorTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/RemoveProcessorTests.java index 8b6e0b9b8bcdb..b8e2e2b526564 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/RemoveProcessorTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/RemoveProcessorTests.java @@ -81,6 +81,7 @@ public void testKeepFields() throws Exception { Processor processor = new RemoveProcessor(null, null, List.of(), templates("name", "address.street"), false); processor.execute(document); + assertTrue(document.hasField("name")); assertTrue(document.hasField("address")); assertTrue(document.hasField("address.street")); @@ -104,21 +105,13 @@ public void testShouldKeep(String a, String b) { IngestDocument document = RandomDocumentPicks.randomIngestDocument(random(), source); assertTrue(shouldKeep("name", templates("name"), document)); - assertTrue(shouldKeep("age", templates("age"), document)); - assertFalse(shouldKeep("name", templates("age"), document)); - assertTrue(shouldKeep("address", templates("address.street"), document)); - assertTrue(shouldKeep("address", templates("address.number"), document)); - assertTrue(shouldKeep("address.street", templates("address"), document)); - assertTrue(shouldKeep("address.number", templates("address"), document)); - assertTrue(shouldKeep("address", templates("address"), document)); - assertFalse(shouldKeep("address.street", templates("address.number"), document)); } From 37edcb061f92adccc17473a77fc2ce10602f0887 Mon Sep 17 00:00:00 2001 From: Joe Gallo Date: Tue, 8 Apr 2025 09:52:33 -0400 Subject: [PATCH 3/3] Make this test actually run --- .../org/elasticsearch/ingest/common/RemoveProcessorTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/RemoveProcessorTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/RemoveProcessorTests.java index b8e2e2b526564..14fa2b0ca5f0d 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/RemoveProcessorTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/RemoveProcessorTests.java @@ -93,7 +93,7 @@ public void testKeepFields() throws Exception { assertTrue(document.hasField("_version_type")); } - public void testShouldKeep(String a, String b) { + public void testShouldKeep() { Map address = new HashMap<>(); address.put("street", "Ipiranga Street"); address.put("number", 123);