1
1
using System ;
2
2
using System . Linq ;
3
3
using System . Threading ;
4
+ using Elasticsearch . Net ;
4
5
using FluentAssertions ;
5
6
using Nest ;
6
7
using Tests . Framework ;
7
8
using Tests . Framework . Integration ;
8
9
using Tests . Framework . MockData ;
9
10
using Xunit ;
10
11
using static Nest . Infer ;
11
- using Elasticsearch . Net ;
12
12
13
13
namespace Tests . Document . Multiple . Reindex
14
14
{
@@ -26,10 +26,13 @@ public override void Boostrap()
26
26
[ Collection ( IntegrationContext . Reindex ) ]
27
27
public class ReindexApiTests : SerializationTestBase
28
28
{
29
- private readonly IObservable < IReindexResponse < ILazyDocument > > _reindexResult ;
29
+ private readonly IObservable < IReindexResponse < ILazyDocument > > _reindexManyTypesResult ;
30
+ private readonly IObservable < IReindexResponse < Project > > _reindexSingleTypeResult ;
30
31
private readonly IElasticClient _client ;
31
32
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 ) } ";
33
36
34
37
private static string IndexName { get ; } = "project" ;
35
38
@@ -64,27 +67,33 @@ public ReindexApiTests(ReindexCluster cluster, EndpointUsage usage)
64
67
bulkResult . IsValid . Should ( ) . BeTrue ( ) ;
65
68
66
69
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 ) ;
68
73
}
69
74
70
75
[ I ] public void ReturnsExpectedResponse ( )
71
76
{
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 > (
74
84
onError : ( e ) => { throw e ; } ,
75
85
completed : ( ) =>
76
86
{
77
- var refresh = this . _client . Refresh ( NewIndexName ) ;
78
-
87
+ var refresh = this . _client . Refresh ( NewManyTypesIndexName ) ;
79
88
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 ) ) ;
81
90
82
91
originalIndexCount . Count . Should ( ) . BeGreaterThan ( 0 ) . And . Be ( newIndexCount . Count ) ;
83
92
84
93
var scroll = "20s" ;
85
94
86
95
var searchResult = this . _client . Search < CommitActivity > ( s => s
87
- . Index ( NewIndexName )
96
+ . Index ( NewManyTypesIndexName )
88
97
. From ( 0 )
89
98
. Size ( 100 )
90
99
. Query ( q => q . MatchAll ( ) )
@@ -103,12 +112,31 @@ [I] public void ReturnsExpectedResponse()
103
112
hit . Routing . Should ( ) . NotBeNullOrEmpty ( ) ;
104
113
}
105
114
} while ( searchResult . IsValid && searchResult . Documents . Any ( ) ) ;
106
- handle . Set ( ) ;
115
+ handles [ 0 ] . Set ( ) ;
107
116
}
108
117
) ;
109
118
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 ) ) ;
112
140
}
113
141
}
114
142
}
0 commit comments