Пример #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCreateConstraintOnMaster()
            public virtual void ShouldCreateConstraintOnMaster()
            {
                // given
                ClusterManager.ManagedCluster cluster = ClusterRule.startCluster();
                HighlyAvailableGraphDatabase  master  = cluster.Master;
                string type = type(0);
                string key  = key(0);

                // when
                using (Transaction tx = master.BeginTx())
                {
                    CreateConstraint(master, type, key);
                    tx.Success();
                }

                cluster.Sync();

                // then
                foreach (HighlyAvailableGraphDatabase clusterMember in cluster.AllMembers)
                {
                    using (Transaction tx = clusterMember.BeginTx())
                    {
                        ConstraintDefinition constraint = GetConstraint(clusterMember, type, key);
                        ValidateLabelOrRelationshipType(constraint, type);
                        assertEquals(key, single(constraint.PropertyKeys));
                        tx.Success();
                    }
                }
            }
Пример #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotBeAbleToWriteToReadReplica() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotBeAbleToWriteToReadReplica()
        {
            // given
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.causalclustering.discovery.Cluster<?> cluster = clusterRule.startCluster();
            Cluster <object> cluster = ClusterRule.startCluster();

            ReadReplicaGraphDatabase readReplica = cluster.FindAnyReadReplica().database();

            // when
            try
            {
                using (Transaction tx = readReplica.BeginTx())
                {
                    Node node = readReplica.CreateNode();
                    node.SetProperty("foobar", "baz_bat");
                    node.AddLabel(Label.label("Foo"));
                    tx.Success();
                    fail("should have thrown");
                }
            }
            catch (WriteOperationsNotAllowedException)
            {
                // then all good
            }
        }
Пример #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReuseIdsInCluster() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReuseIdsInCluster()
        {
            _cluster = ClusterRule.startCluster();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.apache.commons.lang3.mutable.MutableLong first = new org.apache.commons.lang3.mutable.MutableLong();
            MutableLong first = new MutableLong();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.apache.commons.lang3.mutable.MutableLong second = new org.apache.commons.lang3.mutable.MutableLong();
            MutableLong second = new MutableLong();

            CoreClusterMember leader1 = CreateThreeNodes(_cluster, first, second);
            CoreClusterMember leader2 = RemoveTwoNodes(_cluster, first, second);

            assumeTrue(leader1 != null && leader1.Equals(leader2));

            // Force maintenance on leader
            IdMaintenanceOnLeader(leader1);
            IdGeneratorFactory idGeneratorFactory = ResolveDependency(leader1, typeof(IdGeneratorFactory));
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.store.id.IdGenerator idGenerator = idGeneratorFactory.get(org.neo4j.kernel.impl.store.id.IdType.NODE);
            IdGenerator idGenerator = idGeneratorFactory.Get(IdType.NODE);

            assertEquals(2, idGenerator.DefragCount);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.apache.commons.lang3.mutable.MutableLong node1id = new org.apache.commons.lang3.mutable.MutableLong();
            MutableLong node1id = new MutableLong();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.apache.commons.lang3.mutable.MutableLong node2id = new org.apache.commons.lang3.mutable.MutableLong();
            MutableLong node2id = new MutableLong();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.apache.commons.lang3.mutable.MutableLong node3id = new org.apache.commons.lang3.mutable.MutableLong();
            MutableLong node3id = new MutableLong();

            CoreClusterMember clusterMember = _cluster.coreTx((db, tx) =>
            {
                Node node1 = Db.createNode();
                Node node2 = Db.createNode();
                Node node3 = Db.createNode();

                node1id.Value = node1.Id;
                node2id.Value = node2.Id;
                node3id.Value = node3.Id;

                tx.success();
            });

            assumeTrue(leader1.Equals(clusterMember));

            assertEquals(first.longValue(), node1id.longValue());
            assertEquals(second.longValue(), node2id.longValue());
            assertEquals(idGenerator.HighestPossibleIdInUse, node3id.longValue());
        }
Пример #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void restartFirstServer() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void RestartFirstServer()
        {
            // given
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.causalclustering.discovery.Cluster<?> cluster = clusterRule.startCluster();
            Cluster <object> cluster = ClusterRule.startCluster();

            // when
            cluster.RemoveCoreMemberWithServerId(0);
            cluster.AddCoreMemberWithId(0).start();

            // then
            cluster.Shutdown();
        }
