示例#1
0
		public void TextFixtureSetUp()
		{
			_workerNode = new WorkerNode
			{
				Url = new Uri("http://localhost:9050/")
			};
		}
示例#2
0
		public void AddWorkerNode(Uri workerNodeUri)
		{
			var node = new WorkerNode
			{
				Url = workerNodeUri
			};

			_nodeRepository.AddWorkerNode(node);
		}
示例#3
0
		public void AddWorkerNode(WorkerNode workerNode)
		{
			try
			{
				using (var connection = new SqlConnection(_connectionString))
				{
					connection.OpenWithRetry(_retryPolicy);

					using (var workerNodeCommand = connection.CreateCommand())
					{
						workerNodeCommand.CommandText = "INSERT INTO [Stardust].[WorkerNode] " +
													"(Id, Url, Heartbeat, Alive) " +
													"VALUES(@Id, @Url, @Heartbeat, @Alive)";

						workerNodeCommand.Parameters.AddWithValue("@Id", workerNode.Id);
						workerNodeCommand.Parameters.AddWithValue("@Url", workerNode.Url.ToString());
						workerNodeCommand.Parameters.AddWithValue("@Heartbeat", workerNode.Heartbeat);
						workerNodeCommand.Parameters.AddWithValue("@Alive", workerNode.Alive);

						workerNodeCommand.ExecuteNonQueryWithRetry(_retryPolicy);
					}
				}
			}
			catch (Exception exp)
			{
				if (exp.Message.Contains("UQ_WorkerNodes_Url"))
				{
					using (var connection = new SqlConnection(_connectionString))
					{
						connection.OpenWithRetry(_retryPolicy);
						var updateCommandText = @"UPDATE [Stardust].[WorkerNode] SET Heartbeat = @Heartbeat,
											Alive = @Alive
											WHERE Url = @Url";

						using (var command = new SqlCommand(updateCommandText, connection))
						{
							command.Parameters.Add("@Heartbeat", SqlDbType.DateTime).Value = DateTime.UtcNow;
							command.Parameters.Add("@Alive", SqlDbType.Bit).Value = true;
							command.Parameters.Add("@Url", SqlDbType.NVarChar).Value = workerNode.Url.ToString();

							command.ExecuteNonQueryWithRetry(_retryPolicy);
						}
					}
					return;
				}

				this.Log().ErrorWithLineNumber(exp.Message, exp);
				throw;
			}
		}
示例#4
0
		public List<WorkerNode> GetAllWorkerNodes()
		{
			var listToReturn = new List<WorkerNode>();

			try
			{
				using (var connection = new SqlConnection(_connectionString))
				{
					using (var command = connection.CreateCommand())
					{
						command.CommandText = "SELECT Id, Url, Heartbeat, Alive " +
										 "FROM [Stardust].[WorkerNode]";

						connection.OpenWithRetry(_retryPolicy);

						using (var reader = command.ExecuteReaderWithRetry(_retryPolicy))
						{
							if (reader.HasRows)
							{
								var ordinalPositionForIdField = reader.GetOrdinal("Id");
								var ordinalPositionForUrlField = reader.GetOrdinal("Url");
								var ordinalPositionForAliveField = reader.GetOrdinal("Alive");
								var ordinalPositionForHeartbeatField = reader.GetOrdinal("Heartbeat");

								while (reader.Read())
								{
									var workerNode = new WorkerNode
									{
										Id = (Guid)reader.GetValue(ordinalPositionForIdField),
										Url = new Uri((string)reader.GetValue(ordinalPositionForUrlField)),
										Alive = (bool)reader.GetValue(ordinalPositionForAliveField),
										Heartbeat = (DateTime)reader.GetValue(ordinalPositionForHeartbeatField)
									};

									listToReturn.Add(workerNode);
								}
							}
						}
					}
				}
				return listToReturn;
			}
			catch (Exception exp)
			{
				this.Log().ErrorWithLineNumber(exp.Message, exp);
				throw;
			}
		}
		public void ShouldSendTheJobToAnotherNodeIfFirstReturnsConflict()
		{
			var jobQueueItem = new JobQueueItem
			{
				Name = "Name Test",
				CreatedBy = "Created By Test",
				Serialized = "Serialized Test",
				Type = "Type Test"
			};

			var workerNode2 = new WorkerNode
			{
				Url = new Uri("http://localhost:9051/")
			};
			
			NodeRepository.AddWorkerNode(_workerNode);
			Thread.Sleep(TimeSpan.FromSeconds(1));
			NodeRepository.AddWorkerNode(workerNode2);
			ThisNodeIsBusy(workerNode2.Url);

			ManagerController.AddItemToJobQueue(jobQueueItem);
			
			while (true)
			{
				if (JobRepository.GetAllJobs().Count == 1)
					break;
			}
			
			JobRepository.GetAllJobs().First().SentToWorkerNodeUri.Should().Be.EqualTo(_workerNode.Url.ToString());
		}
		public void AddWorkerNode(WorkerNode workerNode)
		{
			_workerNodes.Add(workerNode);
		}