Search in sources :

Example 1 with HazelcastDiscoveryServiceFactory

use of org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory in project neo4j by neo4j.

the class ServerGroupsIT method shouldUpdateGroupsOnStart.

@Test
public void shouldUpdateGroupsOnStart() throws Exception {
    AtomicReference<String> suffix = new AtomicReference<>("before");
    List<List<String>> expected;
    Map<String, IntFunction<String>> instanceCoreParams = new HashMap<>();
    instanceCoreParams.put(CausalClusteringSettings.server_groups.name(), (id) -> String.join(", ", makeCoreGroups(suffix.get(), id)));
    Map<String, IntFunction<String>> instanceReplicaParams = new HashMap<>();
    instanceReplicaParams.put(CausalClusteringSettings.server_groups.name(), (id) -> String.join(", ", makeReplicaGroups(suffix.get(), id)));
    int nServers = 3;
    cluster = new Cluster(testDir.directory("cluster"), nServers, nServers, new HazelcastDiscoveryServiceFactory(), emptyMap(), instanceCoreParams, emptyMap(), instanceReplicaParams, Standard.LATEST_NAME);
    // when
    cluster.start();
    // then
    expected = new ArrayList<>();
    for (CoreClusterMember core : cluster.coreMembers()) {
        expected.add(makeCoreGroups(suffix.get(), core.serverId()));
        expected.add(makeReplicaGroups(suffix.get(), core.serverId()));
    }
    for (CoreClusterMember core : cluster.coreMembers()) {
        assertEventually(core + " should have groups", () -> getServerGroups(core.database()), new GroupsMatcher(expected), 30, SECONDS);
    }
    // when
    expected.remove(makeCoreGroups(suffix.get(), 1));
    expected.remove(makeReplicaGroups(suffix.get(), 2));
    cluster.getCoreMemberById(1).shutdown();
    cluster.getReadReplicaById(2).shutdown();
    // should update groups of restarted servers
    suffix.set("after");
    cluster.addCoreMemberWithId(1).start();
    cluster.addReadReplicaWithId(2).start();
    expected.add(makeCoreGroups(suffix.get(), 1));
    expected.add(makeReplicaGroups(suffix.get(), 2));
    // then
    for (CoreClusterMember core : cluster.coreMembers()) {
        assertEventually(core + " should have groups", () -> getServerGroups(core.database()), new GroupsMatcher(expected), 30, SECONDS);
    }
}
Also used : HashMap(java.util.HashMap) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Cluster(org.neo4j.causalclustering.discovery.Cluster) AtomicReference(java.util.concurrent.atomic.AtomicReference) HazelcastDiscoveryServiceFactory(org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory) IntFunction(java.util.function.IntFunction) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Test(org.junit.Test)

Example 2 with HazelcastDiscoveryServiceFactory

use of org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory in project neo4j by neo4j.

the class ServerPoliciesLoadBalancingIT method defaultBehaviour.

@Test
public void defaultBehaviour() throws Exception {
    cluster = new Cluster(testDir.directory("cluster"), 3, 3, new HazelcastDiscoveryServiceFactory(), emptyMap(), emptyMap(), emptyMap(), emptyMap(), Standard.LATEST_NAME);
    cluster.start();
    assertGetServersEventuallyMatchesOnAllCores(new CountsMatcher(3, 1, 2, 3));
}
Also used : HazelcastDiscoveryServiceFactory(org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory) Cluster(org.neo4j.causalclustering.discovery.Cluster) Test(org.junit.Test)

Example 3 with HazelcastDiscoveryServiceFactory

use of org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory in project neo4j by neo4j.

the class ConnectionInfoIT method hzTest.

