Esempio n. 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotAllowTokenCreationFromAFollowerWithNoInitialTokens() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotAllowTokenCreationFromAFollowerWithNoInitialTokens()
        {
            // given
            CoreClusterMember leader = _cluster.coreTx((db, tx) =>
            {
                Db.createNode();
                tx.success();
            });

            AwaitForDataToBeApplied(leader);
            dataMatchesEventually(leader, _cluster.coreMembers());

            CoreGraphDatabase follower = _cluster.getMemberWithRole(Role.FOLLOWER).database();

            // when
            try
            {
                using (Transaction tx = follower.BeginTx())
                {
                    follower.AllNodes.GetEnumerator().next().setProperty("name", "Mark");
                    tx.Success();
                    fail("Should have thrown exception");
                }
            }
            catch (WriteOperationsNotAllowedException ex)
            {
                assertThat(ex.Message, containsString("No write operations are allowed"));
            }
        }
Esempio n. 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSupportSeveralPolicies() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSupportSeveralPolicies()
        {
            IDictionary <string, System.Func <int, string> > instanceCoreParams = new Dictionary <string, System.Func <int, string> >();

            instanceCoreParams[CausalClusteringSettings.server_groups.name()] = id => "core" + id + ",core";
            IDictionary <string, System.Func <int, string> > instanceReplicaParams = new Dictionary <string, System.Func <int, string> >();

            instanceReplicaParams[CausalClusteringSettings.server_groups.name()] = id => "replica" + id + ",replica";

            string defaultPolicySpec     = "groups(replica0,replica1)";
            string policyOneTwoSpec      = "groups(replica1,replica2)";
            string policyZeroTwoSpec     = "groups(replica0,replica2)";
            string policyAllReplicasSpec = "groups(replica); halt()";
            string allPolicySpec         = "all()";

            IDictionary <string, string> coreParams = stringMap(CausalClusteringSettings.cluster_allow_reads_on_followers.name(), "true", CausalClusteringSettings.load_balancing_config.name() + ".server_policies.all", allPolicySpec, CausalClusteringSettings.load_balancing_config.name() + ".server_policies.default", defaultPolicySpec, CausalClusteringSettings.load_balancing_config.name() + ".server_policies.policy_one_two", policyOneTwoSpec, CausalClusteringSettings.load_balancing_config.name() + ".server_policies.policy_zero_two", policyZeroTwoSpec, CausalClusteringSettings.load_balancing_config.name() + ".server_policies.policy_all_replicas", policyAllReplicasSpec, CausalClusteringSettings.multi_dc_license.name(), "true");

            _cluster = new EnterpriseCluster(TestDir.directory("cluster"), 3, 3, new HazelcastDiscoveryServiceFactory(), coreParams, instanceCoreParams, emptyMap(), instanceReplicaParams, Standard.LATEST_NAME, IpFamily.IPV4, false);

            _cluster.start();
            AssertGetServersEventuallyMatchesOnAllCores(new CountsMatcher(this, 3, 1, 2, 3), PolicyContext("all"));
            // all cores have observed the full topology, now specific policies should all return the same result

            foreach (CoreClusterMember core in _cluster.coreMembers())
            {
                CoreGraphDatabase db = core.Database();

                assertThat(GetServers(db, PolicyContext("default")), new SpecificReplicasMatcher(this, 0, 1));
                assertThat(GetServers(db, PolicyContext("policy_one_two")), new SpecificReplicasMatcher(this, 1, 2));
                assertThat(GetServers(db, PolicyContext("policy_zero_two")), new SpecificReplicasMatcher(this, 0, 2));
                assertThat(GetServers(db, PolicyContext("policy_all_replicas")), new SpecificReplicasMatcher(this, 0, 1, 2));
            }
        }
