Beispiel #1
0
        private void BaseTestForElectionOk(ISet <InstanceId> failed, bool moreThanQuorum)
        {
            IDictionary <InstanceId, URI> members = new Dictionary <InstanceId, URI>();

            members[new InstanceId(1)] = URI.create("server1");
            members[new InstanceId(2)] = URI.create("server2");
            members[new InstanceId(3)] = URI.create("server3");

            Config config = mock(typeof(Config));

            when(config.Get(ClusterSettings.max_acceptors)).thenReturn(10);

            ClusterConfiguration clusterConfiguration = mock(typeof(ClusterConfiguration));

            when(clusterConfiguration.Members).thenReturn(members);

            ClusterContext clusterContext = mock(typeof(ClusterContext));

            when(clusterContext.Configuration).thenReturn(clusterConfiguration);

            MultiPaxosContext context = new MultiPaxosContext(new InstanceId(1), Iterables.iterable(new ElectionRole("coordinator")), clusterConfiguration, mock(typeof(Executor)), NullLogProvider.Instance, mock(typeof(ObjectInputStreamFactory)), mock(typeof(ObjectOutputStreamFactory)), mock(typeof(AcceptorInstanceStore)), mock(typeof(Timeouts)), mock(typeof(ElectionCredentialsProvider)), config);

            context.HeartbeatContext.Failed.addAll(failed);

            ElectionContext toTest = context.ElectionContext;

            assertEquals(moreThanQuorum, !toTest.ElectionOk());
        }
Beispiel #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void voteResponseShouldHaveSameVersionAsVoteRequest() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void VoteResponseShouldHaveSameVersionAsVoteRequest()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.List<org.neo4j.cluster.com.message.Message<?>> messages = new java.util.ArrayList<>(1);
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
            IList <Message <object> > messages = new List <Message <object> >(1);
            MessageHolder             holder   = messages.add;

            ElectionContext context = mock(typeof(ElectionContext));

            const int version = 14;
            Message <ElectionMessage> voteRequest = Message.to(ElectionMessage.Vote, URI.create("some://instance"), new ElectionContext_VoteRequest("coordinator", version)
                                                               );

            voteRequest.SetHeader(Message.HEADER_FROM, "some://other");

            election.handle(context, voteRequest, holder);

            assertEquals(1, messages.Count);
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.cluster.com.message.Message<?> response = messages.get(0);
            Message <object> response = messages[0];

            assertEquals(ElectionMessage.Voted, response.MessageType);
            ElectionMessage.VersionedVotedData payload = response.Payload;
            assertEquals(version, payload.Version);
        }
Beispiel #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testElectionNotOkQuorumFailedTwoInstances()
        public virtual void TestElectionNotOkQuorumFailedTwoInstances()
        {
            ISet <InstanceId> failed = new HashSet <InstanceId>();

            failed.Add(new InstanceId(2));

            IDictionary <InstanceId, URI> members = new Dictionary <InstanceId, URI>();

            members[new InstanceId(1)] = URI.create("server1");
            members[new InstanceId(2)] = URI.create("server2");

            Config config = mock(typeof(Config));

            when(config.Get(ClusterSettings.max_acceptors)).thenReturn(10);

            ClusterConfiguration clusterConfiguration = mock(typeof(ClusterConfiguration));

            when(clusterConfiguration.Members).thenReturn(members);

            ClusterContext clusterContext = mock(typeof(ClusterContext));

            when(clusterContext.Configuration).thenReturn(clusterConfiguration);

            MultiPaxosContext context = new MultiPaxosContext(new InstanceId(1), Iterables.iterable(new ElectionRole("coordinator")), clusterConfiguration, mock(typeof(Executor)), NullLogProvider.Instance, mock(typeof(ObjectInputStreamFactory)), mock(typeof(ObjectOutputStreamFactory)), mock(typeof(AcceptorInstanceStore)), mock(typeof(Timeouts)), mock(typeof(ElectionCredentialsProvider)), config);

            context.HeartbeatContext.Failed.addAll(failed);

            ElectionContext toTest = context.ElectionContext;

            assertFalse(toTest.ElectionOk());
        }
