use of org.elasticsearch.common.io.stream.StreamInput in project crate by crate.
the class FailedShardsExceptionTest method testShardFailureReasonIsNull.
@Test
public void testShardFailureReasonIsNull() throws Exception {
FailedShardsException exception = new FailedShardsException(new ShardOperationFailedException[] { new ShardOperationFailedException() {
@Override
public String index() {
return null;
}
@Override
public int shardId() {
return 0;
}
@Override
public String reason() {
return null;
}
@Override
public RestStatus status() {
return null;
}
@Override
public void readFrom(StreamInput in) throws IOException {
}
@Override
public void writeTo(StreamOutput out) throws IOException {
}
@Override
public Throwable getCause() {
return null;
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
return null;
}
}, null });
assertThat(exception.getMessage(), is("query failed on shards 0 ( null )"));
}
use of org.elasticsearch.common.io.stream.StreamInput in project crate by crate.
the class NodeFetchRequestTest method testStreaming.
@Test
public void testStreaming() throws Exception {
IntObjectHashMap<IntContainer> toFetch = new IntObjectHashMap<>();
IntHashSet docIds = new IntHashSet(3);
toFetch.put(1, docIds);
NodeFetchRequest orig = new NodeFetchRequest(UUID.randomUUID(), 1, true, toFetch);
BytesStreamOutput out = new BytesStreamOutput();
orig.writeTo(out);
StreamInput in = StreamInput.wrap(out.bytes());
NodeFetchRequest streamed = new NodeFetchRequest();
streamed.readFrom(in);
assertThat(orig.jobId(), is(streamed.jobId()));
assertThat(orig.fetchPhaseId(), is(streamed.fetchPhaseId()));
assertThat(orig.isCloseContext(), is(streamed.isCloseContext()));
assertThat(orig.toFetch().toString(), is(streamed.toFetch().toString()));
}
use of org.elasticsearch.common.io.stream.StreamInput in project crate by crate.
the class ParameterSymbolTest method testSerialization.
@Test
public void testSerialization() throws Exception {
ParameterSymbol ps1 = new ParameterSymbol(2, DataTypes.INTEGER);
BytesStreamOutput out = new BytesStreamOutput();
ps1.writeTo(out);
StreamInput in = StreamInput.wrap(out.bytes());
ParameterSymbol ps2 = new ParameterSymbol(in);
assertThat(ps2.index(), is(ps1.index()));
assertThat(ps2.valueType(), is(ps1.valueType()));
}
use of org.elasticsearch.common.io.stream.StreamInput in project elasticsearch by elastic.
the class AbstractStreamableTestCase method copyInstance.
/**
* Round trip {@code instance} through binary serialization, setting the wire compatibility version to {@code version}.
*/
protected T copyInstance(T instance, Version version) throws IOException {
try (BytesStreamOutput output = new BytesStreamOutput()) {
output.setVersion(version);
instance.writeTo(output);
try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), getNamedWriteableRegistry())) {
in.setVersion(version);
T newInstance = createBlankInstance();
newInstance.readFrom(in);
return newInstance;
}
}
}
use of org.elasticsearch.common.io.stream.StreamInput in project elasticsearch by elastic.
the class DeflateCompressTests method doTest.
private void doTest(byte[] bytes) throws IOException {
ByteBuffer bb = ByteBuffer.wrap(bytes);
StreamInput rawIn = new ByteBufferStreamInput(bb);
Compressor c = compressor;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
OutputStreamStreamOutput rawOs = new OutputStreamStreamOutput(bos);
StreamOutput os = c.streamOutput(rawOs);
Random r = random();
int bufferSize = r.nextBoolean() ? 65535 : TestUtil.nextInt(random(), 1, 70000);
int prepadding = r.nextInt(70000);
int postpadding = r.nextInt(70000);
byte[] buffer = new byte[prepadding + bufferSize + postpadding];
// fill block completely with junk
r.nextBytes(buffer);
int len;
while ((len = rawIn.read(buffer, prepadding, bufferSize)) != -1) {
os.write(buffer, prepadding, len);
}
os.close();
rawIn.close();
// now we have compressed byte array
byte[] compressed = bos.toByteArray();
ByteBuffer bb2 = ByteBuffer.wrap(compressed);
StreamInput compressedIn = new ByteBufferStreamInput(bb2);
StreamInput in = c.streamInput(compressedIn);
// randomize constants again
bufferSize = r.nextBoolean() ? 65535 : TestUtil.nextInt(random(), 1, 70000);
prepadding = r.nextInt(70000);
postpadding = r.nextInt(70000);
buffer = new byte[prepadding + bufferSize + postpadding];
// fill block completely with junk
r.nextBytes(buffer);
ByteArrayOutputStream uncompressedOut = new ByteArrayOutputStream();
while ((len = in.read(buffer, prepadding, bufferSize)) != -1) {
uncompressedOut.write(buffer, prepadding, len);
}
uncompressedOut.close();
assertArrayEquals(bytes, uncompressedOut.toByteArray());
}
Aggregations