11using System ;
22using System . Linq ;
33using System . Threading ;
4+ using Elasticsearch . Net ;
45using FluentAssertions ;
56using Nest ;
67using Tests . Framework ;
78using Tests . Framework . Integration ;
89using Tests . Framework . MockData ;
910using Xunit ;
1011using static Nest . Infer ;
11- using Elasticsearch . Net ;
1212
1313namespace Tests . Document . Multiple . Reindex
1414{
@@ -26,10 +26,13 @@ public override void Boostrap()
2626 [ Collection ( IntegrationContext . Reindex ) ]
2727 public class ReindexApiTests : SerializationTestBase
2828 {
29- private readonly IObservable < IReindexResponse < ILazyDocument > > _reindexResult ;
29+ private readonly IObservable < IReindexResponse < ILazyDocument > > _reindexManyTypesResult ;
30+ private readonly IObservable < IReindexResponse < Project > > _reindexSingleTypeResult ;
3031 private readonly IElasticClient _client ;
3132
32- private static string NewIndexName { get ; } = $ "project-copy-{ Guid . NewGuid ( ) . ToString ( "N" ) . Substring ( 8 ) } ";
33+ private static string NewManyTypesIndexName { get ; } = $ "project-copy-{ Guid . NewGuid ( ) . ToString ( "N" ) . Substring ( 8 ) } ";
34+
35+ private static string NewSingleTypeIndexName { get ; } = $ "project-copy-{ Guid . NewGuid ( ) . ToString ( "N" ) . Substring ( 8 ) } ";
3336
3437 private static string IndexName { get ; } = "project" ;
3538
@@ -64,27 +67,33 @@ public ReindexApiTests(ReindexCluster cluster, EndpointUsage usage)
6467 bulkResult . IsValid . Should ( ) . BeTrue ( ) ;
6568
6669 this . _client . Refresh ( IndexName ) ;
67- this . _reindexResult = this . _client . Reindex < ILazyDocument > ( IndexName , NewIndexName , r=> r ) ;
70+
71+ this . _reindexManyTypesResult = this . _client . Reindex < ILazyDocument > ( IndexName , NewManyTypesIndexName , r => r . AllTypes ( ) ) ;
72+ this . _reindexSingleTypeResult = this . _client . Reindex < Project > ( IndexName , NewSingleTypeIndexName ) ;
6873 }
6974
7075 [ I ] public void ReturnsExpectedResponse ( )
7176 {
72- var handle = new ManualResetEvent ( false ) ;
73- var observer = new ReindexObserver < ILazyDocument > (
77+ var handles = new [ ]
78+ {
79+ new ManualResetEvent ( false ) ,
80+ new ManualResetEvent ( false )
81+ } ;
82+
83+ var manyTypesObserver = new ReindexObserver < ILazyDocument > (
7484 onError : ( e ) => { throw e ; } ,
7585 completed : ( ) =>
7686 {
77- var refresh = this . _client . Refresh ( NewIndexName ) ;
78-
87+ var refresh = this . _client . Refresh ( NewManyTypesIndexName ) ;
7988 var originalIndexCount = this . _client . Count < CommitActivity > ( c => c . Index ( IndexName ) ) ;
80- var newIndexCount = this . _client . Count < CommitActivity > ( c => c . Index ( NewIndexName ) ) ;
89+ var newIndexCount = this . _client . Count < CommitActivity > ( c => c . Index ( NewManyTypesIndexName ) ) ;
8190
8291 originalIndexCount . Count . Should ( ) . BeGreaterThan ( 0 ) . And . Be ( newIndexCount . Count ) ;
8392
8493 var scroll = "20s" ;
8594
8695 var searchResult = this . _client . Search < CommitActivity > ( s => s
87- . Index ( NewIndexName )
96+ . Index ( NewManyTypesIndexName )
8897 . From ( 0 )
8998 . Size ( 100 )
9099 . Query ( q => q . MatchAll ( ) )
@@ -103,12 +112,31 @@ [I] public void ReturnsExpectedResponse()
103112 hit . Routing . Should ( ) . NotBeNullOrEmpty ( ) ;
104113 }
105114 } while ( searchResult . IsValid && searchResult . Documents . Any ( ) ) ;
106- handle . Set ( ) ;
115+ handles [ 0 ] . Set ( ) ;
107116 }
108117 ) ;
109118
110- this . _reindexResult . Subscribe ( observer ) ;
111- handle . WaitOne ( TimeSpan . FromMinutes ( 3 ) ) ;
119+ this . _reindexManyTypesResult . Subscribe ( manyTypesObserver ) ;
120+
121+ var singleTypeObserver = new ReindexObserver < Project > (
122+ onError : ( e ) => { throw e ; } ,
123+ completed : ( ) =>
124+ {
125+ var refresh = this . _client . Refresh ( NewSingleTypeIndexName ) ;
126+ var originalIndexCount = this . _client . Count < Project > ( c => c . Index ( IndexName ) ) ;
127+
128+ // new index should only contain project document types
129+ var newIndexCount = this . _client . Count < Project > ( c => c . Index ( NewSingleTypeIndexName ) . AllTypes ( ) ) ;
130+
131+ originalIndexCount . Count . Should ( ) . BeGreaterThan ( 0 ) . And . Be ( newIndexCount . Count ) ;
132+
133+ handles [ 1 ] . Set ( ) ;
134+ }
135+ ) ;
136+
137+ this . _reindexSingleTypeResult . Subscribe ( singleTypeObserver ) ;
138+
139+ WaitHandle . WaitAll ( handles , TimeSpan . FromMinutes ( 3 ) ) ;
112140 }
113141 }
114142}
0 commit comments