@Test public void testFromBytesOffset() { Assert.assertEquals(Long.MAX_VALUE, UVLongTool.getLong(UVLongTool.MAX_VALUE_BYTES, 0)); long ms = 1318966363481L; // System.out.println(ms); byte[] bytes = UVLongTool.getBytes(ms); // System.out.println(Arrays.toString(bytes)); long roundTripped = UVLongTool.getLong(bytes, 0); Assert.assertEquals(ms, roundTripped); int calculatedNumBytes = UVLongTool.numBytes(ms); int actualNumBytes = bytes.length; Assert.assertEquals(actualNumBytes, calculatedNumBytes); byte[] shiftedBytes = new byte[1000]; int shift = 33; System.arraycopy(bytes, 0, shiftedBytes, shift, bytes.length); long shiftedRoundTrip = UVLongTool.getLong(shiftedBytes, shift); Assert.assertEquals(ms, shiftedRoundTrip); }
public void writeVariableBytesToOutputStream(OutputStream os) throws IOException{ UVIntTool.writeBytes(version, os); UVIntTool.writeBytes(numMetaBytes, os); UVIntTool.writeBytes(numKeyValueBytes, os); os.write(getIncludesMvccVersionByte()); UVIntTool.writeBytes(numRowBytes, os); UVIntTool.writeBytes(numFamilyBytes, os); UVIntTool.writeBytes(numQualifierBytes, os); UVIntTool.writeBytes(numTagsBytes, os); UVIntTool.writeBytes(numTimestampBytes, os); UVIntTool.writeBytes(numMvccVersionBytes, os); UVIntTool.writeBytes(numValueBytes, os); UVIntTool.writeBytes(nextNodeOffsetWidth, os); UVIntTool.writeBytes(familyOffsetWidth, os); UVIntTool.writeBytes(qualifierOffsetWidth, os); UVIntTool.writeBytes(tagsOffsetWidth, os); UVIntTool.writeBytes(timestampIndexWidth, os); UVIntTool.writeBytes(mvccVersionIndexWidth, os); UVIntTool.writeBytes(valueOffsetWidth, os); UVIntTool.writeBytes(valueLengthWidth, os); UVIntTool.writeBytes(rowTreeDepth, os); UVIntTool.writeBytes(maxRowLength, os); UVIntTool.writeBytes(maxQualifierLength, os); UVIntTool.writeBytes(maxTagsLength, os); UVLongTool.writeBytes(minTimestamp, os); UVIntTool.writeBytes(timestampDeltaWidth, os); UVLongTool.writeBytes(minMvccVersion, os); UVIntTool.writeBytes(mvccVersionDeltaWidth, os); os.write(getAllSameTypeByte()); os.write(allTypes); UVIntTool.writeBytes(numUniqueRows, os); UVIntTool.writeBytes(numUniqueFamilies, os); UVIntTool.writeBytes(numUniqueQualifiers, os); UVIntTool.writeBytes(numUniqueTags, os); }
@Test public void testNumBytes() { Assert.assertEquals(1, UVLongTool.numBytes(0)); Assert.assertEquals(1, UVLongTool.numBytes(1)); Assert.assertEquals(1, UVLongTool.numBytes(100)); Assert.assertEquals(1, UVLongTool.numBytes(126)); Assert.assertEquals(1, UVLongTool.numBytes(127)); Assert.assertEquals(2, UVLongTool.numBytes(128)); Assert.assertEquals(2, UVLongTool.numBytes(129)); Assert.assertEquals(9, UVLongTool.numBytes(Long.MAX_VALUE)); }
@Test public void testToBytes() { Assert.assertArrayEquals(new byte[] { 0 }, UVLongTool.getBytes(0)); Assert.assertArrayEquals(new byte[] { 1 }, UVLongTool.getBytes(1)); Assert.assertArrayEquals(new byte[] { 63 }, UVLongTool.getBytes(63)); Assert.assertArrayEquals(new byte[] { 127 }, UVLongTool.getBytes(127)); Assert.assertArrayEquals(new byte[] { -128, 1 }, UVLongTool.getBytes(128)); Assert.assertArrayEquals(new byte[] { -128 + 27, 1 }, UVLongTool.getBytes(155)); Assert.assertArrayEquals(UVLongTool.MAX_VALUE_BYTES, UVLongTool.getBytes(Long.MAX_VALUE)); }
@Test public void testRoundTrips() { Random random = new Random(); for (int i = 0; i < 10000; ++i) { long value = RandomNumberUtils.nextPositiveLong(random); byte[] bytes = UVLongTool.getBytes(value); long roundTripped = UVLongTool.getLong(bytes); Assert.assertEquals(value, roundTripped); int calculatedNumBytes = UVLongTool.numBytes(value); int actualNumBytes = bytes.length; Assert.assertEquals(actualNumBytes, calculatedNumBytes); } }
@Test public void testInputStreams() throws IOException { ByteArrayInputStream is; is = new ByteArrayInputStream(new byte[] { 0 }); Assert.assertEquals(0, UVLongTool.getLong(is)); is = new ByteArrayInputStream(new byte[] { 5 }); Assert.assertEquals(5, UVLongTool.getLong(is)); is = new ByteArrayInputStream(new byte[] { -128 + 27, 1 }); Assert.assertEquals(155, UVLongTool.getLong(is)); }
/**************** operate on each field **********************/ public int calculateNumMetaBytes(){ int numBytes = 0; numBytes += UVIntTool.numBytes(version); numBytes += UVLongTool.numBytes(numMetaBytes); numBytes += UVIntTool.numBytes(numKeyValueBytes); ++numBytes;//os.write(getIncludesMvccVersion()); numBytes += UVIntTool.numBytes(numRowBytes); numBytes += UVIntTool.numBytes(numFamilyBytes); numBytes += UVIntTool.numBytes(numQualifierBytes); numBytes += UVIntTool.numBytes(numTagsBytes); numBytes += UVIntTool.numBytes(numTimestampBytes); numBytes += UVIntTool.numBytes(numMvccVersionBytes); numBytes += UVIntTool.numBytes(numValueBytes); numBytes += UVIntTool.numBytes(nextNodeOffsetWidth); numBytes += UVIntTool.numBytes(familyOffsetWidth); numBytes += UVIntTool.numBytes(qualifierOffsetWidth); numBytes += UVIntTool.numBytes(tagsOffsetWidth); numBytes += UVIntTool.numBytes(timestampIndexWidth); numBytes += UVIntTool.numBytes(mvccVersionIndexWidth); numBytes += UVIntTool.numBytes(valueOffsetWidth); numBytes += UVIntTool.numBytes(valueLengthWidth); numBytes += UVIntTool.numBytes(rowTreeDepth); numBytes += UVIntTool.numBytes(maxRowLength); numBytes += UVIntTool.numBytes(maxQualifierLength); numBytes += UVIntTool.numBytes(maxTagsLength); numBytes += UVLongTool.numBytes(minTimestamp); numBytes += UVIntTool.numBytes(timestampDeltaWidth); numBytes += UVLongTool.numBytes(minMvccVersion); numBytes += UVIntTool.numBytes(mvccVersionDeltaWidth); ++numBytes;//os.write(getAllSameTypeByte()); ++numBytes;//os.write(allTypes); numBytes += UVIntTool.numBytes(numUniqueRows); numBytes += UVIntTool.numBytes(numUniqueFamilies); numBytes += UVIntTool.numBytes(numUniqueQualifiers); numBytes += UVIntTool.numBytes(numUniqueTags); return numBytes; }
public void readVariableBytesFromInputStream(InputStream is) throws IOException{ version = UVIntTool.getInt(is); numMetaBytes = UVIntTool.getInt(is); numKeyValueBytes = UVIntTool.getInt(is); setIncludesMvccVersion((byte) is.read()); numRowBytes = UVIntTool.getInt(is); numFamilyBytes = UVIntTool.getInt(is); numQualifierBytes = UVIntTool.getInt(is); numTagsBytes = UVIntTool.getInt(is); numTimestampBytes = UVIntTool.getInt(is); numMvccVersionBytes = UVIntTool.getInt(is); numValueBytes = UVIntTool.getInt(is); nextNodeOffsetWidth = UVIntTool.getInt(is); familyOffsetWidth = UVIntTool.getInt(is); qualifierOffsetWidth = UVIntTool.getInt(is); tagsOffsetWidth = UVIntTool.getInt(is); timestampIndexWidth = UVIntTool.getInt(is); mvccVersionIndexWidth = UVIntTool.getInt(is); valueOffsetWidth = UVIntTool.getInt(is); valueLengthWidth = UVIntTool.getInt(is); rowTreeDepth = UVIntTool.getInt(is); maxRowLength = UVIntTool.getInt(is); maxQualifierLength = UVIntTool.getInt(is); maxTagsLength = UVIntTool.getInt(is); minTimestamp = UVLongTool.getLong(is); timestampDeltaWidth = UVIntTool.getInt(is); minMvccVersion = UVLongTool.getLong(is); mvccVersionDeltaWidth = UVIntTool.getInt(is); setAllSameType((byte) is.read()); allTypes = (byte) is.read(); numUniqueRows = UVIntTool.getInt(is); numUniqueFamilies = UVIntTool.getInt(is); numUniqueQualifiers = UVIntTool.getInt(is); numUniqueTags = UVIntTool.getInt(is); }
public void readVariableBytesFromArray(byte[] bytes, int offset) { int position = offset; version = UVIntTool.getInt(bytes, position); position += UVIntTool.numBytes(version); numMetaBytes = UVIntTool.getInt(bytes, position); position += UVIntTool.numBytes(numMetaBytes); numKeyValueBytes = UVIntTool.getInt(bytes, position); position += UVIntTool.numBytes(numKeyValueBytes); setIncludesMvccVersion(bytes[position]); ++position; numRowBytes = UVIntTool.getInt(bytes, position); position += UVIntTool.numBytes(numRowBytes); numFamilyBytes = UVIntTool.getInt(bytes, position); position += UVIntTool.numBytes(numFamilyBytes); numQualifierBytes = UVIntTool.getInt(bytes, position); position += UVIntTool.numBytes(numQualifierBytes); numTagsBytes = UVIntTool.getInt(bytes, position); position += UVIntTool.numBytes(numTagsBytes); numTimestampBytes = UVIntTool.getInt(bytes, position); position += UVIntTool.numBytes(numTimestampBytes); numMvccVersionBytes = UVIntTool.getInt(bytes, position); position += UVIntTool.numBytes(numMvccVersionBytes); numValueBytes = UVIntTool.getInt(bytes, position); position += UVIntTool.numBytes(numValueBytes); nextNodeOffsetWidth = UVIntTool.getInt(bytes, position); position += UVIntTool.numBytes(nextNodeOffsetWidth); familyOffsetWidth = UVIntTool.getInt(bytes, position); position += UVIntTool.numBytes(familyOffsetWidth); qualifierOffsetWidth = UVIntTool.getInt(bytes, position); position += UVIntTool.numBytes(qualifierOffsetWidth); tagsOffsetWidth = UVIntTool.getInt(bytes, position); position += UVIntTool.numBytes(tagsOffsetWidth); timestampIndexWidth = UVIntTool.getInt(bytes, position); position += UVIntTool.numBytes(timestampIndexWidth); mvccVersionIndexWidth = UVIntTool.getInt(bytes, position); position += UVIntTool.numBytes(mvccVersionIndexWidth); valueOffsetWidth = UVIntTool.getInt(bytes, position); position += UVIntTool.numBytes(valueOffsetWidth); valueLengthWidth = UVIntTool.getInt(bytes, position); position += UVIntTool.numBytes(valueLengthWidth); rowTreeDepth = UVIntTool.getInt(bytes, position); position += UVIntTool.numBytes(rowTreeDepth); maxRowLength = UVIntTool.getInt(bytes, position); position += UVIntTool.numBytes(maxRowLength); maxQualifierLength = UVIntTool.getInt(bytes, position); position += UVIntTool.numBytes(maxQualifierLength); maxTagsLength = UVIntTool.getInt(bytes, position); position += UVIntTool.numBytes(maxTagsLength); minTimestamp = UVLongTool.getLong(bytes, position); position += UVLongTool.numBytes(minTimestamp); timestampDeltaWidth = UVIntTool.getInt(bytes, position); position += UVIntTool.numBytes(timestampDeltaWidth); minMvccVersion = UVLongTool.getLong(bytes, position); position += UVLongTool.numBytes(minMvccVersion); mvccVersionDeltaWidth = UVIntTool.getInt(bytes, position); position += UVIntTool.numBytes(mvccVersionDeltaWidth); setAllSameType(bytes[position]); ++position; allTypes = bytes[position]; ++position; numUniqueRows = UVIntTool.getInt(bytes, position); position += UVIntTool.numBytes(numUniqueRows); numUniqueFamilies = UVIntTool.getInt(bytes, position); position += UVIntTool.numBytes(numUniqueFamilies); numUniqueQualifiers = UVIntTool.getInt(bytes, position); position += UVIntTool.numBytes(numUniqueQualifiers); numUniqueTags = UVIntTool.getInt(bytes, position); position += UVIntTool.numBytes(numUniqueTags); }
@Test public void testFromBytes() { Assert.assertEquals(Long.MAX_VALUE, UVLongTool.getLong(UVLongTool.MAX_VALUE_BYTES)); }