44using System . Reflection ;
55using System . Runtime . ExceptionServices ;
66using System . Security . Permissions ;
7+ using System . Text . RegularExpressions ;
78using System . Threading ;
89using FluentAssertions ;
910using NUnit . Framework ;
@@ -152,7 +153,11 @@ public void SnapshotRestoreObservable()
152153
153154 var d = ElasticsearchConfiguration . DefaultIndex ;
154155
155- var restoreObservable = this . Client . RestoreObservable ( TimeSpan . FromMilliseconds ( 1 ) , r => r
156+ _restoredIndexName = Regex . Replace ( _indexName , d + "_(.+)" , d + "_restored_$1" ) ;
157+ var restoredIndexExistsResponse = this . Client . IndexExists ( f => f . Index ( _restoredIndexName ) ) ;
158+ restoredIndexExistsResponse . Exists . Should ( ) . BeFalse ( ) ;
159+
160+ var restoreObservable = this . Client . RestoreObservable ( TimeSpan . FromMilliseconds ( 100 ) , r => r
156161 . Repository ( _repositoryName )
157162 . Snapshot ( _snapshotName )
158163 . RenamePattern ( d + "_(.+)" )
@@ -187,10 +192,11 @@ public void SnapshotRestoreObservable()
187192 }
188193 }
189194
190- _restoredIndexName = _indexName . Replace ( d + "_" , d + "_restored_" ) ;
191- var restoredIndexExistsResponse = this . Client . IndexExists ( f => f . Index ( _restoredIndexName ) ) ;
195+ restoredIndexExistsResponse = this . Client . IndexExists ( f => f . Index ( _restoredIndexName ) ) ;
192196 restoredIndexExistsResponse . Exists . Should ( ) . BeTrue ( ) ;
193197
198+ var statusResponse = this . Client . Status ( descriptor => descriptor . Index ( _restoredIndexName ) ) ;
199+
194200 var count = this . Client . Count < ElasticsearchProject > ( descriptor => descriptor . Index ( _restoredIndexName ) ) . Count ;
195201 var indexContent = this . Client . SourceMany < ElasticsearchProject > ( _indexedElements . Select ( x => ( long ) x . Id ) ,
196202 _restoredIndexName ) ;
@@ -199,62 +205,4 @@ public void SnapshotRestoreObservable()
199205 indexContent . ShouldBeEquivalentTo ( _indexedElements ) ;
200206 }
201207 }
202-
203- /// <summary>
204- /// http://www.peterprovost.org/blog/2004/11/03/Using-CrossThreadTestRunner/
205- /// </summary>
206- class CrossThreadTestRunner
207- {
208- private Exception lastException ;
209- private readonly Thread thread ;
210- private readonly ThreadStart start ;
211-
212- private const string RemoteStackTraceFieldName = "_remoteStackTraceString" ;
213- private static readonly FieldInfo RemoteStackTraceField = typeof ( Exception ) . GetField ( RemoteStackTraceFieldName , BindingFlags . Instance | BindingFlags . NonPublic ) ;
214-
215- public CrossThreadTestRunner ( ThreadStart start )
216- {
217- this . start = start ;
218- this . thread = new Thread ( Run ) ;
219- this . thread . SetApartmentState ( ApartmentState . STA ) ;
220- }
221-
222- private void Run ( )
223- {
224- try
225- {
226- start . Invoke ( ) ;
227- }
228- catch ( Exception e )
229- {
230- lastException = e ;
231- }
232- }
233-
234- public void Start ( )
235- {
236- lastException = null ;
237- thread . Start ( ) ;
238- }
239-
240- public void Join ( )
241- {
242- thread . Join ( ) ;
243-
244- if ( lastException != null )
245- {
246- ThrowExceptionPreservingStack ( lastException ) ;
247- }
248- }
249-
250- [ ReflectionPermission ( SecurityAction . Demand ) ]
251- private static void ThrowExceptionPreservingStack ( Exception exception )
252- {
253- if ( RemoteStackTraceField != null )
254- {
255- RemoteStackTraceField . SetValue ( exception , exception . StackTrace + Environment . NewLine ) ;
256- }
257- throw exception ;
258- }
259- }
260208}
0 commit comments