Ejemplo n.º 1
0
        /*
         * This test ensures that an instance that cleanly leaves the cluster but is not the elector has no effect on
         * elector id and last version
         */
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void nonElectorLeavingTheClusterMustNotAffectElectorInformation()
        public virtual void NonElectorLeavingTheClusterMustNotAffectElectorInformation()
        {
            // Given
            InstanceId me      = new InstanceId(1);
            InstanceId elector = new InstanceId(2);
            InstanceId other   = new InstanceId(3);

            ClusterConfiguration clusterConfiguration = mock(typeof(ClusterConfiguration));

            when(clusterConfiguration.GetUriForId(other)).thenReturn(URI.create("cluster://instance2"));

            CommonContextState commonContextState = mock(typeof(CommonContextState));

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

            ClusterContext context = new ClusterContextImpl(me, commonContextState, NullLogProvider.Instance, mock(typeof(Timeouts)), mock(typeof(Executor)), mock(typeof(ObjectOutputStreamFactory)), mock(typeof(ObjectInputStreamFactory)), mock(typeof(LearnerContext)), mock(typeof(HeartbeatContext)), mock(typeof(Config)));

            // This means instance 2 was the elector at version 8
            context.LastElector        = elector;
            context.LastElectorVersion = 8;

            // When
            context.Left(other);

            // Then
            assertEquals(context.LastElector, elector);
            assertEquals(context.LastElectorVersion, 8);
        }
Ejemplo n.º 2
0
 private CommonContextState(URI boundAt, long lastKnownLearnedInstanceInCluster, long nextInstanceId, ClusterConfiguration configuration, int maxAcceptors)
 {
     this._boundAt = boundAt;
     this._lastKnownLearnedInstanceInCluster = lastKnownLearnedInstanceInCluster;
     this._nextInstanceId = nextInstanceId;
     this._configuration  = configuration;
     this._maxAcceptors   = maxAcceptors;
 }
Ejemplo n.º 3
0
        private ClusterConfiguration ClusterConfiguration(params URI[] uris)
        {
            LogProvider          logProvider = FormattedLogProvider.toOutputStream(System.out);
            ClusterConfiguration toReturn    = new ClusterConfiguration("neo4j.ha", logProvider, asList(uris));

            toReturn.Joined(_clusterId1, _clusterUri1);
            toReturn.Joined(_clusterId2, _clusterUri2);
            if (uris.Length == 3)
            {
                toReturn.Joined(_clusterId3, _clusterUri3);
            }
            return(toReturn);
        }
Ejemplo n.º 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHasQuorumWhenOneMachineAliveInAClusterWithOneMachine()
        public virtual void ShouldHasQuorumWhenOneMachineAliveInAClusterWithOneMachine()
        {
            //Given
            HeartbeatContext     heartbeatContext = mock(typeof(HeartbeatContext));
            CommonContextState   commonState      = mock(typeof(CommonContextState));
            ClusterConfiguration configuration    = mock(typeof(ClusterConfiguration));

            when(heartbeatContext.Alive).thenReturn(ids(1));
            when(commonState.Configuration()).thenReturn(configuration);
            when(configuration.Members).thenReturn(members(1));

            AtomicBroadcastContextImpl context = new AtomicBroadcastContextImpl(null, commonState, null, null, null, heartbeatContext);                 // we do not care about other args
            //When
            bool hasQuorum = context.HasQuorum();

            //Then
            assertTrue(hasQuorum);
        }
Ejemplo n.º 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDeepClone()
        public virtual void ShouldDeepClone()
        {
            // Given
            ObjectStreamFactory   objStream                 = new ObjectStreamFactory();
            AcceptorInstanceStore acceptorInstances         = mock(typeof(AcceptorInstanceStore));
            Executor                    executor            = mock(typeof(Executor));
            Timeouts                    timeouts            = mock(typeof(Timeouts));
            ClusterConfiguration        clusterConfig       = new ClusterConfiguration("myCluster", NullLogProvider.Instance);
            ElectionCredentialsProvider electionCredentials = mock(typeof(ElectionCredentialsProvider));

            Config config = mock(typeof(Config));

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

            MultiPaxosContext ctx = new MultiPaxosContext(new InstanceId(1), Collections.emptyList(), clusterConfig, executor, NullLogProvider.Instance, objStream, objStream, acceptorInstances, timeouts, electionCredentials, config);

            // When
            MultiPaxosContext snapshot = ctx.Snapshot(NullLogProvider.Instance, timeouts, executor, acceptorInstances, objStream, objStream, electionCredentials);

            // Then
            assertEquals(ctx, snapshot);
        }
Ejemplo n.º 6
0
 internal CommonContextState(ClusterConfiguration configuration, int maxAcceptors)
 {
     this._configuration = configuration;
     this._maxAcceptors  = maxAcceptors;
 }
Ejemplo n.º 7
0
 public MultiPaxosServerFactory(ClusterConfiguration initialConfig, LogProvider logging, StateMachines.Monitor stateMachinesMonitor)
 {
     this._initialConfig        = initialConfig;
     this._logging              = logging;
     this._stateMachinesMonitor = stateMachinesMonitor;
 }
Ejemplo n.º 8
0
        // Cluster events

        /// <summary>
        /// Logged when the instance itself joins or rejoins a cluster
        /// </summary>
        /// <param name="clusterConfiguration"> </param>
        public override void EnteredCluster(ClusterConfiguration clusterConfiguration)
        {
            _myUri = clusterConfiguration.GetUriForId(_myId);
            _log.info("Instance %s entered the cluster", PrintId(_myId, _myUri));
        }