Пример #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void leaderShouldStepDownWhenFollowersAreGone() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void LeaderShouldStepDownWhenFollowersAreGone()
        {
            // when
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.causalclustering.discovery.Cluster<?> cluster = clusterRule.startCluster();
            Cluster <object> cluster = ClusterRule.startCluster();

            //Do some work to make sure the cluster is operating normally.
            CoreClusterMember leader = cluster.CoreTx((db, tx) =>
            {
                Node node = Db.createNode(Label.label("bam"));
                node.setProperty("bam", "bam");
                tx.success();
            });

            ThrowingSupplier <IList <CoreClusterMember>, Exception> followers = () => cluster.CoreMembers().Where(m => m.raft().currentRole() != Role.LEADER).ToList();

            assertEventually("All followers visible", followers, Matchers.hasSize(7), 2, TimeUnit.MINUTES);

            //when
            //shutdown 4 servers, leaving 4 remaining and therefore not a quorum.
            followers.Get().subList(0, 4).forEach(CoreClusterMember.shutdown);

            //then
            assertEventually("Leader should have stepped down.", () => leader.Raft().Leader, Matchers.@is(false), 2, TimeUnit.MINUTES);
        }
Пример #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBeAbleToDownloadLargerFreshSnapshot() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldBeAbleToDownloadLargerFreshSnapshot()
        {
            // given
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.causalclustering.discovery.Cluster<?> cluster = clusterRule.startCluster();
            Cluster <object> cluster = ClusterRule.startCluster();

            CoreClusterMember source = cluster.CoreTx((db, tx) =>
            {
                createData(db, 1000);
                tx.success();
            });

            // when
            CoreClusterMember follower = cluster.AwaitCoreMemberWithRole(Role.FOLLOWER, 5, TimeUnit.SECONDS);

            // shutdown the follower, remove the store, restart
            follower.Shutdown();
            DeleteDirectoryRecursively(follower.DatabaseDirectory(), follower.ServerId());
            DeleteDirectoryRecursively(follower.ClusterStateDirectory(), follower.ServerId());
            follower.Start();

            // then
            assertEquals(DbRepresentation.of(source.Database()), DbRepresentation.of(follower.Database()));
        }
Пример #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void updatePullerSwitchOnNodeModeSwitch() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void UpdatePullerSwitchOnNodeModeSwitch()
        {
            ClusterManager.ManagedCluster cluster = ClusterRule.startCluster();

            Label firstLabel = Label.label("firstLabel");

            CreateLabeledNodeOnMaster(cluster, firstLabel);
            // force update puller to work
            PullUpdatesOnSlave(cluster);
            // node should exist on slave now
            CheckLabeledNodeExistenceOnSlave(cluster, firstLabel);
            // verify that puller working on slave and not working on master
            VerifyUpdatePullerThreads(cluster);

            for (int i = 1; i <= 2; i++)
            {
                // switch roles in cluster - now update puller should be stopped on old slave and start on old master.
                ClusterManager.RepairKit repairKit = cluster.Shutdown(cluster.Master);
                cluster.Await(masterAvailable());

                Label currentLabel = Label.label("label_" + i);

                CreateLabeledNodeOnMaster(cluster, currentLabel);

                repairKit.Repair();
                cluster.Await(allSeesAllAsAvailable(), 120);

                // forcing updates pulling
                PullUpdatesOnSlave(cluster);
                CheckLabeledNodeExistenceOnSlave(cluster, currentLabel);
                // checking pulling threads
                VerifyUpdatePullerThreads(cluster);
            }
        }
Пример #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleSlaveWritingFirstAfterStoryCopy() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldHandleSlaveWritingFirstAfterStoryCopy()
        {
            // Given
            ISet <long> expected = new HashSet <object>();

            ClusterManager.ManagedCluster cluster = ClusterRule.startCluster();
            HighlyAvailableGraphDatabase  master  = cluster.Master;
            HighlyAvailableGraphDatabase  slave   = cluster.AnySlave;

            // When
            expected.Add(CreateOneNode(master));
            cluster.Sync();

            // ... crash the slave
            File slaveStoreDirectory = cluster.GetDatabaseDir(slave);

            ClusterManager.RepairKit shutdownSlave = cluster.Shutdown(slave);
            deleteRecursively(slaveStoreDirectory);

            // ... and slave copy store from master
            slave = shutdownSlave.Repair();
            // ... and first write after crash occurs on salve
            expected.Add(CreateOneNode(slave));
            cluster.Sync();

            // Then
            assertEquals(expected, CollectIds(master));
            assertEquals(expected, CollectIds(slave));
        }
