use of org.janusgraph.core.JanusGraphConfigurationException in project janusgraph by JanusGraph.
the class JanusGraphTest method testManagedOptionMasking.
@Test
public void testManagedOptionMasking() throws BackendException {
// Can't use clopen(...) for this test, because it's aware local vs global option types and
// uses ManagementSystem where necessary. We want to simulate an erroneous attempt to
// override global options by tweaking the local config file (ignoring ManagementSystem),
// so we have to bypass clopen(...).
// clopen(
// option(ALLOW_STALE_CONFIG), false,
// option(ATTRIBUTE_ALLOW_ALL_SERIALIZABLE), false);
// Check this test's assumptions about option default values
Duration customCommitTime = Duration.ofMillis(456L);
Preconditions.checkState(ALLOW_STALE_CONFIG.getDefaultValue());
Preconditions.checkState(ALLOW_STALE_CONFIG.getType().equals(ConfigOption.Type.MASKABLE));
Preconditions.checkState(!customCommitTime.equals(MAX_COMMIT_TIME.getDefaultValue()));
// Disallow managed option masking and verify exception at graph startup
close();
WriteConfiguration wc = getConfiguration();
wc.set(ConfigElement.getPath(ALLOW_STALE_CONFIG), false);
wc.set(ConfigElement.getPath(MAX_COMMIT_TIME), customCommitTime);
try {
graph = (StandardJanusGraph) JanusGraphFactory.open(wc);
fail("Masking managed config options should be disabled in this configuration");
} catch (JanusGraphConfigurationException e) {
// Exception should cite the problematic setting's full name
assertTrue(e.getMessage().contains(ConfigElement.getPath(MAX_COMMIT_TIME)));
}
// Allow managed option masking (default config again) and check that the local value is ignored and
// that no exception is thrown
close();
wc = getConfiguration();
wc.set(ConfigElement.getPath(ALLOW_STALE_CONFIG), true);
wc.set(ConfigElement.getPath(MAX_COMMIT_TIME), customCommitTime);
graph = (StandardJanusGraph) JanusGraphFactory.open(wc);
// Local value should be overridden by the default that already exists in the backend
assertEquals(MAX_COMMIT_TIME.getDefaultValue(), graph.getConfiguration().getMaxCommitTime());
// Wipe the storage backend
graph.getBackend().clearStorage();
try {
graph.close();
} catch (Throwable t) {
log.debug("Swallowing throwable during shutdown after clearing backend storage", t);
}
// Bootstrap a new DB with managed option masking disabled
wc = getConfiguration();
wc.set(ConfigElement.getPath(ALLOW_STALE_CONFIG), false);
graph = (StandardJanusGraph) JanusGraphFactory.open(wc);
close();
// Check for expected exception
wc = getConfiguration();
wc.set(ConfigElement.getPath(MAX_COMMIT_TIME), customCommitTime);
try {
graph = (StandardJanusGraph) JanusGraphFactory.open(wc);
fail("Masking managed config options should be disabled in this configuration");
} catch (JanusGraphConfigurationException e) {
// Exception should cite the problematic setting's full name
assertTrue(e.getMessage().contains(ConfigElement.getPath(MAX_COMMIT_TIME)));
}
// Now check that ALLOW_STALE_CONFIG is actually MASKABLE -- enable it in the local config
wc = getConfiguration();
wc.set(ConfigElement.getPath(ALLOW_STALE_CONFIG), true);
wc.set(ConfigElement.getPath(MAX_COMMIT_TIME), customCommitTime);
graph = (StandardJanusGraph) JanusGraphFactory.open(wc);
// Local value should be overridden by the default that already exists in the backend
assertEquals(MAX_COMMIT_TIME.getDefaultValue(), graph.getConfiguration().getMaxCommitTime());
}
Aggregations