renamed SimulateDocumentSimpleResult to SimulateDocumentBaseResult and added jdocs

This commit is contained in:
Martijn van Groningen 2016-01-20 14:11:45 +01:00
parent 8b520111d0
commit 2645fc9145
8 changed files with 56 additions and 50 deletions

View File

@ -27,22 +27,25 @@ import org.elasticsearch.ingest.core.IngestDocument;
import java.io.IOException; import java.io.IOException;
import java.util.Collections; import java.util.Collections;
public class SimulateDocumentSimpleResult implements SimulateDocumentResult<SimulateDocumentSimpleResult> { /**
* Holds the end result of what a pipeline did to sample document provided via the simulate api.
*/
public final class SimulateDocumentBaseResult implements SimulateDocumentResult<SimulateDocumentBaseResult> {
private static final SimulateDocumentSimpleResult PROTOTYPE = new SimulateDocumentSimpleResult(new WriteableIngestDocument(new IngestDocument(Collections.emptyMap(), Collections.emptyMap()))); private static final SimulateDocumentBaseResult PROTOTYPE = new SimulateDocumentBaseResult(new WriteableIngestDocument(new IngestDocument(Collections.emptyMap(), Collections.emptyMap())));
private WriteableIngestDocument ingestDocument; private WriteableIngestDocument ingestDocument;
private Exception failure; private Exception failure;
public SimulateDocumentSimpleResult(IngestDocument ingestDocument) { public SimulateDocumentBaseResult(IngestDocument ingestDocument) {
this.ingestDocument = new WriteableIngestDocument(ingestDocument); this.ingestDocument = new WriteableIngestDocument(ingestDocument);
} }
private SimulateDocumentSimpleResult(WriteableIngestDocument ingestDocument) { private SimulateDocumentBaseResult(WriteableIngestDocument ingestDocument) {
this.ingestDocument = ingestDocument; this.ingestDocument = ingestDocument;
} }
public SimulateDocumentSimpleResult(Exception failure) { public SimulateDocumentBaseResult(Exception failure) {
this.failure = failure; this.failure = failure;
} }
@ -57,17 +60,17 @@ public class SimulateDocumentSimpleResult implements SimulateDocumentResult<Simu
return failure; return failure;
} }
public static SimulateDocumentSimpleResult readSimulateDocumentSimpleResult(StreamInput in) throws IOException { public static SimulateDocumentBaseResult readSimulateDocumentSimpleResult(StreamInput in) throws IOException {
return PROTOTYPE.readFrom(in); return PROTOTYPE.readFrom(in);
} }
@Override @Override
public SimulateDocumentSimpleResult readFrom(StreamInput in) throws IOException { public SimulateDocumentBaseResult readFrom(StreamInput in) throws IOException {
if (in.readBoolean()) { if (in.readBoolean()) {
Exception exception = in.readThrowable(); Exception exception = in.readThrowable();
return new SimulateDocumentSimpleResult(exception); return new SimulateDocumentBaseResult(exception);
} }
return new SimulateDocumentSimpleResult(new WriteableIngestDocument(in)); return new SimulateDocumentBaseResult(new WriteableIngestDocument(in));
} }
@Override @Override

View File

@ -21,14 +21,17 @@ package org.elasticsearch.action.ingest;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentBuilderString;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
public class SimulateDocumentVerboseResult implements SimulateDocumentResult<SimulateDocumentVerboseResult> { /**
* Holds the result of what a pipeline did to a sample document via the simulate api, but instead of {@link SimulateDocumentBaseResult}
* this result class holds the intermediate result each processor did to the sample document.
*/
public final class SimulateDocumentVerboseResult implements SimulateDocumentResult<SimulateDocumentVerboseResult> {
private static final SimulateDocumentVerboseResult PROTOTYPE = new SimulateDocumentVerboseResult(Collections.emptyList()); private static final SimulateDocumentVerboseResult PROTOTYPE = new SimulateDocumentVerboseResult(Collections.emptyList());

View File

@ -71,15 +71,15 @@ class SimulateExecutionService {
try { try {
executeVerboseDocument(pipelineProcessor, currentIngestDocument, processorResultList); executeVerboseDocument(pipelineProcessor, currentIngestDocument, processorResultList);
} catch (Exception e) { } catch (Exception e) {
return new SimulateDocumentSimpleResult(e); return new SimulateDocumentBaseResult(e);
} }
return new SimulateDocumentVerboseResult(processorResultList); return new SimulateDocumentVerboseResult(processorResultList);
} else { } else {
try { try {
pipeline.execute(ingestDocument); pipeline.execute(ingestDocument);
return new SimulateDocumentSimpleResult(ingestDocument); return new SimulateDocumentBaseResult(ingestDocument);
} catch (Exception e) { } catch (Exception e) {
return new SimulateDocumentSimpleResult(e); return new SimulateDocumentBaseResult(e);
} }
} }
} }