Пример #9
0
        private ClusterManager.ManagedCluster StartCluster()
        {
            _clusterRule.withSharedSetting(GraphDatabaseSettings.lock_manager, LockManagerName);

            ClusterManager.ManagedCluster cluster = _clusterRule.startCluster();
            cluster.Await(ClusterManager.allSeesAllAsAvailable());
            return(cluster);
        }
Пример #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setup() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void Setup()
        {
            _fs      = _fileSystemRule.get();
            _cluster = _clusterRule.startCluster();
            _cluster.coreTx((db, tx) =>
            {
                SampleData.CreateSchema(db);
                tx.success();
            });
        }
Пример #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldMonitorCoreEdge() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldMonitorCoreEdge()
        {
            // given
            _cluster = ClusterRule.startCluster();

            // when
            CoreClusterMember coreMember = _cluster.coreTx((db, tx) =>
            {
                Node node = Db.createNode(label("boo"));
                node.setProperty("foobar", "baz_bat");
                tx.success();
            });

            // then
            foreach (CoreClusterMember db in _cluster.coreMembers())
            {
                AssertAllNodesVisible(Db.database());
            }

            foreach (ReadReplica db in _cluster.readReplicas())
            {
                AssertAllNodesVisible(Db.database());
            }

            File coreMetricsDir = new File(coreMember.HomeDir(), csvPath.DefaultValue);

            assertEventually("append index eventually accurate", () => readLongValue(metricsCsv(coreMetricsDir, CoreMetrics.APPEND_INDEX)), greaterThan(0L), TIMEOUT, TimeUnit.SECONDS);

            assertEventually("commit index eventually accurate", () => readLongValue(metricsCsv(coreMetricsDir, CoreMetrics.COMMIT_INDEX)), greaterThan(0L), TIMEOUT, TimeUnit.SECONDS);

            assertEventually("term eventually accurate", () => readLongValue(metricsCsv(coreMetricsDir, CoreMetrics.TERM)), greaterThanOrEqualTo(0L), TIMEOUT, TimeUnit.SECONDS);

            assertEventually("tx pull requests received eventually accurate", () =>
            {
                long total = 0;
                foreach (File homeDir in _cluster.coreMembers().Select(CoreClusterMember.homeDir).ToList())
                {
                    File metricsDir = new File(homeDir, "metrics");
                    total          += readLongValue(metricsCsv(metricsDir, CatchUpMetrics.TX_PULL_REQUESTS_RECEIVED));
                }
                return(total);
            }, greaterThan(0L), TIMEOUT, TimeUnit.SECONDS);

            assertEventually("tx retries eventually accurate", () => readLongValue(metricsCsv(coreMetricsDir, CoreMetrics.TX_RETRIES)), equalTo(0L), TIMEOUT, TimeUnit.SECONDS);

            assertEventually("is leader eventually accurate", () => readLongValue(metricsCsv(coreMetricsDir, CoreMetrics.IS_LEADER)), greaterThanOrEqualTo(0L), TIMEOUT, TimeUnit.SECONDS);

            File readReplicaMetricsDir = new File(_cluster.getReadReplicaById(0).homeDir(), "metrics");

            assertEventually("pull update request registered", () => readLongValue(metricsCsv(readReplicaMetricsDir, PULL_UPDATES)), greaterThan(0L), TIMEOUT, TimeUnit.SECONDS);

            assertEventually("pull update request registered", () => readLongValue(metricsCsv(readReplicaMetricsDir, PULL_UPDATE_HIGHEST_TX_ID_REQUESTED)), greaterThan(0L), TIMEOUT, TimeUnit.SECONDS);

            assertEventually("pull update response received", () => readLongValue(metricsCsv(readReplicaMetricsDir, PULL_UPDATE_HIGHEST_TX_ID_RECEIVED)), greaterThan(0L), TIMEOUT, TimeUnit.SECONDS);
        }
