Пример #1
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]);
        }
Пример #2
0
        internal static bool CasClusterId(HazelcastInstance hazelcastInstance, ClusterId clusterId, string dbName)
        {
            IMap <string, System.Guid> uuidPerDbCluster = hazelcastInstance.getMap(CLUSTER_UUID_DB_NAME_MAP);

            System.Guid uuid = uuidPerDbCluster.putIfAbsent(dbName, clusterId.Uuid());
            return(uuid == null || clusterId.Uuid().Equals(uuid));
        }
Пример #3
0
        private static ClusterId GetClusterId(HazelcastInstance hazelcastInstance, string dbName)
        {
            IMap <string, System.Guid> uuidPerDbCluster = hazelcastInstance.getMap(CLUSTER_UUID_DB_NAME_MAP);

            System.Guid uuid = uuidPerDbCluster.get(dbName);
            return(uuid != null ? new ClusterId(uuid) : null);
        }
Пример #4
0
        /// <summary>
        /// Retrieves the various maps containing attributes about read replicas from hazelcast. If any maps do not exist, keep track of their keys for logging.
        /// </summary>
        private static Pair <ISet <string>, IDictionary <string, IMap <string, string> > > ValidatedSimpleAttrMaps(HazelcastInstance hazelcastInstance)
        {
            ISet <string> missingAttrKeys = new HashSet <string>();
            IDictionary <string, IMap <string, string> > validatedSimpleAttrMaps = new Dictionary <string, IMap <string, string> >();

            foreach (string attrMapKey in RrAttrKeys)
            {
                IMap <string, string> attrMap = hazelcastInstance.getMap(attrMapKey);
                if (attrMap == null)
                {
                    missingAttrKeys.Add(attrMapKey);
                }
                else
                {
                    validatedSimpleAttrMaps[attrMapKey] = attrMap;
                }
            }

            return(Pair.of(missingAttrKeys, validatedSimpleAttrMaps));
        }
Пример #5
0
        private static ISet <string> GetDBNames(HazelcastInstance hazelcastInstance)
        {
            IMap <string, System.Guid> uuidPerDbCluster = hazelcastInstance.getMap(CLUSTER_UUID_DB_NAME_MAP);

            return(uuidPerDbCluster.Keys);
        }