diff --git a/aerospike-storage-backend/src/main/java/com/playtika/janusgraph/aerospike/AerospikePolicyProvider.java b/aerospike-storage-backend/src/main/java/com/playtika/janusgraph/aerospike/AerospikePolicyProvider.java index d67f427..be7ee13 100644 --- a/aerospike-storage-backend/src/main/java/com/playtika/janusgraph/aerospike/AerospikePolicyProvider.java +++ b/aerospike-storage-backend/src/main/java/com/playtika/janusgraph/aerospike/AerospikePolicyProvider.java @@ -11,6 +11,7 @@ import io.netty.channel.nio.NioEventLoopGroup; import org.janusgraph.diskstorage.configuration.Configuration; +import static com.playtika.janusgraph.aerospike.ConfigOptions.AEROSPIKE_CLIENT_MAX_SOCKET_IDLE; import static com.playtika.janusgraph.aerospike.ConfigOptions.AEROSPIKE_CONNECTIONS_PER_NODE; import static com.playtika.janusgraph.aerospike.ConfigOptions.AEROSPIKE_MIN_CONNECTIONS_PER_NODE; import static com.playtika.janusgraph.aerospike.ConfigOptions.AEROSPIKE_READ_TIMEOUT; @@ -36,6 +37,9 @@ public ClientPolicy clientPolicy() { clientPolicy.password = configuration.has(AUTH_PASSWORD) ? configuration.get(AUTH_PASSWORD) : null; clientPolicy.minConnsPerNode = configuration.get(AEROSPIKE_MIN_CONNECTIONS_PER_NODE); clientPolicy.maxConnsPerNode = configuration.get(AEROSPIKE_CONNECTIONS_PER_NODE); + clientPolicy.maxSocketIdle = configuration.has(AEROSPIKE_CLIENT_MAX_SOCKET_IDLE) + ? configuration.get(AEROSPIKE_CLIENT_MAX_SOCKET_IDLE) + : clientPolicy.maxSocketIdle; clientPolicy.readPolicyDefault = readPolicy(); clientPolicy.scanPolicyDefault = scanPolicy(); clientPolicy.queryPolicyDefault = queryPolicy(); diff --git a/aerospike-storage-backend/src/main/java/com/playtika/janusgraph/aerospike/ConfigOptions.java b/aerospike-storage-backend/src/main/java/com/playtika/janusgraph/aerospike/ConfigOptions.java index c44682b..777e9ba 100644 --- a/aerospike-storage-backend/src/main/java/com/playtika/janusgraph/aerospike/ConfigOptions.java +++ b/aerospike-storage-backend/src/main/java/com/playtika/janusgraph/aerospike/ConfigOptions.java @@ -83,4 +83,8 @@ public class ConfigOptions { "ids-block-ttl", "How long keep history of ids block in milliseconds, default to one week", ConfigOption.Type.LOCAL, 604800000L); + public static final ConfigOption AEROSPIKE_CLIENT_MAX_SOCKET_IDLE = new ConfigOption<>(STORAGE_NS, + "aerospike-client-max-socket-idle", "Maximum socket idle in seconds. If server's proto-fd-idle-ms is zero (no reap), then maxSocketIdle should also be zero", + ConfigOption.Type.LOCAL, 0); + } diff --git a/aerospike-storage-backend/src/test/java/com/playtika/janusgraph/aerospike/AerospikePolicyProviderTest.java b/aerospike-storage-backend/src/test/java/com/playtika/janusgraph/aerospike/AerospikePolicyProviderTest.java new file mode 100644 index 0000000..909754b --- /dev/null +++ b/aerospike-storage-backend/src/test/java/com/playtika/janusgraph/aerospike/AerospikePolicyProviderTest.java @@ -0,0 +1,41 @@ +package com.playtika.janusgraph.aerospike; + +import com.aerospike.client.policy.ClientPolicy; +import org.junit.ClassRule; +import org.junit.Test; +import org.testcontainers.containers.GenericContainer; + +import static com.playtika.janusgraph.aerospike.AerospikeTestUtils.getAerospikeConfiguration; +import static com.playtika.janusgraph.aerospike.AerospikeTestUtils.getAerospikeContainer; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +public class AerospikePolicyProviderTest { + + @ClassRule + public static GenericContainer container = getAerospikeContainer(); + + @Test + public void shouldReturnDefaultClientPolicyMaxSocketIdle() { + var aerospikePolicyProvider = new AerospikePolicyProvider( + getAerospikeConfiguration(container) + ); + + var clientPolicy = aerospikePolicyProvider.clientPolicy(); + + assertThat(clientPolicy.maxSocketIdle) + .isEqualTo(new ClientPolicy().maxSocketIdle); + } + + @Test + public void shouldOverrideClientPolicyMaxSocketIdle() { + var clientMaxSocketIdle = 55; + var aerospikePolicyProvider = new AerospikePolicyProvider( + getAerospikeConfiguration(container) + .set(ConfigOptions.AEROSPIKE_CLIENT_MAX_SOCKET_IDLE, clientMaxSocketIdle) + ); + + var clientPolicy = aerospikePolicyProvider.clientPolicy(); + + assertThat(clientPolicy.maxSocketIdle).isEqualTo(clientMaxSocketIdle); + } +} \ No newline at end of file