@@ -41,18 +41,20 @@ public DefaultSeeder(IElasticClient client) : this(client, null) { }
41
41
42
42
public void SeedNode ( )
43
43
{
44
- if ( ! TestClient . Configuration . ForceReseed && AlreadySeeded ( ) ) return ;
44
+ var alreadySeeded = false ;
45
+ if ( ! TestClient . Configuration . ForceReseed && ( alreadySeeded = AlreadySeeded ( ) ) ) return ;
45
46
46
- var t = Task . Run ( async ( ) => await SeedNodeAsync ( ) ) ;
47
+ var t = Task . Run ( async ( ) => await SeedNodeAsync ( alreadySeeded ) . ConfigureAwait ( false ) ) ;
47
48
48
49
t . Wait ( TimeSpan . FromSeconds ( 40 ) ) ;
49
50
}
50
51
51
52
public void SeedNodeNoData ( )
52
53
{
53
- if ( ! TestClient . Configuration . ForceReseed && AlreadySeeded ( ) ) return ;
54
+ var alreadySeeded = false ;
55
+ if ( ! TestClient . Configuration . ForceReseed && ( alreadySeeded = AlreadySeeded ( ) ) ) return ;
54
56
55
- var t = Task . Run ( async ( ) => await SeedNodeNoDataAsync ( ) ) ;
57
+ var t = Task . Run ( async ( ) => await SeedNodeNoDataAsync ( alreadySeeded ) . ConfigureAwait ( false ) ) ;
56
58
57
59
t . Wait ( TimeSpan . FromSeconds ( 40 ) ) ;
58
60
}
@@ -62,23 +64,23 @@ public void SeedNodeNoData()
62
64
// If raw_fields exists assume this cluster is already seeded.
63
65
private bool AlreadySeeded ( ) => Client . Indices . TemplateExists ( TestsIndexTemplateName ) . Exists ;
64
66
65
- private async Task SeedNodeAsync ( )
67
+ private async Task SeedNodeAsync ( bool alreadySeeded )
66
68
{
67
69
// Ensure a clean slate by deleting everything regardless of whether they may already exist
68
- await DeleteIndicesAndTemplatesAsync ( ) ;
69
- await ClusterSettingsAsync ( ) ;
70
- await PutPipeline ( ) ;
70
+ await DeleteIndicesAndTemplatesAsync ( alreadySeeded ) . ConfigureAwait ( false ) ;
71
+ await ClusterSettingsAsync ( ) . ConfigureAwait ( false ) ;
72
+ await PutPipeline ( ) . ConfigureAwait ( false ) ;
71
73
// and now recreate everything
72
- await CreateIndicesAndSeedIndexDataAsync ( ) ;
74
+ await CreateIndicesAndSeedIndexDataAsync ( ) . ConfigureAwait ( false ) ;
73
75
}
74
76
75
- private async Task SeedNodeNoDataAsync ( )
77
+ private async Task SeedNodeNoDataAsync ( bool alreadySeeded )
76
78
{
77
79
// Ensure a clean slate by deleting everything regardless of whether they may already exist
78
- await DeleteIndicesAndTemplatesAsync ( ) ;
79
- await ClusterSettingsAsync ( ) ;
80
+ await DeleteIndicesAndTemplatesAsync ( alreadySeeded ) . ConfigureAwait ( false ) ;
81
+ await ClusterSettingsAsync ( ) . ConfigureAwait ( false ) ;
80
82
// and now recreate everything
81
- await CreateIndicesAsync ( ) ;
83
+ await CreateIndicesAsync ( ) . ConfigureAwait ( false ) ;
82
84
}
83
85
84
86
public async Task ClusterSettingsAsync ( )
@@ -99,7 +101,7 @@ public async Task ClusterSettingsAsync()
99
101
var putSettingsResponse = await Client . Cluster . PutSettingsAsync ( new ClusterPutSettingsRequest
100
102
{
101
103
Transient = clusterConfiguration
102
- } ) ;
104
+ } ) . ConfigureAwait ( false ) ;
103
105
104
106
putSettingsResponse . ShouldBeValid ( ) ;
105
107
}
@@ -113,32 +115,35 @@ public async Task PutPipeline()
113
115
. Processors ( pp => pp
114
116
. Set < Project > ( s => s . Field ( p => p . Metadata ) . Value ( new { x = "y" } ) )
115
117
)
116
- ) ;
118
+ ) . ConfigureAwait ( false ) ;
117
119
putProcessors . ShouldBeValid ( ) ;
118
120
}
119
121
120
122
121
- public async Task DeleteIndicesAndTemplatesAsync ( )
123
+ public async Task DeleteIndicesAndTemplatesAsync ( bool alreadySeeded )
122
124
{
123
- var tasks = new Task [ ]
125
+ var tasks = new List < Task >
124
126
{
125
- Client . Indices . DeleteTemplateAsync ( TestsIndexTemplateName ) ,
126
127
Client . Indices . DeleteAsync ( typeof ( Project ) ) ,
127
128
Client . Indices . DeleteAsync ( typeof ( Developer ) ) ,
128
129
Client . Indices . DeleteAsync ( typeof ( ProjectPercolation ) )
129
130
} ;
130
- await Task . WhenAll ( tasks ) ;
131
+
132
+ if ( alreadySeeded )
133
+ tasks . Add ( Client . Indices . DeleteTemplateAsync ( TestsIndexTemplateName ) ) ;
134
+
135
+ await Task . WhenAll ( tasks . ToArray ( ) ) . ConfigureAwait ( false ) ;
131
136
}
132
137
133
138
private async Task CreateIndicesAndSeedIndexDataAsync ( )
134
139
{
135
- await CreateIndicesAsync ( ) ;
136
- await SeedIndexDataAsync ( ) ;
140
+ await CreateIndicesAsync ( ) . ConfigureAwait ( false ) ;
141
+ await SeedIndexDataAsync ( ) . ConfigureAwait ( false ) ;
137
142
}
138
143
139
144
public async Task CreateIndicesAsync ( )
140
145
{
141
- var indexTemplateResponse = await CreateIndexTemplateAsync ( ) ;
146
+ var indexTemplateResponse = await CreateIndexTemplateAsync ( ) . ConfigureAwait ( false ) ;
142
147
indexTemplateResponse . ShouldBeValid ( ) ;
143
148
144
149
var tasks = new [ ]
@@ -152,7 +157,7 @@ await Task.WhenAll(tasks)
152
157
{
153
158
foreach ( var r in t . Result )
154
159
r . ShouldBeValid ( ) ;
155
- } ) ;
160
+ } ) . ConfigureAwait ( false ) ;
156
161
}
157
162
158
163
private async Task SeedIndexDataAsync ( )
@@ -172,8 +177,8 @@ private async Task SeedIndexDataAsync()
172
177
( d , c ) => d . Document ( c ) . Routing ( c . ProjectName )
173
178
)
174
179
) } ;
175
- await Task . WhenAll ( tasks ) ;
176
- await Client . Indices . RefreshAsync ( Indices . Index ( typeof ( Project ) , typeof ( Developer ) , typeof ( ProjectPercolation ) ) ) ;
180
+ await Task . WhenAll ( tasks ) . ConfigureAwait ( false ) ;
181
+ await Client . Indices . RefreshAsync ( Indices . Index ( typeof ( Project ) , typeof ( Developer ) , typeof ( ProjectPercolation ) ) ) . ConfigureAwait ( false ) ;
177
182
}
178
183
179
184
private Task < PutIndexTemplateResponse > CreateIndexTemplateAsync ( ) => Client . Indices . PutTemplateAsync (
0 commit comments