Skip to content

Commit

Permalink
Try again to solve remaining TeamCity errors (#4206) (#4221)
Browse files Browse the repository at this point in the history
* Try again to solve remaining TeamCity errors

* added assertEventually to PostgresJdbcTest
  • Loading branch information
vga91 authored Nov 6, 2024
1 parent d8977e6 commit d473d31
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.testcontainers.couchbase.BucketDefinition;
import org.testcontainers.couchbase.CouchbaseContainer;

import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -64,6 +65,7 @@ public class CouchbaseTestUtils {

public static boolean fillDB(Cluster cluster) {
Bucket couchbaseBucket = cluster.bucket(BUCKET_NAME);
couchbaseBucket.waitUntilReady(Duration.ofMinutes(1));
Collection collection = couchbaseBucket.defaultCollection();
collection.insert("artist:vincent_van_gogh", VINCENT_VAN_GOGH);
QueryResult queryResult = cluster.query(String.format(QUERY, BUCKET_NAME),
Expand Down
31 changes: 18 additions & 13 deletions extended-it/src/test/java/apoc/load/PostgresJdbcTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@

import java.sql.SQLException;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import static apoc.util.TestUtil.testCall;
import static apoc.util.TestUtil.testResult;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.neo4j.test.assertion.Assert.assertEventually;

public class PostgresJdbcTest extends AbstractJdbcTest {

Expand Down Expand Up @@ -132,19 +134,22 @@ public void testIssue4141PeriodicIterateWithJdbc() throws Exception {
assertPgStatActivityHasOnlyActiveState();
}

private static void assertPgStatActivityHasOnlyActiveState() throws Exception {
// connect to postgres and execute the query `select state from pg_stat_activity`
String psql = postgress.execInContainer(
"psql", "postgresql://test:test@localhost/test", "-c", "select state from pg_stat_activity;")
.toString();

assertTrue("Current pg_stat_activity is: " + psql, psql.contains("active"));

// the result without the https://github.com/neo4j-contrib/neo4j-apoc-procedures/issues/4141 change
// is not deterministic, can be `too many clients already` or (not very often) `idle`
assertFalse("Current pg_stat_activity is: " + psql,
psql.contains("too many clients already") || psql.contains("idle"));

private static void assertPgStatActivityHasOnlyActiveState() {
assertEventually(() -> {
// connect to postgres and execute the query `select state from pg_stat_activity`
String psql = postgress.execInContainer(
"psql", "postgresql://test:test@localhost/test", "-c", "select state from pg_stat_activity;")
.toString();

assertTrue("Current pg_stat_activity is: " + psql, psql.contains("active"));

// the result without the https://github.com/neo4j-contrib/neo4j-apoc-procedures/issues/4141 change
// is not deterministic, can be `too many clients already` or (not very often) `idle`
assertFalse("Current pg_stat_activity is: " + psql,
psql.contains("too many clients already") || psql.contains("idle"));

return true;
}, v -> v, 20L, TimeUnit.SECONDS);
}

private void assertPeriodicIterate(Result result) {
Expand Down
5 changes: 4 additions & 1 deletion extended/src/test/java/apoc/export/csv/ExportCsvTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public class ExportCsvTest {
@ClassRule
public static TemporaryFolder storeDir = new TemporaryFolder();

@ClassRule
public static TemporaryFolder hdfsDir = new TemporaryFolder();

private static GraphDatabaseService db;
private static DatabaseManagementService dbms;

Expand All @@ -64,7 +67,7 @@ public static void setUp() throws Exception {
apocConfig().setProperty(APOC_EXPORT_FILE_ENABLED, true);
db.executeTransactionally("CREATE (f:User1:User {name:'foo',age:42,male:true,kids:['a','b','c']})-[:KNOWS]->(b:User {name:'bar',age:42}),(c:User {age:12})");
db.executeTransactionally("CREATE (f:Address1:Address {name:'Andrea', city: 'Milano', street:'Via Garibaldi, 7'})-[:NEXT_DELIVERY]->(a:Address {name: 'Bar Sport'}), (b:Address {street: 'via Benni'})");
miniDFSCluster = HdfsTestUtils.getLocalHDFSCluster();
miniDFSCluster = HdfsTestUtils.getLocalHDFSCluster(hdfsDir.getRoot());
}

@AfterClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.neo4j.configuration.GraphDatabaseSettings;
import org.neo4j.test.rule.DbmsRule;
import org.neo4j.test.rule.ImpermanentDbmsRule;
Expand All @@ -28,6 +29,9 @@ public class ParquetHdfsTest {
directory.mkdirs();
}

@ClassRule
public static TemporaryFolder hdfsDir = new TemporaryFolder();

@ClassRule
public static DbmsRule db = new ImpermanentDbmsRule()
.withSetting(GraphDatabaseSettings.load_csv_file_url_root, directory.toPath().toAbsolutePath());
Expand All @@ -37,7 +41,7 @@ public class ParquetHdfsTest {
@BeforeClass
public static void setUp() throws Exception {
beforeClassCommon(db);
miniDFSCluster = HdfsTestUtils.getLocalHDFSCluster();
miniDFSCluster = HdfsTestUtils.getLocalHDFSCluster(hdfsDir.getRoot());
}

@Before
Expand Down
7 changes: 6 additions & 1 deletion extended/src/test/java/apoc/load/LoadHdfsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;

import org.junit.rules.TemporaryFolder;
import org.neo4j.test.rule.DbmsRule;
import org.neo4j.test.rule.ImpermanentDbmsRule;

Expand All @@ -28,6 +30,9 @@

public class LoadHdfsTest {

@ClassRule
public static TemporaryFolder hdfsDir = new TemporaryFolder();

@Rule
public DbmsRule db = new ImpermanentDbmsRule();

Expand All @@ -36,7 +41,7 @@ public class LoadHdfsTest {
@Before public void setUp() throws Exception {
TestUtil.registerProcedure(db, LoadCsv.class);
apocConfig().setProperty(APOC_IMPORT_FILE_ENABLED, true);
miniDFSCluster = HdfsTestUtils.getLocalHDFSCluster();
miniDFSCluster = HdfsTestUtils.getLocalHDFSCluster(hdfsDir.getRoot());
FileSystem fs = miniDFSCluster.getFileSystem();
String fileName = "test.csv";
Path file = new Path(fileName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void testLoadLDAPWithDefaultPort() {
}

private static void testLoadLDAPCommon(int port, boolean ssl) {
Map<String, Object> conn = Map.of("ldapHost", "localhost:" + port,
Map<String, Object> conn = Map.of("ldapHost", ldap.getHost() + ":" + port,
"loginDN", "cn=admin,dc=example,dc=org",
"loginPW", "admin",
"ssl", ssl);
Expand Down
3 changes: 1 addition & 2 deletions extended/src/test/java/apoc/util/HdfsTestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ private static int getFreePort() throws IOException {
}
}

public static MiniDFSCluster getLocalHDFSCluster() throws Exception {
public static MiniDFSCluster getLocalHDFSCluster(File hdfsPath) throws Exception {
setHadoopHomeWindows();
Configuration conf = new HdfsConfiguration();
conf.set("fs.defaultFS", "hdfs://localhost");
File hdfsPath = new File(System.getProperty("user.dir") + File.separator + "hadoop" + File.separator + "hdfs");
hdfsPath.setWritable(true);
conf.set(MiniDFSCluster.HDFS_MINIDFS_BASEDIR, hdfsPath.getAbsolutePath());
MiniDFSCluster miniDFSCluster = new MiniDFSCluster.Builder(conf)
Expand Down

0 comments on commit d473d31

Please sign in to comment.