Beispiel #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void delayedVoteFromPreviousElectionMustNotCauseCurrentElectionToComplete() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void DelayedVoteFromPreviousElectionMustNotCauseCurrentElectionToComplete()
        {
            // Given
            ElectionContext context = mock(typeof(ElectionContext));
            MessageHolder   holder  = mock(typeof(MessageHolder));

            when(context.GetLog(Mockito.any())).thenReturn(NullLog.Instance);

            const string role = "master";
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.cluster.InstanceId voter = new org.neo4j.cluster.InstanceId(2);
            InstanceId voter = new InstanceId(2);

            ElectionCredentials       voteCredentialComparable = mock(typeof(ElectionCredentials));
            Message <ElectionMessage> vote = Message.@internal(voted, new ElectionMessage.VersionedVotedData(role, voter, voteCredentialComparable, 4));

            when(context.Voted(role, voter, voteCredentialComparable, 4)).thenReturn(false);

            // When
            election.handle(context, vote, holder);

            verify(context).getLog(ArgumentMatchers.any());
            verify(context).voted(role, voter, voteCredentialComparable, 4);

            // Then
            verifyNoMoreInteractions(context, holder);
        }
Beispiel #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testElectionFromDemoteIsRejectedIfNoQuorum() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TestElectionFromDemoteIsRejectedIfNoQuorum()
        {
            ElectionContext context            = mock(typeof(ElectionContext));
            ClusterContext  clusterContextMock = mock(typeof(ClusterContext));

            when(context.ElectionOk()).thenReturn(false);
            when(clusterContextMock.GetLog(ArgumentMatchers.any())).thenReturn(NullLog.Instance);
            when(context.GetLog(ArgumentMatchers.any())).thenReturn(NullLog.Instance);

            MessageHolder holder = mock(typeof(MessageHolder));

            election.handle(context, Message.@internal(demote), holder);

            verifyZeroInteractions(holder);
        }
Beispiel #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void electionShouldRemainLocalIfStartedBySingleInstanceWhichIsTheRoleHolder() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ElectionShouldRemainLocalIfStartedBySingleInstanceWhichIsTheRoleHolder()
        {
            /*
             * Ensures that when an instance is alone in the cluster, elections for roles that it holds do not set
             * timeouts or try to reach other instances.
             */

            // Given
            ElectionContext context            = mock(typeof(ElectionContext));
            ClusterContext  clusterContextMock = mock(typeof(ClusterContext));

            when(clusterContextMock.GetLog(ArgumentMatchers.any())).thenReturn(NullLog.Instance);
            MessageHolder holder = mock(typeof(MessageHolder));

            // These mean the election can proceed normally, by us
            when(context.ElectionOk()).thenReturn(true);
            when(context.InCluster).thenReturn(true);
            when(context.Elector).thenReturn(true);

            // Like it says on the box, we are the only instance
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.cluster.InstanceId myInstanceId = new org.neo4j.cluster.InstanceId(1);
            InstanceId myInstanceId = new InstanceId(1);
            IDictionary <InstanceId, URI> members = new Dictionary <InstanceId, URI>();

            members[myInstanceId] = URI.create("ha://me");
            when(context.Members).thenReturn(members);

            // Any role would do, just make sure we have it
            const string role = "master";
            ElectionContext_VoteRequest voteRequest = new ElectionContext_VoteRequest(role, 13);

            when(context.PossibleRoles).thenReturn(Collections.singletonList(new ElectionRole(role)));
            when(context.GetElected(role)).thenReturn(myInstanceId);
            when(context.VoteRequestForRole(new ElectionRole(role))).thenReturn(voteRequest);

            // Required for logging
            when(context.GetLog(Mockito.any())).thenReturn(NullLog.Instance);

            // When
            election.handle(context, Message.@internal(performRoleElections), holder);

            // Then
            // Make sure that we asked ourselves to vote for that role and that no timer was set
            verify(holder, times(1)).offer(ArgumentMatchers.argThat(new MessageArgumentMatcher <ElectionMessage>()
                                                                    .onMessageType(ElectionMessage.Vote).withPayload(voteRequest)));
            verify(context, never()).setTimeout(ArgumentMatchers.any(), ArgumentMatchers.any());
        }
