From f8a67a262210692d1e2bc0f48ee63f70a51809a5 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Wed, 30 Mar 2016 21:42:16 -0400 Subject: [PATCH] Remove PROTOTYPEs from ingest --- .../resources/checkstyle_suppressions.xml | 1 - .../ingest/SimulateDocumentBaseResult.java | 54 +++++++++---------- .../ingest/SimulateDocumentVerboseResult.java | 25 ++++----- .../ingest/SimulatePipelineResponse.java | 4 +- .../SimulateDocumentSimpleResultTests.java | 2 +- 5 files changed, 36 insertions(+), 50 deletions(-) diff --git a/buildSrc/src/main/resources/checkstyle_suppressions.xml b/buildSrc/src/main/resources/checkstyle_suppressions.xml index dabbf43b235..b2331039411 100644 --- a/buildSrc/src/main/resources/checkstyle_suppressions.xml +++ b/buildSrc/src/main/resources/checkstyle_suppressions.xml @@ -187,7 +187,6 @@ - diff --git a/core/src/main/java/org/elasticsearch/action/ingest/SimulateDocumentBaseResult.java b/core/src/main/java/org/elasticsearch/action/ingest/SimulateDocumentBaseResult.java index 036703e98f1..590c5b546ce 100644 --- a/core/src/main/java/org/elasticsearch/action/ingest/SimulateDocumentBaseResult.java +++ b/core/src/main/java/org/elasticsearch/action/ingest/SimulateDocumentBaseResult.java @@ -25,52 +25,35 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.ingest.core.IngestDocument; import java.io.IOException; -import java.util.Collections; /** * Holds the end result of what a pipeline did to sample document provided via the simulate api. */ public final class SimulateDocumentBaseResult implements SimulateDocumentResult { - - private static final SimulateDocumentBaseResult PROTOTYPE = new SimulateDocumentBaseResult(new WriteableIngestDocument(new IngestDocument(Collections.emptyMap(), Collections.emptyMap()))); - - private WriteableIngestDocument ingestDocument; - private Exception failure; + private final WriteableIngestDocument ingestDocument; + private final Exception failure; public SimulateDocumentBaseResult(IngestDocument ingestDocument) { this.ingestDocument = new WriteableIngestDocument(ingestDocument); - } - - private SimulateDocumentBaseResult(WriteableIngestDocument ingestDocument) { - this.ingestDocument = ingestDocument; + failure = null; } public SimulateDocumentBaseResult(Exception failure) { + ingestDocument = null; this.failure = failure; } - public IngestDocument getIngestDocument() { - if (ingestDocument == null) { - return null; - } - return ingestDocument.getIngestDocument(); - } - - public Exception getFailure() { - return failure; - } - - public static SimulateDocumentBaseResult readSimulateDocumentSimpleResult(StreamInput in) throws IOException { - return PROTOTYPE.readFrom(in); - } - - @Override - public SimulateDocumentBaseResult readFrom(StreamInput in) throws IOException { + /** + * Read from a stream. + */ + public SimulateDocumentBaseResult(StreamInput in) throws IOException { if (in.readBoolean()) { - Exception exception = in.readThrowable(); - return new SimulateDocumentBaseResult(exception); + ingestDocument = null; + failure = in.readThrowable(); + } else { + ingestDocument = new WriteableIngestDocument(in); + failure = null; } - return new SimulateDocumentBaseResult(new WriteableIngestDocument(in)); } @Override @@ -84,6 +67,17 @@ public final class SimulateDocumentBaseResult implements SimulateDocumentResult< } } + public IngestDocument getIngestDocument() { + if (ingestDocument == null) { + return null; + } + return ingestDocument.getIngestDocument(); + } + + public Exception getFailure() { + return failure; + } + @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); diff --git a/core/src/main/java/org/elasticsearch/action/ingest/SimulateDocumentVerboseResult.java b/core/src/main/java/org/elasticsearch/action/ingest/SimulateDocumentVerboseResult.java index d9d705f1018..d472cd0fe1c 100644 --- a/core/src/main/java/org/elasticsearch/action/ingest/SimulateDocumentVerboseResult.java +++ b/core/src/main/java/org/elasticsearch/action/ingest/SimulateDocumentVerboseResult.java @@ -24,7 +24,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import java.io.IOException; import java.util.ArrayList; -import java.util.Collections; import java.util.List; /** @@ -32,31 +31,21 @@ import java.util.List; * this result class holds the intermediate result each processor did to the sample document. */ public final class SimulateDocumentVerboseResult implements SimulateDocumentResult { - - private static final SimulateDocumentVerboseResult PROTOTYPE = new SimulateDocumentVerboseResult(Collections.emptyList()); - private final List processorResults; public SimulateDocumentVerboseResult(List processorResults) { this.processorResults = processorResults; } - public List getProcessorResults() { - return processorResults; - } - - public static SimulateDocumentVerboseResult readSimulateDocumentVerboseResultFrom(StreamInput in) throws IOException { - return PROTOTYPE.readFrom(in); - } - - @Override - public SimulateDocumentVerboseResult readFrom(StreamInput in) throws IOException { + /** + * Read from a stream. + */ + public SimulateDocumentVerboseResult(StreamInput in) throws IOException { int size = in.readVInt(); - List processorResults = new ArrayList<>(); + processorResults = new ArrayList<>(size); for (int i = 0; i < size; i++) { processorResults.add(new SimulateProcessorResult(in)); } - return new SimulateDocumentVerboseResult(processorResults); } @Override @@ -67,6 +56,10 @@ public final class SimulateDocumentVerboseResult implements SimulateDocumentResu } } + public List getProcessorResults() { + return processorResults; + } + @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); diff --git a/core/src/main/java/org/elasticsearch/action/ingest/SimulatePipelineResponse.java b/core/src/main/java/org/elasticsearch/action/ingest/SimulatePipelineResponse.java index c7c0822f04a..92f9aad8fec 100644 --- a/core/src/main/java/org/elasticsearch/action/ingest/SimulatePipelineResponse.java +++ b/core/src/main/java/org/elasticsearch/action/ingest/SimulatePipelineResponse.java @@ -79,9 +79,9 @@ public class SimulatePipelineResponse extends ActionResponse implements ToXConte for (int i = 0; i < responsesLength; i++) { SimulateDocumentResult simulateDocumentResult; if (verbose) { - simulateDocumentResult = SimulateDocumentVerboseResult.readSimulateDocumentVerboseResultFrom(in); + simulateDocumentResult = new SimulateDocumentVerboseResult(in); } else { - simulateDocumentResult = SimulateDocumentBaseResult.readSimulateDocumentSimpleResult(in); + simulateDocumentResult = new SimulateDocumentBaseResult(in); } results.add(simulateDocumentResult); } 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 882fca72156..e665c7b6eeb 100644 --- a/core/src/test/java/org/elasticsearch/action/ingest/SimulateDocumentSimpleResultTests.java +++ b/core/src/test/java/org/elasticsearch/action/ingest/SimulateDocumentSimpleResultTests.java @@ -45,7 +45,7 @@ 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) {