Esempio n. 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void procedureCallsShouldReflectMembershipChanges() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ProcedureCallsShouldReflectMembershipChanges()
        {
            string            dbName   = GetFirstDbName(_dbNames);
            CoreClusterMember follower = _cluster.getMemberWithAnyRole(dbName, Role.FOLLOWER);
            int followerId             = follower.ServerId();

            _cluster.removeCoreMemberWithServerId(followerId);

            CoreGraphDatabase db = _cluster.getMemberWithAnyRole(dbName, Role.FOLLOWER, Role.LEADER).database();

            System.Func <CoreGraphDatabase, ISet <Endpoint> > getResult = database =>
            {
                Optional <MultiClusterRoutingResult> optResult = CallProcedure(database, GET_ROUTERS_FOR_ALL_DATABASES, java.util.Collections.emptyMap());

                return(optResult.map(r => r.routers().values().stream().flatMap(System.Collections.IList.stream).collect(Collectors.toSet())).orElse(java.util.Collections.emptySet()));
            };

            assertEventually("The procedure should return one fewer routers when a core member has been removed.", () => getResult(db).size(), @is(_numCores - 1), 15, TimeUnit.SECONDS);

            System.Func <ISet <Endpoint>, CoreClusterMember, bool> containsFollower = (rs, f) => rs.Any(r => r.address().ToString().Equals(f.boltAdvertisedAddress()));

            assertEventually("The procedure should not return a host as a router after it has been removed from the cluster", () => containsFollower(getResult(db), follower), @is(false), 15, TimeUnit.SECONDS);

            CoreClusterMember newFollower = _cluster.addCoreMemberWithId(followerId);

            newFollower.Start();

            assertEventually("The procedure should return one more router when a core member has been added.", () => getResult(db).size(), @is(_numCores), 15, TimeUnit.SECONDS);
            assertEventually("The procedure should return a core member as a router after it has been added to the cluster", () => containsFollower(getResult(db), newFollower), @is(true), 15, TimeUnit.SECONDS);
        }
Esempio n. 4
0
        /// <summary>
        /// Perform a transaction against the leader of the core cluster, retrying as necessary.
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private CoreClusterMember leaderTx(String dbName, System.Action<org.neo4j.causalclustering.core.CoreGraphDatabase,org.neo4j.graphdb.Transaction> op, int timeout, java.util.concurrent.TimeUnit timeUnit) throws Exception
        private CoreClusterMember LeaderTx(string dbName, System.Action <CoreGraphDatabase, Transaction> op, int timeout, TimeUnit timeUnit)
        {
            ThrowingSupplier <CoreClusterMember, Exception> supplier = () =>
            {
                CoreClusterMember member = AwaitLeader(dbName, timeout, timeUnit);
                CoreGraphDatabase db     = member.Database();
                if (db == null)
                {
                    throw new DatabaseShutdownException();
                }

                try
                {
                    using (Transaction tx = Db.beginTx())
                    {
                        op(db, tx);
                        return(member);
                    }
                }
                catch (Exception e)
                {
                    if (IsTransientFailure(e))
                    {
                        return(null);
                    }
                    else
                    {
                        throw e;
                    }
                }
            };

            return(awaitEx(supplier, notNull().test, timeout, timeUnit));
        }
Esempio n. 5
0
        public virtual IList <CoreClusterMember> GetAllMembersWithAnyRole(string dbName, params Role[] roles)
        {
            EnsureDBName(dbName);
//JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter:
            ISet <Role> roleSet = java.util.roles.collect(toSet());

            IList <CoreClusterMember> list = new List <CoreClusterMember>();

            foreach (CoreClusterMember m in _coreMembers.Values)
            {
                CoreGraphDatabase database = m.Database();
                if (database == null)
                {
                    continue;
                }

                if (m.DbName().Equals(dbName))
                {
                    if (roleSet.Contains(database.Role))
                    {
                        list.Add(m);
                    }
                }
            }
            return(list);
        }
Esempio n. 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBeAbleToDownloadToNewInstanceAfterPruning() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldBeAbleToDownloadToNewInstanceAfterPruning()
        {
            // given
            IDictionary <string, string> @params = stringMap(CausalClusteringSettings.state_machine_flush_window_size.name(), "1", CausalClusteringSettings.raft_log_pruning_strategy.name(), "3 entries", CausalClusteringSettings.raft_log_rotation_size.name(), "1K");

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

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

            // when
            foreach (CoreClusterMember coreDb in cluster.CoreMembers())
            {
                coreDb.RaftLogPruner().prune();
            }

            cluster.RemoveCoreMember(leader);                 // to force a change of leader
            leader = cluster.AwaitLeader();

            int newDbId = 3;

            cluster.AddCoreMemberWithId(newDbId).start();
            CoreGraphDatabase newDb = cluster.GetCoreMemberById(newDbId).database();

            // then
            assertEquals(DbRepresentation.of(leader.Database()), DbRepresentation.of(newDb));
        }
