DBZ-3993 Skipping object size based test on Java 16+
This commit is contained in:
parent
028076bac8
commit
c3eed6051b
@ -26,6 +26,8 @@
|
||||
|
||||
import io.debezium.config.Configuration;
|
||||
import io.debezium.connector.postgresql.PostgresConnectorConfig.SnapshotMode;
|
||||
import io.debezium.junit.EqualityCheck;
|
||||
import io.debezium.junit.SkipWhenJavaVersion;
|
||||
import io.debezium.util.Testing;
|
||||
|
||||
/**
|
||||
@ -198,6 +200,7 @@ private void assertStreamingMetrics() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SkipWhenJavaVersion(check = EqualityCheck.GREATER_THAN_OR_EQUAL, value = 16, description = "Deep reflection not allowed by default on this Java version")
|
||||
public void oneRecordInQueue() throws Exception {
|
||||
// Testing.Print.enable();
|
||||
final MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
|
||||
|
@ -0,0 +1,32 @@
|
||||
package io.debezium.util;
|
||||
|
||||
/*
|
||||
* Copyright Debezium Authors.
|
||||
*
|
||||
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Utility class dealing with Java version information.
|
||||
*
|
||||
* @author Gunnar Morling
|
||||
*/
|
||||
public class JvmVersionUtil {
|
||||
|
||||
private JvmVersionUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the feature version of the current JVM, e.g. 8 or 17.
|
||||
*/
|
||||
public static int getFeatureVersion() {
|
||||
try {
|
||||
return Runtime.version().feature();
|
||||
}
|
||||
// The version() is only available on Java 9 and later
|
||||
catch (NoSuchMethodError nsme) {
|
||||
final String specVersion = System.getProperty("java.specification.version");
|
||||
return Integer.parseInt(specVersion.substring(specVersion.indexOf('.') + 1));
|
||||
}
|
||||
}
|
||||
}
|
@ -124,6 +124,7 @@ public static long getObjectSize(Object obj) throws UnsupportedOperationExceptio
|
||||
private final int superclassFieldPadding;
|
||||
|
||||
private final LoadingCache<Class<?>, ClassSizeInfo> classSizeInfos = CacheBuilder.newBuilder().build(new CacheLoader<Class<?>, ClassSizeInfo>() {
|
||||
@Override
|
||||
public ClassSizeInfo load(Class<?> clazz) {
|
||||
return new ClassSizeInfo(clazz);
|
||||
}
|
||||
@ -382,9 +383,8 @@ else if (!"64".equals(dataModel)) {
|
||||
dataModel + "' of sun.arch.data.model system property");
|
||||
}
|
||||
|
||||
final String strVmVersion = System.getProperty("java.vm.version");
|
||||
final int vmVersion = Integer.parseInt(strVmVersion.substring(0,
|
||||
strVmVersion.indexOf('.')));
|
||||
final int vmVersion = JvmVersionUtil.getFeatureVersion();
|
||||
|
||||
if (vmVersion >= 17) {
|
||||
long maxMemory = 0;
|
||||
for (MemoryPoolMXBean mp : ManagementFactory.getMemoryPoolMXBeans()) {
|
||||
|
@ -15,6 +15,7 @@
|
||||
import org.reflections.Reflections;
|
||||
|
||||
import io.debezium.junit.DatabaseVersionResolver.DatabaseVersion;
|
||||
import io.debezium.util.JvmVersionUtil;
|
||||
import io.debezium.util.Testing;
|
||||
|
||||
/**
|
||||
@ -29,6 +30,37 @@ public class SkipTestRule extends AnnotationBasedTestRule {
|
||||
@Override
|
||||
public Statement apply(Statement base,
|
||||
Description description) {
|
||||
SkipWhenJavaVersion skipJavaVersionAnnotation = hasAnnotation(description, SkipWhenJavaVersion.class);
|
||||
if (skipJavaVersionAnnotation != null) {
|
||||
int checkedVersion = skipJavaVersionAnnotation.value();
|
||||
int actualVersion = JvmVersionUtil.getFeatureVersion();
|
||||
boolean isSkippedVersion;
|
||||
|
||||
switch (skipJavaVersionAnnotation.check()) {
|
||||
case EQUAL:
|
||||
isSkippedVersion = actualVersion == checkedVersion;
|
||||
case GREATER_THAN:
|
||||
isSkippedVersion = actualVersion > checkedVersion;
|
||||
break;
|
||||
case GREATER_THAN_OR_EQUAL:
|
||||
isSkippedVersion = actualVersion >= checkedVersion;
|
||||
break;
|
||||
case LESS_THAN:
|
||||
isSkippedVersion = actualVersion < checkedVersion;
|
||||
break;
|
||||
case LESS_THAN_OR_EQUAL:
|
||||
isSkippedVersion = actualVersion <= checkedVersion;
|
||||
break;
|
||||
default:
|
||||
isSkippedVersion = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (isSkippedVersion) {
|
||||
return emptyStatement("Java version=" + actualVersion, description);
|
||||
}
|
||||
}
|
||||
|
||||
SkipLongRunning skipLongRunningAnnotation = hasAnnotation(description, SkipLongRunning.class);
|
||||
if (skipLongRunningAnnotation != null) {
|
||||
String skipLongRunning = System.getProperty(SkipLongRunning.SKIP_LONG_RUNNING_PROPERTY);
|
||||
|
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright Debezium Authors.
|
||||
*
|
||||
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.debezium.junit;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Marker annotation used together with the {@link SkipTestRule} JUnit rule, that allows tests to be skipped
|
||||
* based on the Java version used for testing.
|
||||
*
|
||||
* @author Gunnar Morling
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ ElementType.METHOD, ElementType.TYPE })
|
||||
public @interface SkipWhenJavaVersion {
|
||||
|
||||
int value();
|
||||
|
||||
EqualityCheck check();
|
||||
|
||||
String description();
|
||||
}
|
Loading…
Reference in New Issue
Block a user