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

Do not serialize optimize-queries option in MapConfig #16524

Merged
merged 5 commits into from Jan 24, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -876,7 +876,6 @@ private static void mapConfigXmlGenerator(XmlGenerator gen, Config config) {
gen.open("map", "name", m.getName())
.node("in-memory-format", m.getInMemoryFormat())
.node("statistics-enabled", m.isStatisticsEnabled())
.node("optimize-queries", m.isOptimizeQueries())
.node("cache-deserialized-values", cacheDeserializedVal)
.node("backup-count", m.getBackupCount())
.node("async-backup-count", m.getAsyncBackupCount())
Expand Down
56 changes: 28 additions & 28 deletions hazelcast/src/main/java/com/hazelcast/config/MapConfig.java
Expand Up @@ -819,16 +819,17 @@ public MapConfig setOptimizeQueries(boolean optimizeQueries) {
}

private void validateSetOptimizeQueriesOption(boolean optimizeQueries) {
if (setCacheDeserializedValuesExplicitlyInvoked) {
if (optimizeQueries && cacheDeserializedValues == CacheDeserializedValues.NEVER) {
throw new ConfigurationException("Deprecated option 'optimize-queries' is set to true, "
+ "but 'cacheDeserializedValues' is set to NEVER. "
+ "These are conflicting options. Please remove the `optimize-queries'");
} else if (!optimizeQueries && cacheDeserializedValues == CacheDeserializedValues.ALWAYS) {
throw new ConfigurationException("Deprecated option 'optimize-queries' is set to false, "
+ "but 'cacheDeserializedValues' is set to ALWAYS. "
+ "These are conflicting options. Please remove the `optimize-queries'");
}
if (!setCacheDeserializedValuesExplicitlyInvoked) {
return;
}
if (cacheDeserializedValues != CacheDeserializedValues.ALWAYS && optimizeQueries) {
throw new ConfigurationException("Deprecated option 'optimize-queries' is being set to true, "
+ "but 'cacheDeserializedValues' was set to NEVER or INDEX_ONLY. "
+ "These are conflicting options. Please remove the `optimize-queries'");
} else if (cacheDeserializedValues == CacheDeserializedValues.ALWAYS && !optimizeQueries) {
throw new ConfigurationException("Deprecated option 'optimize-queries' is being set to false, "
+ "but 'cacheDeserializedValues' was set to ALWAYS. "
+ "These are conflicting options. Please remove the `optimize-queries'");
}
}

Expand All @@ -847,24 +848,23 @@ public MapConfig setCacheDeserializedValues(CacheDeserializedValues cacheDeseria
return this;
}

private void validateCacheDeserializedValuesOption(CacheDeserializedValues validatedCacheDeserializedValues) {
if (optimizeQueryExplicitlyInvoked) {
// deprecated {@link #setOptimizeQueries(boolean)} was explicitly invoked
// we need to be strict with validation to detect conflicts
boolean optimizeQuerySet = (cacheDeserializedValues == CacheDeserializedValues.ALWAYS);
if (optimizeQuerySet && validatedCacheDeserializedValues == CacheDeserializedValues.NEVER) {
throw new ConfigurationException("Deprecated option 'optimize-queries' is set to `true`, "
+ "but 'cacheDeserializedValues' is set to NEVER. These are conflicting options. "
+ "Please remove the `optimize-queries'");
}

if (cacheDeserializedValues != validatedCacheDeserializedValues) {
boolean optimizeQueriesFlagState = cacheDeserializedValues == CacheDeserializedValues.ALWAYS;
throw new ConfigurationException("Deprecated option 'optimize-queries' is set to "
+ optimizeQueriesFlagState + " but 'cacheDeserializedValues' is set to "
+ validatedCacheDeserializedValues + ". These are conflicting options. "
+ "Please remove the `optimize-queries'");
}
private void validateCacheDeserializedValuesOption(CacheDeserializedValues newValue) {
if (!optimizeQueryExplicitlyInvoked) {
return;
}

// deprecated {@link #setOptimizeQueries(boolean)} was explicitly invoked
// we need to be strict with validation to detect conflicts
boolean optimizeQueryFlag = (cacheDeserializedValues == CacheDeserializedValues.ALWAYS);

if (optimizeQueryFlag && newValue != CacheDeserializedValues.ALWAYS) {
throw new ConfigurationException("Deprecated option 'optimize-queries' is set to `true`, "
+ "but 'cacheDeserializedValues' is being set to NEVER or INDEX_ONLY."
+ " These are conflicting options. Please remove the `optimize-queries'");
} else if (!optimizeQueryFlag && newValue == CacheDeserializedValues.ALWAYS) {
throw new ConfigurationException("Deprecated option 'optimize-queries' is set to `false`, "
+ "but 'cacheDeserializedValues' is being set to ALWAYS. These are conflicting options."
+ " Please remove the `optimize-queries'");
}
}

Expand Down
Expand Up @@ -851,7 +851,6 @@ boolean check(MapConfig c1, MapConfig c2) {
&& nullSafeEqual(c1.getInMemoryFormat(), c2.getInMemoryFormat())
&& nullSafeEqual(c1.getMetadataPolicy(), c2.getMetadataPolicy())
&& nullSafeEqual(c1.isStatisticsEnabled(), c2.isStatisticsEnabled())
&& nullSafeEqual(c1.isOptimizeQueries(), c2.isOptimizeQueries())
&& nullSafeEqual(c1.getCacheDeserializedValues(), c2.getCacheDeserializedValues())
&& nullSafeEqual(c1.getBackupCount(), c2.getBackupCount())
&& nullSafeEqual(c1.getAsyncBackupCount(), c2.getAsyncBackupCount())
Expand Down
76 changes: 73 additions & 3 deletions hazelcast/src/test/java/com/hazelcast/config/MapConfigTest.java
Expand Up @@ -312,6 +312,46 @@ public void givenCacheDeserializedValuesSetToALWAYS_whenSetOptimizeQueriesToFals
mapConfig.setOptimizeQueries(false);
}

@Test
public void givenCacheDeserializedValuesSetToALWAYS_whenSetOptimizeQueriesToTrue_thenNoException() {
// given
MapConfig mapConfig = new MapConfig();
mapConfig.setCacheDeserializedValues(CacheDeserializedValues.ALWAYS);

// when
mapConfig.setOptimizeQueries(true);
}

@Test
public void givenCacheDeserializedValuesSetToINDEX_ONLY_whenSetOptimizeQueriesToFalse_thenNoException() {
cangencer marked this conversation as resolved.
Show resolved Hide resolved
// given
MapConfig mapConfig = new MapConfig();
mapConfig.setCacheDeserializedValues(CacheDeserializedValues.INDEX_ONLY);

// when
mapConfig.setOptimizeQueries(false);
}

@Test(expected = ConfigurationException.class)
public void givenCacheDeserializedValuesSetToINDEX_ONLY_whenSetOptimizeQueriesToTrue_thenThrowConfigurationException() {
// given
MapConfig mapConfig = new MapConfig();
mapConfig.setCacheDeserializedValues(CacheDeserializedValues.INDEX_ONLY);

// when
mapConfig.setOptimizeQueries(true);
}

@Test
public void givenCacheDeserializedValuesSetToNEVER_whenSetOptimizeQueriesToFalse_thenNoException() {
// given
MapConfig mapConfig = new MapConfig();
mapConfig.setCacheDeserializedValues(CacheDeserializedValues.NEVER);

// when
mapConfig.setOptimizeQueries(false);
}

@Test(expected = ConfigurationException.class)
public void givenCacheDeserializedValuesSetToNEVER_whenSetOptimizeQueriesToTrue_thenThrowConfigurationException() {
// given
Expand Down Expand Up @@ -371,16 +411,26 @@ public void givenCacheDeserializedValuesIsDefault_whenSetCacheDeserializedValues
assertFalse(optimizeQueries);
}

@Test(expected = ConfigurationException.class)
public void givenSetOptimizeQueryIsTrue_whenSetCacheDeserializedValuesToNEVER_thenThrowConfigurationException() {
@Test
public void givenSetOptimizeQueryIsFalse_whenSetCacheDeserializedValuesToNEVER_thenNoException() {
// given
MapConfig mapConfig = new MapConfig();
mapConfig.setOptimizeQueries(true);
mapConfig.setOptimizeQueries(false);

// when
mapConfig.setCacheDeserializedValues(CacheDeserializedValues.NEVER);
}

@Test
public void givenSetOptimizeQueryIsFalse_whenSetCacheDeserializedValuesToINDEX_ONLY_thenThrowNoException() {
// given
MapConfig mapConfig = new MapConfig();
mapConfig.setOptimizeQueries(false);

// when
mapConfig.setCacheDeserializedValues(CacheDeserializedValues.INDEX_ONLY);
}

@Test(expected = ConfigurationException.class)
public void givenSetOptimizeQueryIsFalse_whenSetCacheDeserializedValuesToALWAYS_thenThrowConfigurationException() {
// given
Expand All @@ -391,6 +441,16 @@ public void givenSetOptimizeQueryIsFalse_whenSetCacheDeserializedValuesToALWAYS_
mapConfig.setCacheDeserializedValues(CacheDeserializedValues.ALWAYS);
}

@Test(expected = ConfigurationException.class)
public void givenSetOptimizeQueryIsTrue_whenSetCacheDeserializedValuesToNEVER_thenThrowConfigurationException() {
// given
MapConfig mapConfig = new MapConfig();
mapConfig.setOptimizeQueries(true);

// when
mapConfig.setCacheDeserializedValues(CacheDeserializedValues.NEVER);
}

@Test(expected = ConfigurationException.class)
public void givenSetOptimizeQueryIsTrue_whenSetCacheDeserializedValuesToINDEX_ONLY_thenThrowConfigurationException() {
// given
Expand All @@ -401,6 +461,16 @@ public void givenSetOptimizeQueryIsTrue_whenSetCacheDeserializedValuesToINDEX_ON
mapConfig.setCacheDeserializedValues(CacheDeserializedValues.INDEX_ONLY);
}

@Test
public void givenSetOptimizeQueryIsTrue_whenSetCacheDeserializedValuesToALWAYS_thenNoException() {
// given
MapConfig mapConfig = new MapConfig();
mapConfig.setOptimizeQueries(true);

// when
mapConfig.setCacheDeserializedValues(CacheDeserializedValues.ALWAYS);
}

@Test
@Ignore(value = "this MapStoreConfig does not override equals/hashcode -> this cannot pass right now")
public void givenSetCacheDeserializedValuesIsINDEX_ONLY_whenComparedWithOtherConfigWhereCacheIsINDEX_ONLY_thenReturnTrue() {
Expand Down