Esempio n. 7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReplicateTransactionToCoreMembers() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReplicateTransactionToCoreMembers()
        {
            // given
            TestDirectory testDirectory     = ClusterRule.testDirectory();
            File          dbDir             = testDirectory.CleanDirectory("classic-db-" + RecordFormat);
            int           classicNodeCount  = 1024;
            File          classicNeo4jStore = CreateNeoStore(dbDir, classicNodeCount);

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

            using (DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction())
            {
                foreach (CoreClusterMember core in cluster.CoreMembers())
                {
                    (new RestoreDatabaseCommand(fileSystem, classicNeo4jStore, core.Config(), core.SettingValue(GraphDatabaseSettings.active_database.name()), true)).execute();
                }
            }

            cluster.Start();

            // when
            cluster.CoreTx((coreDB, tx) =>
            {
                Node node = coreDB.createNode(label("boo"));
                node.setProperty("foobar", "baz_bat");
                tx.success();
            });

            cluster.AddReadReplicaWithIdAndRecordFormat(4, RecordFormat).start();

            // then
            foreach (CoreClusterMember server in cluster.CoreMembers())
            {
                CoreGraphDatabase db = server.database();

                using (Transaction tx = Db.beginTx())
                {
                    ThrowingSupplier <long, Exception> nodeCount = () => count(Db.AllNodes);

                    Config config = Db.DependencyResolver.resolveDependency(typeof(Config));

                    assertEventually("node to appear on core server " + config.Get(raft_advertised_address), nodeCount, greaterThan(( long )classicNodeCount), 15, SECONDS);

                    assertEquals(classicNodeCount + 1, count(Db.AllNodes));

                    tx.Success();
                }
            }
        }
Esempio n. 8
0
        internal CoreStatus(OutputFormat output, CoreGraphDatabase db) : base(output)
        {
            this._output = output;
            this._db     = db;

            DependencyResolver dependencyResolver = Db.DependencyResolver;

            this._raftMembershipManager        = dependencyResolver.ResolveDependency(typeof(RaftMembershipManager));
            this._databaseHealth               = dependencyResolver.ResolveDependency(typeof(DatabaseHealth));
            this._topologyService              = dependencyResolver.ResolveDependency(typeof(TopologyService));
            this._raftMachine                  = dependencyResolver.ResolveDependency(typeof(RaftMachine));
            this._raftMessageTimerResetMonitor = dependencyResolver.ResolveDependency(typeof(DurationSinceLastMessageMonitor));
            _commandIndexTracker               = dependencyResolver.ResolveDependency(typeof(CommandIndexTracker));
        }
Esempio n. 9
0
        private static Optional <MultiClusterRoutingResult> CallProcedure(CoreGraphDatabase db, ProcedureNames procedure, IDictionary <string, object> @params)
        {
            Optional <MultiClusterRoutingResult> routingResult = null;

            using (InternalTransaction tx = Db.beginTransaction(KernelTransaction.Type.@explicit, EnterpriseLoginContext.AUTH_DISABLED), Result result = Db.execute(tx, "CALL " + procedure.callName(), ValueUtils.asMapValue(@params)))
            {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                if (result.HasNext())
                {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                    routingResult = MultiClusterRoutingResultFormat.parse(result.Next());
                }
            }
            return(routingResult);
        }
Esempio n. 10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void coreProceduresShouldBeAvailable()
        public virtual void CoreProceduresShouldBeAvailable()
        {
            string[] coreProcs = new string[] { "dbms.cluster.role", "dbms.cluster.routing.getServers", "dbms.cluster.overview", "dbms.procedures", "dbms.listQueries" };

            foreach (string procedure in coreProcs)
            {
                Optional <CoreClusterMember> firstCore = _cluster.coreMembers().First();
                Debug.Assert(firstCore.Present);
                CoreGraphDatabase   database = firstCore.get().database();
                InternalTransaction tx       = database.BeginTransaction(KernelTransaction.Type.@explicit, AUTH_DISABLED);
                Result coreResult            = database.Execute("CALL " + procedure + "()");
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertTrue("core with procedure " + procedure, coreResult.HasNext());
                coreResult.Close();
                tx.Close();
            }
        }
