コード例 #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldValidateReadReplicaAttrMapNullValues()
        public virtual void ShouldValidateReadReplicaAttrMapNullValues()
        {
            // given
            IDictionary <MemberId, ReadReplicaInfo> mockedRRs = new Dictionary <MemberId, ReadReplicaInfo>();

            MemberId        validMemberId          = new MemberId(System.Guid.randomUUID());
            MemberId        invalidMemberId        = new MemberId(System.Guid.randomUUID());
            ReadReplicaInfo validReadReplicaInfo   = GenerateReadReplicaInfo();
            ReadReplicaInfo invalidReadReplicaInfo = GenerateReadReplicaInfo();

            mockedRRs[validMemberId]   = validReadReplicaInfo;
            mockedRRs[invalidMemberId] = invalidReadReplicaInfo;

            IDictionary <MemberId, ISet <string> > nullAttrValues = singletonMap(invalidMemberId, singleton(READ_REPLICA_TRANSACTION_SERVER_ADDRESS_MAP));

            MockReadReplicaAttributes(mockedRRs, emptySet(), nullAttrValues);

            // when
            AssertableLogProvider logProvider = new AssertableLogProvider();
            Log log = logProvider.getLog(this.GetType());
            IDictionary <MemberId, ReadReplicaInfo> rrMap = HazelcastClusterTopology.ReadReplicas(_hzInstance, log);

            // then
            assertEquals(singletonMap(validMemberId, validReadReplicaInfo), rrMap);

            logProvider.RawMessageMatcher().assertContains(Matchers.allOf(Matchers.containsString("Missing attribute %s for read replica")));
        }
コード例 #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCorrectlyReturnCoreMemberRoles()
        public virtual void ShouldCorrectlyReturnCoreMemberRoles()
        {
            //given
            int numMembers = 3;

            IList <MemberId> members = IntStream.range(0, numMembers).mapToObj(ignored => new MemberId(System.Guid.randomUUID())).collect(Collectors.toList());

//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") com.hazelcast.core.IAtomicReference<org.neo4j.causalclustering.core.consensus.LeaderInfo> leaderRef = mock(com.hazelcast.core.IAtomicReference.class);
            IAtomicReference <LeaderInfo> leaderRef = mock(typeof(IAtomicReference));
            MemberId chosenLeaderId = members[0];

            when(leaderRef.get()).thenReturn(new LeaderInfo(chosenLeaderId, 0L));

//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") com.hazelcast.core.IMap<String,java.util.UUID> uuidDBMap = mock(com.hazelcast.core.IMap.class);
            IMap <string, System.Guid> uuidDBMap = mock(typeof(IMap));

            when(uuidDBMap.Keys).thenReturn(Collections.singleton(DEFAULT_DB_NAME));
            when(_hzInstance.getAtomicReference <LeaderInfo>(startsWith(DB_NAME_LEADER_TERM_PREFIX))).thenReturn(leaderRef);
            when(_hzInstance.getMap <string, System.Guid>(eq(CLUSTER_UUID_DB_NAME_MAP))).thenReturn(uuidDBMap);

            // when
            IDictionary <MemberId, RoleInfo> roleMap = HazelcastClusterTopology.GetCoreRoles(_hzInstance, new HashSet <MemberId, RoleInfo>(members));

            // then
            assertEquals("First member was expected to be leader.", RoleInfo.Leader, roleMap[chosenLeaderId]);
        }
コード例 #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCollectReadReplicasAsMap()
        public virtual void ShouldCollectReadReplicasAsMap()
        {
            // given
            MemberId        memberId        = new MemberId(System.Guid.randomUUID());
            ReadReplicaInfo readReplicaInfo = GenerateReadReplicaInfo();
            IDictionary <MemberId, ReadReplicaInfo> mockedRRs = singletonMap(memberId, readReplicaInfo);

            MockReadReplicaAttributes(mockedRRs);

            // when
            IDictionary <MemberId, ReadReplicaInfo> rrMap = HazelcastClusterTopology.ReadReplicas(_hzInstance, NullLog.Instance);

            // then
            assertEquals(mockedRRs, rrMap);
        }
コード例 #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldValidateNullReadReplicaAttrMaps()
        public virtual void ShouldValidateNullReadReplicaAttrMaps()
        {
            // given
            MemberId        memberId        = new MemberId(System.Guid.randomUUID());
            ReadReplicaInfo readReplicaInfo = GenerateReadReplicaInfo();

            MockReadReplicaAttributes(singletonMap(memberId, readReplicaInfo), singleton(READ_REPLICAS_DB_NAME_MAP), emptyMap());

            // when
            AssertableLogProvider logProvider = new AssertableLogProvider();
            Log log = logProvider.getLog(this.GetType());
            IDictionary <MemberId, ReadReplicaInfo> rrMap = HazelcastClusterTopology.ReadReplicas(_hzInstance, log);

            // then
            assertEquals(emptyMap(), rrMap);
            logProvider.FormattedMessageMatcher().assertContains("Some, but not all, of the read replica attribute maps are null");
        }
