annotate Implab.Test/Mock/MockPollingComponent.cs @ 213:9ee78a345738 v2

Minor code changes
author cin
date Tue, 11 Apr 2017 01:35:18 +0300
parents 8200ab154c8a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
203
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
1 using System;
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
2 using Implab.Components;
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
3
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
4 namespace Implab.Test.Mock {
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
5 class MockPollingComponent : PollingComponent {
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
6 public MockPollingComponent(TimeSpan interval, Func<Func<ICancellationToken, IPromise>, IPromise> dispatcher, bool initialized) : base(interval, dispatcher, initialized) {
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
7 }
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
8
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
9 public Action MockInit {
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
10 get;
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
11 set;
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
12 }
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
13
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
14 public Action<Exception> MockOnError {
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
15 get;
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
16 set;
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
17 }
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
18
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
19 public Action<Exception> MockOnCancel {
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
20 get;
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
21 set;
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
22 }
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
23
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
24 public Func<IPromise> MockStart {
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
25 get;
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
26 set;
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
27 }
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
28
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
29 public Func<IPromise> MockStop {
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
30 get;
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
31 set;
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
32 }
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
33
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
34 public Func<ICancellationToken, IPromise> MockTick {
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
35 get;
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
36 set;
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
37 }
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
38
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
39 protected override IPromise OnStart() {
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
40 return MockStart != null ? Safe.Run(MockStart).Chain(base.OnStart) : Safe.Run(base.OnStart);
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
41 }
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
42
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
43 protected override IPromise OnStop() {
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
44 return MockStop != null ? Safe.Run(MockStop).Chain(base.OnStop) : Safe.Run(base.OnStop);
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
45 }
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
46
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
47 protected override void OnInitialize() {
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
48 if (MockInit != null)
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
49 MockInit();
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
50 }
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
51
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
52 protected override IPromise OnTick(ICancellationToken cancellationToken) {
205
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
53 return MockTick != null ? Safe.Run(() => MockTick(cancellationToken)) : Promise.Success;
203
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
54 }
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
55
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
56 protected override void OnTickCancel(Exception error) {
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
57 if (MockOnCancel != null)
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
58 MockOnCancel(error);
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
59 }
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
60
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
61 protected override void OnTickError(Exception error) {
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
62 if (MockOnError != null)
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
63 MockOnError(error);
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
64 }
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
65
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
66 public void CallComponentFail(Exception error) {
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
67 Fail(error);
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
68 }
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
69 }
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
70 }
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
71