Package org.apache.tinkerpop.gremlin
Class GraphManager.ManagedGraphProvider
java.lang.Object
org.apache.tinkerpop.gremlin.GraphManager.ManagedGraphProvider
- All Implemented Interfaces:
AutoCloseable,GraphProvider
- Enclosing class:
- GraphManager
public static class GraphManager.ManagedGraphProvider
extends Object
implements GraphProvider, AutoCloseable
This class provides a way to intercepts calls to
Graph implementation's GraphProvider instances.
When openTestGraph(Configuration) is called the created object is stored in a list and when tests are
complete the tryClearGraphs() is called. When this is called, an attempt is made to close all open graphs.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.tinkerpop.gremlin.GraphProvider
GraphProvider.Descriptor, GraphProvider.TestListener -
Field Summary
Fields inherited from interface org.apache.tinkerpop.gremlin.GraphProvider
CORE_IMPLEMENTATIONS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear(org.apache.commons.configuration2.Configuration configuration) If possible (usually with persisted graph) clear the space on disk given the configuration that would be used to construct the graph.voidClears aGraphof all data and settings.voidclose()Converts an identifier from a test to an identifier accepted by theGraphinstance.convertLabel(String label) Converts an label from a test to an label accepted by the Graph instance.getGraphComputer(Graph graph) Create aGraphComputerfrom theGraphinstance.Get the set of concrete implementations of certain classes and interfaces utilized by the test suite.Gets aGraph.Featuresimplementation that contains graph feature configuration that will never change from execution to execution of the tests given this currentGraphProviderimplementation.Returns aGraphProvider.TestListenerimplementation that provides feedback to theGraphProviderimplementation.Helper method for those buildGraphProviderimplementations that need a standard working directory for tests (e.g.voidloadGraphData(Graph graph, LoadGraphWith loadGraphWith, Class testClass, String testName) Tests are annotated with aLoadGraphWithannotation.org.apache.commons.configuration2.ConfigurationnewGraphConfiguration(String graphName, Class<?> test, String testMethodName, Map<String, Object> configurationOverrides, LoadGraphWith.GraphData loadGraphWith) When implementing this method ensure that a test suite can override any settings EXCEPT the "gremlin.graph" setting which should be defined by the implementer.org.apache.commons.configuration2.ConfigurationnewGraphConfiguration(String graphName, Class<?> test, String testMethodName, LoadGraphWith.GraphData loadGraphWith) When implementing this method ensure that a test suite can override any settings EXCEPT the "gremlin.graph" setting which should be defined by the implementer.openTestGraph(org.apache.commons.configuration2.Configuration config) org.apache.commons.configuration2.ConfigurationstandardGraphConfiguration(Class<?> test, String testMethodName, LoadGraphWith.GraphData loadGraphWith) standardTestGraph(Class<?> test, String testMethodName, LoadGraphWith.GraphData loadGraphWith) Creates a newGraphinstance using the defaultConfigurationfromGraphProvider.standardGraphConfiguration(Class, String, LoadGraphWith.GraphData).Create aGraphTraversalSourcefrom aGraphinstance.traversal(Graph graph, TraversalStrategy... strategies) Create aGraphTraversalSourcefrom aGraphinstance.void
-
Constructor Details
-
ManagedGraphProvider
-
-
Method Details
-
tryClearGraphs
public void tryClearGraphs() -
getWorkingDirectory
Description copied from interface:GraphProviderHelper method for those buildGraphProviderimplementations that need a standard working directory for tests (e.g. graphs that persist data to disk). Typically, there is no need to override the default behavior of this method and if it is overridden, it is usually best to continue to use theTestHelperto produce the working directory as it will create the path in the appropriate build directories.- Specified by:
getWorkingDirectoryin interfaceGraphProvider- Returns:
- UNIX-formatted absolute directory path
-
traversal
Description copied from interface:GraphProviderCreate aGraphTraversalSourcefrom aGraphinstance. The default implementation does not useGraphComputerso providers should override as necessary if their implementation is testing something that requires a different engine type, likeGraphComputer.- Specified by:
traversalin interfaceGraphProvider
-
traversal
Description copied from interface:GraphProviderCreate aGraphTraversalSourcefrom aGraphinstance. The default implementation does not useGraphComputerso providers should override as necessary if their implementation is testing something that requires a different engine type, likeGraphComputer. Implementations should apply strategies as necessary to theGraphTraversalSourcebefore calling it'screatemethod.- Specified by:
traversalin interfaceGraphProvider
-
getGraphComputer
Description copied from interface:GraphProviderCreate aGraphComputerfrom theGraphinstance. The default implementation simply callsgraph.compute().- Specified by:
getGraphComputerin interfaceGraphProvider- Parameters:
graph- the graph to get the graph computer from- Returns:
- a new graph computer
-
standardTestGraph
public Graph standardTestGraph(Class<?> test, String testMethodName, LoadGraphWith.GraphData loadGraphWith) Description copied from interface:GraphProviderCreates a newGraphinstance using the defaultConfigurationfromGraphProvider.standardGraphConfiguration(Class, String, LoadGraphWith.GraphData).- Specified by:
standardTestGraphin interfaceGraphProvider
-
openTestGraph
Description copied from interface:GraphProviderCreates a newGraphinstance from theConfigurationobject usingGraphFactory. The assumption here is that theConfigurationhas been created by one of theGraphProvider.newGraphConfiguration(String, Class, String, LoadGraphWith.GraphData)methods and has therefore already been modified by the implementation as necessary forGraphcreation.- Specified by:
openTestGraphin interfaceGraphProvider
-
standardGraphConfiguration
public org.apache.commons.configuration2.Configuration standardGraphConfiguration(Class<?> test, String testMethodName, LoadGraphWith.GraphData loadGraphWith) Description copied from interface:GraphProviderGets theConfigurationobject that can construct aGraphinstance fromGraphFactory. Note that this method should create aGraphusing thegraphNameof "standard", meaning it should always return a configuration instance that generates the sameGraphfrom theGraphFactory.- Specified by:
standardGraphConfigurationin interfaceGraphProvider
-
clear
Description copied from interface:GraphProviderIf possible (usually with persisted graph) clear the space on disk given the configuration that would be used to construct the graph. The default implementation simply callsGraphProvider.clear(Graph, Configuration)with a null graph argument. Implementations should be able to accept an argument of null for theConfigurationas well, and a proper handling is needed. Otherwise, a NullPointerException may be thrown.- Specified by:
clearin interfaceGraphProvider- Throws:
Exception
-
clear
public void clear(Graph graph, org.apache.commons.configuration2.Configuration configuration) throws Exception Description copied from interface:GraphProviderClears aGraphof all data and settings. Implementations will have different ways of handling this. It is typically expected thatGraph.close()will be called and open transactions will be closed. For a brute force approach, implementers can simply delete data directories provided in the configuration. Implementers may choose a more elegant approach if it exists. Implementations should be able to accept an argument of null for theGraph, in which case the only action that can be performed is a clear given the configuration. The method will typically be called this way as clean up task on setup to ensure that a persisted graph has a clear space to create a test graph. Implementations should be able to accept an argument of null for theConfigurationas well, and a proper handling is needed. Otherwise, a NullPointerException may be thrown. Calls to this method may occur multiple times for a specific test. Develop this method to be idempotent.- Specified by:
clearin interfaceGraphProvider- Throws:
Exception
-
convertId
Description copied from interface:GraphProviderConverts an identifier from a test to an identifier accepted by theGraphinstance. Test that try to utilize an Element identifier will pass it to this method before usage. This method should be sure to be consistent in the return value such that calling it with "x" should always return the same transformed value.- Specified by:
convertIdin interfaceGraphProvider
-
convertLabel
Description copied from interface:GraphProviderConverts an label from a test to an label accepted by the Graph instance. Test that try to utilize a label will pass it to this method before usage.- Specified by:
convertLabelin interfaceGraphProvider
-
newGraphConfiguration
public org.apache.commons.configuration2.Configuration newGraphConfiguration(String graphName, Class<?> test, String testMethodName, Map<String, Object> configurationOverrides, LoadGraphWith.GraphData loadGraphWith) Description copied from interface:GraphProviderWhen implementing this method ensure that a test suite can override any settings EXCEPT the "gremlin.graph" setting which should be defined by the implementer. It should provide aConfigurationthat will generate a graph unique to thatgraphName.- Specified by:
newGraphConfigurationin interfaceGraphProvider- Parameters:
graphName- a unique test graph nametest- the test classtestMethodName- the name of the testconfigurationOverrides- settings to override defaults with.loadGraphWith- the data set to load and will be null if no data is to be loaded
-
newGraphConfiguration
public org.apache.commons.configuration2.Configuration newGraphConfiguration(String graphName, Class<?> test, String testMethodName, LoadGraphWith.GraphData loadGraphWith) Description copied from interface:GraphProviderWhen implementing this method ensure that a test suite can override any settings EXCEPT the "gremlin.graph" setting which should be defined by the implementer. It should provide aConfigurationthat will generate a graph unique to thatgraphName.- Specified by:
newGraphConfigurationin interfaceGraphProvider- Parameters:
graphName- a unique test graph nametest- the test classtestMethodName- the name of the testloadGraphWith- the data set to load and will be null if no data is to be loaded
-
loadGraphData
public void loadGraphData(Graph graph, LoadGraphWith loadGraphWith, Class testClass, String testName) Description copied from interface:GraphProviderTests are annotated with aLoadGraphWithannotation. These annotations tell the test what kind of data to preload into the graph instance. It is up to the implementation to load the graph with the data specified by that annotation. This method also represents the place where indices should be configured according the theGraphimplementation's API. Implementers can use thetestClassandtestNamearguments to implement test specific configurations to their graphs.- Specified by:
loadGraphDatain interfaceGraphProvider- Parameters:
graph- theGraphinstance to load data into constructed by thisGraphProviderloadGraphWith- the annotation for the currently running test - this value may be null if no graph data is to be loaded in front of the test.testClass- the test class being executedtestName- the name of the test method being executed
-
getImplementations
Description copied from interface:GraphProviderGet the set of concrete implementations of certain classes and interfaces utilized by the test suite. This method should return any implementations or extensions of the following interfaces or classes:EdgeElementDefaultGraphTraversalGraphGraph.VariablesGraphTraversalB_LP_O_P_S_SE_SL_TraverserPropertyB_O_S_SE_SL_TraverserTraversalTraverserVertexVertexProperty
GraphProvider.CORE_IMPLEMENTATIONSto theSetbecause these representgremlin-coreimplementations that are likely not registered by the vendor implementations.- Specified by:
getImplementationsin interfaceGraphProvider
-
getTestListener
Description copied from interface:GraphProviderReturns aGraphProvider.TestListenerimplementation that provides feedback to theGraphProviderimplementation. By default, this returns an empty listener.- Specified by:
getTestListenerin interfaceGraphProvider
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
getStaticFeatures
Description copied from interface:GraphProviderGets aGraph.Featuresimplementation that contains graph feature configuration that will never change from execution to execution of the tests given this currentGraphProviderimplementation. Implementing this method will allow the test suite to avoid creation of aGraphinstance and thus speed up the execution of tests if that creation process is expensive. It is important that this static set of features be representative of what theGraphinstance produced by thisGraphProvidercan actually do or else the cost ofGraphinstantiation will be incurred when it doesn't need to be. It is also important that this method be faster than the cost ofGraphcreation in the first place or there really won't be any difference in execution speed. In cases where some features are static and others are not, simply throw anUnsupportedOperationExceptionfrom those features to let the test suite know that it cannot rely on them and the test suite will revert to using a constructedGraphinstance.- Specified by:
getStaticFeaturesin interfaceGraphProvider
-