@Test
public void hzTest() throws Throwable {
    // given
    testSocket = bindPort("0.0.0.0", 4243);
    //when
    AssertableLogProvider logProvider = new AssertableLogProvider();
    AssertableLogProvider userLogProvider = new AssertableLogProvider();
    HazelcastDiscoveryServiceFactory hzFactory = new HazelcastDiscoveryServiceFactory();
    Config config = embeddedDefaults(stringMap(discovery_listen_address.name(), ":" + testSocket.getLocalPort(), CausalClusteringSettings.initial_discovery_members.name(), "localhost:" + testSocket.getLocalPort(), new BoltConnector("bolt").enabled.name(), "true", new HttpConnector("http").enabled.name(), "true"));
    Neo4jJobScheduler jobScheduler = new Neo4jJobScheduler();
    jobScheduler.init();
    CoreTopologyService coreTopologyService = hzFactory.coreTopologyService(config, new MemberId(UUID.randomUUID()), jobScheduler, logProvider, userLogProvider);
    try {
        coreTopologyService.init();
        coreTopologyService.start();
    }//then
     catch (Throwable throwable) {
    //expected
    }
    logProvider.assertContainsMessageContaining("Hazelcast was unable to start with setting");
    userLogProvider.assertContainsMessageContaining("Hazelcast was unable to start with setting");
}
Also used : Neo4jJobScheduler(org.neo4j.kernel.impl.util.Neo4jJobScheduler) MemberId(org.neo4j.causalclustering.identity.MemberId) HttpConnector(org.neo4j.kernel.configuration.HttpConnector) HazelcastDiscoveryServiceFactory(org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory) CoreTopologyService(org.neo4j.causalclustering.discovery.CoreTopologyService) BoltConnector(org.neo4j.kernel.configuration.BoltConnector) Config(org.neo4j.kernel.configuration.Config) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 4 with HazelcastDiscoveryServiceFactory

use of org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory in project neo4j by neo4j.

the class BackupStoreCopyInteractionStressTesting method shouldBehaveCorrectlyUnderStress.

