private void assertValues(TestType type, Directory dir, long[] values) throws CorruptIndexException, IOException { DirectoryReader reader = DirectoryReader.open(dir); assertEquals(1, reader.getSequentialSubReaders().length); IndexReaderContext topReaderContext = reader.getTopReaderContext(); AtomicReaderContext[] children = topReaderContext.leaves(); assertEquals(1, children.length); DocValues docValues = children[0].reader().docValues("promote"); Source directSource = docValues.getDirectSource(); for (int i = 0; i < values.length; i++) { int id = Integer.parseInt(reader.document(i).get("id")); String msg = "id: " + id + " doc: " + i; switch (type) { case Byte: BytesRef bytes = directSource.getBytes(i, new BytesRef()); long value = 0; switch (bytes.length) { case 1: value = bytes.bytes[bytes.offset]; break; case 2: value = ((bytes.bytes[bytes.offset] & 0xFF) << 8) | (bytes.bytes[bytes.offset + 1] & 0xFF); break; case 4: value = ((bytes.bytes[bytes.offset] & 0xFF) << 24) | ((bytes.bytes[bytes.offset + 1] & 0xFF) << 16) | ((bytes.bytes[bytes.offset + 2] & 0xFF) << 8) | (bytes.bytes[bytes.offset + 3] & 0xFF); break; case 8: value = (((long) (bytes.bytes[bytes.offset] & 0xff) << 56) | ((long) (bytes.bytes[bytes.offset + 1] & 0xff) << 48) | ((long) (bytes.bytes[bytes.offset + 2] & 0xff) << 40) | ((long) (bytes.bytes[bytes.offset + 3] & 0xff) << 32) | ((long) (bytes.bytes[bytes.offset + 4] & 0xff) << 24) | ((long) (bytes.bytes[bytes.offset + 5] & 0xff) << 16) | ((long) (bytes.bytes[bytes.offset + 6] & 0xff) << 8) | ((long) (bytes.bytes[bytes.offset + 7] & 0xff))); break; default: fail(msg + " bytessize: " + bytes.length); } assertEquals(msg + " byteSize: " + bytes.length, values[id], value); break; case Float: assertEquals(msg, values[id], Double.doubleToRawLongBits(directSource.getFloat(i))); break; case Int: assertEquals(msg, values[id], directSource.getInt(i)); break; default: break; } } docValues.close(); reader.close(); }
@Override protected void setMergeBytes(Source source, int sourceDoc) { final long value = source.getInt(sourceDoc); template.toBytes(value, bytesRef); }