Beispiel #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testInstanceWithLowestIdFailedIsNotConsideredTheElector()
        public virtual void TestInstanceWithLowestIdFailedIsNotConsideredTheElector()
        {
            // Given
            // A cluster of 5 of which the two lowest instances are failed
            ISet <InstanceId> failed = new HashSet <InstanceId>();

            failed.Add(new InstanceId(1));
            failed.Add(new InstanceId(2));

            // This is the instance that must discover that it is the elector and whose state machine we'll test
            InstanceId lowestNonFailedInstanceId = new InstanceId(3);

            IDictionary <InstanceId, URI> members = new Dictionary <InstanceId, URI>();

            members[new InstanceId(1)]         = URI.create("server1");
            members[new InstanceId(2)]         = URI.create("server2");
            members[lowestNonFailedInstanceId] = URI.create("server3");
            members[new InstanceId(4)]         = URI.create("server4");
            members[new InstanceId(5)]         = URI.create("server5");

            Config config = Config.defaults();
            ClusterConfiguration clusterConfiguration = mock(typeof(ClusterConfiguration));

            when(clusterConfiguration.Members).thenReturn(members);
            when(clusterConfiguration.MemberIds).thenReturn(members.Keys);

            ClusterContext clusterContext = mock(typeof(ClusterContext));

            when(clusterContext.Configuration).thenReturn(clusterConfiguration);

            MultiPaxosContext context = new MultiPaxosContext(lowestNonFailedInstanceId, Iterables.iterable(new ElectionRole("coordinator")), clusterConfiguration, mock(typeof(Executor)), NullLogProvider.Instance, mock(typeof(ObjectInputStreamFactory)), mock(typeof(ObjectOutputStreamFactory)), mock(typeof(AcceptorInstanceStore)), mock(typeof(Timeouts)), mock(typeof(ElectionCredentialsProvider)), config);

            ElectionContext toTest = context.ElectionContext;

            // Sanity check that before learning about lowest failed ids it does not consider itself the elector
            assertFalse(toTest.Elector);

            // When
            // The lowest numbered alive instance receives word about other failed instances
            context.HeartbeatContext.Failed.addAll(failed);

            // Then
            // It should realise it is the elector (lowest instance id alive)
            assertTrue(toTest.Elector);
        }
Beispiel #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testElectionVersionIsResetWhenElectorChangesFromMeToOther()
        public virtual void TestElectionVersionIsResetWhenElectorChangesFromMeToOther()
        {
            const string coordinatorRole = "coordinator";
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.cluster.InstanceId me = new org.neo4j.cluster.InstanceId(1);
            InstanceId me = new InstanceId(1);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.cluster.InstanceId winner = new org.neo4j.cluster.InstanceId(2);
            InstanceId winner = new InstanceId(2);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.cluster.InstanceId elector = new org.neo4j.cluster.InstanceId(2);
            InstanceId       elector          = new InstanceId(2);
            HeartbeatContext heartbeatContext = mock(typeof(HeartbeatContext));

            when(heartbeatContext.Failed).thenReturn(Collections.emptySet());

            Config config = mock(typeof(Config));

            when(config.Get(ClusterSettings.max_acceptors)).thenReturn(10);

            MultiPaxosContext multiPaxosContext = new MultiPaxosContext(me, Iterables.iterable(new ElectionRole(coordinatorRole)), mock(typeof(ClusterConfiguration)), ThreadStart.run, NullLogProvider.Instance, mock(typeof(ObjectInputStreamFactory)), mock(typeof(ObjectOutputStreamFactory)), mock(typeof(AcceptorInstanceStore)), mock(typeof(Timeouts)), mock(typeof(ElectionCredentialsProvider)), config);
            ClusterContext    context           = multiPaxosContext.ClusterContext;
            ElectionContext   electionContext   = multiPaxosContext.ElectionContext;

            ClusterListener listener = mock(typeof(ClusterListener));

            context.LastElectorVersion = 5;
            context.LastElector        = me;
            context.AddClusterListener(listener);

            long expectedVersion = electionContext.NewConfigurationStateChange().Version;

            context.Elected(coordinatorRole, winner, me, expectedVersion);
            verify(listener, times(1)).elected(coordinatorRole, winner, null);

            context.Elected(coordinatorRole, winner, elector, 2);
            verify(listener, times(2)).elected(coordinatorRole, winner, null);

            context.Elected(coordinatorRole, winner, elector, 3);
            verify(listener, times(3)).elected(coordinatorRole, winner, null);

            context.Elected(coordinatorRole, winner, elector, 2);
            verifyNoMoreInteractions(listener);
        }
