From 7d73410b44663301a30253a6366b0ac2cff56ddd Mon Sep 17 00:00:00 2001 From: Giuseppe Villani Date: Thu, 7 Nov 2024 10:08:21 +0100 Subject: [PATCH] Try solving TeamCity errors in 5.26 (#4220) * Try solving TC errors in 5.25 * fix tests * restored GephiMock --- .../test/java/apoc/vectordb/QdrantTest.java | 49 ++++++++++++------- .../src/test/java/apoc/load/LoadCsvTest.java | 19 ++++--- .../src/test/java/apoc/ml/WatsonTest.java | 6 ++- .../test/java/apoc/util/ExtendedTestUtil.java | 6 ++- 4 files changed, 50 insertions(+), 30 deletions(-) diff --git a/extended-it/src/test/java/apoc/vectordb/QdrantTest.java b/extended-it/src/test/java/apoc/vectordb/QdrantTest.java index 3bce11f137..9e6a7965f6 100644 --- a/extended-it/src/test/java/apoc/vectordb/QdrantTest.java +++ b/extended-it/src/test/java/apoc/vectordb/QdrantTest.java @@ -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; @@ -59,6 +60,7 @@ public class QdrantTest { private static final Map ADMIN_AUTHORIZATION = getAuthHeader(ADMIN_KEY); private static final Map READONLY_AUTHORIZATION = getAuthHeader(READONLY_KEY); private static final Map ADMIN_HEADER_CONF = map(HEADERS_KEY, ADMIN_AUTHORIZATION); + public static final long TIMEOUT = 10L; private static String HOST; @@ -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 row = r.next(); @@ -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 row = r.next(); @@ -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" } } ] @@ -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 @@ -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 row = r.next(); @@ -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 row = r.next(); @@ -362,7 +370,8 @@ MAPPING_KEY, map( assertLondonResult(row, NODE); assertNotNull(row.get("score")); assertNotNull(row.get("vector")); - }); + }, + TIMEOUT); assertNodesCreated(db); } @@ -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 row = r.next(); @@ -437,7 +446,8 @@ MAPPING_KEY, map(EMBEDDING_KEY, "vect", assertLondonResult(row, NODE); assertNotNull(row.get("score")); assertNotNull(row.get("vector")); - }); + }, + TIMEOUT); assertNodesCreated(db); } @@ -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 row = r.next(); @@ -467,7 +477,8 @@ MAPPING_KEY, map( assertLondonResult(row, REL); assertNotNull(row.get("score")); assertNotNull(row.get("vector")); - }); + }, + TIMEOUT); assertRelsCreated(db); } diff --git a/extended/src/test/java/apoc/load/LoadCsvTest.java b/extended/src/test/java/apoc/load/LoadCsvTest.java index c8e77d04fb..c33f15907f 100644 --- a/extended/src/test/java/apoc/load/LoadCsvTest.java +++ b/extended/src/test/java/apoc/load/LoadCsvTest.java @@ -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; @@ -47,7 +48,8 @@ public class LoadCsvTest { private static ClientAndServer mockServer; - + private static int PORT; + private static final List> RESPONSE_BODY = List.of( Map.of("headFoo", "one", "headBar", "two"), Map.of("headFoo", "three", "headBar", "four"), @@ -56,7 +58,8 @@ public class LoadCsvTest { @BeforeClass public static void startServer() { - mockServer = startClientAndServer(1080); + PORT = PortFactory.findFreePort(); + mockServer = startClientAndServer(PORT); } @AfterClass @@ -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") @@ -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())) ); } @@ -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") @@ -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())) @@ -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") @@ -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"), diff --git a/extended/src/test/java/apoc/ml/WatsonTest.java b/extended/src/test/java/apoc/ml/WatsonTest.java index 111e0188d8..003830a312 100644 --- a/extended/src/test/java/apoc/ml/WatsonTest.java +++ b/extended/src/test/java/apoc/ml/WatsonTest.java @@ -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; @@ -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") diff --git a/extended/src/test/java/apoc/util/ExtendedTestUtil.java b/extended/src/test/java/apoc/util/ExtendedTestUtil.java index c19a04f859..9aeb6747a5 100644 --- a/extended/src/test/java/apoc/util/ExtendedTestUtil.java +++ b/extended/src/test/java/apoc/util/ExtendedTestUtil.java @@ -126,9 +126,13 @@ public static void testRetryCallEventually(GraphDatabaseService db, String call, * but with multiple results */ public static void testResultEventually(GraphDatabaseService db, String call, Consumer resultConsumer, long timeout) { + testResultEventually(db, call, Map.of(), resultConsumer, timeout); + } + + public static void testResultEventually(GraphDatabaseService db, String call, Map params, Consumer resultConsumer, long timeout) { assertEventually(() -> { try { - return db.executeTransactionally(call, Map.of(), r -> { + return db.executeTransactionally(call, params, r -> { resultConsumer.accept(r); return true; });