Skip to content

Commit

Permalink
Try solving TeamCity errors in 5.26
Browse files Browse the repository at this point in the history
* Try solving TC errors in 5.25

* fix tests

* restored GephiMock
  • Loading branch information
vga91 committed Dec 19, 2024
1 parent ab0ed5e commit b4e60c7
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 44 deletions.
49 changes: 30 additions & 19 deletions extended-it/src/test/java/apoc/vectordb/QdrantTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static apoc.ml.Prompt.API_KEY_CONF;
import static apoc.ml.RestAPIConfig.HEADERS_KEY;
import static apoc.util.ExtendedTestUtil.assertFails;
import static apoc.util.ExtendedTestUtil.testResultEventually;
import static apoc.util.MapUtil.map;
import static apoc.util.TestUtil.testCall;
import static apoc.util.TestUtil.testResult;
Expand Down Expand Up @@ -59,6 +60,7 @@ public class QdrantTest {
private static final Map<String, String> ADMIN_AUTHORIZATION = getAuthHeader(ADMIN_KEY);
private static final Map<String, String> READONLY_AUTHORIZATION = getAuthHeader(READONLY_KEY);
private static final Map<String, Object> ADMIN_HEADER_CONF = map(HEADERS_KEY, ADMIN_AUTHORIZATION);
public static final long TIMEOUT = 10L;

private static String HOST;

Expand Down Expand Up @@ -244,7 +246,7 @@ WITH collect(node) as paths

@Test
public void queryVectors() {
testResult(db, "CALL apoc.vectordb.qdrant.query($host, 'test_collection', [0.2, 0.1, 0.9, 0.7], {}, 5, $conf)",
testResultEventually(db, "CALL apoc.vectordb.qdrant.query($host, 'test_collection', [0.2, 0.1, 0.9, 0.7], {}, 5, $conf)",
map("host", HOST, "conf", map(ALL_RESULTS_KEY, true, HEADERS_KEY, ADMIN_AUTHORIZATION)),
r -> {
Map<String, Object> row = r.next();
Expand All @@ -256,12 +258,13 @@ public void queryVectors() {
assertLondonResult(row, FALSE);
assertNotNull(row.get("score"));
assertNotNull(row.get("vector"));
});
},
TIMEOUT);
}

@Test
public void queryVectorsWithoutVectorResult() {
testResult(db, "CALL apoc.vectordb.qdrant.query($host, 'test_collection', [0.2, 0.1, 0.9, 0.7], {}, 5, $conf)",
testResultEventually(db, "CALL apoc.vectordb.qdrant.query($host, 'test_collection', [0.2, 0.1, 0.9, 0.7], {}, 5, $conf)",
map("host", HOST, "conf", map(HEADERS_KEY, ADMIN_AUTHORIZATION)),
r -> {
Map<String, Object> row = r.next();
Expand All @@ -275,24 +278,26 @@ public void queryVectorsWithoutVectorResult() {
assertNotNull(row.get("score"));
assertNull(row.get("vector"));
assertNull(row.get("id"));
});
},
TIMEOUT);
}

@Test
public void queryVectorsWithYield() {
testResult(db, "CALL apoc.vectordb.qdrant.query($host, 'test_collection', [0.2, 0.1, 0.9, 0.7], {}, 5, $conf) YIELD metadata, id",
testResultEventually(db, "CALL apoc.vectordb.qdrant.query($host, 'test_collection', [0.2, 0.1, 0.9, 0.7], {}, 5, $conf) YIELD metadata, id",
map("host", HOST,
"conf", map(ALL_RESULTS_KEY, true, HEADERS_KEY, ADMIN_AUTHORIZATION)
),
r -> {
assertBerlinResult(r.next(), FALSE);
assertLondonResult(r.next(), FALSE);
});
},
TIMEOUT);
}

