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

Try solving TeamCity errors in 5.25 #4220

Merged
merged 3 commits into from
Nov 7, 2024
Merged
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
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
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.QueryExecutionException;
import org.neo4j.graphdb.Result;
Expand Down Expand Up @@ -46,7 +47,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 @@ -55,7 +57,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
6 changes: 5 additions & 1 deletion extended/src/test/java/apoc/util/ExtendedTestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,13 @@ public static void testRetryCallEventually(GraphDatabaseService db, String call,
* but with multiple results
*/
public static void testResultEventually(GraphDatabaseService db, String call, Consumer<Result> resultConsumer, long timeout) {
testResultEventually(db, call, Map.of(), resultConsumer, timeout);
}

public static void testResultEventually(GraphDatabaseService db, String call, Map<String,Object> params, Consumer<Result> resultConsumer, long timeout) {
assertEventually(() -> {
try {
return db.executeTransactionally(call, Map.of(), r -> {
return db.executeTransactionally(call, params, r -> {
resultConsumer.accept(r);
return true;
});
Expand Down
Loading