Beispiel #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void timeoutMakesElectionBeForgotten() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TimeoutMakesElectionBeForgotten()
        {
            // Given
            string coordinatorRole = "coordinator";

            ElectionContext context = mock(typeof(ElectionContext));

            when(context.GetLog(Mockito.any())).thenReturn(NullLog.Instance);

            MessageHolder holder = mock(typeof(MessageHolder));

            Message <ElectionMessage> timeout = Message.timeout(ElectionMessage.ElectionTimeout, Message.@internal(performRoleElections), new ElectionState.ElectionTimeoutData(coordinatorRole, null));

            // When
            election.handle(context, timeout, holder);

            // Then
            verify(context, times(1)).forgetElection(coordinatorRole);
        }
Beispiel #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSendAtomicBroadcastOnJoiningAClusterWithAnEstablishedCoordinator() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSendAtomicBroadcastOnJoiningAClusterWithAnEstablishedCoordinator()
        {
            // Given
            string     winnerURI = "some://winner";
            InstanceId winner    = new InstanceId(2);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.List<org.neo4j.cluster.com.message.Message<?>> messages = new java.util.ArrayList<>(1);
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
            IList <Message <object> > messages = new List <Message <object> >(1);
            MessageHolder             holder   = messages.add;
            ElectionCredentials       voteCredentialComparable = mock(typeof(ElectionCredentials));

            ElectionContext electionContext = mock(typeof(ElectionContext));

            when(electionContext.Voted(eq(COORDINATOR), eq(new InstanceId(1)), eq(voteCredentialComparable), anyLong())).thenReturn(true);
            when(electionContext.GetVoteCount(COORDINATOR)).thenReturn(3);
            when(electionContext.NeededVoteCount).thenReturn(3);
            when(electionContext.GetElectionWinner(COORDINATOR)).thenReturn(winner);

            when(electionContext.GetLog(any(typeof(Type)))).thenReturn(NullLog.Instance);
            VersionedConfigurationStateChange stateChange = mock(typeof(VersionedConfigurationStateChange));

            when(electionContext.NewConfigurationStateChange()).thenReturn(stateChange);

            when(electionContext.GetUriForId(winner)).thenReturn(URI.create(winnerURI));

            // When
            Message <ElectionMessage> votedMessage = Message.to(ElectionMessage.Voted, URI.create("some://instance"), new ElectionMessage.VotedData(COORDINATOR, new InstanceId(1), voteCredentialComparable));

            votedMessage.SetHeader(Message.HEADER_FROM, "some://other");

            election.handle(electionContext, votedMessage, holder);

            // Then
            assertEquals(1, messages.Count);
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.cluster.com.message.Message<?> message = messages.get(0);
            Message <object> message = messages[0];

            assertEquals(AtomicBroadcastMessage.broadcast, message.MessageType);
        }
