public void TestEmptyArrayDeque() { var deque = new ArrayDeque <int>(); Assert.That(deque.Count, Is.EqualTo(0)); Assert.That(deque.Count(), Is.EqualTo(0)); Assert.That(() => deque.First(), Throws.InvalidOperationException.With.Message.EqualTo("Sequence contains no elements")); }
private void ProcessDispatches( ArrayDeque <NamedWindowConsumerLatch> dispatches, ArrayDeque <NamedWindowConsumerLatch> work, IDictionary <EPStatementAgentInstanceHandle, Object> dispatchesPerStmt) { if (dispatches.Count == 1) { var latch = dispatches.First(); try { latch.Await(); var newData = latch.DeltaData.NewData; var oldData = latch.DeltaData.OldData; foreach (var entry in latch.DispatchTo) { var handle = entry.Key; handle.StatementHandle.MetricsHandle.Call( _metricReportingService.PerformanceCollector, () => { ProcessHandle(handle, entry.Value, newData, oldData); }); if ((_isPrioritized) && (handle.IsPreemptive)) { break; } } } finally { latch.Done(); } return; } // Multiple different-result dispatches to same or different statements are needed in two situations: // a) an event comes in, triggers two insert-into statements inserting into the same named window and the window produces 2 results // b) a time batch is grouped in the named window, and a timer fires for both groups at the same time producing more then one result // c) two on-merge/update/delete statements fire for the same arriving event each updating the named window // Most likely all dispatches go to different statements since most statements are not joins of // named windows that produce results at the same time. Therefore sort by statement handle. // We need to process in N-element chains to preserve dispatches that are next to each other for the same thread. while (!dispatches.IsEmpty()) { // the first latch always gets awaited var first = dispatches.RemoveFirst(); first.Await(); work.Add(first); // determine which further latches are in this chain and // add these, skipping await for any latches in the chain dispatches.RemoveWhere( (next, continuation) => { NamedWindowConsumerLatch earlier = next.Earlier; if (earlier == null || work.Contains(earlier)) { work.Add(next); return(true); } else { continuation.Value = false; return(false); } }); ProcessDispatches(work, dispatchesPerStmt); } }