我正在为Elasticsearch创建单元测试用例。我无法理解以下代码失败的原因:
String data = "<Huge response JSON>";
ByteBuffer bb = ByteBuffer.allocate(data.length());
bb.put(data.getBytes());
StreamInput si = new ByteBufferStreamInput(bb);
InternalSearchResponse internalSearchResponse = new InternalSearchResponse(si);
最后一行抛出以下异常:
java.io.EOFException
at org.elasticsearch.common.io.stream.ByteBufferStreamInput.readByte(ByteBufferStreamInput.java:44)
at org.elasticsearch.common.io.stream.StreamInput.readInt(StreamInput.java:199)
at org.elasticsearch.common.io.stream.StreamInput.readFloat(StreamInput.java:406)
at org.elasticsearch.search.SearchHits.readFrom(SearchHits.java:184)
at org.elasticsearch.search.SearchHits.readSearchHits(SearchHits.java:167)
at org.elasticsearch.search.internal.InternalSearchResponse.<init>(InternalSearchResponse.java:51)