Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FMWK-201 Add support to control creating secondary indexes on startup #604

Merged
merged 4 commits into from
Jul 31, 2023
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 @@ -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