Пример #12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void slavesTerminateOrReadConsistentDataWhenApplyingBatchLargerThanSafeZone() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void SlavesTerminateOrReadConsistentDataWhenApplyingBatchLargerThanSafeZone()
        {
            long safeZone = TimeUnit.MILLISECONDS.toSeconds(0);

            ClusterRule.withSharedSetting(HaSettings.id_reuse_safe_zone_time, safeZone.ToString());
            // given
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster cluster = clusterRule.startCluster();
            ClusterManager.ManagedCluster cluster = ClusterRule.startCluster();
            HighlyAvailableGraphDatabase  master  = cluster.Master;

            // when
            // ... slaves and master has node with long string property
            long entityId = Action.createInitialEntity(master);

            cluster.Sync();
            // ... and property is removed on master
            Action.removeProperties(master, entityId);
            Thread.Sleep(100);
            // ... and maintenance is called to make sure "safe" ids are freed to be reused
            ForceMaintenance(master);
            // ... and a new property is created on master that
            Action.setNewProperties(master, entityId);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.ha.HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
            HighlyAvailableGraphDatabase slave = cluster.AnySlave;
            Race race = new Race();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicBoolean end = new java.util.concurrent.atomic.AtomicBoolean(false);
            AtomicBoolean end = new AtomicBoolean(false);

            for (int i = 0; i < READER_CONTESTANTS; i++)
            {
                race.AddContestant(ReadContestant(Action, entityId, slave, end));
            }

            race.AddContestant(PullUpdatesContestant(slave, end));

            race.Go();
        }
Пример #13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldContinueServingBoltRequestsBetweenInternalRestarts() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldContinueServingBoltRequestsBetweenInternalRestarts()
        {
            // given

            /*
             * Interestingly, it is enough to simply start a slave and then direct sessions to it. The problem seems
             * to arise immediately, since simply from startup to being into SLAVE at least one internal restart happens
             * and that seems sufficient to break the bolt server.
             * However, that would make the test really weird, so we'll start the cluster, make sure we can connect and
             * then isolate the slave, make it shutdown internally, then have it rejoin and it will switch to slave.
             * At the end of this process, it must still be possible to open and execute transactions against the instance.
             */
            ClusterManager.ManagedCluster cluster = ClusterRule.startCluster();
            HighlyAvailableGraphDatabase  slave1  = cluster.AnySlave;

            Driver driver = GraphDatabase.driver(cluster.GetBoltAddress(slave1), AuthTokens.basic("neo4j", "neo4j"));

            /*
             * We'll use a bookmark to enforce use of kernel internals by the bolt server, to make sure that parts that are
             * switched during an internal restart are actually refreshed. Technically, this is not necessary, since the
             * bolt server makes such use for every request. But this puts a nice bow on top of it.
             */
            string lastBookmark = InExpirableSession(driver, Driver.session, s =>
            {
                using (Transaction tx = s.beginTransaction())
                {
                    tx.run("CREATE (person:Person {name: {name}, title: {title}})", parameters("name", "Webber", "title", "Mr"));
                    tx.success();
                }
                return(s.lastBookmark());
            });

            // when
            ClusterManager.RepairKit slaveFailRK = cluster.Fail(slave1);

            cluster.Await(entireClusterSeesMemberAsNotAvailable(slave1));
            slaveFailRK.Repair();
            cluster.Await(masterSeesMembers(3));

            // then
            int?count = InExpirableSession(driver, Driver.session, s =>
            {
                Record record;
                using (Transaction tx = s.beginTransaction(lastBookmark))
                {
                    record = tx.run("MATCH (n:Person) RETURN COUNT(*) AS count").next();
                    tx.success();
                }
                return(record.get("count").asInt());
            });

            assertEquals(1, count.Value);
        }
Пример #14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBeConsistentAfterShutdown() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldBeConsistentAfterShutdown()
        {
            // given
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.causalclustering.discovery.Cluster<?> cluster = clusterRule.startCluster();
            Cluster <object> cluster = ClusterRule.startCluster();

            FireSomeLoadAtTheCluster(cluster);

//JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter:
//JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter:
            ISet <File> storeDirs = cluster.CoreMembers().Select(CoreClusterMember::databaseDirectory).collect(toSet());

//JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter:
            assertEventually("All cores have the same data", () => cluster.CoreMembers().Select(RecoveryIT.dbRepresentation).collect(toSet()).size(), equalTo(1), 10, TimeUnit.SECONDS);

            // when
            cluster.Shutdown();

            // then
            storeDirs.forEach(RecoveryIT.assertConsistent);
        }
