Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/service-registration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ jobs:
BuildAndTest:
runs-on: ubuntu-latest
timeout-minutes: 35
strategy:
fail-fast: false
matrix:
javaVersion: ['17', '25']

steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- uses: ./.github/actions/setup
with:
jdkVersion: ${{ matrix.javaVersion }}

- name: Install BATS to test the shell scripts
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.AppenderBase;

import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Predicate;

Expand All @@ -31,7 +31,7 @@ public TestLogger() {
listening = lastInstance.get().listening;
records = lastInstance.get().records;
} else {
records = new LinkedList<>();
records = new CopyOnWriteArrayList<>();
}
lastInstance.set(this);
}
Expand Down
3 changes: 3 additions & 0 deletions codequality/checkstyle/suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
<suppress checks="MethodName"
files=".*security-module.*"
/>
<suppress checks="IllegalImport"
files=".*RefreshablePeerEurekaNodesTest\.java"
/>
</suppressions>
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@
import org.zowe.apiml.discovery.config.EurekaConfig;
import org.zowe.apiml.discovery.metadata.MetadataFilterService;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.*;
Expand All @@ -49,6 +51,19 @@
@ExtendWith(MockitoExtension.class)
class ApimlInstanceRegistryTest {

/** Call counter for the test MethodHandle stub — replaces mock(MethodHandle.class) verify. */
static final AtomicInteger REPLICATE_CALL_COUNT = new AtomicInteger(0);

/**
* No-op stub for replicateToPeers that records invocations.
* Used to create a real MethodHandle via {@code MethodHandles.lookup().findStatic()}
* instead of {@code mock(MethodHandle.class)} which fails on Java 25 where MethodHandle is sealed.
*/
static Object replicateToPeersTestStub(Object... args) {

Check warning on line 62 in discovery-service/src/test/java/org/zowe/apiml/discovery/ApimlInstanceRegistryTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused method parameter "args".

See more on https://sonarcloud.io/project/issues?id=zowe_api-layer&issues=AZ7aPexpCtsnrywdCEXS&open=AZ7aPexpCtsnrywdCEXS&pullRequest=4728
REPLICATE_CALL_COUNT.incrementAndGet();
return null;
}

private ApimlInstanceRegistry apimlInstanceRegistry;

@Mock private EurekaClientConfig clientConfig;
Expand Down Expand Up @@ -244,7 +259,9 @@
@Test
@SuppressWarnings("unchecked")
void givenStaticRegistration_thenSuccessful() throws Throwable {
var methodHandle = mock(MethodHandle.class);
var methodHandle = MethodHandles.lookup().findStatic(
ApimlInstanceRegistryTest.class, "replicateToPeersTestStub",
MethodType.methodType(Object.class, Object[].class));
ReflectionTestUtils.setField(apimlInstanceRegistry, "replicateToPeersMethodHandle", methodHandle);
var currentStaticIds = (Set<String>) ReflectionTestUtils.getField(apimlInstanceRegistry, "staticRegistrationIds");
assertTrue(currentStaticIds.isEmpty());
Expand All @@ -254,7 +271,6 @@

Map<String, Lease<InstanceInfo>> leaseMap = new HashMap<>();
when(registry.get(anyString())).thenReturn(leaseMap);
doReturn(new Object()).when(methodHandle).invokeWithArguments(any(), any(), any(), any(), any(), any(), any());

apimlInstanceRegistry.registerStatically(standardInstance, false, true);

Expand Down Expand Up @@ -307,13 +323,15 @@

@Test
void givenPeerReplicaHeartbeat_thenSuccess() throws Throwable {
var methodHandle = mock(MethodHandle.class);
REPLICATE_CALL_COUNT.set(0);
var methodHandle = MethodHandles.lookup().findStatic(
ApimlInstanceRegistryTest.class, "replicateToPeersTestStub",
MethodType.methodType(Object.class, Object[].class));
ReflectionTestUtils.setField(apimlInstanceRegistry, "replicateToPeersMethodHandle", methodHandle);
var instance = mock(InstanceInfo.class);
doReturn(new Object()).when(methodHandle).invokeWithArguments(any(), any(), any(), any(), any(), any(), any());
apimlInstanceRegistry.peerAwareHeartbeat(instance);

verify(methodHandle, times(1)).invokeWithArguments(any(), any(), any(), any(), any(), any(), any());
assertEquals(1, REPLICATE_CALL_COUNT.get());
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@
import org.zowe.apiml.product.eureka.client.ApimlPeerEurekaNode;

import javax.net.ssl.SSLContext;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HashSet;
Expand All @@ -43,6 +40,8 @@
import java.util.concurrent.Executors;
import java.util.stream.Stream;

import sun.misc.Unsafe;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.when;
Expand All @@ -52,16 +51,6 @@
class RefreshablePeerEurekaNodesTest {

private static final int DEFAULT_MAX_RETRIES = 10;
private static final VarHandle MODIFIERS;

static {
try {
var lookup = MethodHandles.privateLookupIn(Field.class, MethodHandles.lookup());
MODIFIERS = lookup.findVarHandle(Field.class, "modifiers", int.class);
} catch (IllegalAccessException | NoSuchFieldException ex) {
throw new RuntimeException(ex);
}
}

PeerAwareInstanceRegistry registry;
@Mock
Expand Down Expand Up @@ -95,10 +84,13 @@ void givenEurekaNodeUrl_thenCreateNode() throws NoSuchFieldException, SecurityEx
when(serverConfig.getPeerNodeTotalConnections()).thenReturn(100);
when(serverConfig.getPeerNodeTotalConnectionsPerHost()).thenReturn(10);

Field defaultExecutor = StatsMonitor.class.getDeclaredField("DEFAULT_EXECUTOR");
MODIFIERS.set(defaultExecutor, defaultExecutor.getModifiers() & ~Modifier.FINAL);
defaultExecutor.setAccessible(true);
defaultExecutor.set(null, Executors.newSingleThreadScheduledExecutor());
Field defaultExecutorField = StatsMonitor.class.getDeclaredField("DEFAULT_EXECUTOR");
Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe");
unsafeField.setAccessible(true);
Unsafe unsafe = (Unsafe) unsafeField.get(null);
long offset = unsafe.staticFieldOffset(defaultExecutorField);
Object base = unsafe.staticFieldBase(defaultExecutorField);
unsafe.putObject(base, offset, Executors.newSingleThreadScheduledExecutor());

PeerEurekaNode node = eurekaNodes.createPeerEurekaNode("https://localhost:10013/");
assertInstanceOf(ApimlPeerEurekaNode.class, node);
Expand Down
4 changes: 1 addition & 3 deletions gradle/versions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ dependencyResolutionManagement {
version('micronautPlugin', '4.6.2')
version('shadow', '9.4.2')
version('checkstyle', '10.17.0')
version('jacoco', '0.8.11')
version('jacoco', '0.8.14')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not go to 0.8.15 latest compatible instead of minimum compatible?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because originally I was trying to limit changes to minimum necessary. Otherwise the scope tends to grow quickly and the issues are rather hard to find.

Added the update now.

version('gradle', '9.0')
version('commonsCompress', '1.28.0')
version('bucket4j', '8.19.0')
Expand Down Expand Up @@ -299,12 +299,10 @@ dependencyResolutionManagement {
// Pure Java dependencies - do not use in Spring unless really necessary
version('logback', '1.5.34')
version('mockitoCore', '5.23.0')
version('mockitoInline', '5.2.0')
version('mockServer','5.15.0')

library('logback_classic', 'ch.qos.logback', 'logback-classic').versionRef('logback')
library('mockito_core', 'org.mockito', 'mockito-core').versionRef('mockitoCore')
library('mockito_inline', 'org.mockito', 'mockito-inline').versionRef('mockitoInline')
library('mockito_junit_jupiter', 'org.mockito', 'mockito-junit-jupiter').versionRef('mockitoCore')
library('mock_server','org.mock-server','mockserver-netty').versionRef('mockServer')

Expand Down
1 change: 0 additions & 1 deletion zaas-service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ dependencies {

testImplementation libs.awaitility
testImplementation libs.mockito.core
testImplementation libs.mockito.inline
testImplementation libs.spring.mock.mvc
testImplementation libs.spring.boot.starter.test
testImplementation libs.rest.assured
Expand Down
Loading