/
BasicRaftSteps.cs
105 lines (90 loc) · 3.44 KB
/
BasicRaftSteps.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="BasicRaftSteps.cs" company="Cyrille DUPUYDAUBY">
// Copyright 2013 Cyrille DUPUYDAUBY
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
// <summary>
//
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace RAFTiNG.Tests
{
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Threading;
using NFluent;
using TechTalk.SpecFlow;
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented",
Justification = "Reviewed. Suppression is OK here.")][Binding]
public class BasicRaftSteps: IDisposable
{
private Middleware middleware;
private IDisposable logHandle;
private List<Node<string>> nodes;
public BasicRaftSteps()
{
logHandle = Helpers.InitLog4Net();
}
[Given(@"I have deployed (.*) instances")]
public void GivenIHaveDeployedInstances(int p0)
{
var names = new List<string>(p0);
for (var i = 0; i < p0; i++)
{
names.Add(i.ToString(CultureInfo.InvariantCulture));
}
this.middleware = new Middleware();
this.nodes = new List<Node<string>>(p0);
var settings = new NodeSettings();
settings.Nodes = names.ToArray();
settings.TimeoutInMs = 100;
for (var i = 0; i < p0; i++)
{
settings.NodeId = names[i];
var node = new Node<string>(settings);
node.SetMiddleware(this.middleware);
this.nodes.Add(node);
}
}
[When(@"I start instances (.*), (.*) and (.*)")]
public void WhenIStartInstancesAnd(int p0, int p1, int p2)
{
this.nodes[p0 - 1].Initialize();
this.nodes[p1 - 1].Initialize();
this.nodes[p2 - 1].Initialize();
}
[Then(@"there is (.*) leader")]
public void ThenThereIsLeader(int p0)
{
var leaders = this.nodes.Count(node => node.Status == NodeStatus.Leader);
Check.That(leaders).IsEqualTo(p0);
}
[When(@"I wait (.*) seconde")]
public void WhenIWaitSeconde(int p0)
{
Thread.Sleep(p0 * 1000);
}
/// <summary>
/// Exécute les tâches définies par l'application associées à la libération ou à la redéfinition des ressources non managées.
/// </summary>
public void Dispose()
{
logHandle.Dispose();
foreach (var node in nodes)
{
node.Dispose();
}
}
}
}