From 8a8f8cfdfb6439d897aacbf7e2b244d8670ef3ea Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Sat, 30 Nov 2019 13:27:24 +0100 Subject: [PATCH] Add TypedReflections We have multiple places which are accessing annotation-based type information. This provides a single place to obtain that information. As we have proper encapsulation, add caches for table/column versions. Since we are dealing with Version, this class is updated to be immutable and provide a Range factory. Change-Id: I5c2f1d3553392cbd222a1927fdd36564f895475b Signed-off-by: Robert Varga (cherry picked from commit fe88fed9e88ee27a191143678ac3598296597a12) --- .../ovsdb/lib/impl/OvsdbClientImpl.java | 9 +- .../ovsdb/lib/notation/Version.java | 56 +++----- .../lib/schema/typed/TypedReflections.java | 73 ++++++++++ .../ovsdb/lib/schema/typed/TyperUtils.java | 135 +++++++----------- .../lib/schema/typed/TyperUtilsTest.java | 44 ++---- 5 files changed, 154 insertions(+), 163 deletions(-) create mode 100644 library/impl/src/main/java/org/opendaylight/ovsdb/lib/schema/typed/TypedReflections.java diff --git a/library/impl/src/main/java/org/opendaylight/ovsdb/lib/impl/OvsdbClientImpl.java b/library/impl/src/main/java/org/opendaylight/ovsdb/lib/impl/OvsdbClientImpl.java index 140830a58..083bd0120 100644 --- a/library/impl/src/main/java/org/opendaylight/ovsdb/lib/impl/OvsdbClientImpl.java +++ b/library/impl/src/main/java/org/opendaylight/ovsdb/lib/impl/OvsdbClientImpl.java @@ -55,7 +55,7 @@ import org.opendaylight.ovsdb.lib.schema.GenericTableSchema; import org.opendaylight.ovsdb.lib.schema.TableSchema; import org.opendaylight.ovsdb.lib.schema.typed.TypedBaseTable; import org.opendaylight.ovsdb.lib.schema.typed.TypedDatabaseSchema; -import org.opendaylight.ovsdb.lib.schema.typed.TypedTable; +import org.opendaylight.ovsdb.lib.schema.typed.TypedReflections; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -418,11 +418,8 @@ public class OvsdbClientImpl implements OvsdbClient { * @return DatabaseSchema that matches a Typed Table Class */ private TypedDatabaseSchema getDatabaseSchemaForTypedTable(final Class klazz) { - TypedTable typedTable = klazz.getAnnotation(TypedTable.class); - if (typedTable != null) { - return this.getDatabaseSchema(typedTable.database()); - } - return null; + final String dbName = TypedReflections.getTableDatabase(klazz); + return dbName == null ? null : getDatabaseSchema(dbName); } /** diff --git a/library/impl/src/main/java/org/opendaylight/ovsdb/lib/notation/Version.java b/library/impl/src/main/java/org/opendaylight/ovsdb/lib/notation/Version.java index edcadf212..d81ec692d 100644 --- a/library/impl/src/main/java/org/opendaylight/ovsdb/lib/notation/Version.java +++ b/library/impl/src/main/java/org/opendaylight/ovsdb/lib/notation/Version.java @@ -8,6 +8,7 @@ package org.opendaylight.ovsdb.lib.notation; +import com.google.common.collect.Range; import com.google.errorprone.annotations.Var; /** @@ -18,11 +19,11 @@ import com.google.errorprone.annotations.Var; public class Version implements Comparable { private static final String FORMAT = "(\\d+)\\.(\\d+)\\.(\\d+)"; - private int major; - private int minor; - private int patch; + private final int major; + private final int minor; + private final int patch; - public Version(int major, int minor, int patch) { + public Version(final int major, final int minor, final int patch) { this.major = major; this.minor = minor; this.patch = patch; @@ -31,7 +32,7 @@ public class Version implements Comparable { public static final Version NULL = new Version(0,0,0); public static final String NULL_VERSION_STRING = "0.0.0"; - public static Version fromString(String version) { + public static Version fromString(final String version) { final int firstDot = version.indexOf('.'); final int secondDot = version.indexOf('.', firstDot + 1); if (firstDot == -1 || secondDot == -1) { @@ -51,7 +52,7 @@ public class Version implements Comparable { * has identified this as the top #3 (!) memory allocator overall - 1 GB avoidable String. * @author Michael Vorburger.ch */ - private static int parse(String string, int start, int end) { + private static int parse(final String string, final int start, final int end) { @Var int result = 0; for (int i = start; i < end && i < string.length(); i++) { char character = string.charAt(i); @@ -73,51 +74,27 @@ public class Version implements Comparable { return major; } - public void setMajor(int major) { - this.major = major; - } - public int getMinor() { return minor; } - public void setMinor(int minor) { - this.minor = minor; - } - public int getPatch() { return patch; } - public void setPatch(int patch) { - this.patch = patch; - } - - // ToDo: While format is X.X.X semantics are schema dependent. // Therefore we should allow equals to be overridden by the schema @Override - public boolean equals(Object object) { - if (this == object) { + public boolean equals(final Object obj) { + if (this == obj) { return true; } - if (object == null || getClass() != object.getClass()) { + if (obj == null || getClass() != obj.getClass()) { return false; } - Version version = (Version) object; - - if (major != version.major) { - return false; - } - if (minor != version.minor) { - return false; - } - if (patch != version.patch) { - return false; - } - - return true; + final Version other = (Version) obj; + return major == other.major && minor == other.minor && patch == other.patch; } @Override @@ -131,7 +108,7 @@ public class Version implements Comparable { // ToDo: While format is X.X.X semantics are schema dependent // Therefore we should allow compareTo to be overridden by the schema @Override - public int compareTo(Version version) { + public int compareTo(final Version version) { if (this.equals(version)) { return 0; } @@ -155,4 +132,11 @@ public class Version implements Comparable { // must be less than return -1; } + + public static Range createRangeOf(final Version from, final Version to) { + if (from == null || Version.NULL.equals(from)) { + return to == null || Version.NULL.equals(to) ? Range.all() : Range.atMost(to); + } + return to == null || Version.NULL.equals(to) ? Range.atLeast(from) : Range.closed(from, to); + } } diff --git a/library/impl/src/main/java/org/opendaylight/ovsdb/lib/schema/typed/TypedReflections.java b/library/impl/src/main/java/org/opendaylight/ovsdb/lib/schema/typed/TypedReflections.java new file mode 100644 index 000000000..2b28115f7 --- /dev/null +++ b/library/impl/src/main/java/org/opendaylight/ovsdb/lib/schema/typed/TypedReflections.java @@ -0,0 +1,73 @@ +/* + * Copyright © 2019 PANTHEON.tech, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.ovsdb.lib.schema.typed; + +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; +import com.google.common.collect.Range; +import java.lang.reflect.Method; +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; +import org.opendaylight.ovsdb.lib.notation.Version; + +/** + * Utilities for extracting annotation information at runtime. + */ +public final class TypedReflections { + private static final LoadingCache> COLUMN_VERSIONS = CacheBuilder.newBuilder().weakKeys() + .build(new CacheLoader>() { + @Override + public Range load(final Method key) { + final TypedColumn typedColumn = key.getAnnotation(TypedColumn.class); + return typedColumn == null ? Range.all() + : createVersionRange(typedColumn.fromVersion(), typedColumn.untilVersion()); + } + }); + private static final LoadingCache, Range> TABLE_VERSIONS = CacheBuilder.newBuilder().weakKeys() + .build(new CacheLoader, Range>() { + @Override + public Range load(final Class key) { + final TypedTable typedTable = key.getAnnotation(TypedTable.class); + return typedTable == null ? Range.all() + : createVersionRange(typedTable.fromVersion(), typedTable.untilVersion()); + } + }); + + + private TypedReflections() { + + } + + public static @Nullable String getTableDatabase(final Class type) { + // Pure reflection metadata access -- no need to cache this + final TypedTable typedTable = type.getAnnotation(TypedTable.class); + return typedTable != null ? typedTable.database() : null; + } + + public static @NonNull String getTableName(final Class type) { + // Pure reflection metadata access -- no need to cache this + final TypedTable typedTable = type.getAnnotation(TypedTable.class); + return typedTable != null ? typedTable.name() : type.getSimpleName(); + } + + public static @NonNull Range getTableVersionRange(final Class type) { + // Involves String -> Version conversion, use a cache + return TABLE_VERSIONS.getUnchecked(type); + } + + public static @NonNull Range getColumnVersionRange(final Method method) { + // Involves String -> Version conversion, use a cache + return COLUMN_VERSIONS.getUnchecked(method); + } + + static Range createVersionRange(final String from, final String until) { + return Version.createRangeOf(from == null ? Version.NULL : Version.fromString(from), + until == null ? Version.NULL : Version.fromString(until)); + } +} diff --git a/library/impl/src/main/java/org/opendaylight/ovsdb/lib/schema/typed/TyperUtils.java b/library/impl/src/main/java/org/opendaylight/ovsdb/lib/schema/typed/TyperUtils.java index dddb8d873..3fedd6b11 100644 --- a/library/impl/src/main/java/org/opendaylight/ovsdb/lib/schema/typed/TyperUtils.java +++ b/library/impl/src/main/java/org/opendaylight/ovsdb/lib/schema/typed/TyperUtils.java @@ -8,8 +8,10 @@ package org.opendaylight.ovsdb.lib.schema.typed; +import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Objects; import com.google.common.base.Preconditions; +import com.google.common.collect.Range; import com.google.common.reflect.Reflection; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.lang.reflect.InvocationHandler; @@ -47,14 +49,6 @@ public final class TyperUtils { // Prevent instantiating a utility class } - private static String getTableName(Class klazz) { - TypedTable typedTable = klazz.getAnnotation(TypedTable.class); - if (typedTable != null) { - return typedTable.name(); - } - return klazz.getSimpleName(); - } - /** * Retrieve the table schema for the given table in the given database schema. * @@ -63,17 +57,16 @@ public final class TyperUtils { * using their {@link TypedTable} annotation, if they have one, or by name. * @return the table schema. */ - public static GenericTableSchema getTableSchema(DatabaseSchema dbSchema, Class klazz) { - String tableName = getTableName(klazz); - return dbSchema.table(tableName, GenericTableSchema.class); + public static GenericTableSchema getTableSchema(final DatabaseSchema dbSchema, final Class klazz) { + return dbSchema.table(TypedReflections.getTableName(klazz), GenericTableSchema.class); } - public static ColumnSchema - getColumnSchema(GenericTableSchema tableSchema, String columnName, Class metaClass) { + public static ColumnSchema getColumnSchema(final GenericTableSchema tableSchema, + final String columnName, final Class metaClass) { return tableSchema.column(columnName, metaClass); } - private static String getColumnName(Method method) { + private static String getColumnName(final Method method) { TypedColumn typedColumn = method.getAnnotation(TypedColumn.class); if (typedColumn != null) { return typedColumn.name(); @@ -97,12 +90,12 @@ public final class TyperUtils { return null; } - private static boolean isGetTableSchema(Method method) { + private static boolean isGetTableSchema(final Method method) { TypedColumn typedColumn = method.getAnnotation(TypedColumn.class); return typedColumn != null && typedColumn.method().equals(MethodType.GETTABLESCHEMA); } - private static boolean isGetRow(Method method) { + private static boolean isGetRow(final Method method) { TypedColumn typedColumn = method.getAnnotation(TypedColumn.class); if (typedColumn != null) { return typedColumn.method().equals(MethodType.GETROW); @@ -111,7 +104,7 @@ public final class TyperUtils { return method.getName().startsWith(GET_STARTS_WITH) && method.getName().endsWith(GETROW_ENDS_WITH); } - private static boolean isGetColumn(Method method) { + private static boolean isGetColumn(final Method method) { TypedColumn typedColumn = method.getAnnotation(TypedColumn.class); if (typedColumn != null) { return typedColumn.method().equals(MethodType.GETCOLUMN); @@ -120,7 +113,7 @@ public final class TyperUtils { return method.getName().startsWith(GET_STARTS_WITH) && method.getName().endsWith(GETCOLUMN_ENDS_WITH); } - private static boolean isGetData(Method method) { + private static boolean isGetData(final Method method) { TypedColumn typedColumn = method.getAnnotation(TypedColumn.class); if (typedColumn != null) { return typedColumn.method().equals(MethodType.GETDATA); @@ -129,7 +122,7 @@ public final class TyperUtils { return method.getName().startsWith(GET_STARTS_WITH) && !method.getName().endsWith(GETCOLUMN_ENDS_WITH); } - private static boolean isSetData(Method method) { + private static boolean isSetData(final Method method) { TypedColumn typedColumn = method.getAnnotation(TypedColumn.class); if (typedColumn != null) { return typedColumn.method().equals(MethodType.SETDATA); @@ -138,38 +131,6 @@ public final class TyperUtils { return method.getName().startsWith(SET_STARTS_WITH); } - public static Version getColumnFromVersion(Method method) { - TypedColumn typedColumn = method.getAnnotation(TypedColumn.class); - if (typedColumn != null) { - return Version.fromString(typedColumn.fromVersion()); - } - return Version.NULL; - } - - public static Version getTableFromVersion(final Class klazz) { - TypedTable typedTable = klazz.getAnnotation(TypedTable.class); - if (typedTable != null) { - return Version.fromString(typedTable.fromVersion()); - } - return Version.NULL; - } - - public static Version getColumnUntilVersion(Method method) { - TypedColumn typedColumn = method.getAnnotation(TypedColumn.class); - if (typedColumn != null) { - return Version.fromString(typedColumn.untilVersion()); - } - return Version.NULL; - } - - public static Version getTableUntilVersion(final Class klazz) { - TypedTable typedTable = klazz.getAnnotation(TypedTable.class); - if (typedTable != null) { - return Version.fromString(typedTable.untilVersion()); - } - return Version.NULL; - } - /** * Method that checks validity of the parameter passed to getTypedRowWrapper. * This method checks for a valid Database Schema matching the expected Database for a given table @@ -179,13 +140,13 @@ public final class TyperUtils { * @param klazz Typed Class that represents a Table * @return true if valid, false otherwise */ - private static boolean isValid(DatabaseSchema dbSchema, final Class klazz) { + private static boolean isValid(final DatabaseSchema dbSchema, final Class klazz) { if (dbSchema == null) { return false; } - TypedTable typedTable = klazz.getAnnotation(TypedTable.class); - if (typedTable != null && !dbSchema.getName().equalsIgnoreCase(typedTable.database())) { + final String dbName = TypedReflections.getTableDatabase(klazz); + if (dbName != null && !dbSchema.getName().equalsIgnoreCase(dbName)) { return false; } @@ -194,24 +155,20 @@ public final class TyperUtils { return true; } - private static void checkColumnSchemaVersion(DatabaseSchema dbSchema, Method method) { - Version fromVersion = getColumnFromVersion(method); - Version untilVersion = getColumnUntilVersion(method); - Version schemaVersion = dbSchema.getVersion(); - checkVersion(schemaVersion, fromVersion, untilVersion); + private static void checkColumnSchemaVersion(final DatabaseSchema dbSchema, final Method method) { + checkVersion(dbSchema.getVersion(), TypedReflections.getColumnVersionRange(method)); } - private static void checkTableSchemaVersion(DatabaseSchema dbSchema, Class klazz) { - Version fromVersion = getTableFromVersion(klazz); - Version untilVersion = getTableUntilVersion(klazz); - Version schemaVersion = dbSchema.getVersion(); - checkVersion(schemaVersion, fromVersion, untilVersion); + private static void checkTableSchemaVersion(final DatabaseSchema dbSchema, final Class klazz) { + checkVersion(dbSchema.getVersion(), TypedReflections.getTableVersionRange(klazz)); } - private static void checkVersion(Version schemaVersion, Version fromVersion, Version untilVersion) { - if (!fromVersion.equals(Version.NULL) && schemaVersion.compareTo(fromVersion) < 0 || !untilVersion.equals( - Version.NULL) && schemaVersion.compareTo(untilVersion) > 0) { - throw new SchemaVersionMismatchException(schemaVersion, fromVersion, untilVersion); + @VisibleForTesting + static void checkVersion(final Version schemaVersion, final Range range) { + if (!range.contains(schemaVersion)) { + throw new SchemaVersionMismatchException(schemaVersion, + range.hasLowerBound() ? range.lowerEndpoint() : Version.NULL, + range.hasUpperBound() ? range.upperEndpoint() : Version.NULL); } } @@ -264,7 +221,7 @@ public final class TyperUtils { row.setTableSchema(getTableSchema(dbSchema, klazz)); } return Reflection.newProxy(klazz, new InvocationHandler() { - private Object processGetData(Method method) { + private Object processGetData(final Method method) { String columnName = getColumnName(method); checkColumnSchemaVersion(dbSchema, method); if (columnName == null) { @@ -272,8 +229,8 @@ public final class TyperUtils { } GenericTableSchema tableSchema = getTableSchema(dbSchema, klazz); if (tableSchema == null) { - String message = - TableSchemaNotFoundException.createMessage(getTableName(klazz), dbSchema.getName()); + String message = TableSchemaNotFoundException.createMessage(TypedReflections.getTableName(klazz), + dbSchema.getName()); throw new TableSchemaNotFoundException(message); } ColumnSchema columnSchema = @@ -292,7 +249,7 @@ public final class TyperUtils { return row; } - private Object processGetColumn(Method method) { + private Object processGetColumn(final Method method) { String columnName = getColumnName(method); checkColumnSchemaVersion(dbSchema, method); if (columnName == null) { @@ -300,8 +257,8 @@ public final class TyperUtils { } GenericTableSchema tableSchema = getTableSchema(dbSchema, klazz); if (tableSchema == null) { - String message = - TableSchemaNotFoundException.createMessage(getTableName(klazz), dbSchema.getName()); + String message = TableSchemaNotFoundException.createMessage(TypedReflections.getTableName(klazz), + dbSchema.getName()); throw new TableSchemaNotFoundException(message); } ColumnSchema columnSchema = @@ -318,7 +275,7 @@ public final class TyperUtils { return row.getColumn(columnSchema); } - private Object processSetData(Object proxy, Method method, Object[] args) { + private Object processSetData(final Object proxy, final Method method, final Object[] args) { if (args == null || args.length != 1) { throw new TyperException("Setter method : " + method.getName() + " requires 1 argument"); } @@ -343,23 +300,23 @@ public final class TyperUtils { return getTableSchema(dbSchema, klazz); } - private Boolean isHashCodeMethod(Method method, Object[] args) { + private Boolean isHashCodeMethod(final Method method, final Object[] args) { return (args == null || args.length == 0) && method.getName().equals("hashCode"); } - private Boolean isEqualsMethod(Method method, Object[] args) { + private Boolean isEqualsMethod(final Method method, final Object[] args) { return args != null && args.length == 1 && method.getName().equals("equals") && Object.class.equals(method.getParameterTypes()[0]); } - private Boolean isToStringMethod(Method method, Object[] args) { + private Boolean isToStringMethod(final Method method, final Object[] args) { return (args == null || args.length == 0) && method.getName().equals("toString"); } @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Exception { + public Object invoke(final Object proxy, final Method method, final Object[] args) throws Exception { if (isGetTableSchema(method)) { return processGetTableSchema(); } else if (isGetRow(method)) { @@ -382,7 +339,7 @@ public final class TyperUtils { @Override @SuppressFBWarnings({"EQ_CHECK_FOR_OPERAND_NOT_COMPATIBLE_WITH_THIS", "EQ_UNUSUAL"}) - public boolean equals(Object obj) { + public boolean equals(final Object obj) { if (!(obj instanceof TypedBaseTable)) { return false; } @@ -390,14 +347,16 @@ public final class TyperUtils { return Objects.equal(row, typedRowObj.getRow()); } - @Override public int hashCode() { + @Override + public int hashCode() { if (row == null) { return 0; } return row.hashCode(); } - @Override public String toString() { + @Override + public String toString() { String tableName; TableSchema schema = (TableSchema)processGetTableSchema(); if (schema != null) { @@ -427,7 +386,8 @@ public final class TyperUtils { * @param dbSchema Dbschema for the TableUpdates * @return Map<UUID,T> for the type of things being sought */ - public static Map extractRowsUpdated(Class klazz,TableUpdates updates,DatabaseSchema dbSchema) { + public static Map extractRowsUpdated(final Class klazz, final TableUpdates updates, + final DatabaseSchema dbSchema) { Preconditions.checkNotNull(klazz); Preconditions.checkNotNull(updates); Preconditions.checkNotNull(dbSchema); @@ -456,7 +416,8 @@ public final class TyperUtils { * @param dbSchema Dbschema for the TableUpdates * @return Map<UUID,T> for the type of things being sought */ - public static Map extractRowsOld(Class klazz, TableUpdates updates, DatabaseSchema dbSchema) { + public static Map extractRowsOld(final Class klazz, final TableUpdates updates, + final DatabaseSchema dbSchema) { Preconditions.checkNotNull(klazz); Preconditions.checkNotNull(updates); Preconditions.checkNotNull(dbSchema); @@ -485,7 +446,8 @@ public final class TyperUtils { * @param dbSchema Dbschema for the TableUpdates * @return Map<UUID,T> for the type of things being sought */ - public static Map extractRowsRemoved(Class klazz,TableUpdates updates,DatabaseSchema dbSchema) { + public static Map extractRowsRemoved(final Class klazz, final TableUpdates updates, + final DatabaseSchema dbSchema) { Preconditions.checkNotNull(klazz); Preconditions.checkNotNull(updates); Preconditions.checkNotNull(dbSchema); @@ -517,7 +479,7 @@ public final class TyperUtils { * for the type of things being sought */ public static Map.RowUpdate> - extractRowUpdates(Class klazz,TableUpdates updates,DatabaseSchema dbSchema) { + extractRowUpdates(final Class klazz,final TableUpdates updates,final DatabaseSchema dbSchema) { Preconditions.checkNotNull(klazz); Preconditions.checkNotNull(updates); Preconditions.checkNotNull(dbSchema); @@ -532,5 +494,4 @@ public final class TyperUtils { } return result; } - } diff --git a/library/impl/src/test/java/org/opendaylight/ovsdb/lib/schema/typed/TyperUtilsTest.java b/library/impl/src/test/java/org/opendaylight/ovsdb/lib/schema/typed/TyperUtilsTest.java index 34e12a6cb..5860a2485 100644 --- a/library/impl/src/test/java/org/opendaylight/ovsdb/lib/schema/typed/TyperUtilsTest.java +++ b/library/impl/src/test/java/org/opendaylight/ovsdb/lib/schema/typed/TyperUtilsTest.java @@ -10,25 +10,19 @@ package org.opendaylight.ovsdb.lib.schema.typed; import static org.junit.Assert.assertEquals; import com.google.common.collect.ImmutableMap; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; +import com.google.common.collect.Range; import java.util.Collections; -import org.junit.Assert; import org.junit.Test; import org.opendaylight.ovsdb.lib.error.SchemaVersionMismatchException; import org.opendaylight.ovsdb.lib.notation.Version; import org.opendaylight.ovsdb.lib.schema.DatabaseSchema; import org.opendaylight.ovsdb.lib.schema.DatabaseSchemaImpl; import org.opendaylight.ovsdb.lib.schema.GenericTableSchema; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Test class for {@link TyperUtils}. */ public class TyperUtilsTest { - private static final Logger LOG = LoggerFactory.getLogger(TyperUtilsTest.class); - @TypedTable(name = "TestTypedTable", database = "Open_vSwitch") private class TestTypedTable { @@ -101,7 +95,7 @@ public class TyperUtilsTest { } /** - * Test that {@link TyperUtils#checkVersion(Version, Version, Version)} detects an old version. (The aim here isn't + * Test that {@link TyperUtils#checkVersion(Version, Range)} detects an old version. (The aim here isn't * to test {@link Version#compareTo(Version)}, that should be done in * {@link org.opendaylight.ovsdb.lib.notation.VersionTest}). */ @@ -111,7 +105,7 @@ public class TyperUtilsTest { } /** - * Test that {@link TyperUtils#checkVersion(Version, Version, Version)} detects a new version. + * Test that {@link TyperUtils#checkVersion(Version, Range)} detects a new version. */ @Test(expected = SchemaVersionMismatchException.class) public void testCheckNewVersionFails() throws SchemaVersionMismatchException { @@ -119,7 +113,7 @@ public class TyperUtilsTest { } /** - * Test that {@link TyperUtils#checkVersion(Version, Version, Version)} accepts null boundaries. + * Test that {@link TyperUtils#checkVersion(Version, Range)} accepts null boundaries. */ @Test public void testCheckNullVersionsSucceed() throws SchemaVersionMismatchException { @@ -128,7 +122,7 @@ public class TyperUtilsTest { } /** - * Test that {@link TyperUtils#checkVersion(Version, Version, Version)} accepts the lower boundary version. + * Test that {@link TyperUtils#checkVersion(Version, Range)} accepts the lower boundary version. */ @Test public void testCheckLowerVersionBoundarySucceeds() throws SchemaVersionMismatchException { @@ -137,7 +131,7 @@ public class TyperUtilsTest { } /** - * Test that {@link TyperUtils#checkVersion(Version, Version, Version)} accepts the upper boundary version. + * Test that {@link TyperUtils#checkVersion(Version, Range)} accepts the upper boundary version. */ @Test public void testCheckUpperVersionBoundarySucceeds() throws SchemaVersionMismatchException { @@ -146,7 +140,7 @@ public class TyperUtilsTest { } /** - * Test that {@link TyperUtils#checkVersion(Version, Version, Version)} accepts both boundary versions. + * Test that {@link TyperUtils#checkVersion(Version, Range)} accepts both boundary versions. */ @Test public void testCheckSingleVersionBoundarySucceeds() throws SchemaVersionMismatchException { @@ -155,7 +149,7 @@ public class TyperUtilsTest { } /** - * Test that {@link TyperUtils#checkVersion(Version, Version, Version)} accepts a version within the boundaries + * Test that {@link TyperUtils#checkVersion(Version, Range)} accepts a version within the boundaries * (strictly). */ @Test @@ -165,32 +159,14 @@ public class TyperUtilsTest { } /** - * Call {@link TyperUtils#checkVersion(Version, Version, Version)}. + * Call {@link TyperUtils#checkVersion(Version, Range)}. * * @param schema The schema version (to be checked). * @param from The minimum supported version. * @param to The maximum supported version. * @throws SchemaVersionMismatchException if the schema version isn't supported. */ - // We extract the real cause, which “loses” the original cause, but that’s fine - @SuppressWarnings("checkstyle:AvoidHidingCauseException") private static void callCheckVersion(final Version schema, final Version from, final Version to) { - try { - Method method = - TyperUtils.class.getDeclaredMethod("checkVersion", Version.class, Version.class, Version.class); - method.setAccessible(true); - method.invoke(TyperUtils.class, schema, from, to); - } catch (NoSuchMethodException e) { - LOG.error("Can't find TyperUtils::checkVersion(), TyperUtilsTest::callCheckVersion() may be obsolete", e); - } catch (IllegalAccessException e) { - LOG.error("Error invoking TyperUtils::checkVersion(), please check TyperUtilsTest::callCheckVersion()", e); - } catch (InvocationTargetException e) { - final Throwable cause = e.getCause(); - if (cause instanceof SchemaVersionMismatchException) { - throw (SchemaVersionMismatchException) cause; - } - LOG.error("Unexpected exception thrown by TyperUtils::checkVersion()", cause); - Assert.fail("Unexpected exception thrown by TyperUtils::checkVersion()"); - } + TyperUtils.checkVersion(schema, Version.createRangeOf(from, to)); } } -- 2.36.6