@Test
public void queryVectorsWithFilter() {
testResult(db, """
testResultEventually(db, """
CALL apoc.vectordb.qdrant.query($host, 'test_collection', [0.2, 0.1, 0.9, 0.7],
{ must:
[ { key: "city", match: { value: "London" } } ]
Expand All @@ -303,19 +308,21 @@ public void queryVectorsWithFilter() {
),
r -> {
assertLondonResult(r.next(), FALSE);
});
},
TIMEOUT);
}

@Test
public void queryVectorsWithLimit() {
testResult(db, """
testResultEventually(db, """
CALL apoc.vectordb.qdrant.query($host, 'test_collection', [0.2, 0.1, 0.9, 0.7], {}, 1, $conf) YIELD metadata, id""",
map("host", HOST,
"conf", map(ALL_RESULTS_KEY, true, HEADERS_KEY, ADMIN_AUTHORIZATION)
),
r -> {
assertBerlinResult(r.next(), FALSE);
});
},
TIMEOUT);
}

@Test
Expand All @@ -331,7 +338,7 @@ MAPPING_KEY, map(
MODE_KEY, MappingMode.CREATE_IF_MISSING.toString()
)
);
testResult(db, "CALL apoc.vectordb.qdrant.queryAndUpdate($host, 'test_collection', [0.2, 0.1, 0.9, 0.7], {}, 5, $conf)",
testResultEventually(db, "CALL apoc.vectordb.qdrant.queryAndUpdate($host, 'test_collection', [0.2, 0.1, 0.9, 0.7], {}, 5, $conf)",
map("host", HOST, "conf", conf),
r -> {
Map<String, Object> row = r.next();
Expand All @@ -343,14 +350,15 @@ MAPPING_KEY, map(
assertLondonResult(row, NODE);
assertNotNull(row.get("score"));
assertNotNull(row.get("vector"));
});
},
TIMEOUT);

assertNodesCreated(db);

testResult(db, "MATCH (n:Test) RETURN properties(n) AS props ORDER BY n.myId",
VectorDbTestUtil::vectorEntityAssertions);

testResult(db, "CALL apoc.vectordb.qdrant.queryAndUpdate($host, 'test_collection', [0.2, 0.1, 0.9, 0.7], {}, 5, $conf)",
testResultEventually(db, "CALL apoc.vectordb.qdrant.queryAndUpdate($host, 'test_collection', [0.2, 0.1, 0.9, 0.7], {}, 5, $conf)",
map("host", HOST, "conf", conf),
r -> {
Map<String, Object> row = r.next();
Expand All @@ -362,7 +370,8 @@ MAPPING_KEY, map(
assertLondonResult(row, NODE);
assertNotNull(row.get("score"));
assertNotNull(row.get("vector"));
});
},
TIMEOUT);

assertNodesCreated(db);
}
Expand Down Expand Up @@ -424,8 +433,8 @@ MAPPING_KEY, map(EMBEDDING_KEY, "vect",
NODE_LABEL, "Test",
ENTITY_KEY, "myId",
METADATA_KEY, "foo"));
testResult(db, "CALL apoc.vectordb.qdrant.queryAndUpdate($host, 'test_collection', [0.2, 0.1, 0.9, 0.7], {}, 5, $conf)",

testResultEventually(db, "CALL apoc.vectordb.qdrant.queryAndUpdate($host, 'test_collection', [0.2, 0.1, 0.9, 0.7], {}, 5, $conf)",
map("host", HOST, "conf", conf),
r -> {
Map<String, Object> row = r.next();
Expand All @@ -437,7 +446,8 @@ MAPPING_KEY, map(EMBEDDING_KEY, "vect",
assertLondonResult(row, NODE);
assertNotNull(row.get("score"));
assertNotNull(row.get("vector"));
});
},
TIMEOUT);

assertNodesCreated(db);
}
Expand All @@ -455,7 +465,7 @@ MAPPING_KEY, map(
ENTITY_KEY, "myId",
METADATA_KEY, "foo")
);
testResult(db, "CALL apoc.vectordb.qdrant.queryAndUpdate($host, 'test_collection', [0.2, 0.1, 0.9, 0.7], {}, 5, $conf)",
testResultEventually(db, "CALL apoc.vectordb.qdrant.queryAndUpdate($host, 'test_collection', [0.2, 0.1, 0.9, 0.7], {}, 5, $conf)",
map("host", HOST, "conf", conf),
r -> {
Map<String, Object> row = r.next();
Expand All @@ -467,7 +477,8 @@ MAPPING_KEY, map(
assertLondonResult(row, REL);
assertNotNull(row.get("score"));
assertNotNull(row.get("vector"));
});
},
TIMEOUT);

assertRelsCreated(db);
}
Expand Down
9 changes: 7 additions & 2 deletions extended/src/test/java/apoc/gephi/GephiMock.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.mockserver.client.MockServerClient;
import org.mockserver.integration.ClientAndServer;
import org.mockserver.model.RegexBody;
import org.mockserver.socket.PortFactory;

import java.util.Arrays;
import java.util.HashSet;
Expand All @@ -26,9 +27,13 @@
*/
public class GephiMock {
private final ClientAndServer server;
private final int PORT;
public final String HOST;

public GephiMock() {
this.server = ClientAndServer.startClientAndServer(8080);
PORT = PortFactory.findFreePort();
HOST = "http://localhost:" + PORT;
this.server = ClientAndServer.startClientAndServer(PORT);
}

public void clearAllExpectations() {
Expand All @@ -40,7 +45,7 @@ public void shutdown() {
}

public void mockSuccess(String workspace, GephiEntity... entities) {
new MockServerClient("localhost", 8080)
new MockServerClient("localhost", PORT)
.when(request()
.withMethod("POST")
.withPath("/" + workspace)
Expand Down
30 changes: 18 additions & 12 deletions extended/src/test/java/apoc/gephi/GephiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ public void testAdd() throws Exception {
node(0, "Foo"),
node(1, "Bar"),
relationship(0, "KNOWS",0, 1));
testCall(db, "MATCH p = (:Foo)-->() WITH p CALL apoc.gephi.add(null,$workspace,p) yield nodes, relationships, format return *",
map("workspace", GEPHI_WORKSPACE),
testCall(db, "MATCH p = (:Foo)-->() WITH p CALL apoc.gephi.add($host,$workspace,p) yield nodes, relationships, format return *",
map("host", gephiMock.HOST,
"workspace", GEPHI_WORKSPACE),
r -> {
assertEquals(2L, r.get("nodes"));
assertEquals(1L, r.get("relationships"));
Expand All @@ -67,8 +68,9 @@ public void testWeightParameter() throws Exception {
node(0, "Foo"),
node(1, "Bar"),
relationship(0, "KNOWS",0, 1, "7.2"));
testCall(db, "MATCH p = (:Foo)-->() WITH p CALL apoc.gephi.add(null,$workspace,p,'weight') yield nodes, relationships, format return *",
map("workspace", GEPHI_WORKSPACE),
testCall(db, "MATCH p = (:Foo)-->() WITH p CALL apoc.gephi.add($host,$workspace,p,'weight') yield nodes, relationships, format return *",
map("host", gephiMock.HOST,
"workspace", GEPHI_WORKSPACE),
r -> {
assertEquals(2L, r.get("nodes"));
assertEquals(1L, r.get("relationships"));
Expand All @@ -83,8 +85,9 @@ public void testWrongWeightParameter() throws Exception {
node(0, "Foo"),
node(1, "Bar"),
relationship(0, "KNOWS",0, 1));
testCall(db, "MATCH p = (:Foo)-->() WITH p CALL apoc.gephi.add(null,$workspace,p,'test') yield nodes, relationships, format return *",
map("workspace", GEPHI_WORKSPACE),
testCall(db, "MATCH p = (:Foo)-->() WITH p CALL apoc.gephi.add($host,$workspace,p,'test') yield nodes, relationships, format return *",
map("host", gephiMock.HOST,
"workspace", GEPHI_WORKSPACE),
r -> {
assertEquals(2L, r.get("nodes"));
assertEquals(1L, r.get("relationships"));
Expand All @@ -99,8 +102,9 @@ public void testRightExportParameter() throws Exception {
node(0, "Foo"),
node(1, "Bar"),
relationship(0, "KNOWS",0, 1, "7.2", Set.of("foo")));
testCall(db, "MATCH p = (:Foo)-->() WITH p CALL apoc.gephi.add(null,$workspace,p,'weight',['foo']) yield nodes, relationships, format return *",
map("workspace", GEPHI_WORKSPACE),
testCall(db, "MATCH p = (:Foo)-->() WITH p CALL apoc.gephi.add($host,$workspace,p,'weight',['foo']) yield nodes, relationships, format return *",
map("host", gephiMock.HOST,
"workspace", GEPHI_WORKSPACE),
r -> {
assertEquals(2L, r.get("nodes"));
assertEquals(1L, r.get("relationships"));
Expand All @@ -115,8 +119,9 @@ public void testWrongExportParameter() throws Exception {
node(0, "Foo"),
node(1, "Bar"),
relationship(0, "KNOWS",0, 1, "7.2"));
testCall(db, "MATCH p = (:Foo)-->() WITH p CALL apoc.gephi.add(null,$workspace,p,'weight',['faa','fee']) yield nodes, relationships, format return *",
map("workspace", GEPHI_WORKSPACE),
testCall(db, "MATCH p = (:Foo)-->() WITH p CALL apoc.gephi.add($host,$workspace,p,'weight',['faa','fee']) yield nodes, relationships, format return *",
map("host", gephiMock.HOST,
"workspace", GEPHI_WORKSPACE),
r -> {
assertEquals(2L, r.get("nodes"));
assertEquals(1L, r.get("relationships"));
Expand All @@ -131,8 +136,9 @@ public void reservedExportParameter() throws Exception {
node(0, "Foo"),
node(1, "Bar"),
relationship(0, "KNOWS",0, 1, "7.2"));
testCall(db, "MATCH p = (:Foo)-->() WITH p CALL apoc.gephi.add(null,$workspace,p,'weight',['directed','label']) yield nodes, relationships, format return *",
map("workspace", GEPHI_WORKSPACE),
testCall(db, "MATCH p = (:Foo)-->() WITH p CALL apoc.gephi.add($host,$workspace,p,'weight',['directed','label']) yield nodes, relationships, format return *",
map("host", gephiMock.HOST,
"workspace", GEPHI_WORKSPACE),
r -> {
assertEquals(2L, r.get("nodes"));
assertEquals(1L, r.get("relationships"));
Expand Down
19 changes: 11 additions & 8 deletions extended/src/test/java/apoc/load/LoadCsvTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.mockserver.client.MockServerClient;
import org.mockserver.integration.ClientAndServer;
import org.mockserver.model.Header;
import org.mockserver.socket.PortFactory;
import org.neo4j.configuration.GraphDatabaseSettings;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.QueryExecutionException;
Expand Down Expand Up @@ -47,7 +48,8 @@
public class LoadCsvTest {

private static ClientAndServer mockServer;

private static int PORT;

private static final List<Map<String, Object>> RESPONSE_BODY = List.of(
Map.of("headFoo", "one", "headBar", "two"),
Map.of("headFoo", "three", "headBar", "four"),
Expand All @@ -56,7 +58,8 @@ public class LoadCsvTest {

@BeforeClass
public static void startServer() {
mockServer = startClientAndServer(1080);
PORT = PortFactory.findFreePort();
mockServer = startClientAndServer(PORT);
}

@AfterClass
Expand Down Expand Up @@ -492,7 +495,7 @@ public void testLoadCsvWithUserPassInUrl() throws JsonProcessingException {
String userPass = "user:password";
String token = Util.encodeUserColonPassToBase64(userPass);

new MockServerClient("localhost", 1080)
new MockServerClient("localhost", PORT)
.when(
request()
.withPath("/docs/csv")
Expand All @@ -509,7 +512,7 @@ public void testLoadCsvWithUserPassInUrl() throws JsonProcessingException {
);

testResult(db, "CALL apoc.load.csv($url, {results:['map']}) YIELD map",
map("url", "http://" + userPass + "@localhost:1080/docs/csv"),
map("url", "http://" + userPass + "@localhost:" + PORT + "/docs/csv"),
(row) -> assertEquals(RESPONSE_BODY, row.stream().map(i->i.get("map")).collect(Collectors.toList()))
);
}
Expand All @@ -519,7 +522,7 @@ public void testLoadCsvParamsWithUserPassInUrl() throws JsonProcessingException
String userPass = "user:password";
String token = Util.encodeUserColonPassToBase64(userPass);

new MockServerClient("localhost", 1080)
new MockServerClient("localhost", PORT)
.when(
request()
.withMethod("POST")
Expand All @@ -537,7 +540,7 @@ public void testLoadCsvParamsWithUserPassInUrl() throws JsonProcessingException
);

testResult(db, "CALL apoc.load.csvParams($url, $header, $payload, {results:['map','list','stringMap','strings']})",
map("url", "http://" + userPass + "@localhost:1080/docs/csv",
map("url", "http://" + userPass + "@localhost:" + PORT +"/docs/csv",
"header", map("method", "POST"),
"payload", "{\"query\":\"pagecache\",\"version\":\"3.5\"}"),
(row) -> assertEquals(RESPONSE_BODY, row.stream().map(i->i.get("map")).collect(Collectors.toList()))
Expand All @@ -549,7 +552,7 @@ public void testLoadCsvParamsWithBasicAuth() throws JsonProcessingException {
String userPass = "user:password";
String token = Util.encodeUserColonPassToBase64(userPass);

new MockServerClient("localhost", 1080)
new MockServerClient("localhost", PORT)
.when(
request()
.withMethod("POST")
Expand All @@ -568,7 +571,7 @@ public void testLoadCsvParamsWithBasicAuth() throws JsonProcessingException {
);

testResult(db, "CALL apoc.load.csvParams($url, $header, $payload, {results:['map','list','stringMap','strings']})",
map("url", "http://localhost:1080/docs/csv",
map("url", "http://localhost:" + PORT + "/docs/csv",
"header", map("method",
"POST", "Authorization", "Basic " + token,
"Content-Type", "application/json"),
Expand Down
6 changes: 4 additions & 2 deletions extended/src/test/java/apoc/ml/WatsonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.junit.Test;
import org.mockserver.integration.ClientAndServer;
import org.mockserver.model.Header;
import org.mockserver.socket.PortFactory;
import org.neo4j.test.rule.DbmsRule;
import org.neo4j.test.rule.ImpermanentDbmsRule;

Expand Down Expand Up @@ -42,17 +43,18 @@ public class WatsonTest {

@BeforeClass
public static void startServer() throws Exception {
int port = PortFactory.findFreePort();
TestUtil.registerProcedure(db, Watson.class);

String path = "/generation/text";
apocConfig().setProperty(APOC_ML_WATSON_URL, "http://localhost:1080" + path);
apocConfig().setProperty(APOC_ML_WATSON_URL, "http://localhost:" + port + path);
apocConfig().setProperty(APOC_IMPORT_FILE_ENABLED, true);
apocConfig().setProperty(APOC_ML_WATSON_PROJECT_ID, "fakeProjectId");

File urlFileName = new File(getUrlFileName("watson.json").getFile());
String body = FileUtils.readFileToString(urlFileName, UTF_8);

mockServer = startClientAndServer(1080);
mockServer = startClientAndServer(port);
mockServer.when(
request()
.withMethod("POST")
Expand Down
Loading

0 comments on commit b4e60c7

Please sign in to comment.