Skip to content

Commit

Permalink
Add javadocs to various places.
Browse files Browse the repository at this point in the history
  • Loading branch information
fickludd committed Nov 9, 2017
1 parent 9601398 commit 607308d
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 16 deletions.
Expand Up @@ -26,27 +26,93 @@
*/ */
public interface Write public interface Write
{ {
/**
* Create a node.
* @return The internal id of the created node
*/
long nodeCreate(); long nodeCreate();


/**
* Delete a node.
* @param node the internal id of the node to delete
*/
void nodeDelete( long node ); void nodeDelete( long node );


/**
* Create a relationship between two nodes.
* @param sourceNode the source internal node id
* @param relationshipLabel the label of the relationship to create
* @param targetNode the target internal node id
* @return the internal id of the created relationship
*/
long relationshipCreate( long sourceNode, int relationshipLabel, long targetNode ); long relationshipCreate( long sourceNode, int relationshipLabel, long targetNode );


/**
* Delete a relationship
* @param relationship the internal id of the relationship to delete
*/
void relationshipDelete( long relationship ); void relationshipDelete( long relationship );


/**
* Add a label to a node
* @param node the internal node id
* @param nodeLabel the internal id of the label to add
*/
void nodeAddLabel( long node, int nodeLabel ); void nodeAddLabel( long node, int nodeLabel );


/**
* Remove a label from a node
* @param node the internal node id
* @param nodeLabel the internal id of the label to remove
*/
void nodeRemoveLabel( long node, int nodeLabel ); void nodeRemoveLabel( long node, int nodeLabel );


/**
* Set a property on a node
* @param node the internal node id
* @param propertyKey the property key id
* @param value the value to set
* @return The replaced value, or Values.NO_VALUE if the node did not have the property before
*/
Value nodeSetProperty( long node, int propertyKey, Value value ); Value nodeSetProperty( long node, int propertyKey, Value value );


/**
* Remove a property from a node
* @param node the internal node id
* @param propertyKey the property key id
* @return The removed value, or Values.NO_VALUE if the node did not have the property before
*/
Value nodeRemoveProperty( long node, int propertyKey ); Value nodeRemoveProperty( long node, int propertyKey );


/**
* Set a property on a relationship
* @param relationship the internal relationship id
* @param propertyKey the property key id
* @param value the value to set
* @return The replaced value, or Values.NO_VALUE if the relationship did not have the property before
*/
Value relationshipSetProperty( long relationship, int propertyKey, Value value ); Value relationshipSetProperty( long relationship, int propertyKey, Value value );


/**
* Remove a property from a relationship
* @param node the internal relationship id
* @param propertyKey the property key id
* @return The removed value, or Values.NO_VALUE if the relationship did not have the property before
*/
Value relationshipRemoveProperty( long node, int propertyKey ); Value relationshipRemoveProperty( long node, int propertyKey );


/**
* Set a property on the graph
* @param propertyKey the property key id
* @param value the value to set
* @return The replaced value, or Values.NO_VALUE if the graph did not have the property before
*/
Value graphSetProperty( int propertyKey, Value value ); Value graphSetProperty( int propertyKey, Value value );


/**
* Remove a property from the graph
* @param propertyKey the property key id
* @return The removed value, or Values.NO_VALUE if the graph did not have the property before
*/
Value graphRemoveProperty( int propertyKey ); Value graphRemoveProperty( int propertyKey );
} }
Expand Up @@ -28,8 +28,19 @@


import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.GraphDatabaseService;


