Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patchwork PR: GenerateDocstring #71

Closed
wants to merge 10 commits into from
46 changes: 43 additions & 3 deletions src/test/java/com/falkordb/InstantiationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,69 @@
public class InstantiationTest {
private GraphContextGenerator client;

@Test
```
/**
* Creates a default FalkorDB client and executes a simple graph query.
*
* This test method initializes a FalkorDB client for a graph named "g",
* creates a new node with a 'name' property, and verifies the creation.
*
* @return void
* @throws RuntimeException if the FalkorDB operation fails
*/
``` @Test
public void createDefaultClient() {
client = FalkorDB.driver().graph("g");
ResultSet resultSet = client.query("CREATE ({name:'bsb'})");
Assert.assertEquals(1, resultSet.getStatistics().nodesCreated());
}

@Test
/**
* Tests the creation of a FalkorDB client with specified host and port.
*
* This test method creates a FalkorDB client, connects to a graph named "g",
* executes a Cypher query to create a node, and verifies the result.
*
* @return void This method doesn't return anything
*/ @Test
public void createClientWithHostAndPort() {
client = FalkorDB.driver("localhost", 6379).graph("g");
ResultSet resultSet = client.query("CREATE ({name:'bsb'})");
Assert.assertEquals(1, resultSet.getStatistics().nodesCreated());
}

```
/**
* Tests the creation of a FalkorDB client with host and port without user credentials.
*
* This test method creates a FalkorDB client connection to a local instance,
* executes a simple graph query to create a node, and verifies the result.
*
* @return void This method doesn't return anything
*/
```
@Test
public void createClientWithHostAndPortNoUser() {
client = FalkorDB.driver("localhost", 6379, null, null).graph("g");
ResultSet resultSet = client.query("CREATE ({name:'bsb'})");
Assert.assertEquals(1, resultSet.getStatistics().nodesCreated());
}

@Test
/**
* Creates a FalkorDB client with a specified URL and performs a test query.
*
* @param None
* @return None (void method)
*/ @Test
public void createClientWithURL() {
/**
* Closes the client and deletes the associated graph after test execution.
*
* This method is annotated with @After, indicating it runs after each test method.
* It checks if the client is not null, then deletes the graph and closes the client.
*
* @return void
*/
client = FalkorDB.driver(URI.create("redis://localhost:6379")).graph("g");
ResultSet resultSet = client.query("CREATE ({name:'bsb'})");
Assert.assertEquals(1, resultSet.getStatistics().nodesCreated());
Expand Down
172 changes: 107 additions & 65 deletions src/test/java/com/falkordb/IterableTest.java
Original file line number Diff line number Diff line change
@@ -1,65 +1,107 @@
package com.falkordb;

import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class IterableTest {

private GraphContextGenerator api;

@Before
public void createApi() {
api = FalkorDB.driver().graph("social");
}

@After
public void deleteGraph() {
api.deleteGraph();
api.close();
}

@Test
public void testRecordsIterator() {
api.query("UNWIND(range(0,50)) as i CREATE(:N{i:i})");

ResultSet rs = api.query("MATCH(n) RETURN n");
int count = 0;
for (Record record : rs) {
assertNotNull(record);
count++;
}
assertEquals(rs.size(), count);
}

@Test
public void testRecordsIterable() {
api.query("UNWIND(range(0,50)) as i CREATE(:N{i:i})");

ResultSet rs = api.query("MATCH(n) RETURN n");
int count = 0;
for (@SuppressWarnings("unused")
Record row : rs) {
count++;
}
assertEquals(rs.size(), count);
}

@Test
public void testRecordsIteratorAndIterable() {
api.query("UNWIND(range(0,50)) as i CREATE(:N{i:i})");

ResultSet rs = api.query("MATCH(n) RETURN n");
rs.iterator().next();
int count = 0;
for (Record row : rs) {
assertNotNull(row);
count++;
}
assertEquals(rs.size(), count);
}

}
package com.falkordb;

import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class IterableTest {

private GraphContextGenerator api;

/**
* Sets up the FalkorDB graph API for social network testing.
*
* This method is executed before each test case to initialize the graph API.
* It creates a new graph named "social" using the FalkorDB driver.
*
* @return void
*/
@Before
public void createApi() {
api = FalkorDB.driver().graph("social");
}

```
/**
* Deletes the graph and closes the API connection after test execution.
*
* This method is annotated with @After, indicating it runs after each test method.
* It performs cleanup by deleting the graph and closing the API connection.
*
* @throws RuntimeException if there's an error during graph deletion or API closure
*/
```
@After
public void deleteGraph() {
api.deleteGraph();
api.close();
}

/**
* Tests the functionality of iterating through records in a ResultSet.
*
* This test method creates a set of nodes, queries them, and then iterates
* through the results to ensure proper functionality of the ResultSet iterator.
*
* @return void This method doesn't return anything
*/
@Test
public void testRecordsIterator() {
api.query("UNWIND(range(0,50)) as i CREATE(:N{i:i})");

ResultSet rs = api.query("MATCH(n) RETURN n");
/**
* Tests the iterable behavior of ResultSet records.
*
* This test method creates a series of nodes, queries them, and verifies
* that the ResultSet can be properly iterated over using a for-each loop.
* It also checks if the number of iterated records matches the size reported
* by the ResultSet.
*
* @param None
* @return void
*/
int count = 0;
for (Record record : rs) {
assertNotNull(record);
count++;
}
assertEquals(rs.size(), count);
}

@Test
public void testRecordsIterable() {
api.query("UNWIND(range(0,50)) as i CREATE(:N{i:i})");

ResultSet rs = api.query("MATCH(n) RETURN n");
int count = 0;
for (@SuppressWarnings("unused")
Record row : rs) {
count++;
}
assertEquals(rs.size(), count);
}

/**
* Tests the functionality of ResultSet's iterator and iterable interfaces.
*
* @return void
*/
@Test
public void testRecordsIteratorAndIterable() {
api.query("UNWIND(range(0,50)) as i CREATE(:N{i:i})");

ResultSet rs = api.query("MATCH(n) RETURN n");
rs.iterator().next();
int count = 0;
for (Record row : rs) {
assertNotNull(row);
count++;
}
assertEquals(rs.size(), count);
}

}
52 changes: 52 additions & 0 deletions src/test/java/com/falkordb/PipelineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,43 @@ public class PipelineTest {

private GraphContextGenerator api;

/**
* Initializes the FalkorDB graph API for the 'social' graph before test execution.
*
* This method is annotated with @Before, indicating it runs before each test method.
* It creates a new instance of the FalkorDB graph API, specifically for the 'social' graph.
*
* @return void
*/
@Before
public void createApi() {
api = FalkorDB.driver().graph("social");

}

/**
* Deletes the graph and closes the API connection after test execution.
*
* This method is annotated with @After, indicating it runs after each test method.
* It performs cleanup by deleting the graph and closing the API connection.
*
* @return void
*/
@After
public void deleteGraph() {
api.deleteGraph();
api.close();
}

/**
* Tests the synchronous execution of a pipeline of commands in a graph context.
*
* This method performs a series of operations including setting values, creating nodes,
* incrementing counters, retrieving values, and executing graph queries. It then verifies
* the results of these operations to ensure they are executed correctly and in order.
*
* @return void This test method doesn't return anything
*/
@Test
public void testSync() {
try (GraphContext c = api.getContext()) {
Expand Down Expand Up @@ -115,6 +140,18 @@ record = iterator.next();
}
}

/**
* Tests read-only queries in a graph context using a pipelined approach.
*
* This test method performs the following operations:
* 1. Sets a key-value pair
* 2. Creates two Person nodes
* 3. Executes a read-only query to match a specific Person node
* 4. Calls a procedure to retrieve graph labels
* 5. Validates the results of each operation
*
* @return void This method doesn't return anything
*/
@Test
public void testReadOnlyQueries() {
try (GraphContext c = api.getContext()) {
Expand Down Expand Up @@ -192,6 +229,16 @@ record = iterator.next();
}
}

/**
* Tests the waitReplicas functionality in a GraphPipeline.
*
* This test method creates a GraphContext, performs a series of operations
* in a pipelined manner, and then waits for replicas to synchronize.
* It sets a key-value pair, creates two Person nodes, waits for replicas,
* and then verifies the results.
*
* @return void This method doesn't return anything
*/
@Test
public void testWaitReplicas() {
try (GraphContext c = api.getContext()) {
Expand All @@ -205,6 +252,11 @@ public void testWaitReplicas() {
}
}

/**
* Tests the graph copy functionality by creating a sample graph, copying it, and comparing the contents.
*
* @return void This method doesn't return anything
*/
@Test
public void testGraphCopy() {
Iterator<Record> originalResultSetIterator;
Expand Down
Loading
Loading