Esempio n. 11
0
        private LoadBalancingResult GetServers(CoreGraphDatabase db, IDictionary <string, string> context)
        {
            LoadBalancingResult lbResult = null;

            using (InternalTransaction tx = Db.beginTransaction(KernelTransaction.Type.@explicit, EnterpriseLoginContext.AUTH_DISABLED))
            {
                IDictionary <string, object> parameters = MapUtil.map(ParameterNames.CONTEXT.parameterName(), context);
                using (Result result = Db.execute(tx, "CALL " + GET_SERVERS_V2.callName(), ValueUtils.asMapValue(parameters)))
                {
                    while (result.MoveNext())
                    {
                        lbResult = ResultFormatV1.parse(result.Current);
                    }
                }
            }
            return(lbResult);
        }
Esempio n. 12
0
		 private IList<IList<string>> GetServerGroups( CoreGraphDatabase db )
		 {
			  IList<IList<string>> serverGroups = new List<IList<string>>();
			  using ( InternalTransaction tx = Db.beginTransaction( KernelTransaction.Type.@explicit, EnterpriseLoginContext.AUTH_DISABLED ) )
			  {
					using ( Result result = Db.execute( tx, "CALL dbms.cluster.overview", EMPTY_MAP ) )
					{
						 while ( result.MoveNext() )
						 {
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<String> groups = (java.util.List<String>) result.Current.get("groups");
							  IList<string> groups = ( IList<string> ) result.Current.get( "groups" );
							  serverGroups.Add( groups );
						 }
					}
			  }
			  return serverGroups;
		 }
Esempio n. 13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotAllowSchemaChangesFromAFollower() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotAllowSchemaChangesFromAFollower()
        {
            // given
            _cluster.awaitLeader();

            CoreGraphDatabase follower = _cluster.getMemberWithRole(Role.FOLLOWER).database();

            // when
            try
            {
                using (Transaction tx = follower.BeginTx())
                {
                    follower.Schema().constraintFor(Label.label("Foo")).assertPropertyIsUnique("name").create();
                    tx.Success();
                    fail("Should have thrown exception");
                }
            }
            catch (WriteOperationsNotAllowedException ex)
            {
                // expected
                assertThat(ex.Message, containsString("No write operations are allowed"));
            }
        }
Esempio n. 14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotAllowWritesFromAFollower() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotAllowWritesFromAFollower()
        {
            // given
            _cluster.awaitLeader();

            CoreGraphDatabase follower = _cluster.getMemberWithRole(Role.FOLLOWER).database();

            // when
            try
            {
                using (Transaction tx = follower.BeginTx())
                {
                    follower.CreateNode();
                    tx.Success();
                    fail("Should have thrown exception");
                }
            }
            catch (WriteOperationsNotAllowedException ex)
            {
                // expected
                assertThat(ex.Message, containsString("No write operations are allowed"));
            }
        }
Esempio n. 15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void transactionsShouldNotAppearOnTheReadReplicaWhilePollingIsPaused() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TransactionsShouldNotAppearOnTheReadReplicaWhilePollingIsPaused()
        {
            // 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 readReplicaGraphDatabase = cluster.FindAnyReadReplica().database();
            CatchupPollingProcess    pollingClient            = readReplicaGraphDatabase.DependencyResolver.resolveDependency(typeof(CatchupPollingProcess));

            pollingClient.Stop();

            cluster.CoreTx((coreGraphDatabase, transaction) =>
            {
                coreGraphDatabase.createNode();
                transaction.success();
            });

            CoreGraphDatabase leaderDatabase = cluster.AwaitLeader().database();
            long transactionVisibleOnLeader  = TransactionIdTracker(leaderDatabase).newestEncounteredTxId();

            // when the poller is paused, transaction doesn't make it to the read replica
            try
            {
                TransactionIdTracker(readReplicaGraphDatabase).awaitUpToDate(transactionVisibleOnLeader, ofSeconds(15));
                fail("should have thrown exception");
            }
            catch (TransactionFailureException)
            {
                // expected timeout
            }

            // when the poller is resumed, it does make it to the read replica
            pollingClient.Start();
            TransactionIdTracker(readReplicaGraphDatabase).awaitUpToDate(transactionVisibleOnLeader, ofSeconds(15));
        }