private static boolean isMostRecentVersion(byte version) { return SchemaVersionUtils.decodeAvroSchemaVersion(version) == RowSchemaInfo.VER_CURRENT; }
/** * Processes the provided version byte to ensure that it represents a supported * schema version for a serialized container type. * * @param versionByte The byte representation of the encoded version * @param supportedVersion The currently supported schema version, non-negative * @return True if and only if the processed schema version matches the supported schema version * @throws UnknownSchemaVersionException Thrown if the processed schema version is not supported */ public static boolean processSchemaVersion(final byte versionByte, final int supportedVersion) { checkArgument(supportedVersion >= 0, "The supported schema version is invalid"); final int writerSchemaVersion = decodeAvroSchemaVersion(versionByte); if( writerSchemaVersion != supportedVersion ) { logger.warn(format("Cannot process unknown schema version %d, expected: %d ", writerSchemaVersion, supportedVersion)); throw new UnknownSchemaVersionException(writerSchemaVersion, supportedVersion); } return true; }
@Test(expected = IllegalArgumentException.class) public void testDecodeAvroSchemaVersionOddEncodedValue() { SchemaVersionUtils.decodeAvroSchemaVersion((byte)0x01); } }
@Test(expected = IllegalArgumentException.class) public void testDecodeAvroSchemaVersionExceedMaximumValue() { SchemaVersionUtils.decodeAvroSchemaVersion((byte)0x7F); }
@Test(expected = IllegalArgumentException.class) public void testDecodeAvroSchemaVersionExceedMinimumValue() { SchemaVersionUtils.decodeAvroSchemaVersion((byte)-5); }