@@ -41,11 +41,19 @@ public sealed class CouchbaseBuilder : ContainerBuilder<CouchbaseBuilder, Couchb
41
41
42
42
public const string DefaultPassword = "password" ;
43
43
44
- private readonly KeyValuePair < string , string > _basicAuthenticationHeader = new KeyValuePair < string , string > ( "Authorization" , "Basic " + Convert . ToBase64String ( Encoding . GetEncoding ( "ISO-8859-1" ) . GetBytes ( string . Join ( ":" , DefaultUsername , DefaultPassword ) ) ) ) ;
44
+ private static readonly KeyValuePair < string , string > BasicAuthenticationHeader = new KeyValuePair < string , string > ( "Authorization" , "Basic " + Convert . ToBase64String ( Encoding . GetEncoding ( "ISO-8859-1" ) . GetBytes ( string . Join ( ":" , DefaultUsername , DefaultPassword ) ) ) ) ;
45
45
46
- private readonly IWaitUntil _waitUntilNodeIsReady = new HttpWaitStrategy ( ) . ForPath ( "/pools" ) . ForPort ( MgmtPort ) ;
46
+ private static readonly IWaitUntil WaitUntilNodeIsReady = new HttpWaitStrategy ( ) . ForPath ( "/pools" ) . ForPort ( MgmtPort ) ;
47
47
48
- private readonly ISet < CouchbaseService > _enabledServices = new HashSet < CouchbaseService > ( ) ;
48
+ private static readonly ISet < CouchbaseService > EnabledServices = new HashSet < CouchbaseService > ( ) ;
49
+
50
+ static CouchbaseBuilder ( )
51
+ {
52
+ EnabledServices . Add ( CouchbaseService . Data ) ;
53
+ EnabledServices . Add ( CouchbaseService . Index ) ;
54
+ EnabledServices . Add ( CouchbaseService . Query ) ;
55
+ EnabledServices . Add ( CouchbaseService . Search ) ;
56
+ }
49
57
50
58
/// <summary>
51
59
/// Initializes a new instance of the <see cref="CouchbaseBuilder" /> class.
@@ -54,11 +62,6 @@ public CouchbaseBuilder()
54
62
: this ( new CouchbaseConfiguration ( ) )
55
63
{
56
64
DockerResourceConfiguration = Init ( ) . DockerResourceConfiguration ;
57
-
58
- _enabledServices . Add ( CouchbaseService . Data ) ;
59
- _enabledServices . Add ( CouchbaseService . Index ) ;
60
- _enabledServices . Add ( CouchbaseService . Query ) ;
61
- _enabledServices . Add ( CouchbaseService . Search ) ;
62
65
}
63
66
64
67
/// <summary>
@@ -81,41 +84,41 @@ public override CouchbaseContainer Build()
81
84
82
85
var waitStrategy = Wait . ForUnixContainer ( ) ;
83
86
84
- if ( _enabledServices . Any ( ) )
87
+ if ( EnabledServices . Any ( ) )
85
88
{
86
89
waitStrategy = waitStrategy . UntilHttpRequestIsSucceeded ( request
87
90
=> request
88
91
. ForPath ( "/pools/default" )
89
92
. ForPort ( MgmtPort )
90
93
. ForResponseMessageMatching ( IsNodeHealthyAsync )
91
- . WithHeader ( _basicAuthenticationHeader . Key , _basicAuthenticationHeader . Value ) ) ;
94
+ . WithHeader ( BasicAuthenticationHeader . Key , BasicAuthenticationHeader . Value ) ) ;
92
95
}
93
96
94
- if ( _enabledServices . Contains ( CouchbaseService . Query ) )
97
+ if ( EnabledServices . Contains ( CouchbaseService . Query ) )
95
98
{
96
99
waitStrategy = waitStrategy . UntilHttpRequestIsSucceeded ( request
97
100
=> request
98
101
. ForPath ( "/admin/ping" )
99
102
. ForPort ( QueryPort )
100
- . WithHeader ( _basicAuthenticationHeader . Key , _basicAuthenticationHeader . Value ) ) ;
103
+ . WithHeader ( BasicAuthenticationHeader . Key , BasicAuthenticationHeader . Value ) ) ;
101
104
}
102
105
103
- if ( _enabledServices . Contains ( CouchbaseService . Analytics ) )
106
+ if ( EnabledServices . Contains ( CouchbaseService . Analytics ) )
104
107
{
105
108
waitStrategy = waitStrategy . UntilHttpRequestIsSucceeded ( request
106
109
=> request
107
110
. ForPath ( "/admin/ping" )
108
111
. ForPort ( AnalyticsPort )
109
- . WithHeader ( _basicAuthenticationHeader . Key , _basicAuthenticationHeader . Value ) ) ;
112
+ . WithHeader ( BasicAuthenticationHeader . Key , BasicAuthenticationHeader . Value ) ) ;
110
113
}
111
114
112
- if ( _enabledServices . Contains ( CouchbaseService . Eventing ) )
115
+ if ( EnabledServices . Contains ( CouchbaseService . Eventing ) )
113
116
{
114
117
waitStrategy = waitStrategy . UntilHttpRequestIsSucceeded ( request
115
118
=> request
116
119
. ForPath ( "/api/v1/config" )
117
120
. ForPort ( EventingPort )
118
- . WithHeader ( _basicAuthenticationHeader . Key , _basicAuthenticationHeader . Value ) ) ;
121
+ . WithHeader ( BasicAuthenticationHeader . Key , BasicAuthenticationHeader . Value ) ) ;
119
122
}
120
123
121
124
var couchbaseBuilder = DockerResourceConfiguration . WaitStrategies . Count ( ) > 1 ? this : WithWaitStrategy ( waitStrategy ) ;
@@ -180,7 +183,7 @@ private CouchbaseBuilder WithBucket(params CouchbaseBucket[] bucket)
180
183
/// <param name="ct">Cancellation token.</param>
181
184
private async Task ConfigureCouchbaseAsync ( IContainer container , CancellationToken ct = default )
182
185
{
183
- await WaitStrategy . WaitUntilAsync ( ( ) => _waitUntilNodeIsReady . UntilAsync ( container ) , TimeSpan . FromSeconds ( 2 ) , TimeSpan . FromMinutes ( 5 ) , ct )
186
+ await WaitStrategy . WaitUntilAsync ( ( ) => WaitUntilNodeIsReady . UntilAsync ( container ) , TimeSpan . FromSeconds ( 2 ) , TimeSpan . FromMinutes ( 5 ) , ct )
184
187
. ConfigureAwait ( false ) ;
185
188
186
189
using ( var httpClient = new HttpClient ( ) )
@@ -197,7 +200,7 @@ await EnsureSuccessStatusCodeAsync(response)
197
200
}
198
201
}
199
202
200
- using ( var request = new SetupNodeServicesRequest ( _enabledServices . ToArray ( ) ) )
203
+ using ( var request = new SetupNodeServicesRequest ( EnabledServices . ToArray ( ) ) )
201
204
{
202
205
using ( var response = await httpClient . SendAsync ( request , ct )
203
206
. ConfigureAwait ( false ) )
@@ -207,7 +210,7 @@ await EnsureSuccessStatusCodeAsync(response)
207
210
}
208
211
}
209
212
210
- using ( var request = new SetupMemoryQuotasRequest ( _enabledServices . ToArray ( ) ) )
213
+ using ( var request = new SetupMemoryQuotasRequest ( EnabledServices . ToArray ( ) ) )
211
214
{
212
215
using ( var response = await httpClient . SendAsync ( request , ct )
213
216
. ConfigureAwait ( false ) )
@@ -217,7 +220,7 @@ await EnsureSuccessStatusCodeAsync(response)
217
220
}
218
221
}
219
222
220
- using ( var request = new ConfigureExternalAddressesRequest ( container , _enabledServices . ToArray ( ) ) )
223
+ using ( var request = new ConfigureExternalAddressesRequest ( container , EnabledServices . ToArray ( ) ) )
221
224
{
222
225
using ( var response = await httpClient . SendAsync ( request , ct )
223
226
. ConfigureAwait ( false ) )
@@ -262,7 +265,7 @@ await EnsureSuccessStatusCodeAsync(response)
262
265
. ForPath ( "/pools/default/buckets/" + bucket . Name )
263
266
. ForPort ( MgmtPort )
264
267
. ForResponseMessageMatching ( AllServicesEnabledAsync )
265
- . WithHeader ( _basicAuthenticationHeader . Key , _basicAuthenticationHeader . Value ) ) )
268
+ . WithHeader ( BasicAuthenticationHeader . Key , BasicAuthenticationHeader . Value ) ) )
266
269
. Build ( )
267
270
. Last ( ) ;
268
271
@@ -326,7 +329,7 @@ private async Task<bool> AllServicesEnabledAsync(HttpResponseMessage response)
326
329
. Select ( service => service . GetString ( ) )
327
330
. Where ( service => service != null ) ;
328
331
329
- return _enabledServices . All ( enabledService => services . Any ( service => service . StartsWith ( enabledService . Identifier ) ) ) ;
332
+ return EnabledServices . All ( enabledService => services . Any ( service => service . StartsWith ( enabledService . Identifier ) ) ) ;
330
333
}
331
334
catch
332
335
{
0 commit comments