Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import java.time.Duration;
import java.util.concurrent.TimeUnit;

import com.hazelcast.client.impl.clientside.ClientDynamicClusterConfig;
import com.hazelcast.config.Config;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.map.IMap;
import com.hazelcast.spi.properties.ClusterProperty;
Expand All @@ -36,15 +38,18 @@ public HazelcastConnector(HazelcastInstance hazelcastInstance) {

private static void shutdownHookWarning(
HazelcastInstance hazelcastInstance) {
HazelcastProperties properties = new HazelcastProperties(
hazelcastInstance.getConfig().getProperties());
if (properties.getBoolean(ClusterProperty.SHUTDOWNHOOK_ENABLED)) {
getLogger()
.warn("""
Hazelcast shutdown hook is enabled. This is not recommended for production use because Hazelcast instance \
might be stopped before KubernetesKit can propagate the latest session state to the cluster. \
Please disable the shutdown hook by setting the `hazelcast.shutdownhook.enabled` property to `false`.
""");
Config config = hazelcastInstance.getConfig();
if (!(config instanceof ClientDynamicClusterConfig)) {
HazelcastProperties properties = new HazelcastProperties(
config.getProperties());
if (properties.getBoolean(ClusterProperty.SHUTDOWNHOOK_ENABLED)) {
getLogger()
.warn("""
Hazelcast shutdown hook is enabled. This is not recommended for production use because Hazelcast instance \
might be stopped before KubernetesKit can propagate the latest session state to the cluster. \
Please disable the shutdown hook by setting the `hazelcast.shutdownhook.enabled` property to `false`.
""");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
import java.util.UUID;
import java.util.concurrent.TimeUnit;

import com.hazelcast.client.HazelcastClient;
import com.hazelcast.client.config.ClientConfig;
import com.hazelcast.config.Config;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.map.IMap;
import com.hazelcast.spi.properties.ClusterProperty;
import com.hazelcast.spi.properties.HazelcastProperty;
import org.junit.Assert;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -19,8 +20,10 @@
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand All @@ -36,9 +39,11 @@ void setUp() {

sessionMap = mock(IMap.class);

// disable shutdown hook to prevent logs from being flooded with warning messages
// disable shutdown hook to prevent logs from being flooded with warning
// messages
Config hazelcastConfig = new Config();
hazelcastConfig.getProperties().setProperty(ClusterProperty.SHUTDOWNHOOK_ENABLED.getName(), "false");
hazelcastConfig.getProperties().setProperty(
ClusterProperty.SHUTDOWNHOOK_ENABLED.getName(), "false");

hazelcastInstance = mock(HazelcastInstance.class);
when(hazelcastInstance.getConfig()).thenReturn(hazelcastConfig);
Expand All @@ -48,6 +53,20 @@ void setUp() {
connector = new HazelcastConnector(hazelcastInstance);
}

@Test
void constructor_hazelcastClient_shutdownHookWarningDoesNotThrow() {
ClientConfig config = new ClientConfig();
config.getConnectionStrategyConfig().setAsyncStart(true);
HazelcastInstance instance = spy(
HazelcastClient.newHazelcastClient(config));
doAnswer(i -> mock(IMap.class)).when(instance).getMap(anyString());
try {
new HazelcastConnector(instance);
} finally {
instance.shutdown();
}
}

@Test
void sendSession_sessionIsAdded() {
SessionInfo sessionInfo = new SessionInfo(clusterKey,
Expand Down