-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: switch off stop-writes-sys-memory-pct metric for the Aerospike …
…Enterprise
- Loading branch information
Showing
3 changed files
with
86 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
.../src/main/java/com/playtika/testcontainers/aerospike/enterprise/AsadmCommandExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
.../test/java/com/playtika/testcontainers/aerospike/enterprise/AsadmCommandExecutorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.playtika.testcontainers.aerospike.enterprise; | ||
|
||
import com.playtika.testcontainer.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.BEAN_NAME_AEROSPIKE) | ||
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")); | ||
} | ||
} |