예제 #1
0
		public async Task PingAfterRevival()
		{
			var audit = new Auditor(() => Framework.Cluster
				.Nodes(3)
				.ClientCalls(r => r.SucceedAlways())
				.ClientCalls(r => r.OnPort(9202).Fails(Once))
				.Ping(p => p.SucceedAlways())
				.StaticConnectionPool()
				.AllDefaults()
			);

			audit = await audit.TraceCalls(
				new ClientCall { { PingSuccess, 9200 }, { HealthyResponse, 9200 } },
				new ClientCall { { PingSuccess, 9201 }, { HealthyResponse, 9201 } },
				new ClientCall {
					{ PingSuccess, 9202},
					{ BadResponse, 9202},
					{ HealthyResponse, 9200},
					{ pool =>  pool.Nodes.Where(n=>!n.IsAlive).Should().HaveCount(1) }
				},
				new ClientCall { { HealthyResponse, 9201 } },
				new ClientCall { { HealthyResponse, 9200 } },
				new ClientCall { { HealthyResponse, 9201 } },
				new ClientCall {
					{ HealthyResponse, 9200 },
					{ pool => pool.Nodes.First(n=>!n.IsAlive).DeadUntil.Should().BeAfter(DateTime.UtcNow) }
				}
			);

			audit = await audit.TraceCalls(
				new ClientCall { { HealthyResponse, 9201 } },
				new ClientCall { { HealthyResponse, 9200 } },
				new ClientCall { { HealthyResponse, 9201 } }
			);

			audit.ChangeTime(d => d.AddMinutes(20));

			audit = await audit.TraceCalls(
				new ClientCall { { HealthyResponse, 9201 } },
				new ClientCall {
					{ Resurrection, 9202 },
					{ PingSuccess, 9202 },
					{ HealthyResponse, 9202 }
				}
			);
		}
예제 #2
0
		public async Task ASniffOnStartupHappens()
		{
			var audit = new Auditor(() => Framework.Cluster
				.Nodes(10)
				.MasterEligible(9202, 9203, 9204)
				.ClientCalls(r => r.SucceedAlways())
				.Sniff(s => s.SucceedAlways(Framework.Cluster
					.Nodes(100)
					.MasterEligible(9202, 9203, 9204)
					.ClientCalls(r => r.SucceedAlways())
					.Sniff(ss => ss.SucceedAlways(Framework.Cluster
						.Nodes(10)
						.MasterEligible(9202, 9203, 9204)
						.ClientCalls(r => r.SucceedAlways())
					))
				))
				.SniffingConnectionPool()
				.Settings(s => s
					.DisablePing()
					.SniffOnConnectionFault(false)
					.SniffOnStartup(false)
					.SniffLifeSpan(TimeSpan.FromMinutes(30))
				)
			);
			/** healty cluster all nodes return healthy responses*/
			audit = await audit.TraceCalls(
				new ClientCall { { HealthyResponse, 9200 } },
				new ClientCall { { HealthyResponse, 9201 } },
				new ClientCall { { HealthyResponse, 9202 } },
				new ClientCall { { HealthyResponse, 9203 } },
				new ClientCall { { HealthyResponse, 9204 } },
				new ClientCall { { HealthyResponse, 9205 } },
				new ClientCall { { HealthyResponse, 9206 } },
				new ClientCall { { HealthyResponse, 9207 } },
				new ClientCall { { HealthyResponse, 9208 } },
				new ClientCall { { HealthyResponse, 9209 } },
				new ClientCall {
					{ HealthyResponse, 9200 },
					{ pool => pool.Nodes.Count.Should().Be(10) }
				}
			);
			/** Now let's forward the clock 31 minutes, our sniff lifespan should now go state
			* and the first call should do a sniff which discovered we scaled up to a 100 nodes!
			*/
			audit.ChangeTime(d => d.AddMinutes(31));
			audit = await audit.TraceCalls(
				new ClientCall {
					/** a sniff is done first and it prefers the first node master node */
					{ SniffOnStaleCluster },
					{ SniffSuccess, 9202 },
					{ HealthyResponse, 9201 },
					{ pool => pool.Nodes.Count.Should().Be(100) }
				}
			);

			audit.ChangeTime(d => d.AddMinutes(31));
			audit = await audit.TraceCalls(
				new ClientCall {
					/** a sniff is done first and it prefers the first node master node */
					{ SniffOnStaleCluster },
					{ SniffSuccess, 9202 },
					{ HealthyResponse, 9200 },
					{ pool => pool.Nodes.Count.Should().Be(10) }
				}
			);
		}