public void enqueues_submission_to_the_queue() { var queue = new TestQueue(); var submission = new Submission { Source = new ProgramSource { Code = "test" }, SubmittedAt = new DateTime(1990, 7, 7), Problem = new Problem { TestInfo = new TestInfo(), Contest = new Contest { Beginning = new DateTime(1990, 7, 7), Ending = new DateTime(1992, 7, 7) } } }; var factory = new TestDatabaseConfiguration().DatabaseConfiguration.BuildSessionFactory(); using (var scope = new SessionScope(factory)) scope.Session.Save(submission); using (var scope = new SessionScope(factory)) { var consumer = new JudgeSubmissionConsumer(queue, scope.Session); consumer.Consume(new JudgeSubmission { SubmissionId = submission.Id }); } Assert.Equal(1, queue.Count); Assert.Equal(submission.Source.Code, ((SubmissionInfo)queue.Dequeue().WorkItem).Source.Code); }
private static void Main() { var TestQueue = new TestQueue <int>(1); // Добавляем элементы в очередь TestQueue.Enqueue(1); TestQueue.Enqueue(2); TestQueue.Enqueue(3); TestQueue.Enqueue(4); TestQueue.Enqueue(5); TestQueue.Enqueue(6); // Получаем очеред в виде массива и выводим foreach (int i in TestQueue.ToArray()) { Console.WriteLine(i); } Console.WriteLine(); // Удаляем все элементы из очереди и выводим while (TestQueue.Count > 0) { Console.WriteLine(TestQueue.Dequeue()); } Console.ReadKey(); }
public void Dequeue_IsThreadSafe() { var rand = new Random(1234); var queue = new TestQueue(); var counts = new Dictionary <FFXIVRole, int> { { FFXIVRole.DPS, 0 }, { FFXIVRole.Healer, 0 }, { FFXIVRole.Tank, 0 }, }; for (ulong i = 0; i < 1000; i++) { var curI = i; var nextRole = rand.Next(0, 3) switch { 0 => FFXIVRole.DPS, 1 => FFXIVRole.Healer, 2 => FFXIVRole.Tank, _ => throw new NotImplementedException(), }; counts[nextRole]++; queue.Enqueue(curI, nextRole, ""); } var threads = new List <Thread>(); var outList = new SynchronizedCollection <ulong>(); var roles = new[] { FFXIVRole.DPS, FFXIVRole.Healer, FFXIVRole.Tank }; foreach (var role in roles) { for (var i = 0; i < counts[role]; i++) { var thread = new Thread(() => { Thread.Sleep(rand.Next(0, 1001)); var id = queue.Dequeue(role, null); if (id != null) { outList.Add(id.Value); } }); thread.Start(); threads.Add(thread); } } foreach (var thread in threads) { thread.Join(); } var slots = queue.GetAllSlots().ToList(); Assert.That(!slots.Any()); Assert.That(outList.Count == 1000); }
public void Remove_NoEvent_Works() { var queue = new TestQueue(); queue.EnqueueAndConfirm(UserId, FFXIVRole.DPS, null); queue.Remove(UserId, FFXIVRole.DPS, EventId); var userId = queue.Dequeue(FFXIVRole.DPS, null); Assert.NotNull(userId); }
public void TestToArray() { PopulateTestQueue(); int?[] copyArray = TestQueue.ToArray(); for (int i = 0; i < copyArray.Length; i++) { Assert.Equal(TestQueue.Dequeue(), copyArray[i]); } }
public void Dequeue_Event_PullsForEvent(FFXIVRole role) { var queue = new TestQueue(); var enqueueSuccess = queue.EnqueueAndConfirm(UserId, role, EventId); Assert.IsTrue(enqueueSuccess); var outUId = queue.Dequeue(role, EventId); Assert.IsNotNull(outUId); }
public void TestEnqueue() { PopulateTestQueue(); Assert.Equal(SampleSize, TestQueue.Count); int currentValue = 2; do { Assert.Equal(currentValue, TestQueue.Dequeue()); currentValue++; } while (TestQueue.Count > 0); TestQueue.Enqueue(null); Assert.Null(TestQueue.Dequeue()); }
public void TestDequeue() { PopulateTestQueue(); Assert.Equal(SampleSize, TestQueue.Count); int currentValue = 2; int queueCount = SampleSize; do { Assert.Equal(currentValue, TestQueue.Dequeue()); currentValue++; queueCount--; Assert.Equal(queueCount, TestQueue.Count); } while (TestQueue.Count > 0); Assert.Empty(TestQueue); }
public void TestCopyTo() { PopulateTestQueue(); int?[] copyArray = new int?[SampleSize + 1]; TestQueue.CopyTo(copyArray, 1); for (int i = 1; i < copyArray.Length; i++) { Assert.Equal(TestQueue.Dequeue(), copyArray[i]); } PopulateTestQueue(); int?[] smallList = new int?[TestQueue.Count / 2]; int?[] largeList = new int?[TestQueue.Count * 2]; Assert.Throws <IndexOutOfRangeException>(() => TestQueue.CopyTo(largeList, -1)); Assert.Throws <ArgumentOutOfRangeException>(() => TestQueue.CopyTo(smallList, 0)); Assert.Throws <ArgumentOutOfRangeException>(() => TestQueue.CopyTo(largeList, largeList.Length - 2)); }
public void RunNextTest(string directory) { CurrentTest = TestQueue.Dequeue(); NetworkStream stream = clientSocket.GetStream(); Console.WriteLine("Running " + CurrentTest.TestName + " ..."); SocketUtil.SendMessage(stream, "start;" + CurrentTest.TestName); SQLResponse response = RunQuerySync(CurrentTest.Query); if (response == null) { Console.WriteLine("Test " + CurrentTest.TestName + " failed :("); SocketUtil.SendMessage(stream, "reset;failed"); } else { Console.WriteLine("Test " + CurrentTest.TestName + " Passed! Execution Time: " + response.ExecutionTime + " ms"); SocketUtil.SendMessage(stream, "reset"); string jsonData = GetOrderedResult(stream); HandleResult(directory, jsonData, response); } }