Skip to content

Commit

Permalink
Fix tests performance
Browse files Browse the repository at this point in the history
  • Loading branch information
skarpenko committed Nov 2, 2023
1 parent 7cc4a56 commit a37097a
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
import com.aerospike.AerospikeContainerUtils;
import com.aerospike.AerospikeProperties;
import com.aerospike.client.AerospikeClient;
import com.aerospike.client.IAerospikeClient;
import com.aerospike.client.Info;
import com.aerospike.client.async.EventLoops;
import com.aerospike.client.policy.ClientPolicy;
import org.testcontainers.containers.GenericContainer;

import java.util.stream.Stream;

public class AerospikeTestUtils {

public static AerospikeProperties AEROSPIKE_PROPERTIES = new AerospikeProperties();
Expand All @@ -31,28 +27,4 @@ public static AerospikeClient getAerospikeClient(GenericContainer aerospike, Eve
aerospike.getMappedPort(AEROSPIKE_PROPERTIES.getPort()));
}

public static void deleteAllRecords(GenericContainer container) throws InterruptedException {
try(AerospikeClient client = new AerospikeClient(container.getContainerIpAddress(),
container.getMappedPort(AEROSPIKE_PROPERTIES.getPort()))) {
while(!isEmptyNamespace(client, AEROSPIKE_PROPERTIES.getNamespace())){
truncateNamespace(client, AEROSPIKE_PROPERTIES.getNamespace());
Thread.sleep(100);
}
}
}

public static void truncateNamespace(IAerospikeClient client, String namespace) throws InterruptedException {
while(!isEmptyNamespace(client, namespace)){
client.truncate(null, namespace, null, null);
Thread.sleep(100);
}
}

