use of org.elasticsearch.common.io.stream.StreamInput in project elasticsearch by elastic.
the class SimulateProcessorResultTests method testSerialization.
public void testSerialization() throws IOException {
String processorTag = randomAsciiOfLengthBetween(1, 10);
boolean isSuccessful = randomBoolean();
boolean isIgnoredException = randomBoolean();
SimulateProcessorResult simulateProcessorResult;
if (isSuccessful) {
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
if (isIgnoredException) {
simulateProcessorResult = new SimulateProcessorResult(processorTag, ingestDocument, new IllegalArgumentException("test"));
} else {
simulateProcessorResult = new SimulateProcessorResult(processorTag, ingestDocument);
}
} else {
simulateProcessorResult = new SimulateProcessorResult(processorTag, new IllegalArgumentException("test"));
}
BytesStreamOutput out = new BytesStreamOutput();
simulateProcessorResult.writeTo(out);
StreamInput streamInput = out.bytes().streamInput();
SimulateProcessorResult otherSimulateProcessorResult = new SimulateProcessorResult(streamInput);
assertThat(otherSimulateProcessorResult.getProcessorTag(), equalTo(simulateProcessorResult.getProcessorTag()));
if (isSuccessful) {
assertIngestDocument(otherSimulateProcessorResult.getIngestDocument(), simulateProcessorResult.getIngestDocument());
if (isIgnoredException) {
assertThat(otherSimulateProcessorResult.getFailure(), instanceOf(IllegalArgumentException.class));
IllegalArgumentException e = (IllegalArgumentException) otherSimulateProcessorResult.getFailure();
assertThat(e.getMessage(), equalTo("test"));
} else {
assertThat(otherSimulateProcessorResult.getFailure(), nullValue());
}
} else {
assertThat(otherSimulateProcessorResult.getIngestDocument(), is(nullValue()));
assertThat(otherSimulateProcessorResult.getFailure(), instanceOf(IllegalArgumentException.class));
IllegalArgumentException e = (IllegalArgumentException) otherSimulateProcessorResult.getFailure();
assertThat(e.getMessage(), equalTo("test"));
}
}
use of org.elasticsearch.common.io.stream.StreamInput in project elasticsearch by elastic.
the class WritePipelineResponseTests method testSerializationWithError.
public void testSerializationWithError() throws IOException {
WritePipelineResponse response = new WritePipelineResponse();
BytesStreamOutput out = new BytesStreamOutput();
response.writeTo(out);
StreamInput streamInput = out.bytes().streamInput();
WritePipelineResponse otherResponse = new WritePipelineResponse();
otherResponse.readFrom(streamInput);
assertThat(otherResponse.isAcknowledged(), equalTo(response.isAcknowledged()));
}
use of org.elasticsearch.common.io.stream.StreamInput in project elasticsearch by elastic.
the class WriteableIngestDocumentTests method testSerialization.
public void testSerialization() throws IOException {
Map<String, Object> sourceAndMetadata = RandomDocumentPicks.randomSource(random());
int numFields = randomIntBetween(1, IngestDocument.MetaData.values().length);
for (int i = 0; i < numFields; i++) {
sourceAndMetadata.put(randomFrom(IngestDocument.MetaData.values()).getFieldName(), randomAsciiOfLengthBetween(5, 10));
}
Map<String, Object> ingestMetadata = new HashMap<>();
numFields = randomIntBetween(1, 5);
for (int i = 0; i < numFields; i++) {
ingestMetadata.put(randomAsciiOfLengthBetween(5, 10), randomAsciiOfLengthBetween(5, 10));
}
WriteableIngestDocument writeableIngestDocument = new WriteableIngestDocument(new IngestDocument(sourceAndMetadata, ingestMetadata));
BytesStreamOutput out = new BytesStreamOutput();
writeableIngestDocument.writeTo(out);
StreamInput streamInput = out.bytes().streamInput();
WriteableIngestDocument otherWriteableIngestDocument = new WriteableIngestDocument(streamInput);
assertIngestDocument(otherWriteableIngestDocument.getIngestDocument(), writeableIngestDocument.getIngestDocument());
}
use of org.elasticsearch.common.io.stream.StreamInput in project elasticsearch by elastic.
the class IndexRequestTests method testSerializationOfEmptyRequestWorks.
// reindex makes use of index requests without a source so this needs to be handled
public void testSerializationOfEmptyRequestWorks() throws IOException {
IndexRequest request = new IndexRequest("index", "type");
assertNull(request.getContentType());
try (BytesStreamOutput out = new BytesStreamOutput()) {
request.writeTo(out);
try (StreamInput in = out.bytes().streamInput()) {
IndexRequest serialized = new IndexRequest();
serialized.readFrom(in);
assertNull(request.getContentType());
assertEquals("index", request.index());
assertEquals("type", request.type());
}
}
}
use of org.elasticsearch.common.io.stream.StreamInput in project elasticsearch by elastic.
the class IndexRequestTests method testIndexRequestXContentSerialization.
public void testIndexRequestXContentSerialization() throws IOException {
IndexRequest indexRequest = new IndexRequest("foo", "bar", "1");
indexRequest.source("{}", XContentType.JSON);
assertEquals(XContentType.JSON, indexRequest.getContentType());
BytesStreamOutput out = new BytesStreamOutput();
indexRequest.writeTo(out);
StreamInput in = StreamInput.wrap(out.bytes().toBytesRef().bytes);
IndexRequest serialized = new IndexRequest();
serialized.readFrom(in);
assertEquals(XContentType.JSON, serialized.getContentType());
assertEquals(new BytesArray("{}"), serialized.source());
}
Aggregations