public void Dequeue_ShouldBeThreadSafe_FIFO() { for (var i = 0; i < 10; i++) { var queryQueue = new QueryQueue(); var query1 = new TestQuery(1, QueryFunctionType.SingleQuote); var query2 = new TestQuery(2, QueryFunctionType.IntraDay); var query3 = new TestQuery(3, QueryFunctionType.Weekly); var queryList = new List <TestQuery>() { query1, query2, query3 }; var dequeueList = new ConcurrentBag <TestQuery>(); queryQueue.Enqueue(query1); queryQueue.Enqueue(query2); queryQueue.Enqueue(query3); queryList.AsParallel().ForAll(q => { var dequeued = (TestQuery)queryQueue.Dequeue(1).Single(); dequeueList.Add(dequeued); }); Assert.True(queryQueue.IsEmpty()); Assert.Equal(3, dequeueList.Count); Assert.Contains(query1, dequeueList); Assert.Contains(query2, dequeueList); Assert.Contains(query3, dequeueList); } }
public void IsEmpty_ShouldReturnFalse_WhenQueryAdded() { var queryQueue = new QueryQueue(); var query = new TestQuery(1, QueryFunctionType.SingleQuote); queryQueue.Enqueue(query); Assert.False(queryQueue.IsEmpty()); }
public void Dequeue_ShouldReturnAllItems_WhenDequeueCountExceedsQueueCount() { var queryQueue = new QueryQueue(); var query1 = new TestQuery(1, QueryFunctionType.SingleQuote); var query2 = new TestQuery(2, QueryFunctionType.IntraDay); var query3 = new TestQuery(3, QueryFunctionType.Weekly); queryQueue.Enqueue(query1); queryQueue.Enqueue(query2); queryQueue.Enqueue(query3); var queries = queryQueue.Dequeue(100).ToList(); Assert.Equal(3, queries.Count); Assert.True(queryQueue.IsEmpty()); }
public void ClearAll_ShouldClearEverything() { var queryQueue = new QueryQueue(); var query1 = new TestQuery(1, QueryFunctionType.SingleQuote); var query2 = new TestQuery(2, QueryFunctionType.IntraDay); var query3 = new TestQuery(3, QueryFunctionType.Weekly); queryQueue.Enqueue(query1); queryQueue.Enqueue(query2); queryQueue.Enqueue(query3); queryQueue.ClearAll(); Assert.True(queryQueue.IsEmpty()); // can add query again which means duplication check is gone. Assert.True(queryQueue.Enqueue(query1)); }
public void IsEmpty_ShouldReturnTrue_WhenNoQueriesAdded() { var queryQueue = new QueryQueue(); Assert.True(queryQueue.IsEmpty()); }