public static boolean isEmptyNamespace(IAerospikeClient client, String namespace){
String answer = Info.request(client.getNodes()[0], "sets/" + namespace);
return answer.isEmpty()
|| Stream.of(answer.split(";"))
.allMatch(s -> s.contains("objects=0"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.util.concurrent.atomic.AtomicInteger;

import static nosql.batch.update.aerospike.AerospikeTestUtils.AEROSPIKE_PROPERTIES;
import static nosql.batch.update.aerospike.AerospikeTestUtils.deleteAllRecords;
import static nosql.batch.update.aerospike.AerospikeTestUtils.getAerospikeClient;
import static nosql.batch.update.aerospike.AerospikeTestUtils.getAerospikeContainer;
import static nosql.batch.update.aerospike.basic.BasicConsistencyTest.getValue;
Expand Down Expand Up @@ -56,10 +55,8 @@ public class BasicBatchRetentionTest extends BatchRetentionTest {

static AtomicInteger keyCounter = new AtomicInteger();

static String setName = String.valueOf(BasicBatchRetentionTest.class.hashCode());

private Key key1 = new Key(AEROSPIKE_PROPERTIES.getNamespace(), setName, keyCounter.incrementAndGet());
private Key key2 = new Key(AEROSPIKE_PROPERTIES.getNamespace(), setName, keyCounter.incrementAndGet());
private Key key1;
private Key key2;

@Override
protected void runUpdate() {
Expand All @@ -76,9 +73,13 @@ protected void checkForConsistency() {
assertThat(operations.getWriteAheadLogManager().getTimeRanges(STALE_BATCHES_THRESHOLD, BATCH_SIZE)).isEmpty());
}

private int setNameCounter = 0;

@Override
protected void cleanUp() throws InterruptedException {
deleteAllRecords(aerospike);
protected void cleanUp() {
String setName = String.valueOf(setNameCounter++);
key1 = new Key(AEROSPIKE_PROPERTIES.getNamespace(), setName, keyCounter.incrementAndGet());
key2 = new Key(AEROSPIKE_PROPERTIES.getNamespace(), setName, keyCounter.incrementAndGet());

clock.setTime(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.util.concurrent.atomic.AtomicInteger;

import static nosql.batch.update.aerospike.AerospikeTestUtils.AEROSPIKE_PROPERTIES;
import static nosql.batch.update.aerospike.AerospikeTestUtils.deleteAllRecords;
import static nosql.batch.update.aerospike.AerospikeTestUtils.getAerospikeClient;
import static nosql.batch.update.aerospike.AerospikeTestUtils.getAerospikeContainer;
import static nosql.batch.update.aerospike.basic.BasicConsistencyTest.getValue;
Expand Down Expand Up @@ -56,10 +55,9 @@ public class BasicRecoveryTest extends RecoveryTest {
new DummyExclusiveLocker(),
Executors.newScheduledThreadPool(1));

static String setName = String.valueOf(BasicRecoveryTest.class.hashCode());
static AtomicInteger keyCounter = new AtomicInteger();
private final Key key1 = new Key(AEROSPIKE_PROPERTIES.getNamespace(), setName, keyCounter.incrementAndGet());
private final Key key2 = new Key(AEROSPIKE_PROPERTIES.getNamespace(), setName, keyCounter.incrementAndGet());
private Key key1;
private Key key2;

@Override
protected void runUpdate() {
Expand All @@ -82,9 +80,13 @@ protected void checkForConsistency() {
assertThat(operations.getWriteAheadLogManager().getTimeRanges(STALE_BATCHES_THRESHOLD, BATCH_SIZE)).isEmpty());
}

private int setNameCounter = 0;

@Override
protected void cleanUp() throws InterruptedException {
deleteAllRecords(aerospike);
protected void cleanUp() {
String setName = String.valueOf(setNameCounter++);
key1 = new Key(AEROSPIKE_PROPERTIES.getNamespace(), setName, keyCounter.incrementAndGet());
key2 = new Key(AEROSPIKE_PROPERTIES.getNamespace(), setName, keyCounter.incrementAndGet());

clock.setTime(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
import com.aerospike.AerospikeContainerUtils;
import com.aerospike.AerospikeProperties;
import com.aerospike.client.AerospikeClient;
import com.aerospike.client.IAerospikeClient;
import com.aerospike.client.Info;
import com.aerospike.client.async.EventLoops;
import com.aerospike.client.policy.ClientPolicy;
import org.testcontainers.containers.GenericContainer;

import java.util.stream.Stream;

public class AerospikeTestUtils {

public static AerospikeProperties AEROSPIKE_PROPERTIES = new AerospikeProperties();
Expand All @@ -30,29 +26,4 @@ public static AerospikeClient getAerospikeClient(GenericContainer aerospike, Eve
return new AerospikeClient(clientPolicy, aerospike.getContainerIpAddress(),
aerospike.getMappedPort(AEROSPIKE_PROPERTIES.getPort()));
}

public static void deleteAllRecords(GenericContainer container) throws InterruptedException {
try(AerospikeClient client = new AerospikeClient(container.getContainerIpAddress(),
container.getMappedPort(AEROSPIKE_PROPERTIES.getPort()))) {
while(!isEmptyNamespace(client, AEROSPIKE_PROPERTIES.getNamespace())){
truncateNamespace(client, AEROSPIKE_PROPERTIES.getNamespace());
Thread.sleep(100);
}
}
}

public static void truncateNamespace(IAerospikeClient client, String namespace) throws InterruptedException {
while(!isEmptyNamespace(client, namespace)){
client.truncate(null, namespace, null, null);
Thread.sleep(100);
}
}

public static boolean isEmptyNamespace(IAerospikeClient client, String namespace){
String answer = Info.request(client.getNodes()[0], "sets/" + namespace);
return answer.isEmpty()
|| Stream.of(answer.split(";"))
.allMatch(s -> s.contains("objects=0"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.aerospike.client.reactor.AerospikeReactorClient;
import com.aerospike.client.reactor.IAerospikeReactorClient;
import nosql.batch.update.BatchRetentionTest;
import nosql.batch.update.aerospike.AerospikeTestUtils;
import nosql.batch.update.aerospike.basic.Record;
import nosql.batch.update.aerospike.basic.lock.AerospikeBasicBatchLocks;
import nosql.batch.update.aerospike.lock.AerospikeLock;
Expand All @@ -20,10 +21,7 @@
import java.time.Duration;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;

import static nosql.batch.update.reactor.aerospike.AerospikeTestUtils.AEROSPIKE_PROPERTIES;
import static nosql.batch.update.reactor.aerospike.AerospikeTestUtils.deleteAllRecords;
import static nosql.batch.update.reactor.aerospike.AerospikeTestUtils.getAerospikeClient;
import static nosql.batch.update.reactor.aerospike.AerospikeTestUtils.getAerospikeContainer;
import static nosql.batch.update.reactor.aerospike.basic.BasicConsistencyTest.getValue;
Expand Down Expand Up @@ -59,12 +57,8 @@ public class BasicBatchRetentionTest extends BatchRetentionTest {
new BasicRecoveryTest.DummyExclusiveLocker(),
Executors.newScheduledThreadPool(1));

static AtomicInteger keyCounter = new AtomicInteger();

static String setName = String.valueOf(BasicBatchRetentionTest.class.hashCode());

private Key key1 = new Key(AEROSPIKE_PROPERTIES.getNamespace(), setName, keyCounter.incrementAndGet());
private Key key2 = new Key(AEROSPIKE_PROPERTIES.getNamespace(), setName, keyCounter.incrementAndGet());
private Key key1;
private Key key2;

@Override
protected void runUpdate() {
Expand All @@ -81,9 +75,12 @@ protected void checkForConsistency() {
assertThat(operations.getWriteAheadLogManager().getTimeRanges(STALE_BATCHES_THRESHOLD, BATCH_SIZE)).isEmpty());
}

private int setNameCounter = 0;
@Override
protected void cleanUp() throws InterruptedException {
deleteAllRecords(aerospike);
protected void cleanUp() {
String setName = String.valueOf(setNameCounter++);
key1 = new Key(AerospikeTestUtils.AEROSPIKE_PROPERTIES.getNamespace(), setName, 0);
key2 = new Key(AerospikeTestUtils.AEROSPIKE_PROPERTIES.getNamespace(), setName, 1);

clock.setTime(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.aerospike.client.reactor.AerospikeReactorClient;
import com.aerospike.client.reactor.IAerospikeReactorClient;
import nosql.batch.update.RecoveryTest;
import nosql.batch.update.aerospike.AerospikeTestUtils;
import nosql.batch.update.aerospike.basic.Record;
import nosql.batch.update.aerospike.basic.lock.AerospikeBasicBatchLocks;
import nosql.batch.update.aerospike.lock.AerospikeLock;
Expand All @@ -21,10 +22,7 @@
import java.time.Duration;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;

import static nosql.batch.update.reactor.aerospike.AerospikeTestUtils.AEROSPIKE_PROPERTIES;
import static nosql.batch.update.reactor.aerospike.AerospikeTestUtils.deleteAllRecords;
import static nosql.batch.update.reactor.aerospike.AerospikeTestUtils.getAerospikeClient;
import static nosql.batch.update.reactor.aerospike.AerospikeTestUtils.getAerospikeContainer;
import static nosql.batch.update.reactor.aerospike.basic.BasicConsistencyTest.getValue;
Expand Down Expand Up @@ -59,10 +57,8 @@ public class BasicRecoveryTest extends RecoveryTest {
new DummyExclusiveLocker(),
Executors.newScheduledThreadPool(1));

static String setName = String.valueOf(BasicRecoveryTest.class.hashCode());
static AtomicInteger keyCounter = new AtomicInteger();
private final Key key1 = new Key(AEROSPIKE_PROPERTIES.getNamespace(), setName, keyCounter.incrementAndGet());
private final Key key2 = new Key(AEROSPIKE_PROPERTIES.getNamespace(), setName, keyCounter.incrementAndGet());
private Key key1;
private Key key2;

@Override
protected void runUpdate() {
Expand All @@ -85,9 +81,12 @@ protected void checkForConsistency() {
assertThat(operations.getWriteAheadLogManager().getTimeRanges(STALE_BATCHES_THRESHOLD, BATCH_SIZE)).isEmpty());
}

private int setNameCounter = 0;
@Override
protected void cleanUp() throws InterruptedException {
deleteAllRecords(aerospike);
protected void cleanUp() {
String setName = String.valueOf(setNameCounter++);
key1 = new Key(AerospikeTestUtils.AEROSPIKE_PROPERTIES.getNamespace(), setName, 0);
key2 = new Key(AerospikeTestUtils.AEROSPIKE_PROPERTIES.getNamespace(), setName, 1);

clock.setTime(0);
}
Expand Down
7 changes: 5 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<testcontainers.version>1.19.1</testcontainers.version>
<junit.version>4.12</junit.version>
<assertj.version>3.9.0</assertj.version>
<blockhound.version>1.0.3.RELEASE</blockhound.version>
<blockhound.version>1.0.8.RELEASE</blockhound.version>

<slf4j-log4j12.version>1.8.0-beta0</slf4j-log4j12.version>
<hamcrest.version>1.3</hamcrest.version>
Expand Down Expand Up @@ -252,6 +252,9 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<argLine>-XX:+AllowRedefinitionToAddDeleteMethods</argLine>
</configuration>
</plugin>

<!-- Produce code coverage -->
Expand Down Expand Up @@ -288,7 +291,7 @@
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven.javadoc.plugin.version}</version>
<configuration>
<source>8</source>
<source>17</source>
</configuration>
<executions>
<execution>
Expand Down

0 comments on commit a37097a

Please sign in to comment.