diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaServiceImpl.java index 0accc5c08d5423b1c35b6ff550aefa86aed09dc2..ab3cebb80195698fe9d3b280c801f95b31281c16 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaServiceImpl.java @@ -36,6 +36,7 @@ import org.opengroup.osdu.indexer.model.Kind; import org.opengroup.osdu.indexer.model.indexproperty.PropertyConfigurations; import org.opengroup.osdu.indexer.schema.converter.exeption.SchemaProcessingException; import org.opengroup.osdu.indexer.schema.converter.interfaces.IVirtualPropertiesSchemaCache; +import org.opengroup.osdu.indexer.util.AugmenterSetting; import org.opengroup.osdu.indexer.util.ElasticClientHandler; import org.opengroup.osdu.indexer.util.TypeMapper; import org.springframework.stereotype.Service; @@ -71,6 +72,8 @@ public class IndexSchemaServiceImpl implements IndexSchemaService { private IVirtualPropertiesSchemaCache virtualPropertiesSchemaCache; @Inject private PropertyConfigurationsService propertyConfigurationsService; + @Inject + private AugmenterSetting augmenterSetting; public void processSchemaMessages(Map<String, OperationType> schemaMsgs) throws IOException { try (RestHighLevelClient restClient = this.elasticClientHandler.createRestClient()) { @@ -163,10 +166,12 @@ public class IndexSchemaServiceImpl implements IndexSchemaService { if (Strings.isNullOrEmpty(schema)) { return this.getEmptySchema(kind); } else { - // Merge schema of the extended properties if needed - PropertyConfigurations propertyConfigurations = propertyConfigurationsService.getPropertyConfigurations(kind); - if (propertyConfigurations != null) { - schema = mergeSchemaFromPropertyConfiguration(schema, propertyConfigurations); + if(augmenterSetting.isEnabled()) { + // Merge schema of the extended properties if needed + PropertyConfigurations propertyConfigurations = propertyConfigurationsService.getPropertyConfigurations(kind); + if (propertyConfigurations != null) { + schema = mergeSchemaFromPropertyConfiguration(schema, propertyConfigurations); + } } IndexSchema flatSchemaObj = cacheAndNormalizeSchema(kind, schema); diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerServiceImpl.java index bef40019766c7bd9c66940dbbeb18ae6d9025dc2..cdae2cb43b3c99b3cbc3376867f7c1e7cd142218 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerServiceImpl.java @@ -46,6 +46,7 @@ import org.opengroup.osdu.indexer.logging.AuditLogger; import org.opengroup.osdu.indexer.model.BulkRequestResult; import org.opengroup.osdu.indexer.model.indexproperty.PropertyConfigurations; import org.opengroup.osdu.indexer.provider.interfaces.IPublisher; +import org.opengroup.osdu.indexer.util.AugmenterSetting; import org.opengroup.osdu.indexer.util.ElasticClientHandler; import org.opengroup.osdu.indexer.util.IndexerQueueTaskBuilder; import org.springframework.context.annotation.Primary; @@ -106,6 +107,8 @@ public class IndexerServiceImpl implements IndexerService { private JobStatus jobStatus; @Inject private PropertyConfigurationsService propertyConfigurationsService; + @Inject + private AugmenterSetting augmenterSetting; private DpsHeaders headers; @@ -154,10 +157,12 @@ public class IndexerServiceImpl implements IndexerService { retryAndEnqueueFailedRecords(recordInfos, retryRecordIds, message); } - Map<String, List<String>> upsertKindIds = getUpsertRecordIdsForConfigurationsEnabledKinds(upsertRecordMap, retryRecordIds); - Map<String, List<String>> deleteKindIds = getDeleteRecordIdsForConfigurationsEnabledKinds(deleteRecordMap, retryRecordIds); - if (!upsertKindIds.isEmpty() || !deleteKindIds.isEmpty()) { - propertyConfigurationsService.updateAssociatedRecords(message, upsertKindIds, deleteKindIds); + if(this.augmenterSetting.isEnabled()) { + Map<String, List<String>> upsertKindIds = getUpsertRecordIdsForConfigurationsEnabledKinds(upsertRecordMap, retryRecordIds); + Map<String, List<String>> deleteKindIds = getDeleteRecordIdsForConfigurationsEnabledKinds(deleteRecordMap, retryRecordIds); + if (!upsertKindIds.isEmpty() || !deleteKindIds.isEmpty()) { + propertyConfigurationsService.updateAssociatedRecords(message, upsertKindIds, deleteKindIds); + } } } catch (IOException e) { errorMessage = e.getMessage(); @@ -340,14 +345,16 @@ public class IndexerServiceImpl implements IndexerService { this.jobStatus.addOrUpdateRecordStatus(storageRecord.getId(), IndexingStatus.WARN, HttpStatus.SC_NOT_FOUND, message, String.format("record-id: %s | %s", storageRecord.getId(), message)); } - if(propertyConfigurationsService.isPropertyConfigurationsEnabled(storageRecord.getKind())) { - PropertyConfigurations propertyConfigurations = propertyConfigurationsService.getPropertyConfigurations(storageRecord.getKind()); - if (propertyConfigurations != null) { - // Merge extended properties - dataMap = mergeDataFromPropertyConfiguration(storageRecord.getId(), dataMap, propertyConfigurations); + if(this.augmenterSetting.isEnabled()) { + if(propertyConfigurationsService.isPropertyConfigurationsEnabled(storageRecord.getKind())) { + PropertyConfigurations propertyConfigurations = propertyConfigurationsService.getPropertyConfigurations(storageRecord.getKind()); + if (propertyConfigurations != null) { + // Merge extended properties + dataMap = mergeDataFromPropertyConfiguration(storageRecord.getId(), dataMap, propertyConfigurations); + } + // We cache the dataMap in case the update of this object will trigger update of the related objects. + propertyConfigurationsService.cacheDataRecord(storageRecord.getId(), storageRecord.getKind(), dataMap); } - // We cache the dataMap in case the update of this object will trigger update of the related objects. - propertyConfigurationsService.cacheDataRecord(storageRecord.getId(), storageRecord.getKind(), dataMap); } document.setData(dataMap); diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/AugmenterSetting.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/AugmenterSetting.java new file mode 100644 index 0000000000000000000000000000000000000000..d11d41cc38f5b3c7aaf1cd63cfbafd38ca4250eb --- /dev/null +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/AugmenterSetting.java @@ -0,0 +1,16 @@ +package org.opengroup.osdu.indexer.util; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class AugmenterSetting { + private static final String PROPERTY_NAME = "index-augmenter-enabled"; + + @Autowired + private BooleanFeatureFlagClient booleanFeatureFlagClient; + + public boolean isEnabled() { + return booleanFeatureFlagClient.isEnabled(PROPERTY_NAME, false); + } +} diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/BooleanFeatureFlagClient.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/BooleanFeatureFlagClient.java new file mode 100644 index 0000000000000000000000000000000000000000..a27ec91cd02d9bb54060e8509ec470512b7bd36d --- /dev/null +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/BooleanFeatureFlagClient.java @@ -0,0 +1,81 @@ +package org.opengroup.osdu.indexer.util; + +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.partition.*; +import org.opengroup.osdu.core.common.util.IServiceAccountJwtClient; +import org.opengroup.osdu.indexer.util.geo.decimator.FeatureFlagCache; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Component; + +@Component +public class BooleanFeatureFlagClient { + private static final String TOKEN_PREFIX = "Bearer "; + + @Lazy + @Autowired + private FeatureFlagCache cache; + + @Autowired + private JaxRsDpsLog logger; + + @Autowired + private DpsHeaders headers; + + @Autowired + private IPartitionFactory factory; + + @Autowired + private IServiceAccountJwtClient tokenService; + + public boolean isEnabled(String featureName, boolean defaultValue) { + String dataPartitionId = headers.getPartitionId(); + String cacheKey = String.format("%s-%s", dataPartitionId, featureName); + if (cache != null && cache.containsKey(cacheKey)) + return cache.get(cacheKey); + + boolean isEnabled = defaultValue; + try { + PartitionInfo partitionInfo = getPartitionInfo(dataPartitionId); + isEnabled = getFeatureValue(partitionInfo, featureName, defaultValue); + } catch (Exception e) { + this.logger.error(String.format("PartitionService: Error getting %s for dataPartition with Id: %s. Turn on the feature flag by default.", featureName, dataPartitionId), e); + } + this.cache.put(cacheKey, isEnabled); + return isEnabled; + } + + private PartitionInfo getPartitionInfo(String dataPartitionId) throws PartitionException { + try { + DpsHeaders partitionHeaders = DpsHeaders.createFromMap(headers.getHeaders()); + partitionHeaders.put(DpsHeaders.AUTHORIZATION, this.getAuthorization(dataPartitionId)); + + IPartitionProvider partitionProvider = this.factory.create(partitionHeaders); + PartitionInfo partitionInfo = partitionProvider.get(dataPartitionId); + return partitionInfo; + } catch (PartitionException e) { + logger.error(String.format("Error getting partition info for data-partition: %s", dataPartitionId), e); + throw e; + } + } + + private String getAuthorization(String dataPartitionId) { + String authorization = this.tokenService.getIdToken(dataPartitionId); + if(!authorization.startsWith(TOKEN_PREFIX)) { + authorization = TOKEN_PREFIX + authorization; + } + return authorization; + } + + private boolean getFeatureValue(PartitionInfo partitionInfo, String featureName, boolean defaultValue) { + if(partitionInfo == null || partitionInfo.getProperties() == null) + return defaultValue; + + if(partitionInfo.getProperties().containsKey(featureName)) { + Property property = partitionInfo.getProperties().get(featureName); + return Boolean.parseBoolean((String)property.getValue()); + } + return defaultValue; + } +} diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/geo/decimator/DecimationSettingCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/geo/decimator/FeatureFlagCache.java similarity index 89% rename from indexer-core/src/main/java/org/opengroup/osdu/indexer/util/geo/decimator/DecimationSettingCache.java rename to indexer-core/src/main/java/org/opengroup/osdu/indexer/util/geo/decimator/FeatureFlagCache.java index 127d9e7079bad1ac0d6c6c12d2aa50d32c09aca9..c24d200b7ce3452c89304213d69f0cde47112a9a 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/geo/decimator/DecimationSettingCache.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/geo/decimator/FeatureFlagCache.java @@ -19,8 +19,8 @@ import org.opengroup.osdu.core.common.cache.VmCache; import org.springframework.stereotype.Component; @Component -public class DecimationSettingCache extends VmCache<String, Boolean> { - public DecimationSettingCache() { +public class FeatureFlagCache extends VmCache<String, Boolean> { + public FeatureFlagCache() { super(300, 1000); } diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/geo/decimator/GeoShapeDecimationSetting.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/geo/decimator/GeoShapeDecimationSetting.java index a062c1ac6e645e3e5bdcec4d9c066e0d0230d199..ddab10f0180684167776593c5b064816dadd84e5 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/geo/decimator/GeoShapeDecimationSetting.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/geo/decimator/GeoShapeDecimationSetting.java @@ -15,74 +15,18 @@ package org.opengroup.osdu.indexer.util.geo.decimator; -import org.apache.http.HttpStatus; -import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; -import org.opengroup.osdu.core.common.model.http.AppException; -import org.opengroup.osdu.core.common.model.http.DpsHeaders; -import org.opengroup.osdu.core.common.partition.*; -import org.opengroup.osdu.core.common.util.IServiceAccountJwtClient; +import org.opengroup.osdu.indexer.util.BooleanFeatureFlagClient; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; @Component public class GeoShapeDecimationSetting { private static final String PROPERTY_NAME = "indexer-decimation-enabled"; - @Lazy @Autowired - private DecimationSettingCache cache; - - @Autowired - private JaxRsDpsLog logger; - - @Autowired - private DpsHeaders headers; - - @Autowired - private IPartitionFactory factory; - - @Autowired - private IServiceAccountJwtClient tokenService; + private BooleanFeatureFlagClient booleanFeatureFlagClient; public boolean isDecimationEnabled() { - String dataPartitionId = headers.getPartitionId(); - String cacheKey = String.format("%s-%s", dataPartitionId, PROPERTY_NAME); - if (cache != null && cache.containsKey(cacheKey)) - return cache.get(cacheKey); - - boolean decimationEnabled = true; - try { - PartitionInfo partitionInfo = getPartitionInfo(dataPartitionId); - decimationEnabled = getDecimationSetting(partitionInfo); - } catch (Exception e) { - this.logger.error(String.format("PartitionService: Error getting %s for dataPartition with Id: %s. Turn on the feature flag by default.", PROPERTY_NAME, dataPartitionId), e); - } - this.cache.put(cacheKey, decimationEnabled); - return decimationEnabled; - } - - private PartitionInfo getPartitionInfo(String dataPartitionId) { - try { - DpsHeaders partitionHeaders = DpsHeaders.createFromMap(headers.getHeaders()); - partitionHeaders.put(DpsHeaders.AUTHORIZATION, this.tokenService.getIdToken(dataPartitionId)); - - IPartitionProvider partitionProvider = this.factory.create(partitionHeaders); - PartitionInfo partitionInfo = partitionProvider.get(dataPartitionId); - return partitionInfo; - } catch (PartitionException e) { - throw new AppException(HttpStatus.SC_FORBIDDEN, "Service unavailable", String.format("Error getting partition info for data-partition: %s", dataPartitionId), e); - } - } - - private boolean getDecimationSetting(PartitionInfo partitionInfo) { - if(partitionInfo == null || partitionInfo.getProperties() == null) - return true; - - if(partitionInfo.getProperties().containsKey(PROPERTY_NAME)) { - Property property = partitionInfo.getProperties().get(PROPERTY_NAME); - return Boolean.parseBoolean((String)property.getValue()); - } - return true; + return booleanFeatureFlagClient.isEnabled(PROPERTY_NAME, true); } } diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/IndexerSchemaServiceTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/IndexerSchemaServiceTest.java index ad25654c11483ddc13901ee2dd58a454973fac84..4c488fb13c7b1d66e4a7f7113edf003e40b5bc1e 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/IndexerSchemaServiceTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/IndexerSchemaServiceTest.java @@ -37,6 +37,7 @@ import org.opengroup.osdu.indexer.cache.PartitionSafeSchemaCache; import org.opengroup.osdu.indexer.model.indexproperty.PropertyConfigurations; import org.opengroup.osdu.indexer.schema.converter.exeption.SchemaProcessingException; import org.opengroup.osdu.indexer.schema.converter.interfaces.IVirtualPropertiesSchemaCache; +import org.opengroup.osdu.indexer.util.AugmenterSetting; import org.opengroup.osdu.indexer.util.ElasticClientHandler; import org.powermock.core.classloader.annotations.PrepareForTest; import org.springframework.test.context.junit4.SpringRunner; @@ -85,6 +86,8 @@ public class IndexerSchemaServiceTest { private IVirtualPropertiesSchemaCache virtualPropertiesSchemaCache; @Mock private PropertyConfigurationsService propertyConfigurationsService; + @Mock + private AugmenterSetting augmenterSetting; @InjectMocks private IndexSchemaServiceImpl sut; @@ -93,6 +96,7 @@ public class IndexerSchemaServiceTest { initMocks(this); RestHighLevelClient restHighLevelClient = mock(RestHighLevelClient.class); when(elasticClientHandler.createRestClient()).thenReturn(restHighLevelClient); + when(augmenterSetting.isEnabled()).thenReturn(true); } @Test diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/IndexerServiceImplTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/IndexerServiceImplTest.java index f9764316c621e41d226ee4279b15a916399b6570..5ab9d69ec9d284b08c8dfde688021832d45d8c9d 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/IndexerServiceImplTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/IndexerServiceImplTest.java @@ -41,6 +41,7 @@ import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver; import org.opengroup.osdu.indexer.logging.AuditLogger; import org.opengroup.osdu.indexer.model.indexproperty.PropertyConfigurations; import org.opengroup.osdu.indexer.provider.interfaces.IPublisher; +import org.opengroup.osdu.indexer.util.AugmenterSetting; import org.opengroup.osdu.indexer.util.ElasticClientHandler; import org.opengroup.osdu.indexer.util.IndexerQueueTaskBuilder; import org.powermock.core.classloader.annotations.PrepareForTest; @@ -99,6 +100,8 @@ public class IndexerServiceImplTest { private PropertyConfigurationsService propertyConfigurationsService; @Mock private IndexerQueueTaskBuilder indexerQueueTaskBuilder; + @Mock + private AugmenterSetting augmenterSetting; private List<RecordInfo> recordInfos = new ArrayList<>(); @@ -120,6 +123,7 @@ public class IndexerServiceImplTest { @Before public void setup() throws IOException { + when(augmenterSetting.isEnabled()).thenReturn(true); } @Test diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/StorageIndexerPayloadMapperTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/StorageIndexerPayloadMapperTest.java index a8ede574da14ec07ad905907c98d5854e132a6e0..f11d6cb80a2b258d742bf13e26d2e2ee62dabfa8 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/StorageIndexerPayloadMapperTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/StorageIndexerPayloadMapperTest.java @@ -21,6 +21,7 @@ import org.opengroup.osdu.indexer.service.mock.PartitionFactoryMock; import org.opengroup.osdu.indexer.service.mock.PartitionProviderMock; import org.opengroup.osdu.indexer.service.mock.ServiceAccountJwtClientMock; import org.opengroup.osdu.indexer.service.mock.VirtualPropertiesSchemaCacheMock; +import org.opengroup.osdu.indexer.util.BooleanFeatureFlagClient; import org.opengroup.osdu.indexer.util.geo.decimator.*; import org.opengroup.osdu.indexer.util.parser.BooleanParser; import org.opengroup.osdu.indexer.util.parser.DateTimeParser; @@ -45,8 +46,8 @@ import static org.junit.Assert.*; @RunWith(SpringRunner.class) @SpringBootTest(classes = {StorageIndexerPayloadMapper.class, AttributeParsingServiceImpl.class, NumberParser.class, BooleanParser.class, DateTimeParser.class, GeoShapeParser.class, DouglasPeuckerReducer.class, GeoShapeDecimator.class, - GeometryDecimator.class, GeometryConversionService.class, DecimationSettingCache.class, - GeoShapeDecimationSetting.class, DpsHeaders.class, JobStatus.class, SchemaConverterPropertiesConfig.class, JaxRsDpsLog.class, + GeometryDecimator.class, GeometryConversionService.class, FeatureFlagCache.class, + GeoShapeDecimationSetting.class, BooleanFeatureFlagClient.class,DpsHeaders.class, JobStatus.class, SchemaConverterPropertiesConfig.class, JaxRsDpsLog.class, PartitionFactoryMock.class, PartitionProviderMock.class, ServiceAccountJwtClientMock.class, VirtualPropertiesSchemaCacheMock.class, }) public class StorageIndexerPayloadMapperTest { diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/util/geo/decimator/GeoShapeDecimationSettingTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/util/BooleanFeatureFlagClientTest.java similarity index 73% rename from indexer-core/src/test/java/org/opengroup/osdu/indexer/util/geo/decimator/GeoShapeDecimationSettingTest.java rename to indexer-core/src/test/java/org/opengroup/osdu/indexer/util/BooleanFeatureFlagClientTest.java index 82fc83db7ccd0a520eabb90ea3a0f414ca0338c2..10e73df399a9ba64b858c121df5e7ad365e2fbcd 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/util/geo/decimator/GeoShapeDecimationSettingTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/util/BooleanFeatureFlagClientTest.java @@ -13,7 +13,7 @@ * limitations under the License. */ -package org.opengroup.osdu.indexer.util.geo.decimator; +package org.opengroup.osdu.indexer.util; import org.junit.Assert; import org.junit.Before; @@ -25,6 +25,7 @@ import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.partition.*; import org.opengroup.osdu.core.common.util.IServiceAccountJwtClient; +import org.opengroup.osdu.indexer.util.geo.decimator.FeatureFlagCache; import org.springframework.test.context.junit4.SpringRunner; import java.util.HashMap; @@ -34,14 +35,14 @@ import static org.mockito.ArgumentMatchers.anyString; import static org.powermock.api.mockito.PowerMockito.when; @RunWith(SpringRunner.class) -public class GeoShapeDecimationSettingTest { +public class BooleanFeatureFlagClientTest { private static final String PROPERTY_NAME = "indexer-decimation-enabled"; @InjectMocks - private GeoShapeDecimationSetting sut; + private BooleanFeatureFlagClient sut; @Mock - private DecimationSettingCache cache; + private FeatureFlagCache cache; @Mock private JaxRsDpsLog logger; @@ -74,7 +75,12 @@ public class GeoShapeDecimationSettingTest { property.setValue("true"); partitionInfo.getProperties().put(PROPERTY_NAME, property); when(this.partitionProvider.get(anyString())).thenReturn(partitionInfo); - boolean enabled = sut.isDecimationEnabled(); + + // Default value won't take any effect + boolean enabled = sut.isEnabled(PROPERTY_NAME, true); + Assert.assertTrue(enabled); + + enabled = sut.isEnabled(PROPERTY_NAME, false); Assert.assertTrue(enabled); } @@ -86,25 +92,36 @@ public class GeoShapeDecimationSettingTest { property.setValue("false"); partitionInfo.getProperties().put(PROPERTY_NAME, property); when(this.partitionProvider.get(anyString())).thenReturn(partitionInfo); - boolean enabled = sut.isDecimationEnabled(); + + // Default value won't take any effect + boolean enabled = sut.isEnabled(PROPERTY_NAME, true); + Assert.assertFalse(enabled); + + enabled = sut.isEnabled(PROPERTY_NAME, false); Assert.assertFalse(enabled); } @Test - public void isDecimationEnabled_return_true_when_property_does_not_exist() throws PartitionException { + public void isDecimationEnabled_return_default_value_when_property_does_not_exist() throws PartitionException { // The feature flag is enabled by default PartitionInfo partitionInfo = new PartitionInfo(); when(this.partitionProvider.get(anyString())).thenReturn(partitionInfo); - boolean enabled = sut.isDecimationEnabled(); + boolean enabled = sut.isEnabled(PROPERTY_NAME, true);; Assert.assertTrue(enabled); + + enabled = sut.isEnabled(PROPERTY_NAME, false);; + Assert.assertFalse(enabled); } @Test - public void isDecimationEnabled_return_true_when_partitionProvider_throws_exception() throws PartitionException { + public void isDecimationEnabled_return_default_value_when_partitionProvider_throws_exception() throws PartitionException { // The feature flag is enabled by default when(this.partitionProvider.get(anyString())).thenThrow(PartitionException.class); - boolean enabled = sut.isDecimationEnabled(); + boolean enabled = sut.isEnabled(PROPERTY_NAME, true);; Assert.assertTrue(enabled); + + enabled = sut.isEnabled(PROPERTY_NAME, false);; + Assert.assertFalse(enabled); } } diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/util/geo/decimator/DecimationSettingCacheTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/util/geo/decimator/DecimationSettingCacheTest.java index e850126fe2880d457bd3fcd15ede9e0953b1d779..c32159b5e1186cefa6f72e4bc478d4095aa97bc9 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/util/geo/decimator/DecimationSettingCacheTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/util/geo/decimator/DecimationSettingCacheTest.java @@ -25,11 +25,11 @@ import org.springframework.test.context.junit4.SpringRunner; public class DecimationSettingCacheTest { private static final String VALID_KEY = "Tenant1-indexer-decimation-enabled"; private static final String INVALID_KEY = "Tenant2-indexer-decimation-enabled"; - DecimationSettingCache cache; + FeatureFlagCache cache; @Before public void setup() { - cache = new DecimationSettingCache(); + cache = new FeatureFlagCache(); cache.put(VALID_KEY, true); }