/**
* KernelAPIReadTestBase is the basis of read tests targeting the Kernel API.
*
* As tests are packaged together with the API, they cannot provide all the functionality needed to construct the
* test graph, or provide the concrete Kernel to test. These things are abstracted behind the
* KernelAPIReadTestSupport interface, which needs to be implemented to test reading Kernel implementations.
*
* As read tests do not modify the graph, the test graph is created lazily on the first test run.
*
* @param <ReadSupport> The test support for the current test.
*/
@SuppressWarnings( "WeakerAccess" ) @SuppressWarnings( "WeakerAccess" )
public abstract class KernelAPIReadTestBase<G extends KernelAPIReadTestSupport> public abstract class KernelAPIReadTestBase<ReadSupport extends KernelAPIReadTestSupport>
{ {
protected static final TemporaryFolder folder = new TemporaryFolder(); protected static final TemporaryFolder folder = new TemporaryFolder();
protected static KernelAPIReadTestSupport testSupport; protected static KernelAPIReadTestSupport testSupport;
Expand All @@ -42,9 +53,9 @@ public abstract class KernelAPIReadTestBase<G extends KernelAPIReadTestSupport>
protected Token token; protected Token token;


/** /**
* Creates a new instance of KernelAPITestSupport, which will be used to execute the concrete test * Creates a new instance of KernelAPIReadTestSupport, which will be used to execute the concrete test
*/ */
public abstract G newTestSupport(); public abstract ReadSupport newTestSupport();


/** /**
* Create the graph which all test in the class will be executed against. The graph is only built once, * Create the graph which all test in the class will be executed against. The graph is only built once,
Expand All @@ -65,7 +76,6 @@ public void setupGraph() throws IOException
} }
Kernel kernel = testSupport.kernelToTest(); Kernel kernel = testSupport.kernelToTest();
session = kernel.beginSession( PermissionsFixture.allPermissions() ); session = kernel.beginSession( PermissionsFixture.allPermissions() );
testSupport.beforeEachTest();
cursors = kernel.cursors(); cursors = kernel.cursors();
tx = session.beginTransaction(); tx = session.beginTransaction();
token = session.token(); token = session.token();
Expand Down
Expand Up @@ -25,13 +25,30 @@


import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.GraphDatabaseService;


/**
* This interface defines the functionality that's needed to run Kernel API Read tests (tests that extends
* KernelAPIReadTestBase) on a Kernel.
*/
public interface KernelAPIReadTestSupport public interface KernelAPIReadTestSupport
{ {
/**
* Setup the test. Called once. Starts a Kernel in the provided store directory, and populates the graph using
* the provided create method.
*
* @param storeDir The directory in which to create the database.
* @param create Method which populates the database.
* @throws IOException If database creation failed due to IO problems.
*/
void setup( File storeDir, Consumer<GraphDatabaseService> create ) throws IOException; void setup( File storeDir, Consumer<GraphDatabaseService> create ) throws IOException;


void beforeEachTest(); /**

* The Kernel to test. Called before every test.
* @return The Kernel.
*/
Kernel kernelToTest(); Kernel kernelToTest();


/**
* Teardown the Kernel and any other resources once all tests have completed.
*/
void tearDown(); void tearDown();
} }
Expand Up @@ -28,8 +28,19 @@


import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.GraphDatabaseService;


/**
* KernelAPIWriteTestBase is the basis of write tests targeting the Kernel API.
*
* Just as with KernelAPIReadTestBase, write tests cannot provide all the functionality needed to construct the
* test kernel, and also do not know how to assert the effects of the writes. These things are abstracted behind the
* KernelAPIWriteTestSupport interface, which needs to be implemented to test Kernel write implementations.
*
* Since write tests modify the graph, the test graph is recreated on every test run.
*
* @param <WriteSupport> The test support for the current test.
*/
@SuppressWarnings( "WeakerAccess" ) @SuppressWarnings( "WeakerAccess" )
public abstract class KernelAPIWriteTestBase<G extends KernelAPIWriteTestSupport> public abstract class KernelAPIWriteTestBase<WriteSupport extends KernelAPIWriteTestSupport>
{ {
protected static final TemporaryFolder folder = new TemporaryFolder(); protected static final TemporaryFolder folder = new TemporaryFolder();
protected static KernelAPIWriteTestSupport testSupport; protected static KernelAPIWriteTestSupport testSupport;
Expand All @@ -38,9 +49,9 @@ public abstract class KernelAPIWriteTestBase<G extends KernelAPIWriteTestSupport
protected static GraphDatabaseService graphDb; protected static GraphDatabaseService graphDb;


/** /**
* Creates a new instance of KernelAPITestSupport, which will be used to execute the concrete test * Creates a new instance of WriteSupport, which will be used to execute the concrete test
*/ */
public abstract G newTestSupport(); public abstract WriteSupport newTestSupport();


@Before @Before
public void setupGraph() throws IOException public void setupGraph() throws IOException
Expand All @@ -52,7 +63,7 @@ public void setupGraph() throws IOException
testSupport.setup( folder.getRoot() ); testSupport.setup( folder.getRoot() );
graphDb = testSupport.graphBackdoor(); graphDb = testSupport.graphBackdoor();
} }
testSupport.beforeEachTest(); testSupport.clearGraph();
Kernel kernel = testSupport.kernelToTest(); Kernel kernel = testSupport.kernelToTest();
session = kernel.beginSession( PermissionsFixture.allPermissions() ); session = kernel.beginSession( PermissionsFixture.allPermissions() );
cursors = kernel.cursors(); cursors = kernel.cursors();
Expand Down
Expand Up @@ -24,18 +24,37 @@


import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.GraphDatabaseService;



/**
* This interface defines the functionality that's needed to run Kernel API Write tests (tests that extends
* KernelAPIWriteTestBase) on a Kernel.
*/
public interface KernelAPIWriteTestSupport public interface KernelAPIWriteTestSupport
{ {
/**
* Create the Kernel to test in the provided directory.
* @param storeDir The directory to hold the database
* @throws IOException Thrown on IO failure during database creation
*/
void setup( File storeDir ) throws IOException; void setup( File storeDir ) throws IOException;


void beforeEachTest(); /**
* Clear the graph. Executed before each test.
*/
void clearGraph();


/**
* Return the Kernel to test. Executed before each test.
*/
Kernel kernelToTest(); Kernel kernelToTest();


/** /**
* Backdoor to allow asserting on write effects * Backdoor to allow asserting on write effects
*/ */
GraphDatabaseService graphBackdoor(); GraphDatabaseService graphBackdoor();


/**
* Clean up resources and close the database. Executed after all tests are completed.
*/
void tearDown(); void tearDown();
} }
Expand Up @@ -40,11 +40,6 @@ public void setup( File storeDir, Consumer<GraphDatabaseService> create ) throws
create.accept( db ); create.accept( db );
} }


@Override
public void beforeEachTest()
{
}

@Override @Override
public Kernel kernelToTest() public Kernel kernelToTest()
{ {
Expand Down

0 comments on commit 607308d

Please sign in to comment.