Skip to content

Commit

Permalink
DGS-9162: Address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
akhileshm1 committed Dec 8, 2023
1 parent 6b468ab commit 3bc36b7
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 32 deletions.
Expand Up @@ -63,7 +63,7 @@ public class MockSchemaRegistryClient implements SchemaRegistryClient {

private static final String WILDCARD = "*";

private Config defaultConfig = new Config("BACKWARD", true);
private Config defaultConfig = new Config("BACKWARD");
private final Map<String, Map<ParsedSchema, Integer>> schemaToIdCache;
private final Map<String, Map<ParsedSchema, Integer>> registeredSchemaCache;
private final Map<String, Map<Integer, ParsedSchema>> idToSchemaCache;
Expand Down
Expand Up @@ -66,12 +66,6 @@ public Config(@JsonProperty("compatibilityLevel") String compatibilityLevel) {
this.compatibilityLevel = compatibilityLevel;
}

public Config(@JsonProperty("compatibilityLevel") String compatibilityLevel,
@JsonProperty("validateFields") Boolean validateFields) {
this.compatibilityLevel = compatibilityLevel;
this.validateFields = validateFields;
}

public Config() {
}

Expand Down
Expand Up @@ -235,9 +235,6 @@ public ConfigUpdateRequest updateTopLevelConfig(
throw new RestInvalidRuleSetException(e.getMessage());
}
}
if (request.isValidateFields() == null) {
request.setValidateFields(schemaRegistry.isDefaultValidateFields());
}
try {
Map<String, String> headerProperties = requestHeaderBuilder.buildRequestHeaders(
headers, schemaRegistry.config().whitelistHeaders());
Expand Down
Expand Up @@ -1994,9 +1994,7 @@ public String getGroupId() {
public Config getConfig(String subject)
throws SchemaRegistryStoreException {
try {
return lookupCache.config(subject,
false,
new Config(defaultCompatibilityLevel.name, defaultValidateFields));
return lookupCache.config(subject, false, new Config(defaultCompatibilityLevel.name));
} catch (StoreException e) {
throw new SchemaRegistryStoreException("Failed to write new config value to the store", e);
}
Expand All @@ -2005,9 +2003,7 @@ public Config getConfig(String subject)
public Config getConfigInScope(String subject)
throws SchemaRegistryStoreException {
try {
return lookupCache.config(subject,
true,
new Config(defaultCompatibilityLevel.name, defaultValidateFields));
return lookupCache.config(subject, true, new Config(defaultCompatibilityLevel.name));
} catch (StoreException e) {
throw new SchemaRegistryStoreException("Failed to write new config value to the store", e);
}
Expand Down Expand Up @@ -2339,13 +2335,8 @@ public HostnameVerifier getHostnameVerifier() throws SchemaRegistryStoreExceptio
+ " not supported");
}

public boolean isDefaultValidateFields() {
return defaultValidateFields;
}


private static boolean isSchemaFieldValidationEnabled(Config config) {
return config.isValidateFields() != null ? config.isValidateFields() : false;
private boolean isSchemaFieldValidationEnabled(Config config) {
return config.isValidateFields() != null ? config.isValidateFields() : defaultValidateFields;
}

private static class RawSchema {
Expand Down
Expand Up @@ -106,17 +106,13 @@ public interface LookupCache<K,V> extends Store<K,V> {
* @param subject the subject
* @param returnTopLevelIfNotFound whether to return the top level scope if not found
* @param defaultForTopLevel default value for the top level scope
* @param defaultForValidateFields default value for the top level scope
* @return the compatibility level if found, otherwise null
*/
default CompatibilityLevel compatibilityLevel(String subject,
boolean returnTopLevelIfNotFound,
CompatibilityLevel defaultForTopLevel,
boolean defaultForValidateFields)
CompatibilityLevel defaultForTopLevel)
throws StoreException {
Config config = config(subject,
returnTopLevelIfNotFound,
new Config(defaultForTopLevel.name, defaultForValidateFields));
Config config = config(subject, returnTopLevelIfNotFound, new Config(defaultForTopLevel.name));
return CompatibilityLevel.forName(config.getCompatibilityLevel());
}

Expand Down
Expand Up @@ -189,7 +189,7 @@ public void testCompatibilityLevelChangeToBackward() throws Exception {
restApp.restClient.registerSchema(schemaString1, subject));
// verify that default compatibility level is backward
assertEquals("Default compatibility level should be backward",
new Config(CompatibilityLevel.BACKWARD.name, false),
new Config(CompatibilityLevel.BACKWARD.name),
restApp.restClient.getConfig(null));
// change it to forward
assertEquals("Changing compatibility level should succeed",
Expand All @@ -200,7 +200,7 @@ public void testCompatibilityLevelChangeToBackward() throws Exception {

// verify that new compatibility level is forward
assertEquals("New compatibility level should be forward",
new Config(CompatibilityLevel.FORWARD.name, false),
new Config(CompatibilityLevel.FORWARD.name),
restApp.restClient.getConfig(null));

// register schema that is forward compatible with schemaString1
Expand All @@ -222,7 +222,7 @@ public void testCompatibilityLevelChangeToBackward() throws Exception {

// verify that new compatibility level is backward
assertEquals("Updated compatibility level should be backward",
new Config(CompatibilityLevel.BACKWARD.name, false),
new Config(CompatibilityLevel.BACKWARD.name),
restApp.restClient.getConfig(null));

// register forward compatible schema, which should fail
Expand Down

0 comments on commit 3bc36b7

Please sign in to comment.