@@ -67,19 +67,17 @@ public void testReindexRequest() throws IOException {
67
67
new RemoteInfo (randomAlphaOfLength (5 ), randomAlphaOfLength (5 ), port , null ,
68
68
query , username , password , headers , socketTimeout , connectTimeout ));
69
69
}
70
- ReindexRequest tripped = new ReindexRequest ();
71
- roundTrip (reindex , tripped );
70
+ ReindexRequest tripped = new ReindexRequest (toInputByteStream (reindex ));
72
71
assertRequestEquals (reindex , tripped );
73
72
74
73
// Try slices=auto with a version that doesn't support it, which should fail
75
74
reindex .setSlices (AbstractBulkByScrollRequest .AUTO_SLICES );
76
- Exception e = expectThrows (IllegalArgumentException .class , () -> roundTrip (Version .V_6_0_0_alpha1 , reindex , null ));
75
+ Exception e = expectThrows (IllegalArgumentException .class , () -> toInputByteStream (Version .V_6_0_0_alpha1 , reindex ));
77
76
assertEquals ("Slices set as \" auto\" are not supported before version [6.1.0]. Found version [6.0.0-alpha1]" , e .getMessage ());
78
77
79
78
// Try regular slices with a version that doesn't support slices=auto, which should succeed
80
- tripped = new ReindexRequest ();
81
79
reindex .setSlices (between (1 , Integer .MAX_VALUE ));
82
- roundTrip ( Version . V_6_0_0_alpha1 , reindex , tripped );
80
+ tripped = new ReindexRequest ( toInputByteStream ( reindex ) );
83
81
assertRequestEquals (Version .V_6_0_0_alpha1 , reindex , tripped );
84
82
}
85
83
@@ -89,40 +87,36 @@ public void testUpdateByQueryRequest() throws IOException {
89
87
if (randomBoolean ()) {
90
88
update .setPipeline (randomAlphaOfLength (5 ));
91
89
}
92
- UpdateByQueryRequest tripped = new UpdateByQueryRequest ();
93
- roundTrip (update , tripped );
90
+ UpdateByQueryRequest tripped = new UpdateByQueryRequest (toInputByteStream (update ));
94
91
assertRequestEquals (update , tripped );
95
92
assertEquals (update .getPipeline (), tripped .getPipeline ());
96
93
97
94
// Try slices=auto with a version that doesn't support it, which should fail
98
95
update .setSlices (AbstractBulkByScrollRequest .AUTO_SLICES );
99
- Exception e = expectThrows (IllegalArgumentException .class , () -> roundTrip (Version .V_6_0_0_alpha1 , update , null ));
96
+ Exception e = expectThrows (IllegalArgumentException .class , () -> toInputByteStream (Version .V_6_0_0_alpha1 , update ));
100
97
assertEquals ("Slices set as \" auto\" are not supported before version [6.1.0]. Found version [6.0.0-alpha1]" , e .getMessage ());
101
98
102
99
// Try regular slices with a version that doesn't support slices=auto, which should succeed
103
- tripped = new UpdateByQueryRequest ();
104
100
update .setSlices (between (1 , Integer .MAX_VALUE ));
105
- roundTrip ( Version . V_6_0_0_alpha1 , update , tripped );
101
+ tripped = new UpdateByQueryRequest ( toInputByteStream ( update ) );
106
102
assertRequestEquals (update , tripped );
107
103
assertEquals (update .getPipeline (), tripped .getPipeline ());
108
104
}
109
105
110
106
public void testDeleteByQueryRequest () throws IOException {
111
107
DeleteByQueryRequest delete = new DeleteByQueryRequest (new SearchRequest ());
112
108
randomRequest (delete );
113
- DeleteByQueryRequest tripped = new DeleteByQueryRequest ();
114
- roundTrip (delete , tripped );
109
+ DeleteByQueryRequest tripped = new DeleteByQueryRequest (toInputByteStream (delete ));
115
110
assertRequestEquals (delete , tripped );
116
111
117
112
// Try slices=auto with a version that doesn't support it, which should fail
118
113
delete .setSlices (AbstractBulkByScrollRequest .AUTO_SLICES );
119
- Exception e = expectThrows (IllegalArgumentException .class , () -> roundTrip (Version .V_6_0_0_alpha1 , delete , null ));
114
+ Exception e = expectThrows (IllegalArgumentException .class , () -> toInputByteStream (Version .V_6_0_0_alpha1 , delete ));
120
115
assertEquals ("Slices set as \" auto\" are not supported before version [6.1.0]. Found version [6.0.0-alpha1]" , e .getMessage ());
121
116
122
117
// Try regular slices with a version that doesn't support slices=auto, which should succeed
123
- tripped = new DeleteByQueryRequest ();
124
118
delete .setSlices (between (1 , Integer .MAX_VALUE ));
125
- roundTrip ( Version . V_6_0_0_alpha1 , delete , tripped );
119
+ tripped = new DeleteByQueryRequest ( toInputByteStream ( delete ) );
126
120
assertRequestEquals (delete , tripped );
127
121
}
128
122
@@ -198,23 +192,24 @@ public void testRethrottleRequest() throws IOException {
198
192
request .setTaskId (new TaskId (randomAlphaOfLength (5 ), randomLong ()));
199
193
}
200
194
RethrottleRequest tripped = new RethrottleRequest ();
201
- roundTrip (request , tripped );
195
+ // We use readFrom here because Rethrottle does not support the Writeable.Reader interface
196
+ tripped .readFrom (toInputByteStream (request ));
202
197
assertEquals (request .getRequestsPerSecond (), tripped .getRequestsPerSecond (), 0.00001 );
203
198
assertArrayEquals (request .getActions (), tripped .getActions ());
204
199
assertEquals (request .getTaskId (), tripped .getTaskId ());
205
200
}
206
201
207
- private void roundTrip (Streamable example , Streamable empty ) throws IOException {
208
- roundTrip (Version .CURRENT , example , empty );
202
+ private StreamInput toInputByteStream (Streamable example ) throws IOException {
203
+ return toInputByteStream (Version .CURRENT , example );
209
204
}
210
205
211
- private void roundTrip (Version version , Streamable example , Streamable empty ) throws IOException {
206
+ private StreamInput toInputByteStream (Version version , Streamable example ) throws IOException {
212
207
BytesStreamOutput out = new BytesStreamOutput ();
213
208
out .setVersion (version );
214
209
example .writeTo (out );
215
210
StreamInput in = out .bytes ().streamInput ();
216
211
in .setVersion (version );
217
- empty . readFrom ( in ) ;
212
+ return in ;
218
213
}
219
214
220
215
private Script randomScript () {
0 commit comments