Пример #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void majorityOfNonSuspectedInstancesShouldBeEnoughToMarkAnInstanceAsFailed()
        public virtual void MajorityOfNonSuspectedInstancesShouldBeEnoughToMarkAnInstanceAsFailed()
        {
            // Given
            InstanceId me      = new InstanceId(1);
            InstanceId member2 = new InstanceId(2);
            InstanceId member3 = new InstanceId(3);
            InstanceId member4 = new InstanceId(4);
            InstanceId member5 = new InstanceId(5);

            Timeouts timeouts = mock(typeof(Timeouts));

            CommonContextState   commonState   = mock(typeof(CommonContextState));
            ClusterConfiguration configuration = mock(typeof(ClusterConfiguration));

            when(commonState.Configuration()).thenReturn(configuration);
            when(configuration.Members).thenReturn(members(5));
            when(configuration.MemberIds).thenReturn(ids(5));

            DelayedDirectExecutor executor = new DelayedDirectExecutor(NullLogProvider.Instance);
            HeartbeatContext      context  = new HeartbeatContextImpl(me, commonState, NullLogProvider.Instance, timeouts, executor);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.List<org.neo4j.cluster.InstanceId> failed = new java.util.ArrayList<>(4);
            IList <InstanceId> failed   = new List <InstanceId>(4);
            HeartbeatListener  listener = new HeartbeatListenerAnonymousInnerClass2(this, failed);

            context.AddHeartbeatListener(listener);

            // when
            // just two suspicions come, no extra failing action should be taken since this is not majority
            context.Suspect(member2);
            context.Suspect(member3);
            executor.Drain();

            // then
            assertEquals(0, failed.Count);

            // when
            // the another instance suspects them, therefore have a majority of non suspected, then 2 and 3 must fail
            ISet <InstanceId> suspicionsFrom5 = new HashSet <InstanceId>();

            suspicionsFrom5.Add(member2);
            suspicionsFrom5.Add(member3);
            context.Suspicions(member5, suspicionsFrom5);
            executor.Drain();

            // then
            assertEquals(2, failed.Count);
            assertTrue(failed.Contains(member2));
            assertTrue(failed.Contains(member3));

            // when
            // an instance sends a heartbeat, it should be set as alive
            context.Alive(member2);
            executor.Drain();

            // then
            assertEquals(1, failed.Count);
            assertTrue(failed.Contains(member3));
        }
Пример #2
0
        public static ClusterInstance NewClusterInstance(InstanceId id, URI uri, Monitors monitors, ClusterConfiguration configuration, int maxSurvivableFailedMembers, LogProvider logging)
        {
            MultiPaxosServerFactory factory = new MultiPaxosServerFactory(configuration, logging, monitors.NewMonitor(typeof(StateMachines.Monitor)));

            ClusterInstanceInput  input  = new ClusterInstanceInput();
            ClusterInstanceOutput output = new ClusterInstanceOutput(uri);

            ObjectStreamFactory objStreamFactory = new ObjectStreamFactory();

            ProverTimeouts timeouts = new ProverTimeouts(uri);

            InMemoryAcceptorInstanceStore acceptorInstances = new InMemoryAcceptorInstanceStore();

            Config config = mock(typeof(Config));

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

            DelayedDirectExecutor executor = new DelayedDirectExecutor(logging);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext context = new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext(id, org.neo4j.helpers.collection.Iterables.iterable(new org.neo4j.cluster.protocol.election.ElectionRole(org.neo4j.cluster.protocol.cluster.ClusterConfiguration.COORDINATOR)), new org.neo4j.cluster.protocol.cluster.ClusterConfiguration(configuration.getName(), logging, configuration.getMemberURIs()), executor, logging, objStreamFactory, objStreamFactory, acceptorInstances, timeouts, new org.neo4j.kernel.ha.cluster.DefaultElectionCredentialsProvider(id, new StateVerifierLastTxIdGetter(), new MemberInfoProvider()), config);
            MultiPaxosContext context = new MultiPaxosContext(id, Iterables.iterable(new ElectionRole(ClusterConfiguration.COORDINATOR)), new ClusterConfiguration(configuration.Name, logging, configuration.MemberURIs), executor, logging, objStreamFactory, objStreamFactory, acceptorInstances, timeouts, new DefaultElectionCredentialsProvider(id, new StateVerifierLastTxIdGetter(), new MemberInfoProvider()), config);

            context.ClusterContext.BoundAt = uri;

            SnapshotContext snapshotContext = new SnapshotContext(context.ClusterContext, context.LearnerContext);

            DelayedDirectExecutor taskExecutor = new DelayedDirectExecutor(logging);
            ProtocolServer        ps           = factory.NewProtocolServer(id, input, output, DirectExecutor, taskExecutor, timeouts, context, snapshotContext);

            return(new ClusterInstance(DirectExecutor, logging, factory, ps, context, acceptorInstances, timeouts, input, output, uri));
        }