Beispiel #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void electionBeingForgottenMustIncreaseElectionId()
        public virtual void ElectionBeingForgottenMustIncreaseElectionId()
        {
            // Given
            const string     coordinatorRole  = "coordinator";
            HeartbeatContext heartbeatContext = mock(typeof(HeartbeatContext));

            when(heartbeatContext.Failed).thenReturn(Collections.emptySet());

            Config config = mock(typeof(Config));

            when(config.Get(ClusterSettings.max_acceptors)).thenReturn(10);

            ElectionContext context = (new MultiPaxosContext(new InstanceId(1), Iterables.iterable(new ElectionRole(coordinatorRole)), mock(typeof(ClusterConfiguration)), mock(typeof(Executor)), NullLogProvider.Instance, mock(typeof(ObjectInputStreamFactory)), mock(typeof(ObjectOutputStreamFactory)), mock(typeof(AcceptorInstanceStore)), mock(typeof(Timeouts)), mock(typeof(ElectionCredentialsProvider)), config)).ElectionContext;

            ElectionContext_VoteRequest voteRequestBefore = context.VoteRequestForRole(new ElectionRole(coordinatorRole));

            context.ForgetElection(coordinatorRole);
            ElectionContext_VoteRequest voteRequestAfter = context.VoteRequestForRole(new ElectionRole(coordinatorRole));

            assertEquals(voteRequestBefore.Version + 1, voteRequestAfter.Version);
        }
Beispiel #12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void twoVotesFromSameInstanceForSameRoleShouldBeConsolidated()
        public virtual void TwoVotesFromSameInstanceForSameRoleShouldBeConsolidated()
        {
            // Given
            const string     coordinatorRole  = "coordinator";
            HeartbeatContext heartbeatContext = mock(typeof(HeartbeatContext));

            when(heartbeatContext.Failed).thenReturn(Collections.emptySet());

            IDictionary <InstanceId, URI> members = new Dictionary <InstanceId, URI>();

            members[new InstanceId(1)] = URI.create("server1");
            members[new InstanceId(2)] = URI.create("server2");
            members[new InstanceId(3)] = URI.create("server3");

            Config config = mock(typeof(Config));

            when(config.Get(ClusterSettings.max_acceptors)).thenReturn(10);

            ClusterConfiguration clusterConfiguration = mock(typeof(ClusterConfiguration));

            when(clusterConfiguration.Members).thenReturn(members);

            ClusterContext clusterContext = mock(typeof(ClusterContext));

            when(clusterContext.Configuration).thenReturn(clusterConfiguration);

            MultiPaxosContext context = new MultiPaxosContext(new InstanceId(1), Iterables.iterable(new ElectionRole(coordinatorRole)), clusterConfiguration, mock(typeof(Executor)), NullLogProvider.Instance, mock(typeof(ObjectInputStreamFactory)), mock(typeof(ObjectOutputStreamFactory)), mock(typeof(AcceptorInstanceStore)), mock(typeof(Timeouts)), mock(typeof(ElectionCredentialsProvider)), config);

            ElectionContext toTest = context.ElectionContext;

            // When
            toTest.StartElectionProcess(coordinatorRole);
            toTest.Voted(coordinatorRole, new InstanceId(1), new IntegerElectionCredentials(100), Org.Neo4j.cluster.protocol.cluster.ClusterContext_Fields.NO_ELECTOR_VERSION);
            toTest.Voted(coordinatorRole, new InstanceId(2), new IntegerElectionCredentials(100), Org.Neo4j.cluster.protocol.cluster.ClusterContext_Fields.NO_ELECTOR_VERSION);
            toTest.Voted(coordinatorRole, new InstanceId(2), new IntegerElectionCredentials(101), Org.Neo4j.cluster.protocol.cluster.ClusterContext_Fields.NO_ELECTOR_VERSION);

            // Then
            assertNull(toTest.GetElectionWinner(coordinatorRole));
            assertEquals(2, toTest.GetVoteCount(coordinatorRole));
        }