View File

@ -81,7 +81,7 @@ public class SimulatePipelineResponse extends ActionResponse implements ToXConte
if (verbose) { if (verbose) {
simulateDocumentResult = SimulateDocumentVerboseResult.readSimulateDocumentVerboseResultFrom(in); simulateDocumentResult = SimulateDocumentVerboseResult.readSimulateDocumentVerboseResultFrom(in);
} else { } else {
simulateDocumentResult = SimulateDocumentSimpleResult.readSimulateDocumentSimpleResult(in); simulateDocumentResult = SimulateDocumentBaseResult.readSimulateDocumentSimpleResult(in);
} }
results.add(simulateDocumentResult); results.add(simulateDocumentResult);
} }

View File

@ -34,23 +34,23 @@ public class SimulateDocumentSimpleResultTests extends ESTestCase {
public void testSerialization() throws IOException { public void testSerialization() throws IOException {
boolean isFailure = randomBoolean(); boolean isFailure = randomBoolean();
SimulateDocumentSimpleResult simulateDocumentSimpleResult; SimulateDocumentBaseResult simulateDocumentBaseResult;
if (isFailure) { if (isFailure) {
simulateDocumentSimpleResult = new SimulateDocumentSimpleResult(new IllegalArgumentException("test")); simulateDocumentBaseResult = new SimulateDocumentBaseResult(new IllegalArgumentException("test"));
} else { } else {
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random()); IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
simulateDocumentSimpleResult = new SimulateDocumentSimpleResult(ingestDocument); simulateDocumentBaseResult = new SimulateDocumentBaseResult(ingestDocument);
} }
BytesStreamOutput out = new BytesStreamOutput(); BytesStreamOutput out = new BytesStreamOutput();
simulateDocumentSimpleResult.writeTo(out); simulateDocumentBaseResult.writeTo(out);
StreamInput streamInput = StreamInput.wrap(out.bytes()); StreamInput streamInput = StreamInput.wrap(out.bytes());
SimulateDocumentSimpleResult otherSimulateDocumentSimpleResult = SimulateDocumentSimpleResult.readSimulateDocumentSimpleResult(streamInput); SimulateDocumentBaseResult otherSimulateDocumentBaseResult = SimulateDocumentBaseResult.readSimulateDocumentSimpleResult(streamInput);
assertThat(otherSimulateDocumentSimpleResult.getIngestDocument(), equalTo(simulateDocumentSimpleResult.getIngestDocument())); assertThat(otherSimulateDocumentBaseResult.getIngestDocument(), equalTo(simulateDocumentBaseResult.getIngestDocument()));
if (isFailure) { if (isFailure) {
assertThat(otherSimulateDocumentSimpleResult.getFailure(), instanceOf(IllegalArgumentException.class)); assertThat(otherSimulateDocumentBaseResult.getFailure(), instanceOf(IllegalArgumentException.class));
IllegalArgumentException e = (IllegalArgumentException) otherSimulateDocumentSimpleResult.getFailure(); IllegalArgumentException e = (IllegalArgumentException) otherSimulateDocumentBaseResult.getFailure();
assertThat(e.getMessage(), equalTo("test")); assertThat(e.getMessage(), equalTo("test"));
} }
} }

View File