Пример #3
0
        public virtual ClusterInstance NewCopy()
        {
            // A very invasive method of cloning a protocol server. Nonetheless, since this is mostly an experiment at this
            // point, it seems we can refactor later on to have a cleaner clone mechanism.
            // Because state machines share state, and are simultaneously conceptually unaware of each other, implementing
            // a clean snapshot mechanism is very hard. I've opted for having a dirty one here in the test code rather
            // than introducing a hack into the runtime code.

            ProverTimeouts timeoutsSnapshot = _timeouts.snapshot();
            InMemoryAcceptorInstanceStore snapshotAcceptorInstances = _acceptorInstanceStore.snapshot();

            ClusterInstanceOutput output = new ClusterInstanceOutput(_uri);
            ClusterInstanceInput  input  = new ClusterInstanceInput();

            DelayedDirectExecutor executor = new DelayedDirectExecutor(_logging);

            ObjectStreamFactory objectStreamFactory = new ObjectStreamFactory();
            MultiPaxosContext   snapshotCtx         = _ctx.snapshot(_logging, timeoutsSnapshot, executor, snapshotAcceptorInstances, objectStreamFactory, objectStreamFactory, new DefaultElectionCredentialsProvider(_server.ServerId, new StateVerifierLastTxIdGetter(), new MemberInfoProvider())
                                                                    );

            IList <StateMachine> snapshotMachines = new List <StateMachine>();

            foreach (StateMachine stateMachine in _server.StateMachines.StateMachines)
            {
                snapshotMachines.Add(SnapshotStateMachine(_logging, snapshotCtx, stateMachine));
            }

            ProtocolServer snapshotProtocolServer = _factory.constructSupportingInfrastructureFor(_server.ServerId, input, output, executor, timeoutsSnapshot, _stateMachineExecutor, snapshotCtx, snapshotMachines.ToArray());

            return(new ClusterInstance(_stateMachineExecutor, _logging, _factory, snapshotProtocolServer, snapshotCtx, snapshotAcceptorInstances, timeoutsSnapshot, input, output, _uri));
        }
Пример #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldFailAllInstancesIfAllOtherInstancesAreSuspected()
        public virtual void ShouldFailAllInstancesIfAllOtherInstancesAreSuspected()
        {
            // Given
            InstanceId me      = new InstanceId(1);
            InstanceId member2 = new InstanceId(2);
            InstanceId member3 = new InstanceId(3);

            Timeouts timeouts = mock(typeof(Timeouts));

            CommonContextState   commonState   = mock(typeof(CommonContextState));
            ClusterConfiguration configuration = mock(typeof(ClusterConfiguration));

            when(commonState.Configuration()).thenReturn(configuration);
            when(configuration.Members).thenReturn(members(3));
            when(configuration.MemberIds).thenReturn(ids(3));

            DelayedDirectExecutor executor = new DelayedDirectExecutor(NullLogProvider.Instance);
            HeartbeatContext      context  = new HeartbeatContextImpl(me, commonState, NullLogProvider.Instance, timeouts, executor);

            IList <InstanceId> failed   = new List <InstanceId>(2);
            HeartbeatListener  listener = new HeartbeatListenerAnonymousInnerClass(this, failed);

            context.AddHeartbeatListener(listener);

            // when
            // just one suspicion comes, no extra failing action should be taken
            context.Suspect(member2);
            executor.Drain();

            // then
            assertEquals(0, failed.Count);

            // when
            // the other instance is suspected, all instances must be marked as failed
            context.Suspect(member3);
            executor.Drain();

            // then
            assertEquals(2, failed.Count);
            assertTrue(failed.Contains(member2));
            assertTrue(failed.Contains(member3));

            // when
            // one of them comes alive again, only that instance should be marked as alive
            context.Alive(member2);
            executor.Drain();

            // then
            assertEquals(1, failed.Count);
            assertTrue(failed.Contains(member3));
        }