Beispiel #13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void instanceFailingShouldHaveItsVotesInvalidated()
        public virtual void InstanceFailingShouldHaveItsVotesInvalidated()
        {
            // Given
            const string role1           = "coordinator1";
            const string role2           = "coordinator2";
            InstanceId   me              = new InstanceId(1);
            InstanceId   failingInstance = new InstanceId(2);
            InstanceId   otherInstance   = new InstanceId(3);

            Config config = mock(typeof(Config));

            when(config.Get(ClusterSettings.max_acceptors)).thenReturn(10);

            ClusterConfiguration clusterConfiguration = mock(typeof(ClusterConfiguration));
            IList <InstanceId>   clusterMemberIds     = new LinkedList <InstanceId>();

            clusterMemberIds.Add(failingInstance);
            clusterMemberIds.Add(otherInstance);
            clusterMemberIds.Add(me);
            when(clusterConfiguration.MemberIds).thenReturn(clusterMemberIds);

            MultiPaxosContext context = new MultiPaxosContext(me, Iterables.iterable(new ElectionRole(role1), new ElectionRole(role2)), clusterConfiguration, ThreadStart.run, NullLogProvider.Instance, mock(typeof(ObjectInputStreamFactory)), mock(typeof(ObjectOutputStreamFactory)), mock(typeof(AcceptorInstanceStore)), mock(typeof(Timeouts)), mock(typeof(ElectionCredentialsProvider)), config);

            HeartbeatContext heartbeatContext = context.HeartbeatContext;
            ElectionContext  electionContext  = context.ElectionContext;

            electionContext.StartElectionProcess(role1);
            electionContext.StartElectionProcess(role2);

            electionContext.Voted(role1, failingInstance, mock(typeof(ElectionCredentials)), 2);
            electionContext.Voted(role2, failingInstance, mock(typeof(ElectionCredentials)), 2);

            electionContext.Voted(role1, otherInstance, mock(typeof(ElectionCredentials)), 2);
            electionContext.Voted(role2, otherInstance, mock(typeof(ElectionCredentials)), 2);

            heartbeatContext.Suspect(failingInstance);

            assertEquals(1, electionContext.GetVoteCount(role1));
            assertEquals(1, electionContext.GetVoteCount(role2));
        }
Beispiel #14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void voteFromPreviousSuccessfulElectionMustNotBeCounted()
        public virtual void VoteFromPreviousSuccessfulElectionMustNotBeCounted()
        {
            // Given
            const string     coordinatorRole  = "coordinator";
            HeartbeatContext heartbeatContext = mock(typeof(HeartbeatContext));

            when(heartbeatContext.Failed).thenReturn(Collections.emptySet());

            Config config = mock(typeof(Config));

            when(config.Get(ClusterSettings.max_acceptors)).thenReturn(10);

            ElectionContext context = (new MultiPaxosContext(new InstanceId(1), Iterables.iterable(new ElectionRole(coordinatorRole)), mock(typeof(ClusterConfiguration)), mock(typeof(Executor)), NullLogProvider.Instance, mock(typeof(ObjectInputStreamFactory)), mock(typeof(ObjectOutputStreamFactory)), mock(typeof(AcceptorInstanceStore)), mock(typeof(Timeouts)), mock(typeof(ElectionCredentialsProvider)), config)).ElectionContext;

            // When
            ElectionContext_VoteRequest voteRequestBefore = context.VoteRequestForRole(new ElectionRole(coordinatorRole));

            context.ForgetElection(coordinatorRole);

            // Then
            assertFalse(context.Voted(coordinatorRole, new InstanceId(2), null, voteRequestBefore.Version - 1));
        }
Beispiel #15
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ElectionContext context)
        {
            _env = env;
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
                app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
                {
                    HotModuleReplacement      = true,
                    ReactHotModuleReplacement = true
                });
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }
            app.UseSwagger(options =>
            {
            });
            app.UseSwaggerUI(options =>
            {
                //options.SwaggerEndpoint("/swagger/v0.1.0/swagger.json", "API for election result data");
                options.SwaggerEndpoint("/swagger/v1.0.0/swagger.json", "API for election result data");
            });
            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");

                routes.MapSpaFallbackRoute(
                    name: "spa-fallback",
                    defaults: new { controller = "Home", action = "Index" });
            });
        }
