Skip to content
Open
Show file tree
Hide file tree
Changes from 8 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.

9 changes: 5 additions & 4 deletions src/test/java/com/falkordb/GraphAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import com.falkordb.test.BaseTestContainerTestIT;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
Expand All @@ -21,13 +22,13 @@
import com.falkordb.graph_entities.Property;
import com.falkordb.test.utils.PathBuilder;

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 @@ -1040,7 +1041,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 +1070,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
17 changes: 9 additions & 8 deletions src/test/java/com/falkordb/InstantiationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,38 @@

import java.net.URI;

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

public class InstantiationTest {
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
7 changes: 4 additions & 3 deletions src/test/java/com/falkordb/IterableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@

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 {
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
5 changes: 3 additions & 2 deletions src/test/java/com/falkordb/ListGraphsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@

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 {
public class ListGraphsTest extends BaseTestContainerTestIT {

private Driver driver;

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

@Test
Expand Down
7 changes: 4 additions & 3 deletions src/test/java/com/falkordb/PipelineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.*;

import com.falkordb.test.BaseTestContainerTestIT;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -11,13 +12,13 @@
import com.falkordb.graph_entities.Property;
import com.falkordb.impl.resultset.ResultSetImpl;

public class PipelineTest {
public class PipelineTest extends BaseTestContainerTestIT {

private GraphContextGenerator api;

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

}

Expand Down Expand Up @@ -260,7 +261,7 @@ public void testGraphCopy() {
originalResultSetIterator = originalResultSet.iterator();
}

GraphContextGenerator api2 = FalkorDB.driver().graph("social-copied");
GraphContextGenerator api2 = FalkorDB.driver(getFalkordbHost(),getFalkordbPort()).graph("social-copied");
try {
// Compare graph contents
ResultSet copiedResultSet = api2.query("MATCH (p:person)-[rel:knows]->(p2:person) RETURN p,rel,p2");
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/com/falkordb/TransactionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.List;
import java.util.Map;

import com.falkordb.test.BaseTestContainerTestIT;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -15,7 +16,7 @@
import com.falkordb.graph_entities.Property;
import com.falkordb.impl.resultset.ResultSetImpl;

public class TransactionTest {
public class TransactionTest extends BaseTestContainerTestIT {

private GraphContextGenerator api;

Expand All @@ -24,7 +25,7 @@ public TransactionTest() {

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

@AfterEach
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/com/falkordb/exceptions/GraphErrorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.util.HashMap;

import com.falkordb.test.BaseTestContainerTestIT;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -14,13 +15,13 @@
import com.falkordb.GraphContext;
import com.falkordb.GraphContextGenerator;

public class GraphErrorTest {
public class GraphErrorTest extends BaseTestContainerTestIT {

private GraphContextGenerator api;

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Avoid fixed graph name to prevent cross-test collisions when sharing a container

Multiple tests/classes commonly use "social". With concurrent test execution or shared containers, this can cause interference. Use a unique graph name per test to isolate state.

Apply this one-line change to generate a unique graph name per test:

-        api = FalkorDB.driver(getFalkordbHost(),getFalkordbPort()).graph("social");
+        api = FalkorDB.driver(getFalkordbHost(), getFalkordbPort()).graph("social_" + System.nanoTime());
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
api = FalkorDB.driver(getFalkordbHost(),getFalkordbPort()).graph("social");
api = FalkorDB.driver(getFalkordbHost(), getFalkordbPort()).graph("social_" + System.nanoTime());
🤖 Prompt for AI Agents
In src/test/java/com/falkordb/exceptions/GraphErrorTest.java around line 24, the
test uses a fixed graph name "social" which can cause cross-test collisions;
change the graph creation to use a unique name per test run (for example append
a random UUID or the current timestamp or the test method/class name) so each
test uses its own isolated graph; update the line to build the graph name
dynamically (e.g., "social-" + UUID.randomUUID() or similar) when calling
FalkorDB.driver(...).graph(...).

Assertions.assertNotNull(api.query("CREATE (:person{mixed_prop: 'strval'}), (:person{mixed_prop: 50})"));
}

Expand Down
52 changes: 52 additions & 0 deletions src/test/java/com/falkordb/test/BaseTestContainerTestIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.falkordb.test;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.output.Slf4jLogConsumer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.utility.DockerImageName;

import java.time.Duration;

public class BaseTestContainerTestIT {
private static final Logger log = LoggerFactory.getLogger(BaseTestContainerTestIT.class);
public static final DockerImageName FALKORDB_IMAGE = DockerImageName.parse("falkordb/falkordb:latest");
public static final int FALKORDB_PORT = 6379;

@Container
private static GenericContainer<?> containerFalkorDB;
private static final int falkordbPort = 6379; // Default port for Falkordb, adjust if necessary

Comment on lines +20 to +21
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Remove unused duplicate port constant

The private static falkordbPort (Line 22) duplicates FALKORDB_PORT and is unused.

-    private static final int falkordbPort = 6379; // Default port for Falkordb, adjust if necessary
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
private static final int falkordbPort = 6379; // Default port for Falkordb, adjust if necessary
🤖 Prompt for AI Agents
In src/test/java/com/falkordb/test/BaseTestContainerTestIT.java around lines 22
to 23, there is an unused duplicate constant private static final int
falkordbPort = 6379 that duplicates FALKORDB_PORT; remove this unused field and
update any references to use the existing FALKORDB_PORT constant (or keep only
the single canonical constant) to eliminate redundancy and unused code.

@BeforeAll
public static void setUpContainer() {
// allow overriding image via -Dfalkordb.image=repo/image:tag
DockerImageName image = DockerImageName.parse(
System.getProperty("falkordb.image", FALKORDB_IMAGE.asCanonicalNameString())
);
containerFalkorDB = new GenericContainer<>(image)
.withExposedPorts(FALKORDB_PORT)
.withLogConsumer(new Slf4jLogConsumer(log))
.waitingFor(Wait.forListeningPort())
.withStartupTimeout(Duration.ofSeconds(90));
containerFalkorDB.start();
}

@AfterAll
public static void tearDownContainer() {
if (containerFalkorDB != null) {
containerFalkorDB.stop();
}
}

protected int getFalkordbPort() {
return containerFalkorDB.getFirstMappedPort();
}

protected String getFalkordbHost() {
return containerFalkorDB.getHost();
}
}