예제 #1
0
		public void Follower_as_a_single_node_becomes_leader_automatically()
		{
			var hub = new InMemoryTransportHub();
			var storageEnvironmentOptions = StorageEnvironmentOptions.CreateMemoryOnly();
			storageEnvironmentOptions.OwnsPagers = false;
			
			var raftEngineOptions = new RaftEngineOptions(
				new NodeConnectionInfo { Name = "node1" }, 
				storageEnvironmentOptions,
				hub.CreateTransportFor("node1"),
				new DictionaryStateMachine()
				)
			{
				ElectionTimeout = 1000,
				HeartbeatTimeout = 1000/6
			};

			PersistentState.ClusterBootstrap(raftEngineOptions);
			storageEnvironmentOptions.OwnsPagers = true;

			using (var raftNode = new RaftEngine(raftEngineOptions))
			{
				Assert.Equal(RaftEngineState.Leader, raftNode.State);
			}
		}
예제 #2
0
        public void Follower_as_a_single_node_becomes_leader_automatically()
        {
            var hub = new InMemoryTransportHub();
            var storageEnvironmentOptions = StorageEnvironmentOptions.CreateMemoryOnly();

            storageEnvironmentOptions.OwnsPagers = false;

            var raftEngineOptions = new RaftEngineOptions(
                new NodeConnectionInfo {
                Name = "node1"
            },
                storageEnvironmentOptions,
                hub.CreateTransportFor("node1"),
                new DictionaryStateMachine()
                )
            {
                ElectionTimeout  = 1000,
                HeartbeatTimeout = 1000 / 6
            };

            PersistentState.ClusterBootstrap(raftEngineOptions);
            storageEnvironmentOptions.OwnsPagers = true;

            using (var raftNode = new RaftEngine(raftEngineOptions))
            {
                Assert.Equal(RaftEngineState.Leader, raftNode.State);
            }
        }
예제 #3
0
 protected void ForceTimeout(string name)
 {
     ((InMemoryTransportHub.InMemoryTransport)_inMemoryTransportHub.CreateTransportFor(name)).ForceTimeout();
 }