Beispiel #16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void electionCompletingMakesItBeForgotten() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ElectionCompletingMakesItBeForgotten()
        {
            // Given
            string              coordinatorRole          = "coordinator";
            InstanceId          votingInstance           = new InstanceId(2);
            ElectionCredentials voteCredentialComparable = mock(typeof(ElectionCredentials));

            ElectionContext context = mock(typeof(ElectionContext));

            when(context.GetLog(Mockito.any())).thenReturn(NullLog.Instance);
            when(context.NeededVoteCount).thenReturn(3);
            when(context.GetVoteCount(coordinatorRole)).thenReturn(3);
            when(context.Voted(coordinatorRole, votingInstance, voteCredentialComparable, 4)).thenReturn(true);
            MessageHolder holder = mock(typeof(MessageHolder));

            Message <ElectionMessage> vote = Message.to(ElectionMessage.Voted, URI.create("cluster://elector"), new ElectionMessage.VersionedVotedData(coordinatorRole, votingInstance, voteCredentialComparable, 4));

            // When
            election.handle(context, vote, holder);

            // Then
            verify(context, times(1)).forgetElection(coordinatorRole);
        }
Beispiel #17
0
        public static void Main(string[] args)
        {
            IWebHost host = BuildWebHost(args);

            using (IServiceScope scope = host.Services.CreateScope())
            {
                IServiceProvider services = scope.ServiceProvider;
                try
                {
                    //VDContext context = services.GetRequiredService<VDContext>();
                    //VDInitializer.Initialize(context);
                    ElectionContext context = services.GetRequiredService <ElectionContext>();
                    ILogger         logger  = services.GetRequiredService <ILogger <Program> >();
                    ElectionInitializer.Initialize(context, logger);
                }
                catch (Exception ex)
                {
                    ILogger logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred while seeding VDContext");
                }
            }
            host.Run();
        }
 public CircuitsController(ElectionContext context)
 {
     _context = context;
 }
Beispiel #19
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, ElectionContext context)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Shared/Error");
            }

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            DbInitializer.Initialize(context);
        }
Beispiel #20
0
 public UnitOfWork(ElectionContext electionContext)
 {
     _electionContext = electionContext;
 }
Beispiel #21
0
 public GenericRepository(ElectionContext context)
 {
     _context = context;
     _dbSet   = context.Set <T>();
 }
Beispiel #22
0
 public PartyRepository(ElectionContext electionContext)
 {
     this.electionContext = electionContext;
 }
Beispiel #23
0
 public HomeController(ElectionContext context)
 {
     _context = context;
 }
 public CommentsController(ElectionContext context)
 {
     _context = context;
 }
Beispiel #25
0
 public HomeController(ElectionContext context, Mailer mailer)
 {
     _context = context;
     _mailer  = mailer;
 }
Beispiel #26
0
 /// <summary>
 /// Constructor for the ElectionController, enables database access and logging
 /// </summary>
 /// <param name="context">ElectionContext object that allows access to the database</param>
 /// <param name="logger">Logger that gives information about the context of a log message</param>
 public ElectionController(ElectionContext context, ILogger <ElectionController> logger)
 {
     _context = context;
     _logger  = logger;
 }
Beispiel #27
0
 public AccountController(ElectionContext context)
 {
     db = context;
 }
Beispiel #28
0
 public VotersController(ElectionContext context)
 {
     _context = context;
 }
Beispiel #29
0
 public CandidatesController(ElectionContext context, Mailer mailer)
 {
     _context = context;
     _mailer  = mailer;
 }
 public CandidateRepository(ElectionContext electionContext)
 {
     this.electionContext = electionContext;
 }