Skip to content

Commit

Permalink
iter
Browse files Browse the repository at this point in the history
  • Loading branch information
iverase committed Nov 6, 2024
1 parent c042130 commit 43764d6
Showing 1 changed file with 3 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.TransportVersion;
import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.core.IOUtils;
Expand All @@ -79,7 +77,6 @@
import static org.hamcrest.Matchers.equalTo;

public class LuceneTests extends ESTestCase {
private static final NamedWriteableRegistry EMPTY_REGISTRY = new NamedWriteableRegistry(Collections.emptyList());

public void testCleanIndex() throws IOException {
MockDirectoryWrapper dir = newMockDirectory();
Expand Down Expand Up @@ -556,7 +553,6 @@ public void testSortFieldSerialization() throws IOException {
Tuple<SortField, SortField> sortFieldTuple = randomSortField();
SortField deserialized = copyInstance(
sortFieldTuple.v1(),
EMPTY_REGISTRY,
Lucene::writeSortField,
Lucene::readSortField,
TransportVersionUtils.randomVersion(random())
Expand All @@ -568,25 +564,19 @@ public void testSortValueSerialization() throws IOException {
Object sortValue = randomSortValue();
Object deserialized = copyInstance(
sortValue,
EMPTY_REGISTRY,
Lucene::writeSortValue,
Lucene::readSortValue,
TransportVersionUtils.randomVersion(random())
);
assertEquals(sortValue, deserialized);
}

private static <T> T copyInstance(
T original,
NamedWriteableRegistry namedWriteableRegistry,
Writeable.Writer<T> writer,
Writeable.Reader<T> reader,
TransportVersion version
) throws IOException {
private static <T> T copyInstance(T original, Writeable.Writer<T> writer, Writeable.Reader<T> reader, TransportVersion version)
throws IOException {
try (BytesStreamOutput output = new BytesStreamOutput()) {
output.setTransportVersion(version);
writer.write(output, original);
try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWriteableRegistry)) {
try (StreamInput in = output.bytes().streamInput()) {
in.setTransportVersion(version);
return reader.read(in);
}
Expand Down

0 comments on commit 43764d6

Please sign in to comment.