本文整理汇总了C#中BufferBlock.Complete方法的典型用法代码示例。如果您正苦于以下问题:C# BufferBlock.Complete方法的具体用法?C# BufferBlock.Complete怎么用?C# BufferBlock.Complete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BufferBlock
的用法示例。
在下文中一共展示了BufferBlock.Complete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestExceptionInLoadTxInput
public void TestExceptionInLoadTxInput()
{
var expectedException = new Exception();
var coreStorage = new Mock<ICoreStorage>();
var chainedHeader = RandomData.RandomChainedHeader();
var tx = RandomData.RandomTransaction(new RandomDataOptions { TxInputCount = 1 });
var txLookupKey = new TxLookupKey(UInt256.Zero, 0);
var loadingTx = new LoadingTx(1, tx, chainedHeader, ImmutableArray.Create(txLookupKey));
var loadingTxes = new BufferBlock<LoadingTx>();
loadingTxes.Post(loadingTx);
loadingTxes.Complete();
// throw expected exception when the input transaction is looked up
Transaction outputTx = null;
coreStorage.Setup(x => x.TryGetTransaction(txLookupKey.BlockHash, txLookupKey.TxIndex, out outputTx)).Throws(expectedException);
var loadedTxes = TxLoader.LoadTxes(coreStorage.Object, loadingTxes);
Exception actualEx;
AssertMethods.AssertAggregateThrows<Exception>(() =>
loadedTxes.ToEnumerable().ToList(), out actualEx);
Assert.AreSame(expectedException, actualEx);
}
示例2: ReceiveCompletedTest
public void ReceiveCompletedTest ()
{
var block = new BufferBlock<int> ();
block.Complete ();
AssertEx.Throws<InvalidOperationException> (
() => block.Receive (TimeSpan.FromMilliseconds (1000)));
}
示例3: Start
public void Start()
{
var sink = new ActionBlock<PageResultMessage>((Action<PageResultMessage>)Sink);
var source = new BufferBlock<GetPageMessage>();
var linkOptions = new DataflowLinkOptions {PropagateCompletion = false};
for (int i = 0; i < 10; i++)
{
var options = new ExecutionDataflowBlockOptions
{
BoundedCapacity = 1
};
var worker = new TransformBlock<GetPageMessage, PageResultMessage>(
(Func<GetPageMessage, PageResultMessage>)Worker, options);
source.LinkTo(worker, linkOptions);
worker.LinkTo(sink, linkOptions);
}
foreach (var url in UrlList.Urls)
{
source.Post(new GetPageMessage{ Url = url });
}
source.Complete();
sink.Completion.Wait();
}
示例4: Run
public void Run()
{
Console.WriteLine("Generating first {0} powers of 2.", MaxItems);
var bufferBlock = new BufferBlock<int>();
Enumerable.Range(1, MaxItems)
.ToList()
.ForEach(i => bufferBlock.Post(i));
Console.WriteLine("Signaling completion to the source block.");
bufferBlock.Complete();
Console.WriteLine("Done.");
Console.WriteLine("Creating and linking the remaing blocks to the network.");
var transformBlock = new TransformBlock<int, double>(i =>
{
Thread.Sleep(200);
return Math.Pow(2, i);
}, new ExecutionDataflowBlockOptions { BoundedCapacity = 1 });
var actionBlock = new ActionBlock<double>(async i =>
{
await Task.Delay(500);
Console.WriteLine(i);
}, new ExecutionDataflowBlockOptions { BoundedCapacity = 10 });
bufferBlock.LinkTo(transformBlock, new DataflowLinkOptions { PropagateCompletion = true });
transformBlock.LinkTo(actionBlock, new DataflowLinkOptions { PropagateCompletion = true });
Console.WriteLine("Waiting for the completion to be propagated through the network...");
actionBlock.Completion.ContinueWith(t =>
{
Console.WriteLine("Finished processing.");
Console.WriteLine(string.Format("Completion status: {0}.", t.Status));
}).Wait();
}
示例5: TestCaptureOrder
public void TestCaptureOrder()
{
// post source ints
var intSource = new BufferBlock<int>();
intSource.Post(1);
intSource.Post(2);
intSource.Post(99);
intSource.Post(98);
intSource.Complete();
// capture source order
var orderedInts = OrderingBlock.CaptureOrder<int, long, long>(
intSource, intValue => (long)intValue);
// post longs to combine, in reverse of original order
var longSource = new BufferBlock<long>();
longSource.Post(99);
longSource.Post(98);
longSource.Post(2);
longSource.Post(1);
longSource.Complete();
// apply source order
var orderedLongs = orderedInts.ApplyOrder(longSource, longValue => longValue);
// verify the original order was preserved
CollectionAssert.AreEqual(new long[] { 1, 2, 99, 98 }, orderedLongs.ToEnumerable().ToList());
}
示例6: TestDataBroadcaster2
public async Task TestDataBroadcaster2()
{
var random = new Random();
var buffer = new BufferBlock<int>();
int sum1 = 0;
int sum2 = 0;
int sum3 = 0;
var action1 = new ActionBlock<int>(i => sum1 = sum1 + i);
var action2 = new ActionBlock<int>(i => sum2 = sum2 + i);
var action3 = new ActionBlock<int>(i => sum3 = sum3 + i);
buffer.ToDataflow().LinkToMultiple(new []{action1, action2, action3}.Select(a => a.ToDataflow()).ToArray());
for (int j = 0; j < 1000; j++)
{
buffer.Post((int)(random.NextDouble() * 10000));
}
buffer.Complete();
await TaskEx.AwaitableWhenAll(action1.Completion, action2.Completion, action3.Completion);
Console.WriteLine("sum1 = {0} , sum2 = {1}", sum1, sum2);
Assert.AreEqual(sum1, sum2);
Assert.AreEqual(sum1, sum3);
}
示例7: CompletedImmediateTest
public void CompletedImmediateTest()
{
var source = new BufferBlock<int>();
source.Complete();
var task = source.OutputAvailableAsync();
Assert.IsTrue(task.Wait(1000));
Assert.IsFalse(task.Result);
}
示例8: TestPost
public void TestPost()
{
foreach (int boundedCapacity in new[] { DataflowBlockOptions.Unbounded, 1 })
{
var bb = new BufferBlock<int>(new DataflowBlockOptions { BoundedCapacity = boundedCapacity });
Assert.True(bb.Post(0));
bb.Complete();
Assert.False(bb.Post(0));
}
}
示例9: WithElementsStillLingering
public void WithElementsStillLingering ()
{
var block = new BufferBlock<int> ();
block.Post (42);
block.Complete ();
Console.WriteLine (block.Completion.IsCompleted);
Console.WriteLine (block.Completion.Status);
block.Receive ();
Console.WriteLine (block.Completion.IsCompleted);
Console.WriteLine (block.Completion.Status);
}
示例10: PropagateCompletionSimpleTest
public void PropagateCompletionSimpleTest ()
{
var source = new BufferBlock<int> ();
var target = new BufferBlock<int> ();
Assert.IsNotNull (source.LinkTo (target,
new DataflowLinkOptions { PropagateCompletion = true }));
Assert.IsFalse (target.Completion.Wait (100));
source.Complete ();
Assert.IsTrue (target.Completion.Wait (100));
}
示例11: EmptyAfterReceive
public void EmptyAfterReceive ()
{
var block = new BufferBlock<int> ();
block.Post (42);
block.Complete ();
Assert.IsFalse (block.Completion.IsCompleted);
Assert.AreEqual (TaskStatus.WaitingForActivation, block.Completion.Status);
block.Receive ();
Assert.IsTrue (block.Completion.IsCompleted);
Assert.AreEqual (TaskStatus.RanToCompletion, block.Completion.Status);
}
示例12: TestReadOneLoadingTx
public void TestReadOneLoadingTx()
{
var coreStorageMock = new Mock<ICoreStorage>();
// create a fake transaction with 4 inputs
var prevTxCount = 4;
var txIndex = 1;
var chainedHeader = RandomData.RandomChainedHeader();
// create previous transactions for 4 inputs
var prevTxes = new Transaction[prevTxCount];
var inputs = new TxInput[prevTxCount];
for (var i = 0; i < prevTxCount; i++)
{
var prevTx = RandomData.RandomTransaction();
var prevBlockTx = (BlockTx)BlockTx.Create(i, prevTx);
prevTxes[i] = prevTx;
inputs[i] = new TxInput(prevTx.Hash, 0, ImmutableArray.Create<byte>(), 0);
// mock retrieval of the previous transaction
coreStorageMock.Setup(coreStorage => coreStorage.TryGetTransaction(UInt256.Zero, i, out prevBlockTx)).Returns(true);
}
// create a loading tx with the 4 inputs referencing block hash 0
var tx = RandomData.RandomTransaction(new RandomDataOptions { TxOutputCount = 1 })
.CreateWith(Inputs: inputs.ToImmutableArray()).Transaction;
var prevOutputTxKeys = ImmutableArray.CreateRange(
Enumerable.Range(0, prevTxCount).Select(x => new TxLookupKey(UInt256.Zero, x)));
var loadingTx = new LoadingTx(txIndex, tx, chainedHeader, prevOutputTxKeys);
// begin queuing transactions to load
var loadingTxes = new BufferBlock<LoadingTx>();
loadingTxes.Post(loadingTx);
loadingTxes.Complete();
// begin transaction loading
var txLoader = TxLoader.LoadTxes(coreStorageMock.Object, loadingTxes);
// verify the loaded transaction
var loadedTxesBuffer = new BufferBlock<LoadedTx>();
txLoader.LinkTo(loadedTxesBuffer, new DataflowLinkOptions { PropagateCompletion = true });
txLoader.Completion.Wait();
IList<LoadedTx> actualLoadedTxes;
Assert.IsTrue(loadedTxesBuffer.TryReceiveAll(out actualLoadedTxes));
var actualLoadedTx = actualLoadedTxes.Single();
Assert.AreEqual(loadingTx.TxIndex, actualLoadedTx.TxIndex);
Assert.AreEqual(loadingTx.Transaction, actualLoadedTx.Transaction);
CollectionAssert.AreEqual(prevTxes.Select(x => x.Hash).ToArray(), actualLoadedTx.InputTxes.Select(x => x.Hash).ToArray());
}
示例13: TestToEnumerable
public void TestToEnumerable()
{
var expectedException = new Exception();
var source = new BufferBlock<int>();
source.Post(1);
source.Post(2);
source.Complete();
var actual = source.ToEnumerable().ToList();
CollectionAssert.AreEqual(new[] { 1, 2 }, actual);
}
示例14: TestEmptyUtxoLookAhead
public void TestEmptyUtxoLookAhead()
{
var blockTxes = new BufferBlock<BlockTx>();
blockTxes.Complete();
var deferredCursor = new Mock<IDeferredChainStateCursor>();
deferredCursor.Setup(x => x.CursorCount).Returns(4);
var lookAhead = UtxoLookAhead.LookAhead(blockTxes, deferredCursor.Object);
Assert.AreEqual(0, lookAhead.ReceiveAllAsync().Result.Count);
Assert.IsTrue(lookAhead.Completion.Wait(2000));
}
示例15: CompletedPostponedTest
public void CompletedPostponedTest()
{
var source = new BufferBlock<int>(new DataflowBlockOptions());
var task = source.OutputAvailableAsync();
Assert.IsFalse(task.Wait(100));
source.Complete();
Assert.IsTrue(task.Wait(1000));
Assert.IsFalse(task.Result);
}