test(neo4j): Improve test performance (#6142)

Reuse neo4j graph service in test for performance improvements.
This commit is contained in:
david-leifker 2022-10-24 10:49:06 -05:00 committed by GitHub
parent ac6779989a
commit 7cdc9f7fcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View File

@ -3,6 +3,7 @@ package com.linkedin.metadata.graph.neo4j;
import com.codahale.metrics.Timer;
import com.datahub.util.Statement;
import com.datahub.util.exception.RetryLimitReached;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableMap;
import com.linkedin.common.urn.Urn;
import com.linkedin.metadata.graph.Edge;
@ -254,6 +255,11 @@ public class Neo4jGraphService implements GraphService {
removeNodesMatchingLabel(".*");
}
@VisibleForTesting
public void wipe() {
runQuery(new Statement("MATCH (n) DETACH DELETE n", Map.of())).consume();
}
// visible for testing
@Nonnull
Statement buildStatement(@Nonnull String queryTemplate, @Nonnull Map<String, Object> params) {

View File

@ -10,7 +10,8 @@ import com.linkedin.metadata.query.filter.RelationshipFilter;
import org.neo4j.driver.Driver;
import org.neo4j.driver.GraphDatabase;
import org.testng.SkipException;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@ -28,15 +29,21 @@ public class Neo4jGraphServiceTest extends GraphServiceTestBase {
private Driver _driver;
private Neo4jGraphService _client;
@BeforeMethod
@BeforeClass
public void init() {
_serverBuilder = new Neo4jTestServerBuilder();
_serverBuilder.newServer();
_driver = GraphDatabase.driver(_serverBuilder.boltURI());
_client = new Neo4jGraphService(new LineageRegistry(SnapshotEntityRegistry.getInstance()), _driver);
_client.clear();
}
@AfterMethod
@BeforeMethod
public void wipe() {
_client.wipe();
}
@AfterClass
public void tearDown() {
_serverBuilder.shutdown();
}