Skip to content

Commit

Permalink
add Aerospike ClintPolicy maxSocketIdle property override
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrii Chervoniuk authored and kptfh committed Mar 27, 2024
1 parent 98f7e31 commit 1cdfa83
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer> 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);

}
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 1cdfa83

Please sign in to comment.