Skip to content

Commit

Permalink
Replace NodeEngineImpl mocks with mocks of parent NodeEngine inte…
Browse files Browse the repository at this point in the history
…rface where possible (#1156)

[Several tests are
failing](https://hazelcast.atlassian.net/browse/HZ-2245) only on Azul
Prime JDKs due to an incompatibility between it and Mockito.

In https://github.com/hazelcast/hazelcast-mono/pull/845 it was
discovered that a causal factor was mocking classes, not interfaces.

As such, where possible, `NodeEngineImpl` mocks should be replaced with
mocks of parent `NodeEngine` interface.

This does not target a particular test failure and is a cleanup to
prevent occuring in future.

GitOrigin-RevId: 44be1563736dbffba8400b356f18181c8012f546
  • Loading branch information
JackPGreen authored and actions-user committed Mar 26, 2024
1 parent 38f762f commit 9f6645d
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import com.hazelcast.internal.util.AddressUtil;
import com.hazelcast.logging.LoggingService;
import com.hazelcast.nio.MemberSocketInterceptor;
import com.hazelcast.spi.impl.NodeEngineImpl;
import com.hazelcast.spi.impl.NodeEngine;
import com.hazelcast.spi.impl.eventservice.EventService;
import com.hazelcast.spi.impl.executionservice.ExecutionService;
import com.hazelcast.spi.properties.ClusterProperty;
Expand All @@ -66,11 +66,11 @@
public class TcpServerContext implements ServerContext {

private final Node node;
private final NodeEngineImpl nodeEngine;
private final NodeEngine nodeEngine;
private final RestApiConfig restApiConfig;
private final MemcacheProtocolConfig memcacheProtocolConfig;

public TcpServerContext(Node node, NodeEngineImpl nodeEngine) {
public TcpServerContext(Node node, NodeEngine nodeEngine) {
this.node = node;
this.nodeEngine = nodeEngine;
this.restApiConfig = initRestApiConfig(node.getConfig());
Expand Down Expand Up @@ -140,6 +140,7 @@ public Map<EndpointQualifier, Address> getThisAddresses() {
public void onFatalError(Exception e) {
String hzName = nodeEngine.getHazelcastInstance().getName();
Thread thread = new Thread(createThreadName(hzName, "io.error.shutdown")) {
@Override
public void run() {
node.shutdown(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import com.hazelcast.jet.impl.util.ProgressTracker;
import com.hazelcast.jet.impl.util.Util;
import com.hazelcast.logging.ILogger;
import com.hazelcast.spi.impl.NodeEngineImpl;
import com.hazelcast.spi.impl.NodeEngine;
import com.hazelcast.spi.impl.executionservice.ExecutionService;
import com.hazelcast.spi.properties.HazelcastProperties;
import com.hazelcast.spi.properties.HazelcastProperty;
Expand Down Expand Up @@ -94,7 +94,7 @@ public class TaskletExecutionService {
private final IdleStrategy idlerCooperative;
private final IdleStrategy idlerNonCooperative;

public TaskletExecutionService(NodeEngineImpl nodeEngine, int threadCount, HazelcastProperties properties) {
public TaskletExecutionService(NodeEngine nodeEngine, int threadCount, HazelcastProperties properties) {
hzExecutionService = nodeEngine.getExecutionService();
hzExecutionService.register(TASKLET_INIT_CLOSE_EXECUTOR_NAME,
RuntimeAvailableProcessors.get(), Integer.MAX_VALUE, CACHED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.hazelcast.config.Config;
import com.hazelcast.config.NetworkConfig;
import com.hazelcast.instance.impl.Node;
import com.hazelcast.spi.impl.NodeEngineImpl;
import com.hazelcast.spi.impl.NodeEngine;
import com.hazelcast.spi.properties.HazelcastProperties;
import com.hazelcast.test.HazelcastParallelClassRunner;
import com.hazelcast.test.HazelcastTestSupport;
Expand Down Expand Up @@ -48,7 +48,7 @@ public class TcpServerContextTest extends HazelcastTestSupport {
@Before
public void setUp() {
Node mockNode = mock(Node.class);
NodeEngineImpl mockNodeEngine = mock(NodeEngineImpl.class);
NodeEngine mockNodeEngine = mock(NodeEngine.class);
Config config = new Config();
HazelcastProperties properties = new HazelcastProperties(config);
networkConfig = config.getNetworkConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import com.hazelcast.spi.impl.operationservice.BackupAwareOperation;
import com.hazelcast.spi.impl.operationservice.Operation;
import com.hazelcast.internal.services.RemoteService;
import com.hazelcast.spi.impl.NodeEngineImpl;
import com.hazelcast.spi.impl.NodeEngine;
import com.hazelcast.test.HazelcastParallelClassRunner;
import com.hazelcast.test.HazelcastTestSupport;
import com.hazelcast.test.annotation.ParallelJVMTest;
Expand All @@ -50,7 +50,7 @@
@Category({QuickTest.class, ParallelJVMTest.class})
public class CollectionTxnUtilTest extends HazelcastTestSupport {

private NodeEngineImpl nodeEngine = mock(NodeEngineImpl.class);
private NodeEngine nodeEngine = mock(NodeEngine.class);

private RemoteService remoteService = mock(RemoteService.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import com.hazelcast.logging.ILogger;
import com.hazelcast.logging.Logger;
import com.hazelcast.logging.LoggingService;
import com.hazelcast.spi.impl.NodeEngineImpl;
import com.hazelcast.spi.impl.NodeEngine;
import com.hazelcast.spi.impl.executionservice.ExecutionService;
import com.hazelcast.spi.properties.HazelcastProperties;
import com.hazelcast.test.HazelcastParallelClassRunner;
Expand Down Expand Up @@ -85,7 +85,7 @@ public class TaskletExecutionServiceTest extends JetTestSupport {
@Before
public void before() {
executor = Executors.newCachedThreadPool();
NodeEngineImpl neMock = mock(NodeEngineImpl.class);
NodeEngine neMock = mock(NodeEngine.class);

HazelcastInstance hzMock = mock(HazelcastInstance.class);
when(neMock.getHazelcastInstance()).thenReturn(hzMock);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.hazelcast.instance.impl.Node;
import com.hazelcast.internal.cluster.impl.ClusterServiceImpl;
import com.hazelcast.internal.partition.InternalPartitionService;
import com.hazelcast.spi.impl.NodeEngineImpl;
import com.hazelcast.spi.impl.NodeEngine;
import org.mockito.invocation.InvocationOnMock;

import static com.hazelcast.test.starter.HazelcastProxyFactory.proxyArgumentsIfNeeded;
Expand Down Expand Up @@ -53,7 +53,7 @@ Object answer(InvocationOnMock invocation, String methodName, Object[] arguments
return mock(InternalPartitionService.class, new PartitionServiceAnswer(partitionService));
} else if (arguments.length == 0 && methodName.equals("getNodeEngine")) {
Object nodeEngine = invokeForMock(invocation);
return mock(NodeEngineImpl.class, new NodeEngineAnswer(nodeEngine));
return mock(NodeEngine.class, new NodeEngineAnswer(nodeEngine));
} else if (arguments.length == 1 && methodName.equals("getConnectionManager")) {
arguments = proxyArgumentsIfNeeded(arguments, delegateClassloader);
Object endpointManager = invokeForMock(invocation, arguments);
Expand Down

0 comments on commit 9f6645d

Please sign in to comment.