Rename Data leftovers

This commit is contained in:
javanna 2015-11-24 15:49:25 +01:00 committed by Luca Cavanna
parent 8f1f5d4da0
commit 49bfe6410e
10 changed files with 60 additions and 61 deletions

View File

@ -35,31 +35,31 @@ import static org.elasticsearch.ingest.IngestDocument.MetaData.ID;
import static org.elasticsearch.ingest.IngestDocument.MetaData.INDEX;
import static org.elasticsearch.ingest.IngestDocument.MetaData.TYPE;
public class TransportData implements Writeable<TransportData>, ToXContent {
public class WriteableIngestDocument implements Writeable<WriteableIngestDocument>, ToXContent {
private static final TransportData PROTOTYPE = new TransportData(null);
private static final WriteableIngestDocument PROTOTYPE = new WriteableIngestDocument(null);
private final IngestDocument ingestDocument;
public TransportData(IngestDocument ingestDocument) {
public WriteableIngestDocument(IngestDocument ingestDocument) {
this.ingestDocument = ingestDocument;
}
public IngestDocument get() {
public IngestDocument getIngestDocument() {
return ingestDocument;
}
public static TransportData readTransportDataFrom(StreamInput in) throws IOException {
public static WriteableIngestDocument readWriteableIngestDocumentFrom(StreamInput in) throws IOException {
return PROTOTYPE.readFrom(in);
}
@Override
public TransportData readFrom(StreamInput in) throws IOException {
public WriteableIngestDocument readFrom(StreamInput in) throws IOException {
String index = in.readString();
String type = in.readString();
String id = in.readString();
Map<String, Object> doc = in.readMap();
return new TransportData(new IngestDocument(index, type, id, doc));
return new WriteableIngestDocument(new IngestDocument(index, type, id, doc));
}
@Override
@ -90,7 +90,7 @@ public class TransportData implements Writeable<TransportData>, ToXContent {
if (o == null || getClass() != o.getClass()) {
return false;
}
TransportData that = (TransportData) o;
WriteableIngestDocument that = (WriteableIngestDocument) o;
return Objects.equals(ingestDocument, that.ingestDocument);
}

View File

@ -23,7 +23,7 @@ import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.ingest.IngestDocument;
import org.elasticsearch.plugin.ingest.transport.TransportData;
import org.elasticsearch.plugin.ingest.transport.WriteableIngestDocument;
import java.io.IOException;
@ -31,26 +31,26 @@ public class SimulateDocumentSimpleResult implements SimulateDocumentResult<Simu
private static final SimulateDocumentSimpleResult PROTOTYPE = new SimulateDocumentSimpleResult((IngestDocument)null);
private TransportData data;
private WriteableIngestDocument ingestDocument;
private Exception failure;
public SimulateDocumentSimpleResult(IngestDocument ingestDocument) {
this.data = new TransportData(ingestDocument);
this.ingestDocument = new WriteableIngestDocument(ingestDocument);
}
private SimulateDocumentSimpleResult(TransportData data) {
this.data = data;
private SimulateDocumentSimpleResult(WriteableIngestDocument ingestDocument) {
this.ingestDocument = ingestDocument;
}
public SimulateDocumentSimpleResult(Exception failure) {
this.failure = failure;
}
public IngestDocument getData() {
if (data == null) {
public IngestDocument getIngestDocument() {
if (ingestDocument == null) {
return null;
}
return data.get();
return ingestDocument.getIngestDocument();
}
public Exception getFailure() {
@ -67,14 +67,14 @@ public class SimulateDocumentSimpleResult implements SimulateDocumentResult<Simu
Exception exception = in.readThrowable();
return new SimulateDocumentSimpleResult(exception);
}
return new SimulateDocumentSimpleResult(TransportData.readTransportDataFrom(in));
return new SimulateDocumentSimpleResult(WriteableIngestDocument.readWriteableIngestDocumentFrom(in));
}
@Override
public void writeTo(StreamOutput out) throws IOException {
if (failure == null) {
out.writeBoolean(false);
data.writeTo(out);
ingestDocument.writeTo(out);
} else {
out.writeBoolean(true);
out.writeThrowable(failure);
@ -85,7 +85,7 @@ public class SimulateDocumentSimpleResult implements SimulateDocumentResult<Simu
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
if (failure == null) {
data.toXContent(builder, params);
ingestDocument.toXContent(builder, params);
} else {
ElasticsearchException.renderThrowable(builder, params, failure);
}

View File

@ -26,7 +26,7 @@ import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentBuilderString;
import org.elasticsearch.ingest.IngestDocument;
import org.elasticsearch.plugin.ingest.transport.TransportData;
import org.elasticsearch.plugin.ingest.transport.WriteableIngestDocument;
import java.io.IOException;
@ -35,17 +35,17 @@ public class SimulateProcessorResult implements Writeable<SimulateProcessorResul
private static final SimulateProcessorResult PROTOTYPE = new SimulateProcessorResult(null, (IngestDocument)null);
private String processorId;
private TransportData data;
private WriteableIngestDocument ingestDocument;
private Exception failure;
public SimulateProcessorResult(String processorId, IngestDocument ingestDocument) {
this.processorId = processorId;
this.data = new TransportData(ingestDocument);
this.ingestDocument = new WriteableIngestDocument(ingestDocument);
}
private SimulateProcessorResult(String processorId, TransportData data) {
private SimulateProcessorResult(String processorId, WriteableIngestDocument ingestDocument) {
this.processorId = processorId;
this.data = data;
this.ingestDocument = ingestDocument;
}
public SimulateProcessorResult(String processorId, Exception failure) {
@ -53,11 +53,11 @@ public class SimulateProcessorResult implements Writeable<SimulateProcessorResul
this.failure = failure;
}
public IngestDocument getData() {
if (data == null) {
public IngestDocument getIngestDocument() {
if (ingestDocument == null) {
return null;
}
return data.get();
return ingestDocument.getIngestDocument();
}
public String getProcessorId() {
@ -79,7 +79,7 @@ public class SimulateProcessorResult implements Writeable<SimulateProcessorResul
Exception exception = in.readThrowable();
return new SimulateProcessorResult(processorId, exception);
}
return new SimulateProcessorResult(processorId, TransportData.readTransportDataFrom(in));
return new SimulateProcessorResult(processorId, WriteableIngestDocument.readWriteableIngestDocumentFrom(in));
}
@Override
@ -87,7 +87,7 @@ public class SimulateProcessorResult implements Writeable<SimulateProcessorResul
out.writeString(processorId);
if (failure == null) {
out.writeBoolean(false);
data.writeTo(out);
ingestDocument.writeTo(out);
} else {
out.writeBoolean(true);
out.writeThrowable(failure);
@ -99,7 +99,7 @@ public class SimulateProcessorResult implements Writeable<SimulateProcessorResul
builder.startObject();
builder.field(Fields.PROCESSOR_ID, processorId);
if (failure == null) {
data.toXContent(builder, params);
ingestDocument.toXContent(builder, params);
} else {
ElasticsearchException.renderThrowable(builder, params, failure);
}

View File

@ -24,7 +24,6 @@ import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse;
import org.elasticsearch.action.bulk.BulkItemResponse;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.action.update.UpdateResponse;
@ -116,7 +115,7 @@ public class IngestClientIT extends ESIntegTestCase {
assertThat(response.getResults().get(0), instanceOf(SimulateDocumentSimpleResult.class));
SimulateDocumentSimpleResult simulateDocumentSimpleResult = (SimulateDocumentSimpleResult) response.getResults().get(0);
IngestDocument expectedIngestDocument = new IngestDocument("index", "type", "id", Collections.singletonMap("foo", "bar"));
assertThat(simulateDocumentSimpleResult.getData(), equalTo(expectedIngestDocument));
assertThat(simulateDocumentSimpleResult.getIngestDocument(), equalTo(expectedIngestDocument));
assertThat(simulateDocumentSimpleResult.getFailure(), nullValue());
}

View File

@ -28,12 +28,12 @@ import java.util.Map;
import static org.hamcrest.Matchers.*;
public class DataTests extends ESTestCase {
public class IngestDocumentTests extends ESTestCase {
private IngestDocument ingestDocument;
@Before
public void setData() {
public void setIngestDocument() {
Map<String, Object> document = new HashMap<>();
document.put("foo", "bar");
document.put("int", 123);

View File

@ -31,7 +31,7 @@ import java.util.Map;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
public class TransportDataTests extends ESTestCase {
public class WriteableIngestDocumentTests extends ESTestCase {
public void testEqualsAndHashcode() throws Exception {
String index = randomAsciiOfLengthBetween(1, 10);
@ -39,7 +39,7 @@ public class TransportDataTests extends ESTestCase {
String id = randomAsciiOfLengthBetween(1, 10);
String fieldName = randomAsciiOfLengthBetween(1, 10);
String fieldValue = randomAsciiOfLengthBetween(1, 10);
TransportData transportData = new TransportData(new IngestDocument(index, type, id, Collections.singletonMap(fieldName, fieldValue)));
WriteableIngestDocument writeableIngestDocument = new WriteableIngestDocument(new IngestDocument(index, type, id, Collections.singletonMap(fieldName, fieldValue)));
boolean changed = false;
String otherIndex;
@ -71,28 +71,28 @@ public class TransportDataTests extends ESTestCase {
document = Collections.singletonMap(fieldName, fieldValue);
}
TransportData otherTransportData = new TransportData(new IngestDocument(otherIndex, otherType, otherId, document));
WriteableIngestDocument otherWriteableIngestDocument = new WriteableIngestDocument(new IngestDocument(otherIndex, otherType, otherId, document));
if (changed) {
assertThat(transportData, not(equalTo(otherTransportData)));
assertThat(otherTransportData, not(equalTo(transportData)));
assertThat(writeableIngestDocument, not(equalTo(otherWriteableIngestDocument)));
assertThat(otherWriteableIngestDocument, not(equalTo(writeableIngestDocument)));
} else {
assertThat(transportData, equalTo(otherTransportData));
assertThat(otherTransportData, equalTo(transportData));
TransportData thirdTransportData = new TransportData(new IngestDocument(index, type, id, Collections.singletonMap(fieldName, fieldValue)));
assertThat(thirdTransportData, equalTo(transportData));
assertThat(transportData, equalTo(thirdTransportData));
assertThat(writeableIngestDocument, equalTo(otherWriteableIngestDocument));
assertThat(otherWriteableIngestDocument, equalTo(writeableIngestDocument));
WriteableIngestDocument thirdWriteableIngestDocument = new WriteableIngestDocument(new IngestDocument(index, type, id, Collections.singletonMap(fieldName, fieldValue)));
assertThat(thirdWriteableIngestDocument, equalTo(writeableIngestDocument));
assertThat(writeableIngestDocument, equalTo(thirdWriteableIngestDocument));
}
}
public void testSerialization() throws IOException {
IngestDocument ingestDocument = new IngestDocument(randomAsciiOfLengthBetween(1, 10), randomAsciiOfLengthBetween(1, 10), randomAsciiOfLengthBetween(1, 10),
Collections.singletonMap(randomAsciiOfLengthBetween(1, 10), randomAsciiOfLengthBetween(1, 10)));
TransportData transportData = new TransportData(ingestDocument);
WriteableIngestDocument writeableIngestDocument = new WriteableIngestDocument(ingestDocument);
BytesStreamOutput out = new BytesStreamOutput();
transportData.writeTo(out);
writeableIngestDocument.writeTo(out);
StreamInput streamInput = StreamInput.wrap(out.bytes());
TransportData otherTransportData = TransportData.readTransportDataFrom(streamInput);
assertThat(otherTransportData, equalTo(transportData));
WriteableIngestDocument otherWriteableIngestDocument = WriteableIngestDocument.readWriteableIngestDocumentFrom(streamInput);
assertThat(otherWriteableIngestDocument, equalTo(writeableIngestDocument));
}
}

View File

@ -48,7 +48,7 @@ public class SimulateDocumentSimpleResultTests extends ESTestCase {
StreamInput streamInput = StreamInput.wrap(out.bytes());
SimulateDocumentSimpleResult otherSimulateDocumentSimpleResult = SimulateDocumentSimpleResult.readSimulateDocumentSimpleResult(streamInput);
assertThat(otherSimulateDocumentSimpleResult.getData(), equalTo(simulateDocumentSimpleResult.getData()));
assertThat(otherSimulateDocumentSimpleResult.getIngestDocument(), equalTo(simulateDocumentSimpleResult.getIngestDocument()));
if (isFailure) {
assertThat(otherSimulateDocumentSimpleResult.getFailure(), instanceOf(IllegalArgumentException.class));
IllegalArgumentException e = (IllegalArgumentException) otherSimulateDocumentSimpleResult.getFailure();

View File

@ -68,12 +68,12 @@ public class SimulateExecutionServiceTests extends ESTestCase {
SimulateDocumentVerboseResult simulateDocumentVerboseResult = (SimulateDocumentVerboseResult) actualItemResponse;
assertThat(simulateDocumentVerboseResult.getProcessorResults().size(), equalTo(2));
assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getProcessorId(), equalTo("processor[mock]-0"));
assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getData(), not(sameInstance(ingestDocument)));
assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getData(), equalTo(ingestDocument));
assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getIngestDocument(), not(sameInstance(ingestDocument)));
assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getIngestDocument(), equalTo(ingestDocument));
assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getFailure(), nullValue());
assertThat(simulateDocumentVerboseResult.getProcessorResults().get(1).getProcessorId(), equalTo("processor[mock]-1"));
assertThat(simulateDocumentVerboseResult.getProcessorResults().get(1).getData(), not(sameInstance(ingestDocument)));
assertThat(simulateDocumentVerboseResult.getProcessorResults().get(1).getData(), equalTo(ingestDocument));
assertThat(simulateDocumentVerboseResult.getProcessorResults().get(1).getIngestDocument(), not(sameInstance(ingestDocument)));
assertThat(simulateDocumentVerboseResult.getProcessorResults().get(1).getIngestDocument(), equalTo(ingestDocument));
assertThat(simulateDocumentVerboseResult.getProcessorResults().get(1).getFailure(), nullValue());
}
@ -82,7 +82,7 @@ public class SimulateExecutionServiceTests extends ESTestCase {
verify(processor, times(2)).execute(ingestDocument);
assertThat(actualItemResponse, instanceOf(SimulateDocumentSimpleResult.class));
SimulateDocumentSimpleResult simulateDocumentSimpleResult = (SimulateDocumentSimpleResult) actualItemResponse;
assertThat(simulateDocumentSimpleResult.getData(), equalTo(ingestDocument));
assertThat(simulateDocumentSimpleResult.getIngestDocument(), equalTo(ingestDocument));
assertThat(simulateDocumentSimpleResult.getFailure(), nullValue());
}
@ -95,13 +95,13 @@ public class SimulateExecutionServiceTests extends ESTestCase {
SimulateDocumentVerboseResult simulateDocumentVerboseResult = (SimulateDocumentVerboseResult) actualItemResponse;
assertThat(simulateDocumentVerboseResult.getProcessorResults().size(), equalTo(2));
assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getProcessorId(), equalTo("processor[mock]-0"));
assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getData(), nullValue());
assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getIngestDocument(), nullValue());
assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getFailure(), instanceOf(RuntimeException.class));
RuntimeException runtimeException = (RuntimeException) simulateDocumentVerboseResult.getProcessorResults().get(0).getFailure();
assertThat(runtimeException.getMessage(), equalTo("processor failed"));
assertThat(simulateDocumentVerboseResult.getProcessorResults().get(1).getProcessorId(), equalTo("processor[mock]-1"));
assertThat(simulateDocumentVerboseResult.getProcessorResults().get(1).getData(), not(sameInstance(ingestDocument)));
assertThat(simulateDocumentVerboseResult.getProcessorResults().get(1).getData(), equalTo(ingestDocument));
assertThat(simulateDocumentVerboseResult.getProcessorResults().get(1).getIngestDocument(), not(sameInstance(ingestDocument)));
assertThat(simulateDocumentVerboseResult.getProcessorResults().get(1).getIngestDocument(), equalTo(ingestDocument));
assertThat(simulateDocumentVerboseResult.getProcessorResults().get(1).getFailure(), nullValue());
runtimeException = (RuntimeException) simulateDocumentVerboseResult.getProcessorResults().get(0).getFailure();
assertThat(runtimeException.getMessage(), equalTo("processor failed"));
@ -114,7 +114,7 @@ public class SimulateExecutionServiceTests extends ESTestCase {
verify(processor, times(1)).execute(ingestDocument);
assertThat(actualItemResponse, instanceOf(SimulateDocumentSimpleResult.class));
SimulateDocumentSimpleResult simulateDocumentSimpleResult = (SimulateDocumentSimpleResult) actualItemResponse;
assertThat(simulateDocumentSimpleResult.getData(), nullValue());
assertThat(simulateDocumentSimpleResult.getIngestDocument(), nullValue());
assertThat(simulateDocumentSimpleResult.getFailure(), instanceOf(RuntimeException.class));
RuntimeException runtimeException = (RuntimeException) simulateDocumentSimpleResult.getFailure();
assertThat(runtimeException.getMessage(), equalTo("processor failed"));

View File

@ -91,7 +91,7 @@ public class SimulatePipelineResponseTests extends ESTestCase {
for (SimulateProcessorResult simulateProcessorResult : simulateDocumentVerboseResult.getProcessorResults()) {
SimulateProcessorResult expectedProcessorResult = expectedProcessorResultIterator.next();
assertThat(simulateProcessorResult.getProcessorId(), equalTo(expectedProcessorResult.getProcessorId()));
assertThat(simulateProcessorResult.getData(), equalTo(expectedProcessorResult.getData()));
assertThat(simulateProcessorResult.getIngestDocument(), equalTo(expectedProcessorResult.getIngestDocument()));
if (expectedProcessorResult.getFailure() == null) {
assertThat(simulateProcessorResult.getFailure(), nullValue());
} else {
@ -104,7 +104,7 @@ public class SimulatePipelineResponseTests extends ESTestCase {
SimulateDocumentSimpleResult expectedSimulateDocumentSimpleResult = (SimulateDocumentSimpleResult) expectedResultIterator.next();
assertThat(result, instanceOf(SimulateDocumentSimpleResult.class));
SimulateDocumentSimpleResult simulateDocumentSimpleResult = (SimulateDocumentSimpleResult) result;
assertThat(simulateDocumentSimpleResult.getData(), equalTo(expectedSimulateDocumentSimpleResult.getData()));
assertThat(simulateDocumentSimpleResult.getIngestDocument(), equalTo(expectedSimulateDocumentSimpleResult.getIngestDocument()));
if (expectedSimulateDocumentSimpleResult.getFailure() == null) {
assertThat(simulateDocumentSimpleResult.getFailure(), nullValue());
} else {

View File

@ -49,7 +49,7 @@ public class SimulateProcessorResultTests extends ESTestCase {
StreamInput streamInput = StreamInput.wrap(out.bytes());
SimulateProcessorResult otherSimulateProcessorResult = SimulateProcessorResult.readSimulateProcessorResultFrom(streamInput);
assertThat(otherSimulateProcessorResult.getProcessorId(), equalTo(simulateProcessorResult.getProcessorId()));
assertThat(otherSimulateProcessorResult.getData(), equalTo(simulateProcessorResult.getData()));
assertThat(otherSimulateProcessorResult.getIngestDocument(), equalTo(simulateProcessorResult.getIngestDocument()));
if (isFailure) {
assertThat(otherSimulateProcessorResult.getFailure(), instanceOf(IllegalArgumentException.class));
IllegalArgumentException e = (IllegalArgumentException) otherSimulateProcessorResult.getFailure();