@Test
public void shouldBehaveCorrectlyUnderStress() throws Exception {
    int numberOfCores = parseInt(fromEnv("BACKUP_STORE_COPY_INTERACTION_STRESS_NUMBER_OF_CORES", DEFAULT_NUMBER_OF_CORES));
    int numberOfEdges = parseInt(fromEnv("BACKUP_STORE_COPY_INTERACTION_STRESS_NUMBER_OF_EDGES", DEFAULT_NUMBER_OF_EDGES));
    long durationInMinutes = parseLong(fromEnv("BACKUP_STORE_COPY_INTERACTION_STRESS_DURATION", DEFAULT_DURATION_IN_MINUTES));
    String workingDirectory = fromEnv("BACKUP_STORE_COPY_INTERACTION_STRESS_WORKING_DIRECTORY", DEFAULT_WORKING_DIR);
    int baseCoreBackupPort = parseInt(fromEnv("BACKUP_STORE_COPY_INTERACTION_STRESS_BASE_CORE_BACKUP_PORT", DEFAULT_BASE_CORE_BACKUP_PORT));
    int baseEdgeBackupPort = parseInt(fromEnv("BACKUP_STORE_COPY_INTERACTION_STRESS_BASE_EDGE_BACKUP_PORT", DEFAULT_BASE_EDGE_BACKUP_PORT));
    boolean enableIndexes = parseBoolean(fromEnv("BACKUP_STORE_COPY_INTERACTION_STRESS_ENABLE_INDEXES", DEFAULT_ENABLE_INDEXES));
    String txPrune = fromEnv("BACKUP_STORE_COPY_INTERACTION_STRESS_TX_PRUNE", DEFAULT_TX_PRUNE);
    File clusterDirectory = ensureExistsAndEmpty(new File(workingDirectory, "cluster"));
    File backupDirectory = ensureExistsAndEmpty(new File(workingDirectory, "backups"));
    BiFunction<Boolean, Integer, SocketAddress> backupAddress = (isCore, id) -> new AdvertisedSocketAddress("localhost", (isCore ? baseCoreBackupPort : baseEdgeBackupPort) + id);
    Map<String, String> coreParams = enableRaftMessageLogging(configureRaftLogRotationAndPruning(configureTxLogRotationAndPruning(new HashMap<>(), txPrune)));
    Map<String, String> readReplicaParams = configureTxLogRotationAndPruning(new HashMap<>(), txPrune);
    Map<String, IntFunction<String>> instanceCoreParams = configureBackup(new HashMap<>(), id -> backupAddress.apply(true, id));
    Map<String, IntFunction<String>> instanceReadReplicaParams = configureBackup(new HashMap<>(), id -> backupAddress.apply(false, id));
    HazelcastDiscoveryServiceFactory discoveryServiceFactory = new HazelcastDiscoveryServiceFactory();
    Cluster cluster = new Cluster(clusterDirectory, numberOfCores, numberOfEdges, discoveryServiceFactory, coreParams, instanceCoreParams, readReplicaParams, instanceReadReplicaParams, Standard.LATEST_NAME);
    AtomicBoolean stopTheWorld = new AtomicBoolean();
    BooleanSupplier notExpired = untilTimeExpired(durationInMinutes, MINUTES);
    BooleanSupplier keepGoing = () -> !stopTheWorld.get() && notExpired.getAsBoolean();
    Runnable onFailure = () -> stopTheWorld.set(true);
    ExecutorService service = Executors.newFixedThreadPool(3);
    try {
        cluster.start();
        if (enableIndexes) {
            Workload.setupIndexes(cluster);
        }
        Future<Throwable> workload = service.submit(new Workload(keepGoing, onFailure, cluster));
        Future<Throwable> startStopWorker = service.submit(new StartStopLoad(fs, pageCache, keepGoing, onFailure, cluster, numberOfCores, numberOfEdges));
        Future<Throwable> backupWorker = service.submit(new BackupLoad(keepGoing, onFailure, cluster, numberOfCores, numberOfEdges, backupDirectory, backupAddress));
        long timeout = durationInMinutes + 5;
        assertNull(Exceptions.stringify(workload.get()), workload.get(timeout, MINUTES));
        assertNull(Exceptions.stringify(startStopWorker.get()), startStopWorker.get(timeout, MINUTES));
        assertNull(Exceptions.stringify(backupWorker.get()), backupWorker.get(timeout, MINUTES));
    } finally {
        cluster.shutdown();
        service.shutdown();
    }
    // let's cleanup disk space when everything went well
    FileUtils.deleteRecursively(clusterDirectory);
    FileUtils.deleteRecursively(backupDirectory);
}
Also used : StressTestingHelper.ensureExistsAndEmpty(org.neo4j.helper.StressTestingHelper.ensureExistsAndEmpty) Suppliers.untilTimeExpired(org.neo4j.function.Suppliers.untilTimeExpired) BiFunction(java.util.function.BiFunction) Exceptions(org.neo4j.helpers.Exceptions) StressTestingHelper.fromEnv(org.neo4j.helper.StressTestingHelper.fromEnv) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) MINUTES(java.util.concurrent.TimeUnit.MINUTES) BooleanSupplier(java.util.function.BooleanSupplier) SocketAddress(org.neo4j.helpers.SocketAddress) Future(java.util.concurrent.Future) AdvertisedSocketAddress(org.neo4j.helpers.AdvertisedSocketAddress) ClusterConfiguration.configureRaftLogRotationAndPruning(org.neo4j.causalclustering.stresstests.ClusterConfiguration.configureRaftLogRotationAndPruning) HazelcastDiscoveryServiceFactory(org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory) PageCacheRule(org.neo4j.test.rule.PageCacheRule) Map(java.util.Map) ClusterConfiguration.configureBackup(org.neo4j.causalclustering.stresstests.ClusterConfiguration.configureBackup) System.getProperty(java.lang.System.getProperty) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) IntFunction(java.util.function.IntFunction) Standard(org.neo4j.kernel.impl.store.format.standard.Standard) PageCache(org.neo4j.io.pagecache.PageCache) ClusterConfiguration.enableRaftMessageLogging(org.neo4j.causalclustering.stresstests.ClusterConfiguration.enableRaftMessageLogging) FileUtils(org.neo4j.io.fs.FileUtils) Test(org.junit.Test) Integer.parseInt(java.lang.Integer.parseInt) File(java.io.File) Executors(java.util.concurrent.Executors) Cluster(org.neo4j.causalclustering.discovery.Cluster) RuleChain(org.junit.rules.RuleChain) Rule(org.junit.Rule) DefaultFileSystemRule(org.neo4j.test.rule.fs.DefaultFileSystemRule) Boolean.parseBoolean(java.lang.Boolean.parseBoolean) Assert.assertNull(org.junit.Assert.assertNull) DatabaseConfiguration.configureTxLogRotationAndPruning(org.neo4j.helper.DatabaseConfiguration.configureTxLogRotationAndPruning) Long.parseLong(java.lang.Long.parseLong) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) AdvertisedSocketAddress(org.neo4j.helpers.AdvertisedSocketAddress) HazelcastDiscoveryServiceFactory(org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Boolean.parseBoolean(java.lang.Boolean.parseBoolean) SocketAddress(org.neo4j.helpers.SocketAddress) AdvertisedSocketAddress(org.neo4j.helpers.AdvertisedSocketAddress) BooleanSupplier(java.util.function.BooleanSupplier) Cluster(org.neo4j.causalclustering.discovery.Cluster) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IntFunction(java.util.function.IntFunction) ExecutorService(java.util.concurrent.ExecutorService) File(java.io.File) Test(org.junit.Test)

Example 5 with HazelcastDiscoveryServiceFactory

use of org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory in project neo4j by neo4j.

the class CatchupStoreCopyInteractionStressTesting method shouldBehaveCorrectlyUnderStress.

@Test
public void shouldBehaveCorrectlyUnderStress() throws Exception {
    int numberOfCores = parseInt(fromEnv("CATCHUP_STORE_COPY_INTERACTION_STRESS_NUMBER_OF_CORES", DEFAULT_NUMBER_OF_CORES));
    int numberOfEdges = parseInt(fromEnv("CATCHUP_STORE_COPY_INTERACTION_STRESS_NUMBER_OF_EDGES", DEFAULT_NUMBER_OF_EDGES));
    long durationInMinutes = parseLong(fromEnv("CATCHUP_STORE_COPY_INTERACTION_STRESS_DURATION", DEFAULT_DURATION_IN_MINUTES));
    String workingDirectory = fromEnv("CATCHUP_STORE_COPY_INTERACTION_STRESS_WORKING_DIRECTORY", DEFAULT_WORKING_DIR);
    boolean enableIndexes = parseBoolean(fromEnv("CATCHUP_STORE_COPY_INTERACTION_STRESS_ENABLE_INDEXES", DEFAULT_ENABLE_INDEXES));
    String txPrune = fromEnv("CATCHUP_STORE_COPY_INTERACTION_STRESS_TX_PRUNE", DEFAULT_TX_PRUNE);
    File clusterDirectory = ensureExistsAndEmpty(new File(workingDirectory, "cluster"));
    Map<String, String> coreParams = enableRaftMessageLogging(configureRaftLogRotationAndPruning(configureTxLogRotationAndPruning(new HashMap<>(), txPrune)));
    Map<String, String> edgeParams = configureTxLogRotationAndPruning(new HashMap<>(), txPrune);
    HazelcastDiscoveryServiceFactory discoveryServiceFactory = new HazelcastDiscoveryServiceFactory();
    Cluster cluster = new Cluster(clusterDirectory, numberOfCores, numberOfEdges, discoveryServiceFactory, coreParams, emptyMap(), edgeParams, emptyMap(), Standard.LATEST_NAME);
    AtomicBoolean stopTheWorld = new AtomicBoolean();
    BooleanSupplier notExpired = untilTimeExpired(durationInMinutes, MINUTES);
    BooleanSupplier keepGoing = () -> !stopTheWorld.get() && notExpired.getAsBoolean();
    Runnable onFailure = () -> stopTheWorld.set(true);
    ExecutorService service = Executors.newCachedThreadPool();
    try {
        cluster.start();
        if (enableIndexes) {
            Workload.setupIndexes(cluster);
        }
        Future<Throwable> workload = service.submit(new Workload(keepGoing, onFailure, cluster));
        Future<Throwable> startStopWorker = service.submit(new StartStopLoad(fs, pageCache, keepGoing, onFailure, cluster, numberOfCores, numberOfEdges));
        Future<Throwable> catchUpWorker = service.submit(new CatchUpLoad(keepGoing, onFailure, cluster));
        long timeout = durationInMinutes + 5;
        assertNull(Exceptions.stringify(workload.get()), workload.get(timeout, MINUTES));
        assertNull(Exceptions.stringify(startStopWorker.get()), startStopWorker.get(timeout, MINUTES));
        assertNull(Exceptions.stringify(catchUpWorker.get()), catchUpWorker.get(timeout, MINUTES));
    } finally {
        cluster.shutdown();
        service.shutdown();
    }
    // let's cleanup disk space when everything went well
    FileUtils.deleteRecursively(clusterDirectory);
}
Also used : Cluster(org.neo4j.causalclustering.discovery.Cluster) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HazelcastDiscoveryServiceFactory(org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory) ExecutorService(java.util.concurrent.ExecutorService) File(java.io.File) BooleanSupplier(java.util.function.BooleanSupplier) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 HazelcastDiscoveryServiceFactory (org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory)8 Cluster (org.neo4j.causalclustering.discovery.Cluster)7 HashMap (java.util.HashMap)4 IntFunction (java.util.function.IntFunction)4 File (java.io.File)2 ExecutorService (java.util.concurrent.ExecutorService)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 BooleanSupplier (java.util.function.BooleanSupplier)2 CoreClusterMember (org.neo4j.causalclustering.discovery.CoreClusterMember)2 Boolean.parseBoolean (java.lang.Boolean.parseBoolean)1 Integer.parseInt (java.lang.Integer.parseInt)1 Long.parseLong (java.lang.Long.parseLong)1 System.getProperty (java.lang.System.getProperty)1 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 List (java.util.List)1 Map (java.util.Map)1 Executors (java.util.concurrent.Executors)1 Future (java.util.concurrent.Future)1