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

[2kuFEKOe] Fix flaky test #508

Closed
wants to merge 1 commit into from
Closed
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
15 changes: 15 additions & 0 deletions core/src/test/java/apoc/cypher/CypherInitializerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@
import apoc.util.TestUtil;
import apoc.util.Utils;
import apoc.util.collection.Iterators;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;

import java.util.Collections;
import java.util.Map;

import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.kernel.availability.AvailabilityListener;
Expand All @@ -40,6 +43,7 @@
import org.neo4j.test.rule.ImpermanentDbmsRule;

import static apoc.ApocConfig.APOC_CONFIG_INITIALIZER;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME;
import static org.neo4j.configuration.GraphDatabaseSettings.SYSTEM_DATABASE_NAME;
Expand Down Expand Up @@ -135,6 +139,17 @@ public void multipleInitializersWorks2() {
expectNodeCount(1);
}

@Ignore // TODO This should work according to the documentation
@Env({
@EnvSetting(key= APOC_CONFIG_INITIALIZER + "." + SYSTEM_DATABASE_NAME + ".0", value="create database hellohi if not exists")
})
public void createDbInInitialize() {
GraphDatabaseService systemDb = dbmsRule.getManagementService().database(SYSTEM_DATABASE_NAME);
final var databases = systemDb
.executeTransactionally( "show databases yield name", Map.of(), res -> res.stream().map(r -> r.get("name")).toList());
assertThat(databases, Matchers.hasItem("hellohi"));
}

@Test
@Env({ // this only creates 2 nodes if the statements run in same order
@EnvSetting(key= APOC_CONFIG_INITIALIZER + "." + SYSTEM_DATABASE_NAME, value="create user dummy set password 'abcd1234'")
Expand Down
24 changes: 12 additions & 12 deletions it/src/test/java/apoc/it/core/TriggerEnterpriseFeaturesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import org.neo4j.driver.AuthTokens;
import org.neo4j.driver.Driver;
import org.neo4j.driver.GraphDatabase;
Expand All @@ -37,7 +38,6 @@
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;

import static apoc.ApocConfig.APOC_CONFIG_INITIALIZER;
import static apoc.ApocConfig.APOC_TRIGGER_ENABLED;
import static apoc.SystemPropertyKeys.database;
import static apoc.trigger.TriggerHandler.TRIGGER_REFRESH;
Expand All @@ -57,6 +57,7 @@
import static org.neo4j.driver.SessionConfig.forDatabase;
import static org.neo4j.test.assertion.Assert.assertEventually;


public class TriggerEnterpriseFeaturesTest {
private static final String FOO_DB = "foo";
private static final String INIT_DB = "initdb";
Expand All @@ -68,26 +69,25 @@ public class TriggerEnterpriseFeaturesTest {
private static Session session;

@BeforeClass
public static void beforeAll() {
final String cypherInitializer = String.format("%s.%s.0",
APOC_CONFIG_INITIALIZER, SYSTEM_DATABASE_NAME);
final String createInitDb = String.format("CREATE DATABASE %s IF NOT EXISTS", INIT_DB);
public static void beforeAll()
{
//final String cypherInitializer = String.format("%s.%s.0", APOC_CONFIG_INITIALIZER, SYSTEM_DATABASE_NAME);
//final String createInitDb = String.format("CREATE DATABASE %s IF NOT EXISTS", INIT_DB);

// We build the project, the artifact will be placed into ./build/libs
neo4jContainer = createEnterpriseDB(List.of(TestContainerUtil.ApocPackage.CORE), true)
.withEnv(APOC_TRIGGER_ENABLED, "true")
.withEnv(TRIGGER_REFRESH, String.valueOf(TRIGGER_DEFAULT_REFRESH))
.withEnv(cypherInitializer, createInitDb);
.withEnv(TRIGGER_REFRESH, String.valueOf(TRIGGER_DEFAULT_REFRESH));
//.withEnv(cypherInitializer, createInitDb); // TODO Bug in initializer prevents us from doing this
neo4jContainer.start();
session = neo4jContainer.getSession();

assertTrue(neo4jContainer.isRunning());

try (Session sysSession = neo4jContainer.getDriver().session(forDatabase(SYSTEM_DATABASE_NAME))) {
sysSession.writeTransaction(tx -> tx.run(String.format("CREATE DATABASE %s WAIT;", FOO_DB)));

sysSession.run(String.format("CREATE USER %s SET PASSWORD '%s' SET PASSWORD CHANGE NOT REQUIRED",
NO_ADMIN_USER, NO_ADMIN_PWD));
try (final var sysSession = neo4jContainer.getDriver().session(forDatabase(SYSTEM_DATABASE_NAME))) {
sysSession.run("CREATE DATABASE %s WAIT".formatted(FOO_DB)).consume();
sysSession.run("CREATE DATABASE %s WAIT".formatted(INIT_DB)).consume();
sysSession.run("CREATE USER %s SET PASSWORD '%s' SET PASSWORD CHANGE NOT REQUIRED".formatted(NO_ADMIN_USER, NO_ADMIN_PWD)).consume();
}
}

Expand Down
Loading