2
2
using System . Collections . Generic ;
3
3
using System . Linq ;
4
4
using System . Threading . Tasks ;
5
- using Foundatio . Logging ;
6
5
using Foundatio . Repositories . Elasticsearch . Tests . Repositories . Configuration . Indexes ;
7
6
using Foundatio . Repositories . Elasticsearch . Tests . Repositories . Configuration . Types ;
8
7
using Foundatio . Repositories . Elasticsearch . Tests . Repositories . Models ;
12
11
using Nest ;
13
12
using Xunit ;
14
13
using Xunit . Abstractions ;
15
- using LogLevel = Foundatio . Logging . LogLevel ;
16
14
17
15
namespace Foundatio . Repositories . Elasticsearch . Tests {
18
16
public sealed class PipelineTests : ElasticRepositoryTestBase {
@@ -71,11 +69,35 @@ public async Task JsonPatch() {
71
69
72
70
employee = await _employeeRepository . GetByIdAsync ( employee . Id ) ;
73
71
Assert . Equal ( EmployeeGenerator . Default . Age , employee . Age ) ;
74
- Assert . Equal ( "Patched " , employee . Name ) ;
72
+ Assert . Equal ( "patched " , employee . Name ) ;
75
73
Assert . Equal ( 2 , employee . Version ) ;
76
74
}
77
75
78
76
[ Fact ]
77
+ public async Task JsonPatchAll ( ) {
78
+ var utcNow = SystemClock . UtcNow ;
79
+ var employees = new List < Employee > {
80
+ EmployeeGenerator . Generate ( ObjectId . GenerateNewId ( utcNow . AddDays ( - 1 ) ) . ToString ( ) , createdUtc : utcNow . AddDays ( - 1 ) , companyId : "1" , yearsEmployed : 0 ) ,
81
+ EmployeeGenerator . Generate ( createdUtc : utcNow , companyId : "1" , yearsEmployed : 0 ) ,
82
+ EmployeeGenerator . Generate ( createdUtc : utcNow , companyId : "2" , yearsEmployed : 0 ) ,
83
+ } ;
84
+
85
+ await _employeeRepository . AddAsync ( employees ) ;
86
+
87
+ await _client . RefreshAsync ( Indices . All ) ;
88
+ var patch = new PatchDocument ( new ReplaceOperation { Path = "name" , Value = "Patched" } ) ;
89
+ await _employeeRepository . PatchAsync ( employees . Select ( l => l . Id ) , patch ) ;
90
+
91
+ await _client . RefreshAsync ( Indices . All ) ;
92
+ var results = await _employeeRepository . GetAllByCompanyAsync ( "1" ) ;
93
+ Assert . Equal ( 2 , results . Documents . Count ) ;
94
+ foreach ( var document in results . Documents ) {
95
+ Assert . Equal ( "1" , document . CompanyId ) ;
96
+ Assert . Equal ( "patched" , document . Name ) ;
97
+ }
98
+ }
99
+
100
+ [ Fact ( Skip = "Not yet supported: https://github.com/elastic/elasticsearch/issues/17895" ) ]
79
101
public async Task PartialPatch ( ) {
80
102
var employee = await _employeeRepository . AddAsync ( EmployeeGenerator . Default ) ;
81
103
await _employeeRepository . PatchAsync ( employee . Id , new { name = "Patched" } ) ;
@@ -86,7 +108,30 @@ public async Task PartialPatch() {
86
108
Assert . Equal ( 2 , employee . Version ) ;
87
109
}
88
110
89
- [ Fact ]
111
+ [ Fact ( Skip = "Not yet supported: https://github.com/elastic/elasticsearch/issues/17895" ) ]
112
+ public async Task PartialPatchAll ( ) {
113
+ var utcNow = SystemClock . UtcNow ;
114
+ var employees = new List < Employee > {
115
+ EmployeeGenerator . Generate ( ObjectId . GenerateNewId ( utcNow . AddDays ( - 1 ) ) . ToString ( ) , createdUtc : utcNow . AddDays ( - 1 ) , companyId : "1" , yearsEmployed : 0 ) ,
116
+ EmployeeGenerator . Generate ( createdUtc : utcNow , companyId : "1" , yearsEmployed : 0 ) ,
117
+ EmployeeGenerator . Generate ( createdUtc : utcNow , companyId : "2" , yearsEmployed : 0 ) ,
118
+ } ;
119
+
120
+ await _employeeRepository . AddAsync ( employees ) ;
121
+
122
+ await _client . RefreshAsync ( Indices . All ) ;
123
+ await _employeeRepository . PatchAsync ( employees . Select ( l => l . Id ) , new { name = "Patched" } ) ;
124
+
125
+ await _client . RefreshAsync ( Indices . All ) ;
126
+ var results = await _employeeRepository . GetAllByCompanyAsync ( "1" ) ;
127
+ Assert . Equal ( 2 , results . Documents . Count ) ;
128
+ foreach ( var document in results . Documents ) {
129
+ Assert . Equal ( "1" , document . CompanyId ) ;
130
+ Assert . Equal ( "patched" , document . Name ) ;
131
+ }
132
+ }
133
+
134
+ [ Fact ( Skip = "Not yet supported: https://github.com/elastic/elasticsearch/issues/17895" ) ]
90
135
public async Task ScriptPatch ( ) {
91
136
var employee = await _employeeRepository . AddAsync ( EmployeeGenerator . Default ) ;
92
137
await _employeeRepository . PatchAsync ( employee . Id , "ctx._source.name = 'Patched';" ) ;
@@ -97,77 +142,27 @@ public async Task ScriptPatch() {
97
142
Assert . Equal ( 2 , employee . Version ) ;
98
143
}
99
144
100
- [ Fact ]
145
+ [ Fact ( Skip = "Not yet supported: https://github.com/elastic/elasticsearch/issues/17895" ) ]
101
146
public async Task ScriptPatchAll ( ) {
102
147
var utcNow = SystemClock . UtcNow ;
103
- var logs = new List < Employee > {
104
- EmployeeGenerator . Generate ( ObjectId . GenerateNewId ( utcNow . AddDays ( - 1 ) ) . ToString ( ) , createdUtc : utcNow . AddDays ( - 1 ) , companyId : "1" ) ,
105
- EmployeeGenerator . Generate ( createdUtc : utcNow , companyId : "1" ) ,
106
- EmployeeGenerator . Generate ( createdUtc : utcNow , companyId : "2" ) ,
148
+ var employees = new List < Employee > {
149
+ EmployeeGenerator . Generate ( ObjectId . GenerateNewId ( utcNow . AddDays ( - 1 ) ) . ToString ( ) , createdUtc : utcNow . AddDays ( - 1 ) , companyId : "1" , yearsEmployed : 0 ) ,
150
+ EmployeeGenerator . Generate ( createdUtc : utcNow , companyId : "1" , yearsEmployed : 0 ) ,
151
+ EmployeeGenerator . Generate ( createdUtc : utcNow , companyId : "2" , yearsEmployed : 0 ) ,
107
152
} ;
108
153
109
- await _employeeRepository . AddAsync ( logs , addToCache : true ) ;
110
- Assert . Equal ( 5 , _cache . Count ) ;
111
- Assert . Equal ( 0 , _cache . Hits ) ;
112
- Assert . Equal ( 0 , _cache . Misses ) ;
154
+ await _employeeRepository . AddAsync ( employees ) ;
113
155
114
156
await _client . RefreshAsync ( Indices . All ) ;
115
- Assert . Equal ( 3 , await _employeeRepository . IncrementYearsEmployeed ( logs . Select ( l => l . Id ) . ToArray ( ) ) ) ;
116
- Assert . Equal ( 2 , _cache . Count ) ;
117
- Assert . Equal ( 0 , _cache . Hits ) ;
118
- Assert . Equal ( 0 , _cache . Misses ) ;
157
+ await _employeeRepository . PatchAsync ( employees . Select ( l => l . Id ) , "ctx._source.name = 'Patched';" ) ;
119
158
120
159
await _client . RefreshAsync ( Indices . All ) ;
121
160
var results = await _employeeRepository . GetAllByCompanyAsync ( "1" ) ;
122
161
Assert . Equal ( 2 , results . Documents . Count ) ;
123
162
foreach ( var document in results . Documents ) {
124
163
Assert . Equal ( "1" , document . CompanyId ) ;
125
- Assert . Equal ( 1 , document . YearsEmployed ) ;
126
- }
127
-
128
- await _employeeRepository . SaveAsync ( logs , addToCache : true ) ;
129
- await _client . RefreshAsync ( Indices . All ) ;
130
-
131
- results = await _employeeRepository . GetAllByCompanyAsync ( "1" ) ;
132
- Assert . Equal ( 2 , results . Documents . Count ) ;
133
- foreach ( var document in results . Documents ) {
134
- Assert . Equal ( "1" , document . CompanyId ) ;
135
- Assert . Equal ( 0 , document . YearsEmployed ) ;
164
+ Assert . Equal ( "patched" , document . Name ) ;
136
165
}
137
166
}
138
-
139
- [ Fact ]
140
- public async Task PatchAllBulk ( ) {
141
- Log . SetLogLevel < EmployeeRepository > ( LogLevel . Warning ) ;
142
- const int COUNT = 1000 * 10 ;
143
- int added = 0 ;
144
- do {
145
- await _employeeRepository . AddAsync ( EmployeeGenerator . GenerateEmployees ( 1000 ) ) ;
146
- added += 1000 ;
147
- } while ( added < COUNT ) ;
148
- Log . SetLogLevel < EmployeeRepository > ( LogLevel . Trace ) ;
149
-
150
- await _client . RefreshAsync ( Indices . All ) ;
151
- Assert . Equal ( COUNT , await _employeeRepository . IncrementYearsEmployeed ( new string [ 0 ] ) ) ;
152
- }
153
-
154
- [ Fact ]
155
- public async Task PatchAllBulkConcurrently ( ) {
156
- Log . SetLogLevel < EmployeeRepository > ( LogLevel . Warning ) ;
157
- const int COUNT = 1000 * 10 ;
158
- int added = 0 ;
159
- do {
160
- await _employeeRepository . AddAsync ( EmployeeGenerator . GenerateEmployees ( 1000 ) ) ;
161
- added += 1000 ;
162
- } while ( added < COUNT ) ;
163
- Log . SetLogLevel < EmployeeRepository > ( LogLevel . Trace ) ;
164
-
165
- await _client . RefreshAsync ( Indices . All ) ;
166
- var tasks = Enumerable . Range ( 1 , 6 ) . Select ( async i => {
167
- Assert . Equal ( COUNT , await _employeeRepository . IncrementYearsEmployeed ( new string [ 0 ] , i ) ) ;
168
- } ) ;
169
-
170
- await Task . WhenAll ( tasks ) ;
171
- }
172
167
}
173
168
}
0 commit comments