public static class GraphManager.ManagedGraphProvider extends Object implements GraphProvider, AutoCloseable
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.GraphProvider.Descriptor, GraphProvider.TestListener
CORE_IMPLEMENTATIONS
Constructor and Description |
---|
ManagedGraphProvider(GraphProvider innerGraphProvider) |
Modifier and Type | Method and Description |
---|---|
void |
clear(Configuration configuration)
If possible (usually with persisted graph) clear the space on disk given the configuration that would be used
to construct the graph.
|
void |
clear(Graph graph,
Configuration configuration)
Clears a
Graph of all data and settings. |
void |
close() |
Object |
convertId(Object id,
Class<? extends Element> c)
Converts an identifier from a test to an identifier accepted by the
Graph instance. |
String |
convertLabel(String label)
Converts an label from a test to an label accepted by the Graph instance.
|
GraphComputer |
getGraphComputer(Graph graph)
Create a
GraphComputer from the Graph instance. |
Set<Class> |
getImplementations()
Get the set of concrete implementations of certain classes and interfaces utilized by the test suite.
|
Optional<Graph.Features> |
getStaticFeatures()
Gets a
Graph.Features implementation that contains graph feature configuration that will never change
from execution to execution of the tests given this current GraphProvider implementation. |
Optional<GraphProvider.TestListener> |
getTestListener()
Returns a
GraphProvider.TestListener implementation that provides feedback to the GraphProvider implementation. |
String |
getWorkingDirectory()
Helper method for those build
GraphProvider implementations that need a standard working directory
for tests (e.g. |
void |
loadGraphData(Graph graph,
LoadGraphWith loadGraphWith,
Class testClass,
String testName)
Tests are annotated with a
LoadGraphWith annotation. |
Configuration |
newGraphConfiguration(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.
|
Configuration |
newGraphConfiguration(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.
|
Graph |
openTestGraph(Configuration config)
|
Configuration |
standardGraphConfiguration(Class<?> test,
String testMethodName,
LoadGraphWith.GraphData loadGraphWith)
|
Graph |
standardTestGraph(Class<?> test,
String testMethodName,
LoadGraphWith.GraphData loadGraphWith)
Creates a new
Graph instance using the default
org.apache.commons.configuration.Configuration from
GraphProvider.standardGraphConfiguration(Class, String, LoadGraphWith.GraphData) . |
GraphTraversalSource |
traversal(Graph graph)
Create a
GraphTraversalSource from a Graph instance. |
GraphTraversalSource |
traversal(Graph graph,
TraversalStrategy... strategies)
Create a
GraphTraversalSource from a Graph instance. |
void |
tryClearGraphs() |
public ManagedGraphProvider(GraphProvider innerGraphProvider)
public void tryClearGraphs()
public String getWorkingDirectory()
GraphProvider
GraphProvider
implementations 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 the TestHelper
to produce the working directory as it will create the path in the appropriate build directories.getWorkingDirectory
in interface GraphProvider
public GraphTraversalSource traversal(Graph graph)
GraphProvider
GraphTraversalSource
from a Graph
instance. The default implementation does not
use GraphComputer
so providers should override as necessary if their implementation is testing
something that requires a different engine type, like GraphComputer
.traversal
in interface GraphProvider
public GraphTraversalSource traversal(Graph graph, TraversalStrategy... strategies)
GraphProvider
GraphTraversalSource
from a Graph
instance. The default implementation does not use
GraphComputer
so providers should override as necessary if their implementation is testing
something that requires a different engine type, like GraphComputer
.
Implementations should apply strategies as necessary to the
GraphTraversalSource
before calling it's create
method.traversal
in interface GraphProvider
public GraphComputer getGraphComputer(Graph graph)
GraphProvider
GraphComputer
from the Graph
instance. The default implementation simply calls graph.compute()
.getGraphComputer
in interface GraphProvider
graph
- the graph to get the graph computer frompublic Graph standardTestGraph(Class<?> test, String testMethodName, LoadGraphWith.GraphData loadGraphWith)
GraphProvider
Graph
instance using the default
org.apache.commons.configuration.Configuration
from
GraphProvider.standardGraphConfiguration(Class, String, LoadGraphWith.GraphData)
.standardTestGraph
in interface GraphProvider
public Graph openTestGraph(Configuration config)
GraphProvider
Graph
instance from the Configuration
object using GraphFactory
.
The assumption here is that the Configuration
has been created by one of the
GraphProvider.newGraphConfiguration(String, Class, String, LoadGraphWith.GraphData)
methods and has therefore
already been modified by the implementation as necessary for Graph
creation.openTestGraph
in interface GraphProvider
public Configuration standardGraphConfiguration(Class<?> test, String testMethodName, LoadGraphWith.GraphData loadGraphWith)
GraphProvider
Configuration
object that can construct a Graph
instance from GraphFactory
.
Note that this method should create a Graph
using the graphName
of "standard", meaning it
should always return a configuration instance that generates the same Graph
from the
GraphFactory
.standardGraphConfiguration
in interface GraphProvider
public void clear(Configuration configuration) throws Exception
GraphProvider
#clear(Graph, org.apache.commons.configuration.Configuration)
with
a null graph argument.
Implementations should be able to accept an argument of null for the org.apache.commons.configuration.Configuration
as well, and a proper handling is needed. Otherwise, a NullPointerException may be thrown.clear
in interface GraphProvider
Exception
public void clear(Graph graph, Configuration configuration) throws Exception
GraphProvider
Graph
of all data and settings. Implementations will have different ways of handling this.
It is typically expected that Graph.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 the Graph
, 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 the org.apache.commons.configuration.Configuration
as 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.clear
in interface GraphProvider
Exception
public Object convertId(Object id, Class<? extends Element> c)
GraphProvider
Graph
instance. 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.convertId
in interface GraphProvider
public String convertLabel(String label)
GraphProvider
convertLabel
in interface GraphProvider
public Configuration newGraphConfiguration(String graphName, Class<?> test, String testMethodName, Map<String,Object> configurationOverrides, LoadGraphWith.GraphData loadGraphWith)
GraphProvider
Configuration
that will generate a graph unique to that graphName
.newGraphConfiguration
in interface GraphProvider
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 loadedpublic Configuration newGraphConfiguration(String graphName, Class<?> test, String testMethodName, LoadGraphWith.GraphData loadGraphWith)
GraphProvider
Configuration
that will generate a graph unique to that graphName
.newGraphConfiguration
in interface GraphProvider
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 loadedpublic void loadGraphData(Graph graph, LoadGraphWith loadGraphWith, Class testClass, String testName)
GraphProvider
LoadGraphWith
annotation. 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
the Graph
implementation's API. Implementers can use the testClass
and testName
arguments to implement test specific configurations to their graphs.loadGraphData
in interface GraphProvider
graph
- the Graph
instance to load data into constructed by this GraphProvider
loadGraphWith
- 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 executedpublic Set<Class> getImplementations()
GraphProvider
Edge
Element
DefaultGraphTraversal
Graph
Graph.Variables
GraphTraversal
B_LP_O_P_S_SE_SL_Traverser
Property
B_O_S_SE_SL_Traverser
Traversal
Traverser
Vertex
VertexProperty
GraphProvider.CORE_IMPLEMENTATIONS
to the
Set
because these represent gremlin-core
implementations that are likely not registered
by the vendor implementations.getImplementations
in interface GraphProvider
public Optional<GraphProvider.TestListener> getTestListener()
GraphProvider
GraphProvider.TestListener
implementation that provides feedback to the GraphProvider
implementation.
By default, this returns an empty listener.getTestListener
in interface GraphProvider
public void close() throws Exception
close
in interface AutoCloseable
Exception
public Optional<Graph.Features> getStaticFeatures()
GraphProvider
Graph.Features
implementation that contains graph feature configuration that will never change
from execution to execution of the tests given this current GraphProvider
implementation. Implementing
this method will allow the test suite to avoid creation of a Graph
instance 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 the Graph
instance produced by this GraphProvider
can actually do or
else the cost of Graph
instantiation will be incurred when it doesn't need to be. It is also important
that this method be faster than the cost of Graph
creation 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
an UnsupportedOperationException
from those features to let the test suite know that it cannot rely
on them and the test suite will revert to using a constructed Graph
instance.getStaticFeatures
in interface GraphProvider
Copyright © 2013–2020 Apache Software Foundation. All rights reserved.