Пример #15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setup() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
            public virtual void Setup()
            {
                // setup a cluster with some data and entries in log files in fully functional and shutdown state
                ClusterManager.ManagedCluster cluster = ClusterRule.startCluster();

                try
                {
                    cluster.Await(allSeesAllAsAvailable());

                    OldMaster = cluster.Master;
                    CreateSomeData(OldMaster);
                    cluster.Sync();

                    OldSlave1 = cluster.AnySlave;
                    OldSlave2 = cluster.GetAnySlave(OldSlave1);
                }
                finally
                {
                    ClusterRule.shutdownCluster();
                }
                AssertAllStoreConsistent(cluster);
            }
Пример #16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCatchupThroughHierarchy() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCatchupThroughHierarchy()
        {
            ClusterRule = ClusterRule.withInstanceReadReplicaParam(CausalClusteringSettings.server_groups, id => _serverGroups[id]).withInstanceCoreParam(CausalClusteringSettings.server_groups, id => _serverGroups[id]);

            // given
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.causalclustering.discovery.Cluster<?> cluster = clusterRule.startCluster();
            Cluster <object> cluster  = ClusterRule.startCluster();
            int numberOfNodesToCreate = 100;

            cluster.CoreTx((db, tx) =>
            {
                Db.schema().constraintFor(label("Foo")).assertPropertyIsUnique("foobar").create();
                tx.success();
            });

            // 0, 1, 2 are core instances
            createLabelledNodesWithProperty(cluster, numberOfNodesToCreate, label("Foo"), () => Pair.of("foobar", string.Format("baz_bat{0}", System.Guid.randomUUID())));

            // 3, 4 are other DCs
            ReadReplica east3 = cluster.AddReadReplicaWithId(3);

            east3.Start();
            ReadReplica west4 = cluster.AddReadReplicaWithId(4);

            west4.Start();

            checkDataHasReplicatedToReadReplicas(cluster, numberOfNodesToCreate);

            foreach (CoreClusterMember coreClusterMember in cluster.CoreMembers())
            {
                coreClusterMember.DisableCatchupServer();
            }

            // 5, 6 are other DCs
            ReadReplica east5 = cluster.AddReadReplicaWithId(5);

            east5.UpstreamDatabaseSelectionStrategy = "connect-randomly-within-server-group";
            east5.Start();
            ReadReplica west6 = cluster.AddReadReplicaWithId(6);

            west6.UpstreamDatabaseSelectionStrategy = "connect-randomly-within-server-group";
            west6.Start();

            checkDataHasReplicatedToReadReplicas(cluster, numberOfNodesToCreate);
        }
Пример #17
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReplicateWithCompression() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReplicateWithCompression()
        {
            // given
            ClusterRule.withSharedCoreParam(compression_implementations, ModifierProtocol.implementation()).withSharedReadReplicaParam(compression_implementations, ModifierProtocol.implementation());

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.causalclustering.discovery.Cluster<?> cluster = clusterRule.startCluster();
            Cluster <object> cluster = ClusterRule.startCluster();

            // when
            int numberOfNodes        = 10;
            CoreClusterMember leader = createLabelledNodesWithProperty(cluster, numberOfNodes, label("Foo"), () => Pair.of("foobar", format("baz_bat%s", System.Guid.randomUUID())));

            // then
            assertEquals(numberOfNodes, countNodes(leader));
            dataMatchesEventually(leader, cluster.CoreMembers());
        }