@ -164,10 +164,10 @@ public class SimulateExecutionServiceTests extends ESTestCase {
Pipeline pipeline = new Pipeline("_id", "_description", new CompoundProcessor(processor, processor)); Pipeline pipeline = new Pipeline("_id", "_description", new CompoundProcessor(processor, processor));
SimulateDocumentResult actualItemResponse = executionService.executeDocument(pipeline, ingestDocument, false); SimulateDocumentResult actualItemResponse = executionService.executeDocument(pipeline, ingestDocument, false);
assertThat(processor.getInvokedCounter(), equalTo(2)); assertThat(processor.getInvokedCounter(), equalTo(2));
assertThat(actualItemResponse, instanceOf(SimulateDocumentSimpleResult.class)); assertThat(actualItemResponse, instanceOf(SimulateDocumentBaseResult.class));
SimulateDocumentSimpleResult simulateDocumentSimpleResult = (SimulateDocumentSimpleResult) actualItemResponse; SimulateDocumentBaseResult simulateDocumentBaseResult = (SimulateDocumentBaseResult) actualItemResponse;
assertThat(simulateDocumentSimpleResult.getIngestDocument(), equalTo(ingestDocument)); assertThat(simulateDocumentBaseResult.getIngestDocument(), equalTo(ingestDocument));
assertThat(simulateDocumentSimpleResult.getFailure(), nullValue()); assertThat(simulateDocumentBaseResult.getFailure(), nullValue());
} }
public void testExecuteVerboseItemWithFailure() throws Exception { public void testExecuteVerboseItemWithFailure() throws Exception {
@ -196,11 +196,11 @@ public class SimulateExecutionServiceTests extends ESTestCase {
Pipeline pipeline = new Pipeline("_id", "_description", new CompoundProcessor(processor, processor)); Pipeline pipeline = new Pipeline("_id", "_description", new CompoundProcessor(processor, processor));
SimulateDocumentResult actualItemResponse = executionService.executeDocument(pipeline, ingestDocument, false); SimulateDocumentResult actualItemResponse = executionService.executeDocument(pipeline, ingestDocument, false);
assertThat(processor.getInvokedCounter(), equalTo(1)); assertThat(processor.getInvokedCounter(), equalTo(1));
assertThat(actualItemResponse, instanceOf(SimulateDocumentSimpleResult.class)); assertThat(actualItemResponse, instanceOf(SimulateDocumentBaseResult.class));
SimulateDocumentSimpleResult simulateDocumentSimpleResult = (SimulateDocumentSimpleResult) actualItemResponse; SimulateDocumentBaseResult simulateDocumentBaseResult = (SimulateDocumentBaseResult) actualItemResponse;
assertThat(simulateDocumentSimpleResult.getIngestDocument(), nullValue()); assertThat(simulateDocumentBaseResult.getIngestDocument(), nullValue());
assertThat(simulateDocumentSimpleResult.getFailure(), instanceOf(RuntimeException.class)); assertThat(simulateDocumentBaseResult.getFailure(), instanceOf(RuntimeException.class));
RuntimeException runtimeException = (RuntimeException) simulateDocumentSimpleResult.getFailure(); RuntimeException runtimeException = (RuntimeException) simulateDocumentBaseResult.getFailure();
assertThat(runtimeException.getMessage(), equalTo("processor failed")); assertThat(runtimeException.getMessage(), equalTo("processor failed"));
} }
} }

View File

@ -58,14 +58,14 @@ public class SimulatePipelineResponseTests extends ESTestCase {
} }
results.add(new SimulateDocumentVerboseResult(processorResults)); results.add(new SimulateDocumentVerboseResult(processorResults));
} else { } else {
results.add(new SimulateDocumentSimpleResult(ingestDocument)); results.add(new SimulateDocumentBaseResult(ingestDocument));
SimulateDocumentSimpleResult simulateDocumentSimpleResult; SimulateDocumentBaseResult simulateDocumentBaseResult;
if (isFailure) { if (isFailure) {
simulateDocumentSimpleResult = new SimulateDocumentSimpleResult(new IllegalArgumentException("test")); simulateDocumentBaseResult = new SimulateDocumentBaseResult(new IllegalArgumentException("test"));
} else { } else {
simulateDocumentSimpleResult = new SimulateDocumentSimpleResult(ingestDocument); simulateDocumentBaseResult = new SimulateDocumentBaseResult(ingestDocument);
} }
results.add(simulateDocumentSimpleResult); results.add(simulateDocumentBaseResult);
} }
} }
@ -100,15 +100,15 @@ public class SimulatePipelineResponseTests extends ESTestCase {
} }
} }
} else { } else {
SimulateDocumentSimpleResult expectedSimulateDocumentSimpleResult = (SimulateDocumentSimpleResult) expectedResultIterator.next(); SimulateDocumentBaseResult expectedSimulateDocumentBaseResult = (SimulateDocumentBaseResult) expectedResultIterator.next();
assertThat(result, instanceOf(SimulateDocumentSimpleResult.class)); assertThat(result, instanceOf(SimulateDocumentBaseResult.class));
SimulateDocumentSimpleResult simulateDocumentSimpleResult = (SimulateDocumentSimpleResult) result; SimulateDocumentBaseResult simulateDocumentBaseResult = (SimulateDocumentBaseResult) result;
assertThat(simulateDocumentSimpleResult.getIngestDocument(), equalTo(expectedSimulateDocumentSimpleResult.getIngestDocument())); assertThat(simulateDocumentBaseResult.getIngestDocument(), equalTo(expectedSimulateDocumentBaseResult.getIngestDocument()));
if (expectedSimulateDocumentSimpleResult.getFailure() == null) { if (expectedSimulateDocumentBaseResult.getFailure() == null) {
assertThat(simulateDocumentSimpleResult.getFailure(), nullValue()); assertThat(simulateDocumentBaseResult.getFailure(), nullValue());
} else { } else {
assertThat(simulateDocumentSimpleResult.getFailure(), instanceOf(IllegalArgumentException.class)); assertThat(simulateDocumentBaseResult.getFailure(), instanceOf(IllegalArgumentException.class));
IllegalArgumentException e = (IllegalArgumentException) simulateDocumentSimpleResult.getFailure(); IllegalArgumentException e = (IllegalArgumentException) simulateDocumentBaseResult.getFailure();
assertThat(e.getMessage(), equalTo("test")); assertThat(e.getMessage(), equalTo("test"));
} }
} }

