forked from JanusGraph/janusgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ConfigurationManagementGraph to throw Exception with custom ID setting
Fixes JanusGraph#4535 Signed-off-by: Boxuan Li <[email protected]>
- Loading branch information
Showing
3 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...org/janusgraph/graphdb/management/utils/ConfigurationManagementGraphSettingException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2024 JanusGraph Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
|
||
package org.janusgraph.graphdb.management.utils; | ||
|
||
public class ConfigurationManagementGraphSettingException extends RuntimeException { | ||
public ConfigurationManagementGraphSettingException(String message) { | ||
super(message); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...ph-inmemory/src/test/java/org/janusgraph/core/inmemory/MisconfiguredGraphFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright 2024 JanusGraph Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package org.janusgraph.core.inmemory; | ||
|
||
import org.apache.commons.configuration2.MapConfiguration; | ||
import org.apache.tinkerpop.gremlin.server.Settings; | ||
import org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration; | ||
import org.janusgraph.graphdb.configuration.builder.GraphDatabaseConfigurationBuilder; | ||
import org.janusgraph.graphdb.database.StandardJanusGraph; | ||
import org.janusgraph.graphdb.management.ConfigurationManagementGraph; | ||
import org.janusgraph.graphdb.management.JanusGraphManager; | ||
import org.janusgraph.graphdb.management.utils.ConfigurationManagementGraphSettingException; | ||
import org.janusgraph.util.system.ConfigurationUtil; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.ALLOW_CUSTOM_VERTEX_ID_TYPES; | ||
import static org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.ALLOW_SETTING_VERTEX_ID; | ||
import static org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.STORAGE_BACKEND; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
/** | ||
* This class is dedicated to test a common configuration error people consistently make | ||
* when they aim to use ConfiguredGraphFactory: their management graph config contains | ||
* `graph.set-vertex-id=true` which leads to runtime error because ConfigurationManagementGraph | ||
* is managed by JanusGraph internally and doesn't support custom ID | ||
*/ | ||
public class MisconfiguredGraphFactoryTest { | ||
|
||
private static JanusGraphManager gm; | ||
|
||
protected MapConfiguration getManagementConfig() { | ||
final Map<String, Object> map = new HashMap<>(); | ||
map.put(STORAGE_BACKEND.toStringWithoutRoot(), "inmemory"); | ||
|
||
// management graph config is not allowed to use custom vertex id | ||
map.put(ALLOW_SETTING_VERTEX_ID.toStringWithoutRoot(), "true"); | ||
map.put(ALLOW_CUSTOM_VERTEX_ID_TYPES.toStringWithoutRoot(), "true"); | ||
return ConfigurationUtil.loadMapConfiguration(map); | ||
} | ||
|
||
@Test | ||
public void shouldRejectInvalidConfig() throws Exception { | ||
gm = new JanusGraphManager(new Settings()); | ||
final MapConfiguration config = getManagementConfig(); | ||
final StandardJanusGraph graph = new StandardJanusGraph(new GraphDatabaseConfigurationBuilder().build(new CommonsConfiguration(config))); | ||
|
||
// Cannot instantiate the ConfigurationManagementGraph Singleton because custom vertex ID is not allowed | ||
assertThrows(ConfigurationManagementGraphSettingException.class, () -> new ConfigurationManagementGraph(graph)); | ||
} | ||
} | ||
|