Пример #18
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void clusterWithCustomTransactionLogLocation() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ClusterWithCustomTransactionLogLocation()
        {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.causalclustering.discovery.Cluster<?> cluster = clusterRule.startCluster();
            Cluster <object> cluster = ClusterRule.startCluster();

            for (int i = 0; i < 10; i++)
            {
                cluster.CoreTx((db, tx) =>
                {
                    Db.createNode();
                    tx.success();
                });
            }

            ICollection <CoreClusterMember> coreClusterMembers = cluster.CoreMembers();

            foreach (CoreClusterMember coreClusterMember in coreClusterMembers)
            {
                DependencyResolver dependencyResolver = coreClusterMember.Database().DependencyResolver;
                LogFiles           logFiles           = dependencyResolver.ResolveDependency(typeof(LogFiles));
                assertEquals(logFiles.LogFilesDirectory().Name, "core-tx-logs-" + coreClusterMember.ServerId());
                assertTrue(logFiles.HasAnyEntries(0));
                File[] coreLogDirectories = coreClusterMember.DatabaseDirectory().listFiles(file => file.Name.StartsWith("core"));
                assertThat(coreLogDirectories, Matchers.arrayWithSize(1));

                LogFileInStoreDirectoryDoesNotExist(coreClusterMember.DatabaseDirectory(), dependencyResolver);
            }

            ICollection <ReadReplica> readReplicas = cluster.ReadReplicas();

            foreach (ReadReplica readReplica in readReplicas)
            {
                readReplica.TxPollingClient().upToDateFuture().get();
                DependencyResolver dependencyResolver = readReplica.Database().DependencyResolver;
                LogFiles           logFiles           = dependencyResolver.ResolveDependency(typeof(LogFiles));
                assertEquals(logFiles.LogFilesDirectory().Name, "replica-tx-logs-" + readReplica.ServerId());
                assertTrue(logFiles.HasAnyEntries(0));
                File[] replicaLogDirectories = readReplica.DatabaseDirectory().listFiles(file => file.Name.StartsWith("replica"));
                assertThat(replicaLogDirectories, Matchers.arrayWithSize(1));

                LogFileInStoreDirectoryDoesNotExist(readReplica.DatabaseDirectory(), dependencyResolver);
            }
        }
Пример #19
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAccessHaBeans()
        public virtual void ShouldAccessHaBeans()
        {
            ManagedCluster cluster = ClusterRule.startCluster();

            // High Availability bean
            HighAvailability ha = ha(cluster.Master);

            assertNotNull("could not get ha bean", ha);
            AssertMasterInformation(ha);
            AssertMasterAndSlaveInformation(ha.InstancesInCluster);
            foreach (ClusterMemberInfo info in ha.InstancesInCluster)
            {
                assertTrue(info.Alive);
                assertTrue(info.Available);
            }

            // Branched data bean
            BranchedStore bs = Beans(cluster.Master).BranchedStoreBean;

            assertNotNull("could not get branched store bean", bs);
        }
Пример #20
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotSeeFreedIdsCrossRoleSwitch() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotSeeFreedIdsCrossRoleSwitch()
        {
            // GIVEN
            ManagedCluster cluster = ClusterRule.startCluster();
            HighlyAvailableGraphDatabase firstMaster = cluster.Master;

            // WHEN
            // a node with a property
            Node node = CreateNodeWithProperties(firstMaster, 1);

            // sync cluster
            cluster.Sync();
            // a transaction on master which deletes the property
            DeleteNode(node, firstMaster);
            TriggerIdMaintenance(firstMaster);
            CreateNodeWithProperties(firstMaster, 1);                 // <-- this one reuses the same property id 0
            // a transaction T on slave which will be kept open using a barrier
            GraphDatabaseAPI slave = cluster.AnySlave;

            Org.Neo4j.Test.Barrier_Control barrier = new Org.Neo4j.Test.Barrier_Control();
            Future <Void> t = T2.execute(BarrierControlledReadTransaction(slave, barrier));

            // pull updates on slave
            barrier.Await();
            slave.DependencyResolver.resolveDependency(typeof(UpdatePuller)).pullUpdates();
            // a role switch
            cluster.Shutdown(firstMaster);
            cluster.Await(masterAvailable(firstMaster));
            // close T
            barrier.Release();
            t.get();
            TriggerIdMaintenance(slave);

            // THEN the deleted property record should now not be in freelist on new master
            CreateNodeWithProperties(slave, 10); // <-- this transaction should introduce inconsistencies
            cluster.Stop();                      // <-- CC will be run here since that's configured above ^^^
        }
