From 90a580a0816e22026b203b6b7e890e0540be2d9f Mon Sep 17 00:00:00 2001 From: Savvas Kyriacou Date: Tue, 20 Aug 2024 13:35:24 +0100 Subject: [PATCH] updated sdv manager tests and workflows to match jvm changes Signed-off-by: Savvas Kyriacou --- .github/workflows/build.yaml | 4 +- .github/workflows/pr-build.yaml | 4 +- .../src/main/groovy/galasa.manager.gradle | 2 +- .../dev.galasa.sdv.manager/build.gradle | 2 +- .../config/spotbugs/excludes.xml | 4 + .../sdv/internal/TestSdvHttpRecorderImpl.java | 992 ++++++++++-------- .../sdv/internal/TestSdvManagerImpl.java | 109 +- .../TestSdvManagersResourceMonitor.java | 124 ++- .../galasa/sdv/internal/TestSdvUserPool.java | 17 +- .../internal/TestSdvUserResourceMonitor.java | 109 +- 10 files changed, 735 insertions(+), 632 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 434bb760f..b32bffb5b 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -48,7 +48,7 @@ jobs: - name: Setup JDK uses: actions/setup-java@v4 with: - java-version: '11' + java-version: '17' distribution: 'semeru' - name: Print githash @@ -58,7 +58,7 @@ jobs: - name: Setup Gradle uses: gradle/actions/setup-gradle@v3 with: - gradle-version: 6.9.2 + gradle-version: 8.9 - name: Build Managers source code if: github.event_name == 'push' diff --git a/.github/workflows/pr-build.yaml b/.github/workflows/pr-build.yaml index 7fe26321d..d5897bcb1 100644 --- a/.github/workflows/pr-build.yaml +++ b/.github/workflows/pr-build.yaml @@ -16,7 +16,7 @@ jobs: - name: Setup JDK uses: actions/setup-java@v4 with: - java-version: '11' + java-version: '17' distribution: 'semeru' - name: Print githash @@ -26,7 +26,7 @@ jobs: - name: Setup Gradle uses: gradle/actions/setup-gradle@v3 with: - gradle-version: 6.9.2 + gradle-version: 8.9 - name: Build Managers source code run: | diff --git a/galasa-managers-parent/buildSrc/src/main/groovy/galasa.manager.gradle b/galasa-managers-parent/buildSrc/src/main/groovy/galasa.manager.gradle index 2ff26348d..9dfcd0d29 100644 --- a/galasa-managers-parent/buildSrc/src/main/groovy/galasa.manager.gradle +++ b/galasa-managers-parent/buildSrc/src/main/groovy/galasa.manager.gradle @@ -21,7 +21,7 @@ dependencies { } jacoco { - toolVersion = "0.8.6" + toolVersion = "0.8.7" } test { diff --git a/galasa-managers-parent/galasa-managers-testingtools-parent/dev.galasa.sdv.manager/build.gradle b/galasa-managers-parent/galasa-managers-testingtools-parent/dev.galasa.sdv.manager/build.gradle index 9067f47c9..1b42d130a 100644 --- a/galasa-managers-parent/galasa-managers-testingtools-parent/dev.galasa.sdv.manager/build.gradle +++ b/galasa-managers-parent/galasa-managers-testingtools-parent/dev.galasa.sdv.manager/build.gradle @@ -2,7 +2,7 @@ plugins { id 'galasa.manager' id 'checkstyle' id 'pmd' - id("com.github.spotbugs") version "4.7.0" + id("com.github.spotbugs") version "6.0.20" } description = 'Galasa SDV Manager' diff --git a/galasa-managers-parent/galasa-managers-testingtools-parent/dev.galasa.sdv.manager/config/spotbugs/excludes.xml b/galasa-managers-parent/galasa-managers-testingtools-parent/dev.galasa.sdv.manager/config/spotbugs/excludes.xml index 423a426f9..57a96c9ec 100644 --- a/galasa-managers-parent/galasa-managers-testingtools-parent/dev.galasa.sdv.manager/config/spotbugs/excludes.xml +++ b/galasa-managers-parent/galasa-managers-testingtools-parent/dev.galasa.sdv.manager/config/spotbugs/excludes.xml @@ -5,6 +5,10 @@ + + + + diff --git a/galasa-managers-parent/galasa-managers-testingtools-parent/dev.galasa.sdv.manager/src/test/java/dev/galasa/sdv/internal/TestSdvHttpRecorderImpl.java b/galasa-managers-parent/galasa-managers-testingtools-parent/dev.galasa.sdv.manager/src/test/java/dev/galasa/sdv/internal/TestSdvHttpRecorderImpl.java index 3afa33691..c6bdf72b5 100644 --- a/galasa-managers-parent/galasa-managers-testingtools-parent/dev.galasa.sdv.manager/src/test/java/dev/galasa/sdv/internal/TestSdvHttpRecorderImpl.java +++ b/galasa-managers-parent/galasa-managers-testingtools-parent/dev.galasa.sdv.manager/src/test/java/dev/galasa/sdv/internal/TestSdvHttpRecorderImpl.java @@ -47,7 +47,6 @@ import java.io.IOException; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Modifier; import java.net.URI; import java.net.URISyntaxException; import java.nio.file.Files; @@ -67,6 +66,7 @@ import org.junit.jupiter.api.Test; import org.mockito.MockedStatic; import org.mockito.Mockito; +import sun.misc.Unsafe; class TestSdvHttpRecorderImpl { @@ -109,7 +109,7 @@ class TestSdvHttpRecorderImpl { private String jclDeleteLogstreamPathString = "/jcl/deletelogstreams.jcl"; private String jclGetYamlPathString = "/jcl/getYaml.jcl"; private String structureString = "A_STRUCTURE"; - private String modifiersString = "modifiers"; + private String theUnsafeString = "theUnsafe"; private String managerPrefixString = "manager."; private String runningManagersString = "runningManagers."; private String falseString = "false"; @@ -314,18 +314,20 @@ void testPrepareEnvironmentsAsFirstManagerOnRegionWithSdcActivation() dssService, null); // Replace LOG - Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); - loggerField.setAccessible(true); - Field loggerSuperField = - sdvHttpRecorderImplClass.getSuperclass().getDeclaredField(logVariableString); - loggerSuperField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - modifiersField.setInt(loggerSuperField, loggerSuperField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvHttpRecorder, mockLog); - loggerSuperField.set(sdvHttpRecorder, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); + + final Field superLoggerField = sdvHttpRecorderImplClass.getSuperclass() + .getDeclaredField(logVariableString); + final Object staticSuperLoggerFieldBase = unsafe.staticFieldBase(superLoggerField); + final long staticSuperLoggerFieldOffset = unsafe.staticFieldOffset(superLoggerField); + unsafe.putObject(staticSuperLoggerFieldBase, staticSuperLoggerFieldOffset, mockLog); sdvSdcActivation.when(() -> SdvSdcActivation.get(regionaTag)).thenReturn(true); sdvSdcActivation.when(() -> SdvSdcActivation.get(regionbTag)).thenReturn(true); @@ -460,18 +462,20 @@ void testPrepareEnvironmentsAsSecondManagerOnRegion() dssService, null); // Replace LOG - Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); - loggerField.setAccessible(true); - Field loggerSuperField = - sdvHttpRecorderImplClass.getSuperclass().getDeclaredField(logVariableString); - loggerSuperField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - modifiersField.setInt(loggerSuperField, loggerSuperField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvHttpRecorder, mockLog); - loggerSuperField.set(sdvHttpRecorder, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); + + final Field superLoggerField = sdvHttpRecorderImplClass.getSuperclass() + .getDeclaredField(logVariableString); + final Object staticSuperLoggerFieldBase = unsafe.staticFieldBase(superLoggerField); + final long staticSuperLoggerFieldOffset = unsafe.staticFieldOffset(superLoggerField); + unsafe.putObject(staticSuperLoggerFieldBase, staticSuperLoggerFieldOffset, mockLog); sdvSdcActivation.when(() -> SdvSdcActivation.get(regionaTag)).thenReturn(true); @@ -577,18 +581,20 @@ void testPrepareEnvironmentsLogstreamJobFailsDueToExisting() dssService, null); // Replace LOG - Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); - loggerField.setAccessible(true); - Field loggerSuperField = - sdvHttpRecorderImplClass.getSuperclass().getDeclaredField(logVariableString); - loggerSuperField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - modifiersField.setInt(loggerSuperField, loggerSuperField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvHttpRecorder, mockLog); - loggerSuperField.set(sdvHttpRecorder, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); + + final Field superLoggerField = sdvHttpRecorderImplClass.getSuperclass() + .getDeclaredField(logVariableString); + final Object staticSuperLoggerFieldBase = unsafe.staticFieldBase(superLoggerField); + final long staticSuperLoggerFieldOffset = unsafe.staticFieldOffset(superLoggerField); + unsafe.putObject(staticSuperLoggerFieldBase, staticSuperLoggerFieldOffset, mockLog); sdvSdcActivation.when(() -> SdvSdcActivation.get(regionaTag)).thenReturn(true); @@ -700,18 +706,20 @@ void testPrepareEnvironmentsLogstreamJobFailsDueToError() dssService, null); // Replace LOG - Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); - loggerField.setAccessible(true); - Field loggerSuperField = - sdvHttpRecorderImplClass.getSuperclass().getDeclaredField(logVariableString); - loggerSuperField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - modifiersField.setInt(loggerSuperField, loggerSuperField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvHttpRecorder, mockLog); - loggerSuperField.set(sdvHttpRecorder, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); + + final Field superLoggerField = sdvHttpRecorderImplClass.getSuperclass() + .getDeclaredField(logVariableString); + final Object staticSuperLoggerFieldBase = unsafe.staticFieldBase(superLoggerField); + final long staticSuperLoggerFieldOffset = unsafe.staticFieldOffset(superLoggerField); + unsafe.putObject(staticSuperLoggerFieldBase, staticSuperLoggerFieldOffset, mockLog); sdvSdcActivation.when(() -> SdvSdcActivation.get(regionaTag)).thenReturn(true); @@ -812,18 +820,20 @@ void testPrepareEnvironmentsCedaCreateException() dssService, null); // Replace LOG - Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); - loggerField.setAccessible(true); - Field loggerSuperField = - sdvHttpRecorderImplClass.getSuperclass().getDeclaredField(logVariableString); - loggerSuperField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - modifiersField.setInt(loggerSuperField, loggerSuperField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvHttpRecorder, mockLog); - loggerSuperField.set(sdvHttpRecorder, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); + + final Field superLoggerField = sdvHttpRecorderImplClass.getSuperclass() + .getDeclaredField(logVariableString); + final Object staticSuperLoggerFieldBase = unsafe.staticFieldBase(superLoggerField); + final long staticSuperLoggerFieldOffset = unsafe.staticFieldOffset(superLoggerField); + unsafe.putObject(staticSuperLoggerFieldBase, staticSuperLoggerFieldOffset, mockLog); sdvSdcActivation.when(() -> SdvSdcActivation.get(regionaTag)).thenReturn(true); @@ -922,18 +932,20 @@ void testPrepareEnvironmentsCedaInstallSdvGrpException() dssService, null); // Replace LOG - Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); - loggerField.setAccessible(true); - Field loggerSuperField = - sdvHttpRecorderImplClass.getSuperclass().getDeclaredField(logVariableString); - loggerSuperField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - modifiersField.setInt(loggerSuperField, loggerSuperField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvHttpRecorder, mockLog); - loggerSuperField.set(sdvHttpRecorder, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); + + final Field superLoggerField = sdvHttpRecorderImplClass.getSuperclass() + .getDeclaredField(logVariableString); + final Object staticSuperLoggerFieldBase = unsafe.staticFieldBase(superLoggerField); + final long staticSuperLoggerFieldOffset = unsafe.staticFieldOffset(superLoggerField); + unsafe.putObject(staticSuperLoggerFieldBase, staticSuperLoggerFieldOffset, mockLog); sdvSdcActivation.when(() -> SdvSdcActivation.get(regionaTag)).thenReturn(true); @@ -1034,18 +1046,20 @@ void testPrepareEnvironmentsCedaInstallDfhxsdException() dssService, null); // Replace LOG - Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); - loggerField.setAccessible(true); - Field loggerSuperField = - sdvHttpRecorderImplClass.getSuperclass().getDeclaredField(logVariableString); - loggerSuperField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - modifiersField.setInt(loggerSuperField, loggerSuperField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvHttpRecorder, mockLog); - loggerSuperField.set(sdvHttpRecorder, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); + + final Field superLoggerField = sdvHttpRecorderImplClass.getSuperclass() + .getDeclaredField(logVariableString); + final Object staticSuperLoggerFieldBase = unsafe.staticFieldBase(superLoggerField); + final long staticSuperLoggerFieldOffset = unsafe.staticFieldOffset(superLoggerField); + unsafe.putObject(staticSuperLoggerFieldBase, staticSuperLoggerFieldOffset, mockLog); sdvSdcActivation.when(() -> SdvSdcActivation.get(regionaTag)).thenReturn(true); @@ -1132,18 +1146,20 @@ void testPrepareEnvironmentsBatchJobThrowsException() throws CredentialsExceptio dssService, null); // Replace LOG - Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); - loggerField.setAccessible(true); - Field loggerSuperField = - sdvHttpRecorderImplClass.getSuperclass().getDeclaredField(logVariableString); - loggerSuperField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - modifiersField.setInt(loggerSuperField, loggerSuperField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvHttpRecorder, mockLog); - loggerSuperField.set(sdvHttpRecorder, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); + + final Field superLoggerField = sdvHttpRecorderImplClass.getSuperclass() + .getDeclaredField(logVariableString); + final Object staticSuperLoggerFieldBase = unsafe.staticFieldBase(superLoggerField); + final long staticSuperLoggerFieldOffset = unsafe.staticFieldOffset(superLoggerField); + unsafe.putObject(staticSuperLoggerFieldBase, staticSuperLoggerFieldOffset, mockLog); sdvSdcActivation.when(() -> SdvSdcActivation.get(regionaTag)).thenReturn(true); @@ -1201,18 +1217,20 @@ void testPrepareEnvironmentsDssThrowsException() .newInstance(framework, recordingRegions, null, null, null, dssService, null); // Replace LOG - Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); - loggerField.setAccessible(true); - Field loggerSuperField = - sdvHttpRecorderImplClass.getSuperclass().getDeclaredField(logVariableString); - loggerSuperField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - modifiersField.setInt(loggerSuperField, loggerSuperField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvHttpRecorder, mockLog); - loggerSuperField.set(sdvHttpRecorder, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); + + final Field superLoggerField = sdvHttpRecorderImplClass.getSuperclass() + .getDeclaredField(logVariableString); + final Object staticSuperLoggerFieldBase = unsafe.staticFieldBase(superLoggerField); + final long staticSuperLoggerFieldOffset = unsafe.staticFieldOffset(superLoggerField); + unsafe.putObject(staticSuperLoggerFieldBase, staticSuperLoggerFieldOffset, mockLog); sdvSdcActivation.when(() -> SdvSdcActivation.get(regionaTag)).thenReturn(true); @@ -1311,18 +1329,20 @@ void testPrepareEnvironmentsCemtThrowsException() throws DynamicStatusStoreExcep dssService, null); // Replace LOG - Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); - loggerField.setAccessible(true); - Field loggerSuperField = - sdvHttpRecorderImplClass.getSuperclass().getDeclaredField(logVariableString); - loggerSuperField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - modifiersField.setInt(loggerSuperField, loggerSuperField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvHttpRecorder, mockLog); - loggerSuperField.set(sdvHttpRecorder, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); + + final Field superLoggerField = sdvHttpRecorderImplClass.getSuperclass() + .getDeclaredField(logVariableString); + final Object staticSuperLoggerFieldBase = unsafe.staticFieldBase(superLoggerField); + final long staticSuperLoggerFieldOffset = unsafe.staticFieldOffset(superLoggerField); + unsafe.putObject(staticSuperLoggerFieldBase, staticSuperLoggerFieldOffset, mockLog); sdvSdcActivation.when(() -> SdvSdcActivation.get(regionaTag)).thenReturn(true); @@ -1435,18 +1455,20 @@ void testPrepareEnvironmentsPortNotFound() throws SdvManagerException, IllegalAr dssService, null); // Replace LOG - Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); - loggerField.setAccessible(true); - Field loggerSuperField = - sdvHttpRecorderImplClass.getSuperclass().getDeclaredField(logVariableString); - loggerSuperField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - modifiersField.setInt(loggerSuperField, loggerSuperField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvHttpRecorder, mockLog); - loggerSuperField.set(sdvHttpRecorder, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); + + final Field superLoggerField = sdvHttpRecorderImplClass.getSuperclass() + .getDeclaredField(logVariableString); + final Object staticSuperLoggerFieldBase = unsafe.staticFieldBase(superLoggerField); + final long staticSuperLoggerFieldOffset = unsafe.staticFieldOffset(superLoggerField); + unsafe.putObject(staticSuperLoggerFieldBase, staticSuperLoggerFieldOffset, mockLog); sdvSdcActivation.when(() -> SdvSdcActivation.get(regionaTag)).thenReturn(true); @@ -1551,18 +1573,20 @@ void testPrepareEnvironmentsHttpResourcesDoNotAlreadyExist() dssService, null); // Replace LOG - Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); - loggerField.setAccessible(true); - Field loggerSuperField = - sdvHttpRecorderImplClass.getSuperclass().getDeclaredField(logVariableString); - loggerSuperField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - modifiersField.setInt(loggerSuperField, loggerSuperField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvHttpRecorder, mockLog); - loggerSuperField.set(sdvHttpRecorder, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); + + final Field superLoggerField = sdvHttpRecorderImplClass.getSuperclass() + .getDeclaredField(logVariableString); + final Object staticSuperLoggerFieldBase = unsafe.staticFieldBase(superLoggerField); + final long staticSuperLoggerFieldOffset = unsafe.staticFieldOffset(superLoggerField); + unsafe.putObject(staticSuperLoggerFieldBase, staticSuperLoggerFieldOffset, mockLog); sdvSdcActivation.when(() -> SdvSdcActivation.get(regionaTag)).thenReturn(true); @@ -1683,18 +1707,20 @@ void testCleanUpEnvironmentsAsLastManagerOnRegionWithSdcActivation() dssService, null); // Replace LOG - Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); - loggerField.setAccessible(true); - Field loggerSuperField = - sdvHttpRecorderImplClass.getSuperclass().getDeclaredField(logVariableString); - loggerSuperField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - modifiersField.setInt(loggerSuperField, loggerSuperField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvHttpRecorder, mockLog); - loggerSuperField.set(sdvHttpRecorder, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); + + final Field superLoggerField = sdvHttpRecorderImplClass.getSuperclass() + .getDeclaredField(logVariableString); + final Object staticSuperLoggerFieldBase = unsafe.staticFieldBase(superLoggerField); + final long staticSuperLoggerFieldOffset = unsafe.staticFieldOffset(superLoggerField); + unsafe.putObject(staticSuperLoggerFieldBase, staticSuperLoggerFieldOffset, mockLog); sdvSdcActivation.when(() -> SdvSdcActivation.get(regionaTag)).thenReturn(true); sdvSdcActivation.when(() -> SdvSdcActivation.get(regionbTag)).thenReturn(true); @@ -1790,18 +1816,20 @@ void testCleanUpEnvironmentsNotAsLastManagerOnRegionWithSdcActivation() .newInstance(framework, recordingRegions, null, null, null, dssService, null); // Replace LOG - Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); - loggerField.setAccessible(true); - Field loggerSuperField = - sdvHttpRecorderImplClass.getSuperclass().getDeclaredField(logVariableString); - loggerSuperField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - modifiersField.setInt(loggerSuperField, loggerSuperField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvHttpRecorder, mockLog); - loggerSuperField.set(sdvHttpRecorder, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); + + final Field superLoggerField = sdvHttpRecorderImplClass.getSuperclass() + .getDeclaredField(logVariableString); + final Object staticSuperLoggerFieldBase = unsafe.staticFieldBase(superLoggerField); + final long staticSuperLoggerFieldOffset = unsafe.staticFieldOffset(superLoggerField); + unsafe.putObject(staticSuperLoggerFieldBase, staticSuperLoggerFieldOffset, mockLog); sdvSdcActivation.when(() -> SdvSdcActivation.get(regionaTag)).thenReturn(true); sdvSdcActivation.when(() -> SdvSdcActivation.get(regionbTag)).thenReturn(true); @@ -1857,18 +1885,20 @@ void testCleanUpEnvironmentsDssException() throws CredentialsException, SdvManag .newInstance(framework, recordingRegions, null, null, null, dssService, null); // Replace LOG - Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); - loggerField.setAccessible(true); - Field loggerSuperField = - sdvHttpRecorderImplClass.getSuperclass().getDeclaredField(logVariableString); - loggerSuperField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - modifiersField.setInt(loggerSuperField, loggerSuperField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvHttpRecorder, mockLog); - loggerSuperField.set(sdvHttpRecorder, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); + + final Field superLoggerField = sdvHttpRecorderImplClass.getSuperclass() + .getDeclaredField(logVariableString); + final Object staticSuperLoggerFieldBase = unsafe.staticFieldBase(superLoggerField); + final long staticSuperLoggerFieldOffset = unsafe.staticFieldOffset(superLoggerField); + unsafe.putObject(staticSuperLoggerFieldBase, staticSuperLoggerFieldOffset, mockLog); sdvSdcActivation.when(() -> SdvSdcActivation.get(regionaTag)).thenReturn(true); @@ -1956,18 +1986,20 @@ void testCleanUpEnvironmentsCedaDeleteGroupThrowsException() dssService, null); // Replace LOG - Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); - loggerField.setAccessible(true); - Field loggerSuperField = - sdvHttpRecorderImplClass.getSuperclass().getDeclaredField(logVariableString); - loggerSuperField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - modifiersField.setInt(loggerSuperField, loggerSuperField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvHttpRecorder, mockLog); - loggerSuperField.set(sdvHttpRecorder, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); + + final Field superLoggerField = sdvHttpRecorderImplClass.getSuperclass() + .getDeclaredField(logVariableString); + final Object staticSuperLoggerFieldBase = unsafe.staticFieldBase(superLoggerField); + final long staticSuperLoggerFieldOffset = unsafe.staticFieldOffset(superLoggerField); + unsafe.putObject(staticSuperLoggerFieldBase, staticSuperLoggerFieldOffset, mockLog); sdvSdcActivation.when(() -> SdvSdcActivation.get(regionaTag)).thenReturn(true); @@ -2063,18 +2095,20 @@ void testCleanUpEnvironmentsDeleteSrrLogstreamJobError() dssService, null); // Replace LOG - Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); - loggerField.setAccessible(true); - Field loggerSuperField = - sdvHttpRecorderImplClass.getSuperclass().getDeclaredField(logVariableString); - loggerSuperField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - modifiersField.setInt(loggerSuperField, loggerSuperField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvHttpRecorder, mockLog); - loggerSuperField.set(sdvHttpRecorder, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); + + final Field superLoggerField = sdvHttpRecorderImplClass.getSuperclass() + .getDeclaredField(logVariableString); + final Object staticSuperLoggerFieldBase = unsafe.staticFieldBase(superLoggerField); + final long staticSuperLoggerFieldOffset = unsafe.staticFieldOffset(superLoggerField); + unsafe.putObject(staticSuperLoggerFieldBase, staticSuperLoggerFieldOffset, mockLog); sdvSdcActivation.when(() -> SdvSdcActivation.get(regionaTag)).thenReturn(true); @@ -2158,18 +2192,20 @@ void testCleanUpEnvironmentsArtifactManagerException() throws CicstsManagerExcep null); // Replace LOG - Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); - loggerField.setAccessible(true); - Field loggerSuperField = - sdvHttpRecorderImplClass.getSuperclass().getDeclaredField(logVariableString); - loggerSuperField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - modifiersField.setInt(loggerSuperField, loggerSuperField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvHttpRecorder, mockLog); - loggerSuperField.set(sdvHttpRecorder, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); + + final Field superLoggerField = sdvHttpRecorderImplClass.getSuperclass() + .getDeclaredField(logVariableString); + final Object staticSuperLoggerFieldBase = unsafe.staticFieldBase(superLoggerField); + final long staticSuperLoggerFieldOffset = unsafe.staticFieldOffset(superLoggerField); + unsafe.putObject(staticSuperLoggerFieldBase, staticSuperLoggerFieldOffset, mockLog); sdvSdcActivation.when(() -> SdvSdcActivation.get(regionaTag)).thenReturn(true); @@ -2261,18 +2297,20 @@ void testCleanUpEnvironmentsCemtSetResourceException() dssService, null); // Replace LOG - Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); - loggerField.setAccessible(true); - Field loggerSuperField = - sdvHttpRecorderImplClass.getSuperclass().getDeclaredField(logVariableString); - loggerSuperField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - modifiersField.setInt(loggerSuperField, loggerSuperField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvHttpRecorder, mockLog); - loggerSuperField.set(sdvHttpRecorder, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); + + final Field superLoggerField = sdvHttpRecorderImplClass.getSuperclass() + .getDeclaredField(logVariableString); + final Object staticSuperLoggerFieldBase = unsafe.staticFieldBase(superLoggerField); + final long staticSuperLoggerFieldOffset = unsafe.staticFieldOffset(superLoggerField); + unsafe.putObject(staticSuperLoggerFieldBase, staticSuperLoggerFieldOffset, mockLog); sdvSdcActivation.when(() -> SdvSdcActivation.get(regionaTag)).thenReturn(true); sdvSdcActivation.when(() -> SdvSdcActivation.get(regionbTag)).thenReturn(true); @@ -2407,18 +2445,20 @@ void testStartRecordingNoExistingSdcForMultipleRegionsAndUsers() .newInstance(null, recordingRegions, null, null, null, null, httpManager); // Replace LOG - Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); - loggerField.setAccessible(true); - Field loggerSuperField = - sdvHttpRecorderImplClass.getSuperclass().getDeclaredField(logVariableString); - loggerSuperField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - modifiersField.setInt(loggerSuperField, loggerSuperField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvHttpRecorder, mockLog); - loggerSuperField.set(sdvHttpRecorder, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); + + final Field superLoggerField = sdvHttpRecorderImplClass.getSuperclass() + .getDeclaredField(logVariableString); + final Object staticSuperLoggerFieldBase = unsafe.staticFieldBase(superLoggerField); + final long staticSuperLoggerFieldOffset = unsafe.staticFieldOffset(superLoggerField); + unsafe.putObject(staticSuperLoggerFieldBase, staticSuperLoggerFieldOffset, mockLog); // Make call to funtion under test sdvHttpRecorder.startRecording(); @@ -2582,18 +2622,20 @@ void testStartRecordingExistingSdcForMultipleRegionsAndUsers() .newInstance(null, recordingRegions, null, null, null, null, httpManager); // Replace LOG - Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); - loggerField.setAccessible(true); - Field loggerSuperField = - sdvHttpRecorderImplClass.getSuperclass().getDeclaredField(logVariableString); - loggerSuperField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - modifiersField.setInt(loggerSuperField, loggerSuperField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvHttpRecorder, mockLog); - loggerSuperField.set(sdvHttpRecorder, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); + + final Field superLoggerField = sdvHttpRecorderImplClass.getSuperclass() + .getDeclaredField(logVariableString); + final Object staticSuperLoggerFieldBase = unsafe.staticFieldBase(superLoggerField); + final long staticSuperLoggerFieldOffset = unsafe.staticFieldOffset(superLoggerField); + unsafe.putObject(staticSuperLoggerFieldBase, staticSuperLoggerFieldOffset, mockLog); // Make call to funtion under test sdvHttpRecorder.startRecording(); @@ -2684,18 +2726,20 @@ void testStartRecordingHttpGetSdcServerError() throws CredentialsException, SdvM .newInstance(null, recordingRegions, null, null, null, null, httpManager); // Replace LOG - Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); - loggerField.setAccessible(true); - Field loggerSuperField = - sdvHttpRecorderImplClass.getSuperclass().getDeclaredField(logVariableString); - loggerSuperField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - modifiersField.setInt(loggerSuperField, loggerSuperField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvHttpRecorder, mockLog); - loggerSuperField.set(sdvHttpRecorder, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); + + final Field superLoggerField = sdvHttpRecorderImplClass.getSuperclass() + .getDeclaredField(logVariableString); + final Object staticSuperLoggerFieldBase = unsafe.staticFieldBase(superLoggerField); + final long staticSuperLoggerFieldOffset = unsafe.staticFieldOffset(superLoggerField); + unsafe.putObject(staticSuperLoggerFieldBase, staticSuperLoggerFieldOffset, mockLog); // Make call to funtion under test SdvManagerException exception = Assertions.assertThrows(SdvManagerException.class, () -> { @@ -2757,18 +2801,20 @@ void testStartRecordingGetHttpClientException() .newInstance(null, recordingRegions, null, null, null, null, httpManager); // Replace LOG - Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); - loggerField.setAccessible(true); - Field loggerSuperField = - sdvHttpRecorderImplClass.getSuperclass().getDeclaredField(logVariableString); - loggerSuperField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - modifiersField.setInt(loggerSuperField, loggerSuperField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvHttpRecorder, mockLog); - loggerSuperField.set(sdvHttpRecorder, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); + + final Field superLoggerField = sdvHttpRecorderImplClass.getSuperclass() + .getDeclaredField(logVariableString); + final Object staticSuperLoggerFieldBase = unsafe.staticFieldBase(superLoggerField); + final long staticSuperLoggerFieldOffset = unsafe.staticFieldOffset(superLoggerField); + unsafe.putObject(staticSuperLoggerFieldBase, staticSuperLoggerFieldOffset, mockLog); // Make call to funtion under test SdvManagerException exception = Assertions.assertThrows(SdvManagerException.class, () -> { @@ -2845,18 +2891,20 @@ void testStartRecordingHttpDeleteSdcServerError() .newInstance(null, recordingRegions, null, null, null, null, httpManager); // Replace LOG - Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); - loggerField.setAccessible(true); - Field loggerSuperField = - sdvHttpRecorderImplClass.getSuperclass().getDeclaredField(logVariableString); - loggerSuperField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - modifiersField.setInt(loggerSuperField, loggerSuperField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvHttpRecorder, mockLog); - loggerSuperField.set(sdvHttpRecorder, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); + + final Field superLoggerField = sdvHttpRecorderImplClass.getSuperclass() + .getDeclaredField(logVariableString); + final Object staticSuperLoggerFieldBase = unsafe.staticFieldBase(superLoggerField); + final long staticSuperLoggerFieldOffset = unsafe.staticFieldOffset(superLoggerField); + unsafe.putObject(staticSuperLoggerFieldBase, staticSuperLoggerFieldOffset, mockLog); // Make call to funtion under test SdvManagerException exception = Assertions.assertThrows(SdvManagerException.class, () -> { @@ -2929,18 +2977,20 @@ void testStartRecordingDeleteHttpClientException() .newInstance(null, recordingRegions, null, null, null, null, httpManager); // Replace LOG - Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); - loggerField.setAccessible(true); - Field loggerSuperField = - sdvHttpRecorderImplClass.getSuperclass().getDeclaredField(logVariableString); - loggerSuperField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - modifiersField.setInt(loggerSuperField, loggerSuperField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvHttpRecorder, mockLog); - loggerSuperField.set(sdvHttpRecorder, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); + + final Field superLoggerField = sdvHttpRecorderImplClass.getSuperclass() + .getDeclaredField(logVariableString); + final Object staticSuperLoggerFieldBase = unsafe.staticFieldBase(superLoggerField); + final long staticSuperLoggerFieldOffset = unsafe.staticFieldOffset(superLoggerField); + unsafe.putObject(staticSuperLoggerFieldBase, staticSuperLoggerFieldOffset, mockLog); // Make call to funtion under test SdvManagerException exception = Assertions.assertThrows(SdvManagerException.class, () -> { @@ -3016,18 +3066,20 @@ void testStartRecordingHttpPostSdcServerError() .newInstance(null, recordingRegions, null, null, null, null, httpManager); // Replace LOG - Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); - loggerField.setAccessible(true); - Field loggerSuperField = - sdvHttpRecorderImplClass.getSuperclass().getDeclaredField(logVariableString); - loggerSuperField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - modifiersField.setInt(loggerSuperField, loggerSuperField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvHttpRecorder, mockLog); - loggerSuperField.set(sdvHttpRecorder, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); + + final Field superLoggerField = sdvHttpRecorderImplClass.getSuperclass() + .getDeclaredField(logVariableString); + final Object staticSuperLoggerFieldBase = unsafe.staticFieldBase(superLoggerField); + final long staticSuperLoggerFieldOffset = unsafe.staticFieldOffset(superLoggerField); + unsafe.putObject(staticSuperLoggerFieldBase, staticSuperLoggerFieldOffset, mockLog); // Make call to funtion under test SdvManagerException exception = Assertions.assertThrows(SdvManagerException.class, () -> { @@ -3100,18 +3152,20 @@ void testStartRecordingPostHttpClientException() .newInstance(null, recordingRegions, null, null, null, null, httpManager); // Replace LOG - Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); - loggerField.setAccessible(true); - Field loggerSuperField = - sdvHttpRecorderImplClass.getSuperclass().getDeclaredField(logVariableString); - loggerSuperField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - modifiersField.setInt(loggerSuperField, loggerSuperField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvHttpRecorder, mockLog); - loggerSuperField.set(sdvHttpRecorder, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); + + final Field superLoggerField = sdvHttpRecorderImplClass.getSuperclass() + .getDeclaredField(logVariableString); + final Object staticSuperLoggerFieldBase = unsafe.staticFieldBase(superLoggerField); + final long staticSuperLoggerFieldOffset = unsafe.staticFieldOffset(superLoggerField); + unsafe.putObject(staticSuperLoggerFieldBase, staticSuperLoggerFieldOffset, mockLog); // Make call to funtion under test SdvManagerException exception = Assertions.assertThrows(SdvManagerException.class, () -> { @@ -3186,18 +3240,20 @@ void testStartRecordingNoSrrIdInResponse() .newInstance(null, recordingRegions, null, null, null, null, httpManager); // Replace LOG - Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); - loggerField.setAccessible(true); - Field loggerSuperField = - sdvHttpRecorderImplClass.getSuperclass().getDeclaredField(logVariableString); - loggerSuperField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - modifiersField.setInt(loggerSuperField, loggerSuperField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvHttpRecorder, mockLog); - loggerSuperField.set(sdvHttpRecorder, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); + + final Field superLoggerField = sdvHttpRecorderImplClass.getSuperclass() + .getDeclaredField(logVariableString); + final Object staticSuperLoggerFieldBase = unsafe.staticFieldBase(superLoggerField); + final long staticSuperLoggerFieldOffset = unsafe.staticFieldOffset(superLoggerField); + unsafe.putObject(staticSuperLoggerFieldBase, staticSuperLoggerFieldOffset, mockLog); // Make call to funtion under test SdvManagerException exception = Assertions.assertThrows(SdvManagerException.class, () -> { @@ -3255,18 +3311,20 @@ void testStartRecordingBadUri() throws IllegalArgumentException, IllegalAccessEx .newInstance(null, recordingRegions, null, null, null, null, httpManager); // Replace LOG - Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); - loggerField.setAccessible(true); - Field loggerSuperField = - sdvHttpRecorderImplClass.getSuperclass().getDeclaredField(logVariableString); - loggerSuperField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - modifiersField.setInt(loggerSuperField, loggerSuperField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvHttpRecorder, mockLog); - loggerSuperField.set(sdvHttpRecorder, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); + + final Field superLoggerField = sdvHttpRecorderImplClass.getSuperclass() + .getDeclaredField(logVariableString); + final Object staticSuperLoggerFieldBase = unsafe.staticFieldBase(superLoggerField); + final long staticSuperLoggerFieldOffset = unsafe.staticFieldOffset(superLoggerField); + unsafe.putObject(staticSuperLoggerFieldBase, staticSuperLoggerFieldOffset, mockLog); // Make call to funtion under test SdvManagerException exception = Assertions.assertThrows(SdvManagerException.class, () -> { @@ -3379,18 +3437,20 @@ void testEndRecordingForMultipleRegionsAndUsers() .newInstance(null, recordingRegions, null, null, null, null, httpManager); // Replace LOG - Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); - loggerField.setAccessible(true); - Field loggerSuperField = - sdvHttpRecorderImplClass.getSuperclass().getDeclaredField(logVariableString); - loggerSuperField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - modifiersField.setInt(loggerSuperField, loggerSuperField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvHttpRecorder, mockLog); - loggerSuperField.set(sdvHttpRecorder, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); + + final Field superLoggerField = sdvHttpRecorderImplClass.getSuperclass() + .getDeclaredField(logVariableString); + final Object staticSuperLoggerFieldBase = unsafe.staticFieldBase(superLoggerField); + final long staticSuperLoggerFieldOffset = unsafe.staticFieldOffset(superLoggerField); + unsafe.putObject(staticSuperLoggerFieldBase, staticSuperLoggerFieldOffset, mockLog); // Make call to funtion under test sdvHttpRecorder.endRecording(); @@ -3464,18 +3524,20 @@ void testEndRecordingDeleteServerError() .newInstance(null, recordingRegions, null, null, null, null, httpManager); // Replace LOG - Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); - loggerField.setAccessible(true); - Field loggerSuperField = - sdvHttpRecorderImplClass.getSuperclass().getDeclaredField(logVariableString); - loggerSuperField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - modifiersField.setInt(loggerSuperField, loggerSuperField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvHttpRecorder, mockLog); - loggerSuperField.set(sdvHttpRecorder, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); + + final Field superLoggerField = sdvHttpRecorderImplClass.getSuperclass() + .getDeclaredField(logVariableString); + final Object staticSuperLoggerFieldBase = unsafe.staticFieldBase(superLoggerField); + final long staticSuperLoggerFieldOffset = unsafe.staticFieldOffset(superLoggerField); + unsafe.putObject(staticSuperLoggerFieldBase, staticSuperLoggerFieldOffset, mockLog); // Make call to funtion under test SdvManagerException exception = Assertions.assertThrows(SdvManagerException.class, () -> { @@ -3554,18 +3616,20 @@ void testEndRecordingDeleteHttpClientException() .newInstance(null, recordingRegions, null, null, null, null, httpManager); // Replace LOG - Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); - loggerField.setAccessible(true); - Field loggerSuperField = - sdvHttpRecorderImplClass.getSuperclass().getDeclaredField(logVariableString); - loggerSuperField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - modifiersField.setInt(loggerSuperField, loggerSuperField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvHttpRecorder, mockLog); - loggerSuperField.set(sdvHttpRecorder, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); + + final Field superLoggerField = sdvHttpRecorderImplClass.getSuperclass() + .getDeclaredField(logVariableString); + final Object staticSuperLoggerFieldBase = unsafe.staticFieldBase(superLoggerField); + final long staticSuperLoggerFieldOffset = unsafe.staticFieldOffset(superLoggerField); + unsafe.putObject(staticSuperLoggerFieldBase, staticSuperLoggerFieldOffset, mockLog); // Make call to funtion under test SdvManagerException exception = Assertions.assertThrows(SdvManagerException.class, () -> { @@ -3632,18 +3696,20 @@ void testEndRecordingBadUri() throws CredentialsException, SdvManagerException, .newInstance(null, recordingRegions, null, null, null, null, httpManager); // Replace LOG - Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); - loggerField.setAccessible(true); - Field loggerSuperField = - sdvHttpRecorderImplClass.getSuperclass().getDeclaredField(logVariableString); - loggerSuperField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - modifiersField.setInt(loggerSuperField, loggerSuperField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvHttpRecorder, mockLog); - loggerSuperField.set(sdvHttpRecorder, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); + + final Field superLoggerField = sdvHttpRecorderImplClass.getSuperclass() + .getDeclaredField(logVariableString); + final Object staticSuperLoggerFieldBase = unsafe.staticFieldBase(superLoggerField); + final long staticSuperLoggerFieldOffset = unsafe.staticFieldOffset(superLoggerField); + unsafe.putObject(staticSuperLoggerFieldBase, staticSuperLoggerFieldOffset, mockLog); // Make call to funtion under test SdvManagerException exception = Assertions.assertThrows(SdvManagerException.class, () -> { @@ -3782,18 +3848,20 @@ void testExportRecordingsForMulitpleRegions() Mockito.eq(regionByaml.getBytes(utfString)), Mockito.any())).thenReturn(null); // Replace LOG - Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); - loggerField.setAccessible(true); - Field loggerSuperField = - sdvHttpRecorderImplClass.getSuperclass().getDeclaredField(logVariableString); - loggerSuperField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - modifiersField.setInt(loggerSuperField, loggerSuperField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvHttpRecorder, mockLog); - loggerSuperField.set(sdvHttpRecorder, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); + + final Field superLoggerField = sdvHttpRecorderImplClass.getSuperclass() + .getDeclaredField(logVariableString); + final Object staticSuperLoggerFieldBase = unsafe.staticFieldBase(superLoggerField); + final long staticSuperLoggerFieldOffset = unsafe.staticFieldOffset(superLoggerField); + unsafe.putObject(staticSuperLoggerFieldBase, staticSuperLoggerFieldOffset, mockLog); sdvHttpRecorder.exportRecordings("bundleB", "TestClassB"); @@ -3854,18 +3922,20 @@ void testExportRecordingsWithBadSrrIdForRecording() .newInstance(null, recordingRegions, artifactManager, null, null, null, null); // Replace LOG - Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); - loggerField.setAccessible(true); - Field loggerSuperField = - sdvHttpRecorderImplClass.getSuperclass().getDeclaredField(logVariableString); - loggerSuperField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - modifiersField.setInt(loggerSuperField, loggerSuperField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvHttpRecorder, mockLog); - loggerSuperField.set(sdvHttpRecorder, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); + + final Field superLoggerField = sdvHttpRecorderImplClass.getSuperclass() + .getDeclaredField(logVariableString); + final Object staticSuperLoggerFieldBase = unsafe.staticFieldBase(superLoggerField); + final long staticSuperLoggerFieldOffset = unsafe.staticFieldOffset(superLoggerField); + unsafe.putObject(staticSuperLoggerFieldBase, staticSuperLoggerFieldOffset, mockLog); files.when(() -> Files.write(Mockito.any(Path.class), Mockito.any(byte[].class), Mockito.any(OpenOption.class))).thenReturn(null); @@ -3940,18 +4010,20 @@ void testExportRecordingsYamlJobErrorCode() Mockito.any(OpenOption.class))).thenReturn(null); // Replace LOG - Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); - loggerField.setAccessible(true); - Field loggerSuperField = - sdvHttpRecorderImplClass.getSuperclass().getDeclaredField(logVariableString); - loggerSuperField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - modifiersField.setInt(loggerSuperField, loggerSuperField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvHttpRecorder, mockLog); - loggerSuperField.set(sdvHttpRecorder, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); + + final Field superLoggerField = sdvHttpRecorderImplClass.getSuperclass() + .getDeclaredField(logVariableString); + final Object staticSuperLoggerFieldBase = unsafe.staticFieldBase(superLoggerField); + final long staticSuperLoggerFieldOffset = unsafe.staticFieldOffset(superLoggerField); + unsafe.putObject(staticSuperLoggerFieldBase, staticSuperLoggerFieldOffset, mockLog); // Make call to funtion under test SdvManagerException exception = Assertions.assertThrows(SdvManagerException.class, () -> { @@ -4018,18 +4090,20 @@ void testExportRecordingsArtifactFindException() throws CredentialsException, Mockito.any(OpenOption.class))).thenReturn(null); // Replace LOG - Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); - loggerField.setAccessible(true); - Field loggerSuperField = - sdvHttpRecorderImplClass.getSuperclass().getDeclaredField(logVariableString); - loggerSuperField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - modifiersField.setInt(loggerSuperField, loggerSuperField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvHttpRecorder, mockLog); - loggerSuperField.set(sdvHttpRecorder, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); + + final Field superLoggerField = sdvHttpRecorderImplClass.getSuperclass() + .getDeclaredField(logVariableString); + final Object staticSuperLoggerFieldBase = unsafe.staticFieldBase(superLoggerField); + final long staticSuperLoggerFieldOffset = unsafe.staticFieldOffset(superLoggerField); + unsafe.putObject(staticSuperLoggerFieldBase, staticSuperLoggerFieldOffset, mockLog); // Make call to funtion under test SdvManagerException exception = Assertions.assertThrows(SdvManagerException.class, () -> { @@ -4128,18 +4202,20 @@ void testExportRecordingsUnableToSaveYamlFile() throws CredentialsException, .thenThrow(new IOException("path not there")); // Replace LOG - Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); - loggerField.setAccessible(true); - Field loggerSuperField = - sdvHttpRecorderImplClass.getSuperclass().getDeclaredField(logVariableString); - loggerSuperField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - modifiersField.setInt(loggerSuperField, loggerSuperField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvHttpRecorder, mockLog); - loggerSuperField.set(sdvHttpRecorder, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvHttpRecorderImplClass.getDeclaredField(logVariableString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); + + final Field superLoggerField = sdvHttpRecorderImplClass.getSuperclass() + .getDeclaredField(logVariableString); + final Object staticSuperLoggerFieldBase = unsafe.staticFieldBase(superLoggerField); + final long staticSuperLoggerFieldOffset = unsafe.staticFieldOffset(superLoggerField); + unsafe.putObject(staticSuperLoggerFieldBase, staticSuperLoggerFieldOffset, mockLog); // Make call to funtion under test SdvManagerException exception = Assertions.assertThrows(SdvManagerException.class, () -> { diff --git a/galasa-managers-parent/galasa-managers-testingtools-parent/dev.galasa.sdv.manager/src/test/java/dev/galasa/sdv/internal/TestSdvManagerImpl.java b/galasa-managers-parent/galasa-managers-testingtools-parent/dev.galasa.sdv.manager/src/test/java/dev/galasa/sdv/internal/TestSdvManagerImpl.java index 2e2f11bf8..7b5d3c103 100644 --- a/galasa-managers-parent/galasa-managers-testingtools-parent/dev.galasa.sdv.manager/src/test/java/dev/galasa/sdv/internal/TestSdvManagerImpl.java +++ b/galasa-managers-parent/galasa-managers-testingtools-parent/dev.galasa.sdv.manager/src/test/java/dev/galasa/sdv/internal/TestSdvManagerImpl.java @@ -38,7 +38,6 @@ import dev.galasa.zosbatch.IZosBatchJob; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -51,6 +50,7 @@ import org.junit.jupiter.api.Test; import org.mockito.MockedStatic; import org.mockito.Mockito; +import sun.misc.Unsafe; class TestSdvManagerImpl { @@ -93,7 +93,7 @@ class TestSdvManagerImpl { private String frameworkString = "framework"; private String sdvRecorderVarName = "sdvRecorder"; private String logString = "LOG"; - private String modifiersString = "modifiers"; + private String theUnsafeString = "theUnsafe"; private String regionaApplid = "APPL1"; private String runName = "RUN123"; private String regionbApplid = "APPL2"; @@ -764,13 +764,14 @@ void testProvisionGenerateOldCicsVersionForRegionA() sdvUsersToRecordList.set(sdvManager, listOfUsersForAllRegions); // Replace LOG - Field loggerField = sdvManagerImplClass.getDeclaredField(logString); - loggerField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvManager, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvManagerImplClass.getDeclaredField(logString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); // Make call to funtion under test sdvManager.provisionGenerate(); @@ -912,13 +913,14 @@ void testProvisionGenerateNoSecMsg() throws ClassNotFoundException, Instantiatio sdvUsersToRecordList.set(sdvManager, listOfUsersForAllRegions); // Replace LOG - Field loggerField = sdvManagerImplClass.getDeclaredField(logString); - loggerField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvManager, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvManagerImplClass.getDeclaredField(logString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); // Make call to funtion under test sdvManager.provisionGenerate(); @@ -1057,13 +1059,14 @@ void testProvisionGenerateNoUsersForRegion() sdvUsersToRecordList.set(sdvManager, listOfUsersForAllRegions); // Replace LOG - Field loggerField = sdvManagerImplClass.getDeclaredField(logString); - loggerField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvManager, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvManagerImplClass.getDeclaredField(logString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); // Make call to funtion under test sdvManager.provisionGenerate(); @@ -1422,13 +1425,14 @@ void testProvisionStopEndRecordingException() throws InstantiationException, frameworkField.set(sdvManager, framework); // Replace LOG - Field loggerField = sdvManagerImplClass.getDeclaredField(logString); - loggerField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvManager, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvManagerImplClass.getDeclaredField(logString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); // Make call to funtion under test sdvManager.provisionStop(); @@ -1539,13 +1543,14 @@ void testProvisionStopReleaseUsersException() throws InstantiationException, frameworkField.set(sdvManager, framework); // Replace LOG - Field loggerField = sdvManagerImplClass.getDeclaredField(logString); - loggerField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvManager, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvManagerImplClass.getDeclaredField(logString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); // Make call to funtion under test sdvManager.provisionStop(); @@ -1656,13 +1661,14 @@ void testProvisionStopcleanUpEnvironmentsException() throws InstantiationExcepti frameworkField.set(sdvManager, framework); // Replace LOG - Field loggerField = sdvManagerImplClass.getDeclaredField(logString); - loggerField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvManager, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvManagerImplClass.getDeclaredField(logString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); // Make call to funtion under test sdvManager.provisionStop(); @@ -1896,13 +1902,14 @@ void testReleaseUsersException() throws CredentialsException, NoSuchFieldExcepti frameworkField.set(sdvManager, framework); // Replace LOG - Field loggerField = sdvManagerImplClass.getDeclaredField(logString); - loggerField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvManager, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvManagerImplClass.getDeclaredField(logString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); // Make call to funtion under test sdvManager.provisionStop(); diff --git a/galasa-managers-parent/galasa-managers-testingtools-parent/dev.galasa.sdv.manager/src/test/java/dev/galasa/sdv/internal/TestSdvManagersResourceMonitor.java b/galasa-managers-parent/galasa-managers-testingtools-parent/dev.galasa.sdv.manager/src/test/java/dev/galasa/sdv/internal/TestSdvManagersResourceMonitor.java index e4d441276..63cb2c0f8 100644 --- a/galasa-managers-parent/galasa-managers-testingtools-parent/dev.galasa.sdv.manager/src/test/java/dev/galasa/sdv/internal/TestSdvManagersResourceMonitor.java +++ b/galasa-managers-parent/galasa-managers-testingtools-parent/dev.galasa.sdv.manager/src/test/java/dev/galasa/sdv/internal/TestSdvManagersResourceMonitor.java @@ -14,7 +14,6 @@ import dev.galasa.framework.spi.IResourceManagement; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Modifier; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -23,6 +22,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mockito; +import sun.misc.Unsafe; class TestSdvManagersResourceMonitor { @@ -31,7 +31,7 @@ class TestSdvManagersResourceMonitor { private String sdvManagersResourceMonitorClassString = "dev.galasa.sdv.internal.SdvManagersResourceMonitor"; private String logString = "LOG"; - private String modifiersString = "modifiers"; + private String theUnsafeString = "theUnsafe"; private String runOneString = "RUN1"; private String runTwoString = "RUN2"; @@ -85,13 +85,14 @@ void testRunWithNoActiveRunsOrDssEntries() .newInstance(framework, resMan, dssService); // Replace LOG - Field loggerField = sdvManagersResourceMonitorClass.getDeclaredField(logString); - loggerField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvManagersResourceMonitor, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvManagersResourceMonitorClass.getDeclaredField(logString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); // Make call to funtion under test sdvManagersResourceMonitor.run(); @@ -140,13 +141,14 @@ void testRunWithActiveRunsMatchingDssEntries() .newInstance(framework, resMan, dssService); // Replace LOG - Field loggerField = sdvManagersResourceMonitorClass.getDeclaredField(logString); - loggerField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvManagersResourceMonitor, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvManagersResourceMonitorClass.getDeclaredField(logString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); // Make call to funtion under test sdvManagersResourceMonitor.run(); @@ -183,13 +185,14 @@ void testRunException() .newInstance(framework, resMan, dssService); // Replace LOG - Field loggerField = sdvManagersResourceMonitorClass.getDeclaredField(logString); - loggerField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvManagersResourceMonitor, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvManagersResourceMonitorClass.getDeclaredField(logString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); // Make call to funtion under test sdvManagersResourceMonitor.run(); @@ -245,13 +248,14 @@ void testRunWithDssEntryNotInActiveRunsButNotLastManagerOnRegion() .newInstance(framework, resMan, dssService); // Replace LOG - Field loggerField = sdvManagersResourceMonitorClass.getDeclaredField(logString); - loggerField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvManagersResourceMonitor, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvManagersResourceMonitorClass.getDeclaredField(logString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); // Make call to funtion under test sdvManagersResourceMonitor.run(); @@ -299,13 +303,14 @@ void testRunWithDssEntryNotInActiveRunsButIsLastManagerOnRegion() .newInstance(framework, resMan, dssService); // Replace LOG - Field loggerField = sdvManagersResourceMonitorClass.getDeclaredField(logString); - loggerField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvManagersResourceMonitor, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvManagersResourceMonitorClass.getDeclaredField(logString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); // Make call to funtion under test sdvManagersResourceMonitor.run(); @@ -348,13 +353,14 @@ void testrunFinishedOrDeletedIsLastManagerOnRegion() .newInstance(framework, resMan, dssService); // Replace LOG - Field loggerField = sdvManagersResourceMonitorClass.getDeclaredField(logString); - loggerField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvManagersResourceMonitor, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvManagersResourceMonitorClass.getDeclaredField(logString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); // Make call to funtion under test sdvManagersResourceMonitor.runFinishedOrDeleted(runOneString); @@ -394,13 +400,14 @@ void testrunFinishedOrDeletedNotLastManagerOnRegion() .newInstance(framework, resMan, dssService); // Replace LOG - Field loggerField = sdvManagersResourceMonitorClass.getDeclaredField(logString); - loggerField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvManagersResourceMonitor, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvManagersResourceMonitorClass.getDeclaredField(logString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); // Make call to funtion under test sdvManagersResourceMonitor.runFinishedOrDeleted(runThreeString); @@ -437,13 +444,14 @@ void testrunFinishedOrDeletedException() .newInstance(framework, resMan, dssService); // Replace LOG - Field loggerField = sdvManagersResourceMonitorClass.getDeclaredField(logString); - loggerField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvManagersResourceMonitor, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvManagersResourceMonitorClass.getDeclaredField(logString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); // Make call to funtion under test sdvManagersResourceMonitor.runFinishedOrDeleted(runOneString); diff --git a/galasa-managers-parent/galasa-managers-testingtools-parent/dev.galasa.sdv.manager/src/test/java/dev/galasa/sdv/internal/TestSdvUserPool.java b/galasa-managers-parent/galasa-managers-testingtools-parent/dev.galasa.sdv.manager/src/test/java/dev/galasa/sdv/internal/TestSdvUserPool.java index d31a8a923..1c7c228e5 100644 --- a/galasa-managers-parent/galasa-managers-testingtools-parent/dev.galasa.sdv.manager/src/test/java/dev/galasa/sdv/internal/TestSdvUserPool.java +++ b/galasa-managers-parent/galasa-managers-testingtools-parent/dev.galasa.sdv.manager/src/test/java/dev/galasa/sdv/internal/TestSdvUserPool.java @@ -20,7 +20,6 @@ import dev.galasa.zos.IZosImage; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.List; import org.apache.commons.logging.Log; @@ -30,6 +29,7 @@ import org.junit.jupiter.api.Test; import org.mockito.MockedStatic; import org.mockito.Mockito; +import sun.misc.Unsafe; class TestSdvUserPool { @@ -115,13 +115,14 @@ void testAllocateUser() throws SdvManagerException, ResourceUnavailableException frameworkField.set(sdvUserPool, framework); // Replace LOG - Field loggerField = sdvUserPoolClass.getDeclaredField("LOG"); - loggerField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvUserPool, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe"); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvUserPoolClass.getDeclaredField("LOG"); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); // Make call to funtion under test String userCred = sdvUserPool.allocateUser(roleName, mockCicsaRegion); diff --git a/galasa-managers-parent/galasa-managers-testingtools-parent/dev.galasa.sdv.manager/src/test/java/dev/galasa/sdv/internal/TestSdvUserResourceMonitor.java b/galasa-managers-parent/galasa-managers-testingtools-parent/dev.galasa.sdv.manager/src/test/java/dev/galasa/sdv/internal/TestSdvUserResourceMonitor.java index 991dc141b..328823c27 100644 --- a/galasa-managers-parent/galasa-managers-testingtools-parent/dev.galasa.sdv.manager/src/test/java/dev/galasa/sdv/internal/TestSdvUserResourceMonitor.java +++ b/galasa-managers-parent/galasa-managers-testingtools-parent/dev.galasa.sdv.manager/src/test/java/dev/galasa/sdv/internal/TestSdvUserResourceMonitor.java @@ -15,7 +15,6 @@ import dev.galasa.framework.spi.IResourceManagement; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Modifier; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -27,6 +26,7 @@ import org.junit.jupiter.api.Test; import org.mockito.MockedStatic; import org.mockito.Mockito; +import sun.misc.Unsafe; class TestSdvUserResourceMonitor { @@ -37,7 +37,7 @@ class TestSdvUserResourceMonitor { private String sdvUserResourceMonitorClassString = "dev.galasa.sdv.internal.SdvUserResourceMonitor"; private String logString = "LOG"; - private String modifiersString = "modifiers"; + private String theUnsafeString = "theUnsafe"; private String dssEntryUser1RegionA = "sdvuser.APPL1.USER1"; private String dssEntryUser2RegionA = "sdvuser.APPL1.USER2"; @@ -100,13 +100,14 @@ void testRunWithNoActiveRunsOrDssEntries() .newInstance(framework, resMan, dssService); // Replace LOG - Field loggerField = sdvUserResourceMonitorClass.getDeclaredField(logString); - loggerField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvUserResourceMonitorClass, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvUserResourceMonitorClass.getDeclaredField(logString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); // Make call to funtion under test sdvUserResourceMonitor.run(); @@ -154,13 +155,14 @@ void testRunWithActiveRunsMatchingDssEntries() .newInstance(framework, resMan, dssService); // Replace LOG - Field loggerField = sdvUserResourceMonitorClass.getDeclaredField(logString); - loggerField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvUserResourceMonitorClass, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvUserResourceMonitorClass.getDeclaredField(logString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); // Make call to funtion under test sdvUserResourceMonitor.run(); @@ -206,13 +208,14 @@ void testRunWithDssEntriesNotInActiveRuns() throws FrameworkException, ClassNotF .newInstance(framework, resMan, dssService); // Replace LOG - Field loggerField = sdvUserResourceMonitorClass.getDeclaredField(logString); - loggerField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvUserResourceMonitorClass, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvUserResourceMonitorClass.getDeclaredField(logString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); // Make call to funtion under test sdvUserResourceMonitor.run(); @@ -261,13 +264,14 @@ void testRunException() throws FrameworkException, ClassNotFoundException, NoSuc .newInstance(framework, resMan, dssService); // Replace LOG - Field loggerField = sdvUserResourceMonitorClass.getDeclaredField(logString); - loggerField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvUserResourceMonitorClass, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvUserResourceMonitorClass.getDeclaredField(logString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); // Make call to funtion under test sdvUserResourceMonitor.run(); @@ -311,13 +315,14 @@ void testrunFinishedOrDeleted() throws FrameworkException, ClassNotFoundExceptio .newInstance(framework, resMan, dssService); // Replace LOG - Field loggerField = sdvUserResourceMonitorClass.getDeclaredField(logString); - loggerField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvUserResourceMonitorClass, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvUserResourceMonitorClass.getDeclaredField(logString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); // Make call to funtion under test sdvUserResourceMonitor.runFinishedOrDeleted(runThreeString); @@ -359,13 +364,14 @@ void testrunFinishedOrDeletedException() throws FrameworkException, ClassNotFoun .newInstance(framework, resMan, dssService); // Replace LOG - Field loggerField = sdvUserResourceMonitorClass.getDeclaredField(logString); - loggerField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvUserResourceMonitorClass, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvUserResourceMonitorClass.getDeclaredField(logString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); // Make call to funtion under test sdvUserResourceMonitor.runFinishedOrDeleted(runThreeString); @@ -410,13 +416,14 @@ void testrunFinishedOrDeletedDssDeleteException() .newInstance(framework, resMan, dssService); // Replace LOG - Field loggerField = sdvUserResourceMonitorClass.getDeclaredField(logString); - loggerField.setAccessible(true); - // remove final modifier - Field modifiersField = Field.class.getDeclaredField(modifiersString); - modifiersField.setAccessible(true); - modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL); - loggerField.set(sdvUserResourceMonitorClass, mockLog); + final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString); + unsafeField.setAccessible(true); + final Unsafe unsafe = (Unsafe) unsafeField.get(null); + + final Field loggerField = sdvUserResourceMonitorClass.getDeclaredField(logString); + final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField); + final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField); + unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog); sdvUserPoolStatic.when(() -> SdvUserPool.deleteDss(Mockito.eq(user1String), Mockito.any(), Mockito.eq(runThreeString), Mockito.any()))