diff options
author | Jason Tedor <jason@tedor.me> | 2016-05-14 17:33:52 -0400 |
---|---|---|
committer | Jason Tedor <jason@tedor.me> | 2016-05-14 20:23:59 -0400 |
commit | 15d3d74444ede63651f5ef10dd172da5293529ad (patch) | |
tree | 5628f7c0166e21e559bd76b3791f5faf27292c3a /core/src/test/java/org/elasticsearch/action/ingest | |
parent | dcd2642dad0ac54a6a58abe47b809ca9c665a6dd (diff) | |
parent | d3d57da89ff3ae4071f93af97c1f71e7b8d3364a (diff) |
Merge branch 'master' into feature/seq_no
* master: (904 commits)
Removes unused methods in the o/e/common/Strings class.
Add note regarding thread stack size on Windows
painless: restore accidentally removed test
Documented fuzzy_transpositions in match query
Add not-null precondition check in BulkRequest
Build: Make run task you full zip distribution
Build: More pom generation improvements
Add test for wrong array index
Take return type from "after" field.
painless: build descriptor of array and field load/store in code; fix array index to adapt type not DEF
Build: Add developer info to generated pom files
painless: improve exception stacktraces
painless: Rename the dynamic call site factory to DefBootstrap and make the inner class very short (PIC = Polymorphic Inline Cache)
Remove dead code.
Avoid race while retiring executors
Allow only a single extension for a scripting engine
Adding REST tests to ensure key_as_string behavior stays consistent
[test] Set logging to 11 on reindex test
[TEST] increase logger level until we know what is going on
Don't allow `fuzziness` for `multi_match` types cross_fields, phrase and phrase_prefix
...
Diffstat (limited to 'core/src/test/java/org/elasticsearch/action/ingest')
7 files changed, 80 insertions, 42 deletions
diff --git a/core/src/test/java/org/elasticsearch/action/ingest/IngestProxyActionFilterTests.java b/core/src/test/java/org/elasticsearch/action/ingest/IngestProxyActionFilterTests.java index c027e4ecd1..a62946bf0f 100644 --- a/core/src/test/java/org/elasticsearch/action/ingest/IngestProxyActionFilterTests.java +++ b/core/src/test/java/org/elasticsearch/action/ingest/IngestProxyActionFilterTests.java @@ -46,7 +46,9 @@ import org.hamcrest.CustomTypeSafeMatcher; import org.mockito.stubbing.Answer; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; +import java.util.Set; import static org.hamcrest.CoreMatchers.equalTo; import static org.mockito.Matchers.any; @@ -72,12 +74,11 @@ public class IngestProxyActionFilterTests extends ESTestCase { for (int i = 0; i < totalNodes; i++) { String nodeId = "node" + i; Map<String, String> attributes = new HashMap<>(); - if (i >= ingestNodes) { - attributes.put("ingest", "false"); - } else if (randomBoolean()) { - attributes.put("ingest", "true"); + Set<DiscoveryNode.Role> roles = new HashSet<>(); + if (i < ingestNodes) { + roles.add(DiscoveryNode.Role.INGEST); } - DiscoveryNode node = new DiscoveryNode(nodeId, nodeId, DummyTransportAddress.INSTANCE, attributes, VersionUtils.randomVersion(random())); + DiscoveryNode node = new DiscoveryNode(nodeId, nodeId, DummyTransportAddress.INSTANCE, attributes, roles, VersionUtils.randomVersion(random())); builder.put(node); if (i == totalNodes - 1) { localNode = node; diff --git a/core/src/test/java/org/elasticsearch/action/ingest/SimulateDocumentSimpleResultTests.java b/core/src/test/java/org/elasticsearch/action/ingest/SimulateDocumentSimpleResultTests.java index 882fca7215..52c13b9270 100644 --- a/core/src/test/java/org/elasticsearch/action/ingest/SimulateDocumentSimpleResultTests.java +++ b/core/src/test/java/org/elasticsearch/action/ingest/SimulateDocumentSimpleResultTests.java @@ -21,12 +21,13 @@ package org.elasticsearch.action.ingest; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.ingest.core.IngestDocument; import org.elasticsearch.ingest.RandomDocumentPicks; +import org.elasticsearch.ingest.core.IngestDocument; import org.elasticsearch.test.ESTestCase; import java.io.IOException; +import static org.elasticsearch.ingest.core.IngestDocumentTests.assertIngestDocument; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.instanceOf; @@ -45,13 +46,15 @@ public class SimulateDocumentSimpleResultTests extends ESTestCase { BytesStreamOutput out = new BytesStreamOutput(); simulateDocumentBaseResult.writeTo(out); StreamInput streamInput = StreamInput.wrap(out.bytes()); - SimulateDocumentBaseResult otherSimulateDocumentBaseResult = SimulateDocumentBaseResult.readSimulateDocumentSimpleResult(streamInput); + SimulateDocumentBaseResult otherSimulateDocumentBaseResult = new SimulateDocumentBaseResult(streamInput); - assertThat(otherSimulateDocumentBaseResult.getIngestDocument(), equalTo(simulateDocumentBaseResult.getIngestDocument())); if (isFailure) { + assertThat(otherSimulateDocumentBaseResult.getIngestDocument(), equalTo(simulateDocumentBaseResult.getIngestDocument())); assertThat(otherSimulateDocumentBaseResult.getFailure(), instanceOf(IllegalArgumentException.class)); IllegalArgumentException e = (IllegalArgumentException) otherSimulateDocumentBaseResult.getFailure(); assertThat(e.getMessage(), equalTo("test")); + } else { + assertIngestDocument(otherSimulateDocumentBaseResult.getIngestDocument(), simulateDocumentBaseResult.getIngestDocument()); } } } diff --git a/core/src/test/java/org/elasticsearch/action/ingest/SimulateExecutionServiceTests.java b/core/src/test/java/org/elasticsearch/action/ingest/SimulateExecutionServiceTests.java index f66dfa81ea..56e67bb4ad 100644 --- a/core/src/test/java/org/elasticsearch/action/ingest/SimulateExecutionServiceTests.java +++ b/core/src/test/java/org/elasticsearch/action/ingest/SimulateExecutionServiceTests.java @@ -23,7 +23,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.ingest.RandomDocumentPicks; import org.elasticsearch.ingest.TestProcessor; import org.elasticsearch.ingest.core.CompoundProcessor; -import org.elasticsearch.ingest.core.Processor; import org.elasticsearch.ingest.core.IngestDocument; import org.elasticsearch.ingest.core.Pipeline; import org.elasticsearch.test.ESTestCase; @@ -34,6 +33,7 @@ import org.junit.Before; import java.util.Collections; import java.util.Map; +import static org.elasticsearch.ingest.core.IngestDocumentTests.assertIngestDocument; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.not; @@ -44,7 +44,6 @@ public class SimulateExecutionServiceTests extends ESTestCase { private ThreadPool threadPool; private SimulateExecutionService executionService; - private Processor processor; private IngestDocument ingestDocument; @Before @@ -55,7 +54,6 @@ public class SimulateExecutionServiceTests extends ESTestCase { .build() ); executionService = new SimulateExecutionService(threadPool); - processor = new TestProcessor("id", "mock", ingestDocument -> {}); ingestDocument = RandomDocumentPicks.randomIngestDocument(random()); } @@ -73,17 +71,19 @@ public class SimulateExecutionServiceTests extends ESTestCase { SimulateDocumentVerboseResult simulateDocumentVerboseResult = (SimulateDocumentVerboseResult) actualItemResponse; assertThat(simulateDocumentVerboseResult.getProcessorResults().size(), equalTo(2)); assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getProcessorTag(), equalTo("test-id")); - assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getIngestDocument(), not(sameInstance(ingestDocument))); - assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getIngestDocument(), equalTo(ingestDocument)); - assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getIngestDocument().getSourceAndMetadata(), not(sameInstance(ingestDocument.getSourceAndMetadata()))); + IngestDocument firstProcessorIngestDocument = simulateDocumentVerboseResult.getProcessorResults().get(0).getIngestDocument(); + assertThat(firstProcessorIngestDocument, not(sameInstance(this.ingestDocument))); + assertIngestDocument(firstProcessorIngestDocument, this.ingestDocument); + assertThat(firstProcessorIngestDocument.getSourceAndMetadata(), not(sameInstance(this.ingestDocument.getSourceAndMetadata()))); assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getFailure(), nullValue()); assertThat(simulateDocumentVerboseResult.getProcessorResults().get(1).getProcessorTag(), equalTo("test-id")); - assertThat(simulateDocumentVerboseResult.getProcessorResults().get(1).getIngestDocument(), not(sameInstance(ingestDocument))); - assertThat(simulateDocumentVerboseResult.getProcessorResults().get(1).getIngestDocument(), equalTo(ingestDocument)); - assertThat(simulateDocumentVerboseResult.getProcessorResults().get(1).getIngestDocument().getSourceAndMetadata(), not(sameInstance(ingestDocument.getSourceAndMetadata()))); - assertThat(simulateDocumentVerboseResult.getProcessorResults().get(1).getIngestDocument().getSourceAndMetadata(), - not(sameInstance(simulateDocumentVerboseResult.getProcessorResults().get(0).getIngestDocument().getSourceAndMetadata()))); + IngestDocument secondProcessorIngestDocument = simulateDocumentVerboseResult.getProcessorResults().get(1).getIngestDocument(); + assertThat(secondProcessorIngestDocument, not(sameInstance(this.ingestDocument))); + assertIngestDocument(secondProcessorIngestDocument, this.ingestDocument); + assertThat(secondProcessorIngestDocument.getSourceAndMetadata(), not(sameInstance(this.ingestDocument.getSourceAndMetadata()))); + assertThat(secondProcessorIngestDocument.getSourceAndMetadata(), + not(sameInstance(firstProcessorIngestDocument.getSourceAndMetadata()))); assertThat(simulateDocumentVerboseResult.getProcessorResults().get(1).getFailure(), nullValue()); } @@ -113,7 +113,7 @@ public class SimulateExecutionServiceTests extends ESTestCase { assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getProcessorTag(), equalTo("processor_0")); assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getFailure(), nullValue()); assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getIngestDocument(), not(sameInstance(ingestDocument))); - assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getIngestDocument(), equalTo(ingestDocument)); + assertIngestDocument(simulateDocumentVerboseResult.getProcessorResults().get(0).getIngestDocument(), ingestDocument); assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getIngestDocument().getSourceAndMetadata(), not(sameInstance(ingestDocument.getSourceAndMetadata()))); assertThat(simulateDocumentVerboseResult.getProcessorResults().get(1).getProcessorTag(), equalTo("processor_1")); assertThat(simulateDocumentVerboseResult.getProcessorResults().get(1).getIngestDocument(), nullValue()); @@ -148,13 +148,13 @@ public class SimulateExecutionServiceTests extends ESTestCase { metadata.put(CompoundProcessor.ON_FAILURE_PROCESSOR_TYPE_FIELD, "mock"); metadata.put(CompoundProcessor.ON_FAILURE_PROCESSOR_TAG_FIELD, "processor_0"); metadata.put(CompoundProcessor.ON_FAILURE_MESSAGE_FIELD, "processor failed"); - assertThat(simulateDocumentVerboseResult.getProcessorResults().get(1).getIngestDocument(), equalTo(ingestDocumentWithOnFailureMetadata)); + assertIngestDocument(simulateDocumentVerboseResult.getProcessorResults().get(1).getIngestDocument(), ingestDocumentWithOnFailureMetadata); assertThat(simulateDocumentVerboseResult.getProcessorResults().get(1).getFailure(), nullValue()); assertThat(simulateDocumentVerboseResult.getProcessorResults().get(2).getProcessorTag(), equalTo("processor_2")); assertThat(simulateDocumentVerboseResult.getProcessorResults().get(2).getIngestDocument(), not(sameInstance(ingestDocument))); - assertThat(simulateDocumentVerboseResult.getProcessorResults().get(2).getIngestDocument(), equalTo(ingestDocument)); + assertIngestDocument(simulateDocumentVerboseResult.getProcessorResults().get(2).getIngestDocument(), ingestDocument); assertThat(simulateDocumentVerboseResult.getProcessorResults().get(2).getFailure(), nullValue()); } diff --git a/core/src/test/java/org/elasticsearch/action/ingest/SimulatePipelineRequestParsingTests.java b/core/src/test/java/org/elasticsearch/action/ingest/SimulatePipelineRequestParsingTests.java index de0a28fd7e..b7cd5ef0b9 100644 --- a/core/src/test/java/org/elasticsearch/action/ingest/SimulatePipelineRequestParsingTests.java +++ b/core/src/test/java/org/elasticsearch/action/ingest/SimulatePipelineRequestParsingTests.java @@ -39,6 +39,7 @@ import java.util.List; import java.util.Map; import static org.elasticsearch.action.ingest.SimulatePipelineRequest.Fields; +import static org.elasticsearch.action.ingest.SimulatePipelineRequest.SIMULATED_PIPELINE_ID; import static org.elasticsearch.ingest.core.IngestDocument.MetaData.ID; import static org.elasticsearch.ingest.core.IngestDocument.MetaData.INDEX; import static org.elasticsearch.ingest.core.IngestDocument.MetaData.TYPE; @@ -55,12 +56,12 @@ public class SimulatePipelineRequestParsingTests extends ESTestCase { public void init() throws IOException { TestProcessor processor = new TestProcessor(ingestDocument -> {}); CompoundProcessor pipelineCompoundProcessor = new CompoundProcessor(processor); - Pipeline pipeline = new Pipeline(SimulatePipelineRequest.SIMULATED_PIPELINE_ID, null, pipelineCompoundProcessor); + Pipeline pipeline = new Pipeline(SIMULATED_PIPELINE_ID, null, pipelineCompoundProcessor); ProcessorsRegistry.Builder processorRegistryBuilder = new ProcessorsRegistry.Builder(); processorRegistryBuilder.registerProcessor("mock_processor", ((templateService, registry) -> mock(Processor.Factory.class))); ProcessorsRegistry processorRegistry = processorRegistryBuilder.build(TestTemplateService.instance()); store = mock(PipelineStore.class); - when(store.get(SimulatePipelineRequest.SIMULATED_PIPELINE_ID)).thenReturn(pipeline); + when(store.get(SIMULATED_PIPELINE_ID)).thenReturn(pipeline); when(store.getProcessorRegistry()).thenReturn(processorRegistry); } @@ -91,7 +92,7 @@ public class SimulatePipelineRequestParsingTests extends ESTestCase { expectedDocs.add(expectedDoc); } - SimulatePipelineRequest.Parsed actualRequest = SimulatePipelineRequest.parseWithPipelineId(SimulatePipelineRequest.SIMULATED_PIPELINE_ID, requestContent, false, store); + SimulatePipelineRequest.Parsed actualRequest = SimulatePipelineRequest.parseWithPipelineId(SIMULATED_PIPELINE_ID, requestContent, false, store); assertThat(actualRequest.isVerbose(), equalTo(false)); assertThat(actualRequest.getDocuments().size(), equalTo(numDocs)); Iterator<Map<String, Object>> expectedDocsIterator = expectedDocs.iterator(); @@ -104,7 +105,7 @@ public class SimulatePipelineRequestParsingTests extends ESTestCase { assertThat(ingestDocument.getSourceAndMetadata(), equalTo(expectedDocument.get(Fields.SOURCE))); } - assertThat(actualRequest.getPipeline().getId(), equalTo(SimulatePipelineRequest.SIMULATED_PIPELINE_ID)); + assertThat(actualRequest.getPipeline().getId(), equalTo(SIMULATED_PIPELINE_ID)); assertThat(actualRequest.getPipeline().getDescription(), nullValue()); assertThat(actualRequest.getPipeline().getProcessors().size(), equalTo(1)); } @@ -177,8 +178,27 @@ public class SimulatePipelineRequestParsingTests extends ESTestCase { assertThat(ingestDocument.getSourceAndMetadata(), equalTo(expectedDocument.get(Fields.SOURCE))); } - assertThat(actualRequest.getPipeline().getId(), equalTo(SimulatePipelineRequest.SIMULATED_PIPELINE_ID)); + assertThat(actualRequest.getPipeline().getId(), equalTo(SIMULATED_PIPELINE_ID)); assertThat(actualRequest.getPipeline().getDescription(), nullValue()); assertThat(actualRequest.getPipeline().getProcessors().size(), equalTo(numProcessors)); } + + public void testNullPipelineId() { + Map<String, Object> requestContent = new HashMap<>(); + List<Map<String, Object>> docs = new ArrayList<>(); + requestContent.put(Fields.DOCS, docs); + Exception e = expectThrows(IllegalArgumentException.class, + () -> SimulatePipelineRequest.parseWithPipelineId(null, requestContent, false, store)); + assertThat(e.getMessage(), equalTo("param [pipeline] is null")); + } + + public void testNonExistentPipelineId() { + String pipelineId = randomAsciiOfLengthBetween(1, 10); + Map<String, Object> requestContent = new HashMap<>(); + List<Map<String, Object>> docs = new ArrayList<>(); + requestContent.put(Fields.DOCS, docs); + Exception e = expectThrows(IllegalArgumentException.class, + () -> SimulatePipelineRequest.parseWithPipelineId(pipelineId, requestContent, false, store)); + assertThat(e.getMessage(), equalTo("pipeline [" + pipelineId + "] does not exist")); + } } diff --git a/core/src/test/java/org/elasticsearch/action/ingest/SimulatePipelineResponseTests.java b/core/src/test/java/org/elasticsearch/action/ingest/SimulatePipelineResponseTests.java index 12a62f0684..c8f09a5ba8 100644 --- a/core/src/test/java/org/elasticsearch/action/ingest/SimulatePipelineResponseTests.java +++ b/core/src/test/java/org/elasticsearch/action/ingest/SimulatePipelineResponseTests.java @@ -30,6 +30,7 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import static org.elasticsearch.ingest.core.IngestDocumentTests.assertIngestDocument; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.nullValue; @@ -90,7 +91,9 @@ public class SimulatePipelineResponseTests extends ESTestCase { for (SimulateProcessorResult simulateProcessorResult : simulateDocumentVerboseResult.getProcessorResults()) { SimulateProcessorResult expectedProcessorResult = expectedProcessorResultIterator.next(); assertThat(simulateProcessorResult.getProcessorTag(), equalTo(expectedProcessorResult.getProcessorTag())); - assertThat(simulateProcessorResult.getIngestDocument(), equalTo(expectedProcessorResult.getIngestDocument())); + if (simulateProcessorResult.getIngestDocument() != null) { + assertIngestDocument(simulateProcessorResult.getIngestDocument(), expectedProcessorResult.getIngestDocument()); + } if (expectedProcessorResult.getFailure() == null) { assertThat(simulateProcessorResult.getFailure(), nullValue()); } else { @@ -103,7 +106,9 @@ public class SimulatePipelineResponseTests extends ESTestCase { SimulateDocumentBaseResult expectedSimulateDocumentBaseResult = (SimulateDocumentBaseResult) expectedResultIterator.next(); assertThat(result, instanceOf(SimulateDocumentBaseResult.class)); SimulateDocumentBaseResult simulateDocumentBaseResult = (SimulateDocumentBaseResult) result; - assertThat(simulateDocumentBaseResult.getIngestDocument(), equalTo(expectedSimulateDocumentBaseResult.getIngestDocument())); + if (simulateDocumentBaseResult.getIngestDocument() != null) { + assertIngestDocument(simulateDocumentBaseResult.getIngestDocument(), expectedSimulateDocumentBaseResult.getIngestDocument()); + } if (expectedSimulateDocumentBaseResult.getFailure() == null) { assertThat(simulateDocumentBaseResult.getFailure(), nullValue()); } else { diff --git a/core/src/test/java/org/elasticsearch/action/ingest/SimulateProcessorResultTests.java b/core/src/test/java/org/elasticsearch/action/ingest/SimulateProcessorResultTests.java index 0885475adc..0ee1a5699d 100644 --- a/core/src/test/java/org/elasticsearch/action/ingest/SimulateProcessorResultTests.java +++ b/core/src/test/java/org/elasticsearch/action/ingest/SimulateProcessorResultTests.java @@ -21,14 +21,17 @@ package org.elasticsearch.action.ingest; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.ingest.core.IngestDocument; import org.elasticsearch.ingest.RandomDocumentPicks; +import org.elasticsearch.ingest.core.IngestDocument; import org.elasticsearch.test.ESTestCase; import java.io.IOException; +import static org.elasticsearch.ingest.core.IngestDocumentTests.assertIngestDocument; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; public class SimulateProcessorResultTests extends ESTestCase { @@ -48,11 +51,13 @@ public class SimulateProcessorResultTests extends ESTestCase { StreamInput streamInput = StreamInput.wrap(out.bytes()); SimulateProcessorResult otherSimulateProcessorResult = new SimulateProcessorResult(streamInput); assertThat(otherSimulateProcessorResult.getProcessorTag(), equalTo(simulateProcessorResult.getProcessorTag())); - assertThat(otherSimulateProcessorResult.getIngestDocument(), equalTo(simulateProcessorResult.getIngestDocument())); if (isFailure) { + assertThat(simulateProcessorResult.getIngestDocument(), is(nullValue())); assertThat(otherSimulateProcessorResult.getFailure(), instanceOf(IllegalArgumentException.class)); IllegalArgumentException e = (IllegalArgumentException) otherSimulateProcessorResult.getFailure(); assertThat(e.getMessage(), equalTo("test")); + } else { + assertIngestDocument(otherSimulateProcessorResult.getIngestDocument(), simulateProcessorResult.getIngestDocument()); } } } diff --git a/core/src/test/java/org/elasticsearch/action/ingest/WriteableIngestDocumentTests.java b/core/src/test/java/org/elasticsearch/action/ingest/WriteableIngestDocumentTests.java index 828c36e7a3..810947c8e0 100644 --- a/core/src/test/java/org/elasticsearch/action/ingest/WriteableIngestDocumentTests.java +++ b/core/src/test/java/org/elasticsearch/action/ingest/WriteableIngestDocumentTests.java @@ -21,22 +21,23 @@ package org.elasticsearch.action.ingest; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.ingest.RandomDocumentPicks; import org.elasticsearch.ingest.core.IngestDocument; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.test.XContentTestUtils; import java.io.IOException; import java.util.Collections; import java.util.HashMap; import java.util.Map; -import static org.elasticsearch.test.XContentTestUtils.convertToMap; -import static org.elasticsearch.test.XContentTestUtils.differenceBetweenMapsIgnoringArrayOrder; +import static org.elasticsearch.common.xcontent.ToXContent.EMPTY_PARAMS; +import static org.elasticsearch.ingest.core.IngestDocumentTests.assertIngestDocument; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.nullValue; public class WriteableIngestDocumentTests extends ESTestCase { @@ -107,14 +108,13 @@ public class WriteableIngestDocumentTests extends ESTestCase { for (int i = 0; i < numFields; i++) { ingestMetadata.put(randomAsciiOfLengthBetween(5, 10), randomAsciiOfLengthBetween(5, 10)); } - Map<String, Object> document = RandomDocumentPicks.randomSource(random()); WriteableIngestDocument writeableIngestDocument = new WriteableIngestDocument(new IngestDocument(sourceAndMetadata, ingestMetadata)); BytesStreamOutput out = new BytesStreamOutput(); writeableIngestDocument.writeTo(out); StreamInput streamInput = StreamInput.wrap(out.bytes()); WriteableIngestDocument otherWriteableIngestDocument = new WriteableIngestDocument(streamInput); - assertThat(otherWriteableIngestDocument, equalTo(writeableIngestDocument)); + assertIngestDocument(otherWriteableIngestDocument.getIngestDocument(), writeableIngestDocument.getIngestDocument()); } @SuppressWarnings("unchecked") @@ -122,7 +122,13 @@ public class WriteableIngestDocumentTests extends ESTestCase { IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random()); WriteableIngestDocument writeableIngestDocument = new WriteableIngestDocument(new IngestDocument(ingestDocument)); - Map<String, Object> toXContentMap = convertToMap(writeableIngestDocument); + // using a cbor builder here, so that byte arrays do not get converted, so equalTo() below works + XContentBuilder builder = XContentFactory.cborBuilder(); + builder.startObject(); + writeableIngestDocument.toXContent(builder, EMPTY_PARAMS); + builder.endObject(); + Map<String, Object> toXContentMap = XContentHelper.convertToMap(builder.bytes(), false).v2(); + Map<String, Object> toXContentDoc = (Map<String, Object>) toXContentMap.get("doc"); Map<String, Object> toXContentSource = (Map<String, Object>) toXContentDoc.get("_source"); Map<String, String> toXContentIngestMetadata = (Map<String, String>) toXContentDoc.get("_ingest"); @@ -137,9 +143,7 @@ public class WriteableIngestDocumentTests extends ESTestCase { } } - String sourceDiff = differenceBetweenMapsIgnoringArrayOrder(toXContentSource, ingestDocument.getSourceAndMetadata()); - assertThat(sourceDiff, is(nullValue())); - - assertThat(toXContentIngestMetadata, equalTo(ingestDocument.getIngestMetadata())); + IngestDocument serializedIngestDocument = new IngestDocument(toXContentSource, toXContentIngestMetadata); + assertThat(serializedIngestDocument, equalTo(serializedIngestDocument)); } } |