Пример #21
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(timeout = 240_000) public void shouldNotBePossibleToStartTransactionsWhenReadReplicaCopiesStore() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotBePossibleToStartTransactionsWhenReadReplicaCopiesStore()
        {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.causalclustering.discovery.Cluster<?> cluster = clusterRule.startCluster();
            Cluster <object> cluster = ClusterRule.startCluster();

            ReadReplica readReplica = cluster.FindAnyReadReplica();

            readReplica.TxPollingClient().stop();

            WriteSomeDataAndForceLogRotations(cluster);
            Semaphore storeCopyBlockingSemaphore = AddStoreCopyBlockingMonitor(readReplica);

            try
            {
                readReplica.TxPollingClient().start();
                WaitForStoreCopyToStartAndBlock(storeCopyBlockingSemaphore);

                ReadReplicaGraphDatabase replicaGraphDatabase = readReplica.Database();
                try
                {
                    replicaGraphDatabase.BeginTx();
                    fail("Exception expected");
                }
                catch (Exception e)
                {
                    assertThat(e, instanceOf(typeof(TransactionFailureException)));
                    assertThat(e.Message, containsString("Database is stopped to copy store"));
                }
            }
            finally
            {
                // release all waiters of the semaphore
                storeCopyBlockingSemaphore.release(int.MaxValue);
            }
        }
Пример #22
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setup() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void Setup()
        {
            _backupsDir = ClusterRule.testDirectory().cleanDirectory("backups");
            _cluster    = ClusterRule.startCluster();
        }
Пример #23
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @BeforeClass public static void setup() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public static void Setup()
        {
            _cluster = ClusterRule.startCluster();
        }
Пример #24
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setup() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void Setup()
        {
            _clusterRule.withDiscoveryServiceType(_discoveryType);
            _fs      = _fileSystemRule.get();
            _cluster = _clusterRule.startCluster();
        }
Пример #25
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setup() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void Setup()
        {
            _cluster = ClusterRule.startCluster();
        }
Пример #26
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setUp()
        public virtual void SetUp()
        {
            _managedCluster = ClusterRule.startCluster();
        }
Пример #27
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setup() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void Setup()
        {
            _backupPath = ClusterRule.TestDirectory.storeDir("backup-db");
            createSomeData(ClusterRule.startCluster().Master);
        }
Пример #28
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void oneRound() throws Throwable
        private void OneRound()
        {
            // GIVEN a cluster and a node
            const string key = "key";

            ClusterManager.ManagedCluster cluster = ClusterRule.startCluster();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.GraphDatabaseService master = cluster.getMaster();
            GraphDatabaseService master = cluster.Master;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long nodeId = createNode(master);
            long nodeId = CreateNode(master);

            cluster.Sync();

            // and a bunch of workers contending on that node, each changing it
            Workers <ThreadStart> transactors = new Workers <ThreadStart>("Transactors");
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicInteger successes = new java.util.concurrent.atomic.AtomicInteger();
            AtomicInteger successes = new AtomicInteger();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicBoolean end = new java.util.concurrent.atomic.AtomicBoolean();
            AtomicBoolean end = new AtomicBoolean();

            for (int i = 0; i < 10; i++)
            {
                transactors.Start(() =>
                {
                    Random random = ThreadLocalRandom.current();
                    while (!end.get())
                    {
                        bool committed = true;
                        try
                        {
                            using (Transaction tx = master.BeginTx())
                            {
                                Node node = master.GetNodeById(nodeId);

                                // Acquiring lock, read int property value, increment, set incremented int property
                                // should not break under any circumstances.
                                tx.acquireWriteLock(node);
                                node.setProperty(key, ( int? )node.getProperty(key, 0) + 1);
                                // Throw in relationship for good measure
                                node.createRelationshipTo(master.CreateNode(), TEST);

                                Thread.Sleep(random.Next(1_000));
                                tx.success();
                            }
                        }
                        catch (Exception)
                        {
                            // It's OK
                            committed = false;
                        }
                        if (committed)
                        {
                            successes.incrementAndGet();
                        }
                    }
                });
            }

            // WHEN entering a period of induced cluster instabilities
            ReelectTheSameMasterMakingItGoToPendingAndBack(cluster);

            // ... letting transactions run a bit after the role switch as well.
            long targetSuccesses = successes.get() + 20;

            while (successes.get() < targetSuccesses)
            {
                Thread.Sleep(100);
            }
            end.set(true);
            transactors.AwaitAndThrowOnError();

            // THEN verify that the count is equal to the number of successful transactions
            assertEquals(successes.get(), GetNodePropertyValue(master, nodeId, key));
        }