View File

@ -28,7 +28,7 @@ import org.elasticsearch.action.ingest.DeletePipelineRequest;
import org.elasticsearch.action.ingest.GetPipelineRequest; import org.elasticsearch.action.ingest.GetPipelineRequest;
import org.elasticsearch.action.ingest.GetPipelineResponse; import org.elasticsearch.action.ingest.GetPipelineResponse;
import org.elasticsearch.action.ingest.PutPipelineRequest; import org.elasticsearch.action.ingest.PutPipelineRequest;
import org.elasticsearch.action.ingest.SimulateDocumentSimpleResult; import org.elasticsearch.action.ingest.SimulateDocumentBaseResult;
import org.elasticsearch.action.ingest.SimulatePipelineRequest; import org.elasticsearch.action.ingest.SimulatePipelineRequest;
import org.elasticsearch.action.ingest.SimulatePipelineResponse; import org.elasticsearch.action.ingest.SimulatePipelineResponse;
import org.elasticsearch.action.ingest.WritePipelineResponse; import org.elasticsearch.action.ingest.WritePipelineResponse;
@ -114,15 +114,15 @@ public class IngestClientIT extends ESIntegTestCase {
assertThat(response.isVerbose(), equalTo(false)); assertThat(response.isVerbose(), equalTo(false));
assertThat(response.getPipelineId(), equalTo("_id")); assertThat(response.getPipelineId(), equalTo("_id"));
assertThat(response.getResults().size(), equalTo(1)); assertThat(response.getResults().size(), equalTo(1));
assertThat(response.getResults().get(0), instanceOf(SimulateDocumentSimpleResult.class)); assertThat(response.getResults().get(0), instanceOf(SimulateDocumentBaseResult.class));
SimulateDocumentSimpleResult simulateDocumentSimpleResult = (SimulateDocumentSimpleResult) response.getResults().get(0); SimulateDocumentBaseResult simulateDocumentBaseResult = (SimulateDocumentBaseResult) response.getResults().get(0);
Map<String, Object> source = new HashMap<>(); Map<String, Object> source = new HashMap<>();
source.put("foo", "bar"); source.put("foo", "bar");
source.put("fail", false); source.put("fail", false);
source.put("processed", true); source.put("processed", true);
IngestDocument ingestDocument = new IngestDocument("index", "type", "id", null, null, null, null, source); IngestDocument ingestDocument = new IngestDocument("index", "type", "id", null, null, null, null, source);
assertThat(simulateDocumentSimpleResult.getIngestDocument().getSourceAndMetadata(), equalTo(ingestDocument.getSourceAndMetadata())); assertThat(simulateDocumentBaseResult.getIngestDocument().getSourceAndMetadata(), equalTo(ingestDocument.getSourceAndMetadata()));
assertThat(simulateDocumentSimpleResult.getFailure(), nullValue()); assertThat(simulateDocumentBaseResult.getFailure(), nullValue());
} }
public void testBulkWithIngestFailures() throws Exception { public void testBulkWithIngestFailures() throws Exception {