Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
396 changes: 222 additions & 174 deletions pom.xml

Large diffs are not rendered by default.

71 changes: 33 additions & 38 deletions src/test/java/com/falkordb/GraphAPITest.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
package com.falkordb;

import static org.junit.jupiter.api.Assertions.fail;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import org.junit.jupiter.api.Assertions;
import com.falkordb.Statistics.Label;
import com.falkordb.exceptions.GraphException;
import com.falkordb.graph_entities.*;
import com.falkordb.test.BaseTestContainerTestIT;
import com.falkordb.test.utils.PathBuilder;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import com.falkordb.Statistics.Label;
import com.falkordb.exceptions.GraphException;
import com.falkordb.graph_entities.Edge;
import com.falkordb.graph_entities.Node;
import com.falkordb.graph_entities.Path;
import com.falkordb.graph_entities.Point;
import com.falkordb.graph_entities.Property;
import com.falkordb.test.utils.PathBuilder;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import static org.junit.jupiter.api.Assertions.fail;

public class GraphAPITest {
public class GraphAPITest extends BaseTestContainerTestIT {

private GraphContextGenerator client;

@BeforeEach
public void createApi() {
client = FalkorDB.driver().graph("social");
client = FalkorDB.driver(getFalkordbHost(), getFalkordbPort()).graph("social");
}

@AfterEach
Expand Down Expand Up @@ -293,8 +288,8 @@ public void testRecord() {
"r.place", "r.since", "r.doubleValue", "r.boolValue"), record.keys());

Assertions.assertEquals(Arrays.asList(expectedNode, expectedEdge,
name, (long) age, doubleValue, true,
place, (long) since, doubleValue, false),
name, (long) age, doubleValue, true,
place, (long) since, doubleValue, false),
record.values());

Node a = record.getValue("a");
Expand Down Expand Up @@ -580,8 +575,8 @@ public void testContextedAPI() {
"r.place", "r.since", "r.doubleValue", "r.boolValue"), record.keys());

Assertions.assertEquals(Arrays.asList(expectedNode, expectedEdge,
name, (long) age, doubleValue, true,
place, (long) since, doubleValue, false),
name, (long) age, doubleValue, true,
place, (long) since, doubleValue, false),
record.values());

