Skip to content

Commit

Permalink
FMWK-201 Add support to control creating secondary indexes on startup (
Browse files Browse the repository at this point in the history
  • Loading branch information
agrgr authored Jul 31, 2023
1 parent 54fcdbe commit f2ea8d8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,6 @@ protected FieldNamingStrategy fieldNamingStrategy() {

protected abstract String nameSpace();

@SuppressWarnings("SameReturnValue")
protected boolean isCreateIndexesOnStartup() {
return true;
}

protected AerospikeDataSettings aerospikeDataSettings() {
AerospikeDataSettings.AerospikeDataSettingsBuilder builder = AerospikeDataSettings.builder();
configureDataSettings(builder);
Expand All @@ -163,7 +158,7 @@ protected AerospikeDataSettings aerospikeDataSettings() {
protected void configureDataSettings(AerospikeDataSettings.AerospikeDataSettingsBuilder builder) {
builder.scansEnabled(false);
builder.sendKey(true);
builder.createIndexesOnStartup(isCreateIndexesOnStartup());
builder.createIndexesOnStartup(true);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import com.aerospike.client.Host;
import com.aerospike.client.IAerospikeClient;
import com.aerospike.client.policy.ClientPolicy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.data.aerospike.AdditionalAerospikeTestOperations;
import org.springframework.data.aerospike.BlockingAerospikeTestOperations;
import org.springframework.data.aerospike.SampleClasses;
Expand Down Expand Up @@ -34,6 +36,9 @@ public class BlockingTestConfig extends AbstractAerospikeDataConfiguration {
@Value("${embedded.aerospike.port}")
protected int port;

@Autowired
Environment env;

@Override
protected List<?> customConverters() {
return Arrays.asList(
Expand All @@ -55,6 +60,8 @@ protected String nameSpace() {
@Override
protected void configureDataSettings(AerospikeDataSettings.AerospikeDataSettingsBuilder builder) {
builder.scansEnabled(true);
boolean indexesOnStartup = Boolean.parseBoolean(env.getProperty("createIndexesOnStartup"));
builder.createIndexesOnStartup(indexesOnStartup);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import com.aerospike.client.IAerospikeClient;
import com.aerospike.client.async.EventLoops;
import com.aerospike.client.async.NioEventLoops;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.data.aerospike.AdditionalAerospikeTestOperations;
import org.springframework.data.aerospike.ReactiveBlockingAerospikeTestOperations;
import org.springframework.data.aerospike.SampleClasses;
Expand Down Expand Up @@ -34,6 +36,9 @@ public class ReactiveTestConfig extends AbstractReactiveAerospikeDataConfigurati
@Value("${embedded.aerospike.port}")
protected int port;

@Autowired
Environment env;

@Override
protected List<?> customConverters() {
return Arrays.asList(
Expand Down Expand Up @@ -76,6 +81,8 @@ protected EventLoops eventLoops() {
@Override
protected void configureDataSettings(AerospikeDataSettings.AerospikeDataSettingsBuilder builder) {
builder.scansEnabled(true);
boolean indexesOnStartup = Boolean.parseBoolean(env.getProperty("createIndexesOnStartup"));
builder.createIndexesOnStartup(indexesOnStartup);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.springframework.data.aerospike.IndexUtils;
import org.springframework.data.aerospike.mapping.Document;
import org.springframework.data.aerospike.query.model.Index;
import org.springframework.test.context.TestPropertySource;

import java.util.List;
import java.util.Map;
Expand All @@ -22,6 +23,8 @@
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.springframework.data.aerospike.AwaitilityUtils.awaitTenSecondsUntil;

@TestPropertySource(properties = {"createIndexesOnStartup = true"})
// this test class requires secondary indexes created on startup
public class AerospikeTemplateIndexTests extends BaseBlockingIntegrationTests {

private static final String INDEX_TEST_1 = "index-test-77777";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
import org.springframework.data.aerospike.sample.Address;
import org.springframework.data.aerospike.sample.IndexedPerson;
import org.springframework.data.annotation.Id;
import org.springframework.test.context.TestPropertySource;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;

@TestPropertySource(properties = {"createIndexesOnStartup = true"})
// this test class requires secondary indexes created on startup
public class IndexedAnnotationTests extends BaseBlockingIntegrationTests {

@Test
Expand Down

0 comments on commit f2ea8d8

Please sign in to comment.