コード例 #5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void refreshRoles() throws InterruptedException
        private void RefreshRoles()
        {
            WaitOnHazelcastInstanceCreation();
            LeaderInfo            localLeaderInfo   = _leaderInfo.get();
            Optional <LeaderInfo> localStepDownInfo = _stepDownInfo.get();

            if (localStepDownInfo.Present)
            {
                HazelcastClusterTopology.CasLeaders(_hazelcastInstance, localStepDownInfo.get(), _localDBName, Log);
                _stepDownInfo.compareAndSet(localStepDownInfo, null);
            }
            else if (localLeaderInfo.MemberId() != null && localLeaderInfo.MemberId().Equals(MyselfConflict))
            {
                HazelcastClusterTopology.CasLeaders(_hazelcastInstance, localLeaderInfo, _localDBName, Log);
            }

            _coreRoles = HazelcastClusterTopology.GetCoreRoles(_hazelcastInstance, AllCoreServers().members().Keys);
        }
コード例 #6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void refreshRoles() throws HazelcastInstanceNotActiveException
        private void RefreshRoles()
        {
            _coreRoles = _hzInstance.apply(hz => HazelcastClusterTopology.GetCoreRoles(hz, AllCoreServers().members().Keys));
        }
コード例 #7
0
        private HazelcastInstance CreateHazelcastInstance()
        {
            JoinConfig joinConfig = new JoinConfig();

            joinConfig.MulticastConfig.Enabled = false;
            TcpIpConfig tcpIpConfig = joinConfig.TcpIpConfig;

            tcpIpConfig.Enabled = true;

//JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter:
            ICollection <string> initialMembers = _remoteMembersResolver.resolve(SocketAddress::toString);

            initialMembers.forEach(tcpIpConfig.addMember);

            ListenSocketAddress hazelcastAddress = Config.get(discovery_listen_address);
            NetworkConfig       networkConfig    = new NetworkConfig();

            if (!hazelcastAddress.Wildcard)
            {
                InterfacesConfig interfaces = new InterfacesConfig();
                interfaces.addInterface(hazelcastAddress.Hostname);
                interfaces.Enabled       = true;
                networkConfig.Interfaces = interfaces;
            }

            networkConfig.Port = hazelcastAddress.Port;
            networkConfig.Join = joinConfig;
            networkConfig.PortAutoIncrement = false;

            // We'll use election_timeout as a base value to calculate HZ timeouts. We multiply by 1.5
            long?electionTimeoutMillis      = Config.get(CausalClusteringSettings.leader_election_timeout).toMillis();
            long?baseHazelcastTimeoutMillis = (3 * electionTimeoutMillis) / 2;

            /*
             * Some HZ settings require the value in seconds. Adding the divider and subtracting 1 is equivalent to the
             * ceiling function for integers ( Math.ceil() returns double ). Anything < 0 will return 0, any
             * multiple of 1000 returns the result of the division by 1000, any non multiple of 1000 returns the result
             * of the division + 1. In other words, values in millis are rounded up.
             */
            long baseHazelcastTimeoutSeconds = (baseHazelcastTimeoutMillis + 1000 - 1) / 1000;

            com.hazelcast.config.Config c = new com.hazelcast.config.Config();
            c.setProperty(OPERATION_CALL_TIMEOUT_MILLIS.Name, baseHazelcastTimeoutMillis.ToString());
            c.setProperty(MERGE_NEXT_RUN_DELAY_SECONDS.Name, baseHazelcastTimeoutSeconds.ToString());
            c.setProperty(MERGE_FIRST_RUN_DELAY_SECONDS.Name, baseHazelcastTimeoutSeconds.ToString());
            c.setProperty(INITIAL_MIN_CLUSTER_SIZE.Name, HAZELCAST_MIN_CLUSTER.ToString());

            if (Config.get(disable_middleware_logging))
            {
                c.setProperty(LOGGING_TYPE.Name, "none");
            }

            if (hazelcastAddress.IPv6)
            {
                c.setProperty(PREFER_IPv4_STACK.Name, "false");
            }

            c.NetworkConfig = networkConfig;

            MemberAttributeConfig memberAttributeConfig = HazelcastClusterTopology.BuildMemberAttributesForCore(MyselfConflict, Config);

            c.MemberAttributeConfig = memberAttributeConfig;
            LogConnectionInfo(initialMembers);
            c.addListenerConfig(new ListenerConfig(new OurMembershipListener(this)));

            JobHandle logJob = _scheduler.schedule(Group.HZ_TOPOLOGY_HEALTH, _hazelcastIsHealthyTimeoutMs, () => Log.warn("The server has not been able to connect in a timely fashion to the " + "cluster. Please consult the logs for more details. Rebooting the server may " + "solve the problem."));

            try
            {
                _hazelcastInstance = Hazelcast.newHazelcastInstance(c);
                logJob.Cancel(true);
            }
            catch (HazelcastException e)
            {
                string errorMessage = string.Format("Hazelcast was unable to start with setting: {0} = {1}", discovery_listen_address.name(), Config.get(discovery_listen_address));
                UserLog.error(errorMessage);
                Log.error(errorMessage, e);
                throw new Exception(e);
            }

            IList <string> groups = Config.get(CausalClusteringSettings.server_groups);

            refreshGroups(_hazelcastInstance, MyselfConflict.Uuid.ToString(), groups);

            return(_hazelcastInstance);
        }
コード例 #8
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public boolean setClusterId(org.neo4j.causalclustering.identity.ClusterId clusterId, String dbName) throws InterruptedException
        public override bool SetClusterId(ClusterId clusterId, string dbName)
        {
            WaitOnHazelcastInstanceCreation();
            return(HazelcastClusterTopology.CasClusterId(_hazelcastInstance, clusterId, dbName));
        }