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 @@ -3,7 +3,6 @@
import com.playtika.test.aerospike.AerospikeProperties;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.testcontainers.containers.Container;
import org.testcontainers.containers.GenericContainer;

import java.io.IOException;
Expand All @@ -15,26 +14,29 @@ public class AerospikeEnterpriseConfigurer {
private final AerospikeProperties aerospikeProperties;
private final AerospikeEnterpriseProperties enterpriseProperties;

public void configure(GenericContainer<?> aerospikeContainer) throws IOException, InterruptedException {
public void configure(GenericContainer<?> aerospikeContainer) throws IOException, InterruptedException {
if (aerospikeProperties.getFeatureKey() == null || aerospikeProperties.getFeatureKey().isEmpty()) {
log.warn("Evaluation feature key file not provided by 'embedded.aerospike.featureKey' property. " +
"Pay attention to license details: https://github.com/aerospike/aerospike-server.docker/blob/master/enterprise/ENTERPRISE_LICENSE");
}

setupDisallowExpunge(aerospikeContainer);
}

private void setupDisallowExpunge(GenericContainer<?> aerospikeContainer) throws IOException, InterruptedException {
if (!enterpriseProperties.isDurableDeletes()) {
return;
}
log.info("Setting up 'disallow-expunge' to true...");
String namespace = aerospikeProperties.getNamespace();
Container.ExecResult result = aerospikeContainer.execInContainer("asadm", "-e",
String.format("enable; manage config namespace %s param disallow-expunge to true", namespace));
if (result.getStderr().length() > 0) {
throw new IllegalStateException("Failed to set up 'disallow-expunge' to true: " + result.getStderr());
AsadmCommandExecutor asadmCommandExecutor = new AsadmCommandExecutor(aerospikeContainer);

/*
By default, the value of this metric is 90%, we set it to 100% to prevent stopping writes for the Aerospike
Enterprise container during high consumption of system memory. For the Aerospike Community Edition, this metric is not used.
Documentation: https://aerospike.com/docs/server/reference/configuration#stop-writes-sys-memory-pct
*/
log.info("Switching off 'stop-writes-sys-memory-pct'... ");
asadmCommandExecutor.execute(String.format("manage config namespace %s param stop-writes-sys-memory-pct to 100", namespace));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why don't you check execute the result of the command?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is checked in AsadmCommandExecutor

log.info("Success switching off 'stop-writes-sys-memory-pct'");

if (enterpriseProperties.isDurableDeletes()) {
log.info("Setting up 'disallow-expunge' to true...");
asadmCommandExecutor.execute(String.format("manage config namespace %s param disallow-expunge to true", namespace));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why don't you check execute the result of the command?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is checked in AsadmCommandExecutor

log.info("Success setting up 'disallow-expunge' to true");
}
log.info("Set up 'disallow-expunge' to true: {}", result.getStdout());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.playtika.testcontainers.aerospike.enterprise;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.testcontainers.containers.Container;
import org.testcontainers.containers.GenericContainer;

import java.io.IOException;

@RequiredArgsConstructor
@Slf4j
public class AsadmCommandExecutor {

private final GenericContainer<?> aerospikeContainer;

public void execute(String command) throws IOException, InterruptedException {
Container.ExecResult result = aerospikeContainer.execInContainer("asadm", "--enable", "-e", command);
logStdout(result);
if (result.getExitCode() != 0 || isBadResponse(result)) {
throw new IllegalStateException(String.format("Failed to execute \"asadm --enable -e '%s'\": \nstdout:\n%s\nstderr:\n%s",
command, result.getStdout(), result.getStderr()));
}
}

private boolean isBadResponse(Container.ExecResult execResult) {
String stdout = execResult.getStdout();
/*
Example of the stdout without error:
~Set Namespace Param stop-writes-sys-memory-pct to 100~
Node|Response
728bb242e58c:3000|ok
Number of rows: 1
*/
return !stdout.contains("|ok");
}

private static void logStdout(Container.ExecResult result) {
log.debug("Aerospike asadm util stdout: \n{}\n{}", result.getStdout(), result.getStderr());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ public class EnterpriseAerospikeTestOperationsAutoConfiguration {
@Bean
@ConditionalOnProperty(value = "embedded.aerospike.time-travel.enabled", havingValue = "true", matchIfMissing = true)
public ExpiredDocumentsCleaner expiredDocumentsCleaner(AerospikeClient client,
AerospikeEnterpriseProperties aerospikeEnterpriseProperties,
AerospikeProperties properties) {
return new AerospikeExpiredDocumentsCleaner(client, properties.getNamespace(), true);
return new AerospikeExpiredDocumentsCleaner(client, properties.getNamespace(), aerospikeEnterpriseProperties.isDurableDeletes());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.playtika.testcontainers.aerospike.enterprise;

import com.playtika.test.aerospike.AerospikeProperties;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.testcontainers.containers.GenericContainer;

import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

public class AsadmCommandExecutorTest extends BaseEnterpriseAerospikeTest {

@Autowired
@Qualifier(AerospikeProperties.AEROSPIKE_BEAN_NAME)
private GenericContainer<?> aerospikeContainer;

@Test
public void shouldFailCommandExecutionWithBadOption() {
AsadmCommandExecutor commandExecutor = new AsadmCommandExecutor(aerospikeContainer);
assertThatExceptionOfType(IllegalStateException.class)
.isThrownBy(() -> commandExecutor.execute("-tttttt"));
}

@Test
public void shouldFailCommandExecutionWithBadCommand() {
AsadmCommandExecutor commandExecutor = new AsadmCommandExecutor(aerospikeContainer);
assertThatExceptionOfType(IllegalStateException.class)
.isThrownBy(() -> commandExecutor.execute("manage config namespace NAMESPACE_NOT_EXISTS param disallow-expunge to true"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ void failOnNonEnterpriseImage() {

@Test
void failOnUnsuitableEnterpriseImageVersion() {
contextRunner.withPropertyValues("embedded.aerospike.dockerImage=aerospike/aerospike-server-enterprise:6.1.0.16_1")
contextRunner.withPropertyValues("embedded.aerospike.dockerImage=aerospike/aerospike-server-enterprise:6.1.0.16")
.run(context -> assertThat(context).hasFailed());
}

@Test
void skipValidation() {
contextRunner.withPropertyValues("embedded.aerospike.dockerImage=aerospike-server:6.1.0.16_1",
contextRunner.withPropertyValues("embedded.aerospike.dockerImage=aerospike-server:6.1.0.16",
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not 16_1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it just checks version format, no matter

"embedded.aerospike.enabled=false")
.run(context -> assertThat(context).hasNotFailed());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</Console>
</Appenders>
<Loggers>
<Logger name="com.playtika.testcontainer" level="info"/>
<Logger name="com.playtika.testcontainers" level="info"/>
<Logger name="org.springframework" level="error"/>
<Root level="error">
<AppenderRef ref="Console"/>
Expand Down