//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]); }
internal static void CasLeaders(HazelcastInstance hazelcastInstance, LeaderInfo leaderInfo, string dbName, Log log) { IAtomicReference <LeaderInfo> leaderRef = hazelcastInstance.getAtomicReference(DB_NAME_LEADER_TERM_PREFIX + dbName); LeaderInfo current = leaderRef.get(); Optional <LeaderInfo> currentOpt = Optional.ofNullable(current); //JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter: bool sameLeader = currentOpt.map(LeaderInfo::memberId).Equals(Optional.ofNullable(leaderInfo.MemberId())); int termComparison = currentOpt.map(l => Long.compare(l.term(), leaderInfo.Term())).orElse(-1); bool greaterTermExists = termComparison > 0; bool sameTermButNoStepdown = termComparison == 0 && !leaderInfo.SteppingDown; if (sameLeader || greaterTermExists || sameTermButNoStepdown) { return; } bool success = leaderRef.compareAndSet(current, leaderInfo); if (!success) { log.Warn("Fail to set new leader info: %s. Latest leader info: %s.", leaderInfo, leaderRef.get()); } }
private static Optional <LeaderInfo> GetLeaderForDBName(HazelcastInstance hazelcastInstance, string dbName) { IAtomicReference <LeaderInfo> leader = hazelcastInstance.getAtomicReference(DB_NAME_LEADER_TERM_PREFIX + dbName); return(Optional.ofNullable(leader.get())); }