use of org.opensearch.common.io.stream.ByteBufferStreamInput in project OpenSearch by opensearch-project.
the class PrimaryReplicaSyncerTests method testStatusSerialization.
public void testStatusSerialization() throws IOException {
PrimaryReplicaSyncer.ResyncTask.Status status = new PrimaryReplicaSyncer.ResyncTask.Status(randomAlphaOfLength(10), randomIntBetween(0, 1000), randomIntBetween(0, 1000), randomIntBetween(0, 1000));
final BytesStreamOutput out = new BytesStreamOutput();
status.writeTo(out);
final ByteBufferStreamInput in = new ByteBufferStreamInput(ByteBuffer.wrap(out.bytes().toBytesRef().bytes));
PrimaryReplicaSyncer.ResyncTask.Status serializedStatus = new PrimaryReplicaSyncer.ResyncTask.Status(in);
assertEquals(status, serializedStatus);
}
use of org.opensearch.common.io.stream.ByteBufferStreamInput in project OpenSearch by opensearch-project.
the class ActiveShardCountTests method doWriteRead.
private void doWriteRead(ActiveShardCount activeShardCount) throws IOException {
final BytesStreamOutput out = new BytesStreamOutput();
activeShardCount.writeTo(out);
final ByteBufferStreamInput in = new ByteBufferStreamInput(ByteBuffer.wrap(out.bytes().toBytesRef().bytes));
ActiveShardCount readActiveShardCount = ActiveShardCount.readFrom(in);
if (activeShardCount == ActiveShardCount.DEFAULT || activeShardCount == ActiveShardCount.ALL || activeShardCount == ActiveShardCount.NONE) {
assertSame(activeShardCount, readActiveShardCount);
} else {
assertEquals(activeShardCount, readActiveShardCount);
}
}
use of org.opensearch.common.io.stream.ByteBufferStreamInput in project OpenSearch by opensearch-project.
the class SearchContextId method decode.
public static SearchContextId decode(NamedWriteableRegistry namedWriteableRegistry, String id) {
final ByteBuffer byteBuffer;
try {
byteBuffer = ByteBuffer.wrap(Base64.getUrlDecoder().decode(id));
} catch (Exception e) {
throw new IllegalArgumentException("invalid id: [" + id + "]", e);
}
try (StreamInput in = new NamedWriteableAwareStreamInput(new ByteBufferStreamInput(byteBuffer), namedWriteableRegistry)) {
final Version version = Version.readVersion(in);
in.setVersion(version);
final Map<ShardId, SearchContextIdForNode> shards = in.readMap(ShardId::new, SearchContextIdForNode::new);
final Map<String, AliasFilter> aliasFilters = in.readMap(StreamInput::readString, AliasFilter::new);
if (in.available() > 0) {
throw new IllegalArgumentException("Not all bytes were read");
}
return new SearchContextId(Collections.unmodifiableMap(shards), Collections.unmodifiableMap(aliasFilters));
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
}
use of org.opensearch.common.io.stream.ByteBufferStreamInput in project OpenSearch by opensearch-project.
the class UnassignedInfoTests method testAllocationStatusSerialization.
public void testAllocationStatusSerialization() throws IOException {
for (AllocationStatus allocationStatus : AllocationStatus.values()) {
BytesStreamOutput out = new BytesStreamOutput();
allocationStatus.writeTo(out);
ByteBufferStreamInput in = new ByteBufferStreamInput(ByteBuffer.wrap(out.bytes().toBytesRef().bytes));
AllocationStatus readStatus = AllocationStatus.readFrom(in);
assertThat(readStatus, equalTo(allocationStatus));
}
}
use of org.opensearch.common.io.stream.ByteBufferStreamInput in project OpenSearch by opensearch-project.
the class BaseTranslogReader method checksummedStream.
/**
* reads an operation at the given position and returns it. The buffer length is equal to the number
* of bytes reads.
*/
protected final BufferedChecksumStreamInput checksummedStream(ByteBuffer reusableBuffer, long position, int opSize, BufferedChecksumStreamInput reuse) throws IOException {
final ByteBuffer buffer;
if (reusableBuffer.capacity() >= opSize) {
buffer = reusableBuffer;
} else {
buffer = ByteBuffer.allocate(opSize);
}
buffer.clear();
buffer.limit(opSize);
readBytes(buffer, position);
buffer.flip();
return new BufferedChecksumStreamInput(new ByteBufferStreamInput(buffer), path.toString(), reuse);
}
Aggregations