Node a = record.getValue("a");
Expand All @@ -599,13 +594,13 @@ public void testContextedAPI() {
// Test profile functionality in contexted API
ResultSet profileResult = c.profile("MATCH (a:person) WHERE (a.name = 'roi') RETURN a.age");
Assertions.assertNotNull(profileResult);

// Verify profile result structure in contexted API
Assertions.assertTrue(profileResult.size() > 0, "Profile result should contain execution plan operations");
Header profileHeader = profileResult.getHeader();
Assertions.assertNotNull(profileHeader, "Profile result should have a header");
Assertions.assertTrue(profileHeader.getSchemaNames().size() > 0, "Profile result header should have columns");

// Verify profile result contains meaningful data
Iterator<Record> profileIterator = profileResult.iterator();
Assertions.assertTrue(profileIterator.hasNext(), "Profile result should have execution plan operations");
Expand Down Expand Up @@ -826,7 +821,7 @@ public void testVecf32() {
Object res = vector.get(0);

// The result can be either Double or Float depending on the server version
if ( res instanceof Double) {
if (res instanceof Double) {
List<Double> v = r.getValue(0);
Assertions.assertEquals(2.1, v.get(0), 0.01);
Assertions.assertEquals(-0.82, v.get(1), 0.01);
Expand Down Expand Up @@ -986,44 +981,44 @@ public void testProfile() {
// Create sample data for profiling
client.query("CREATE (:person{name:'alice',age:30})");
client.query("CREATE (:person{name:'bob',age:25})");

// Test basic profile
ResultSet profileResult = client.profile("MATCH (a:person) WHERE (a.name = 'alice') RETURN a.age");
Assertions.assertNotNull(profileResult);

// Verify profile result has expected structure
Assertions.assertTrue(profileResult.size() > 0, "Profile result should contain execution plan operations");

// Verify profile result has a header
Header header = profileResult.getHeader();
Assertions.assertNotNull(header, "Profile result should have a header");
Assertions.assertTrue(header.getSchemaNames().size() > 0, "Profile result header should have columns");

// Verify the profile result contains timing information (execution plan data)
// Profile results typically contain execution plan operations with timing data
Iterator<Record> iterator = profileResult.iterator();
Assertions.assertTrue(iterator.hasNext(), "Profile result should have at least one operation");

Record firstRecord = iterator.next();
Assertions.assertNotNull(firstRecord, "Profile result record should not be null");
Assertions.assertTrue(firstRecord.size() > 0, "Profile result record should have values");

// Test profile with parameters
Map<String, Object> params = new HashMap<>();
params.put("name", "alice");
ResultSet profileResultWithParams = client.profile("MATCH (a:person) WHERE (a.name = $name) RETURN a.age", params);
Assertions.assertNotNull(profileResultWithParams);

// Verify parameterized profile result has expected structure
Assertions.assertTrue(profileResultWithParams.size() > 0, "Parameterized profile result should contain execution plan operations");
Header paramHeader = profileResultWithParams.getHeader();
Assertions.assertNotNull(paramHeader, "Parameterized profile result should have a header");

// Test profile with more complex query
ResultSet complexProfileResult = client.profile("MATCH (p:person) WHERE p.age > 20 RETURN p.name, p.age ORDER BY p.age");
Assertions.assertNotNull(complexProfileResult);
Assertions.assertTrue(complexProfileResult.size() > 0, "Complex profile result should contain execution plan operations");

// Verify all profile results have statistics (execution plans should have execution time)
Assertions.assertNotNull(profileResult.getStatistics(), "Profile result should have statistics");
Assertions.assertNotNull(profileResultWithParams.getStatistics(), "Parameterized profile result should have statistics");
Expand All @@ -1040,7 +1035,7 @@ public void testGraphCopy() {
// Copy the graph
client.copyGraph("social-copied");

GraphContextGenerator client2 = FalkorDB.driver().graph("social-copied");
GraphContextGenerator client2 = FalkorDB.driver(getFalkordbHost(), getFalkordbPort()).graph("social-copied");
try {
// Compare graph contents
ResultSet copiedResultSet = client2.query("MATCH (p:person)-[rel:knows]->(p2:person) RETURN p,rel,p2");
Expand Down Expand Up @@ -1069,7 +1064,7 @@ public void testGraphCopyContextedAPI() {
c.copyGraph("social-copied");
}

GraphContextGenerator client2 = FalkorDB.driver().graph("social-copied");
GraphContextGenerator client2 = FalkorDB.driver(getFalkordbHost(), getFalkordbPort()).graph("social-copied");
try {
// Compare graph contents
ResultSet copiedResultSet = client2.query("MATCH (p:person)-[rel:knows]->(p2:person) RETURN p,rel,p2");
Expand Down Expand Up @@ -1098,9 +1093,9 @@ public void testExplain() {
Assertions.assertFalse(explainResult.isEmpty());
// Should contain typical execution plan keywords in one of the lines
boolean containsExpectedKeywords = explainResult.stream()
.anyMatch(line -> line.toLowerCase().contains("scan") ||
line.toLowerCase().contains("project") ||
line.toLowerCase().contains("results"));
.anyMatch(line -> line.toLowerCase().contains("scan") ||
line.toLowerCase().contains("project") ||
line.toLowerCase().contains("results"));
Assertions.assertTrue(containsExpectedKeywords);

// Test explain with parameters
Expand Down
17 changes: 10 additions & 7 deletions src/test/java/com/falkordb/InstantiationTest.java
Original file line number Diff line number Diff line change
@@ -1,38 +1,41 @@
package com.falkordb;

import java.net.URI;

import com.falkordb.test.BaseTestContainerTestIT;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class InstantiationTest {
import java.net.URI;

public class InstantiationTest extends BaseTestContainerTestIT {
private GraphContextGenerator client;

@Test
public void createDefaultClient() {
client = FalkorDB.driver().graph("g");

client = FalkorDB.driver(getFalkordbHost(), getFalkordbPort()).graph("g");
ResultSet resultSet = client.query("CREATE ({name:'bsb'})");
Assertions.assertEquals(1, resultSet.getStatistics().nodesCreated());
}

@Test
public void createClientWithHostAndPort() {
client = FalkorDB.driver("localhost", 6379).graph("g");
client = FalkorDB.driver(getFalkordbHost(), getFalkordbPort()).graph("g");
ResultSet resultSet = client.query("CREATE ({name:'bsb'})");
Assertions.assertEquals(1, resultSet.getStatistics().nodesCreated());
}

@Test
public void createClientWithHostAndPortNoUser() {
client = FalkorDB.driver("localhost", 6379, null, null).graph("g");
client = FalkorDB.driver(getFalkordbHost(), getFalkordbPort(), null, null).graph("g");
ResultSet resultSet = client.query("CREATE ({name:'bsb'})");
Assertions.assertEquals(1, resultSet.getStatistics().nodesCreated());
}

@Test
public void createClientWithURL() {
client = FalkorDB.driver(URI.create("redis://localhost:6379")).graph("g");
client = FalkorDB.driver(URI.create(String.format("redis://%s:%d",
getFalkordbHost(), getFalkordbPort()))).graph("g");
ResultSet resultSet = client.query("CREATE ({name:'bsb'})");
Assertions.assertEquals(1, resultSet.getStatistics().nodesCreated());
}
Expand Down
11 changes: 6 additions & 5 deletions src/test/java/com/falkordb/IterableTest.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package com.falkordb;

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

import com.falkordb.test.BaseTestContainerTestIT;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class IterableTest {
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

public class IterableTest extends BaseTestContainerTestIT {

private GraphContextGenerator api;

@BeforeEach
public void createApi() {
api = FalkorDB.driver().graph("social");
api = FalkorDB.driver(getFalkordbHost(), getFalkordbPort()).graph("social");
}

@AfterEach
Expand Down
37 changes: 19 additions & 18 deletions src/test/java/com/falkordb/ListGraphsTest.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package com.falkordb;

import java.util.List;

import com.falkordb.test.BaseTestContainerTestIT;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class ListGraphsTest {
import java.util.List;

public class ListGraphsTest extends BaseTestContainerTestIT {

private Driver driver;

@BeforeEach
public void setUp() {
driver = FalkorDB.driver();
driver = FalkorDB.driver(getFalkordbHost(), getFalkordbPort());
}

@Test
Expand All @@ -29,13 +30,13 @@ public void testListGraphsWithCreatedGraph() {
// Create a test graph
GraphContextGenerator testGraph = driver.graph("test-list-graph");
testGraph.query("CREATE (:TestNode {name:'test'})");

try {
// List graphs and verify our graph is included
List<String> graphs = driver.listGraphs();
Assertions.assertNotNull(graphs);
Assertions.assertTrue(graphs.contains("test-list-graph"),
"Graph list should contain the created graph: " + graphs);
Assertions.assertTrue(graphs.contains("test-list-graph"),
"Graph list should contain the created graph: " + graphs);
} finally {
// Clean up the test graph
testGraph.deleteGraph();
Expand All @@ -48,38 +49,38 @@ public void testListGraphsAfterDeletion() {
// Create a test graph
GraphContextGenerator testGraph = driver.graph("test-delete-graph");
testGraph.query("CREATE (:TestNode {name:'test'})");

// Verify graph exists
List<String> graphsBefore = driver.listGraphs();
Assertions.assertTrue(graphsBefore.contains("test-delete-graph"));

// Delete the graph
testGraph.deleteGraph();
testGraph.close();

// Verify graph is no longer in the list
List<String> graphsAfter = driver.listGraphs();
Assertions.assertFalse(graphsAfter.contains("test-delete-graph"),
"Graph list should not contain the deleted graph: " + graphsAfter);
Assertions.assertFalse(graphsAfter.contains("test-delete-graph"),
"Graph list should not contain the deleted graph: " + graphsAfter);
}

@Test
public void testListGraphsMultiple() {
GraphContextGenerator graph1 = driver.graph("test-multi-1");
GraphContextGenerator graph2 = driver.graph("test-multi-2");

try {
// Create nodes in both graphs
graph1.query("CREATE (:TestNode {name:'test1'})");
graph2.query("CREATE (:TestNode {name:'test2'})");

// List graphs and verify both are included
List<String> graphs = driver.listGraphs();
Assertions.assertNotNull(graphs);
Assertions.assertTrue(graphs.contains("test-multi-1"),
"Graph list should contain test-multi-1: " + graphs);
Assertions.assertTrue(graphs.contains("test-multi-2"),
"Graph list should contain test-multi-2: " + graphs);
Assertions.assertTrue(graphs.contains("test-multi-1"),
"Graph list should contain test-multi-1: " + graphs);
Assertions.assertTrue(graphs.contains("test-multi-2"),
"Graph list should contain test-multi-2: " + graphs);
} finally {
// Clean up both test graphs
graph1.deleteGraph();
Expand Down
Loading