@@ -67,19 +67,17 @@ public void testReindexRequest() throws IOException {
6767 new RemoteInfo (randomAlphaOfLength (5 ), randomAlphaOfLength (5 ), port , null ,
6868 query , username , password , headers , socketTimeout , connectTimeout ));
6969 }
70- ReindexRequest tripped = new ReindexRequest ();
71- roundTrip (reindex , tripped );
70+ ReindexRequest tripped = new ReindexRequest (toInputByteStream (reindex ));
7271 assertRequestEquals (reindex , tripped );
7372
7473 // Try slices=auto with a version that doesn't support it, which should fail
7574 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 ));
7776 assertEquals ("Slices set as \" auto\" are not supported before version [6.1.0]. Found version [6.0.0-alpha1]" , e .getMessage ());
7877
7978 // Try regular slices with a version that doesn't support slices=auto, which should succeed
80- tripped = new ReindexRequest ();
8179 reindex .setSlices (between (1 , Integer .MAX_VALUE ));
82- roundTrip ( Version . V_6_0_0_alpha1 , reindex , tripped );
80+ tripped = new ReindexRequest ( toInputByteStream ( reindex ) );
8381 assertRequestEquals (Version .V_6_0_0_alpha1 , reindex , tripped );
8482 }
8583
@@ -89,40 +87,36 @@ public void testUpdateByQueryRequest() throws IOException {
8987 if (randomBoolean ()) {
9088 update .setPipeline (randomAlphaOfLength (5 ));
9189 }
92- UpdateByQueryRequest tripped = new UpdateByQueryRequest ();
93- roundTrip (update , tripped );
90+ UpdateByQueryRequest tripped = new UpdateByQueryRequest (toInputByteStream (update ));
9491 assertRequestEquals (update , tripped );
9592 assertEquals (update .getPipeline (), tripped .getPipeline ());
9693
9794 // Try slices=auto with a version that doesn't support it, which should fail
9895 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 ));
10097 assertEquals ("Slices set as \" auto\" are not supported before version [6.1.0]. Found version [6.0.0-alpha1]" , e .getMessage ());
10198
10299 // Try regular slices with a version that doesn't support slices=auto, which should succeed
103- tripped = new UpdateByQueryRequest ();
104100 update .setSlices (between (1 , Integer .MAX_VALUE ));
105- roundTrip ( Version . V_6_0_0_alpha1 , update , tripped );
101+ tripped = new UpdateByQueryRequest ( toInputByteStream ( update ) );
106102 assertRequestEquals (update , tripped );
107103 assertEquals (update .getPipeline (), tripped .getPipeline ());
108104 }
109105
110106 public void testDeleteByQueryRequest () throws IOException {
111107 DeleteByQueryRequest delete = new DeleteByQueryRequest (new SearchRequest ());
112108 randomRequest (delete );
113- DeleteByQueryRequest tripped = new DeleteByQueryRequest ();
114- roundTrip (delete , tripped );
109+ DeleteByQueryRequest tripped = new DeleteByQueryRequest (toInputByteStream (delete ));
115110 assertRequestEquals (delete , tripped );
116111
117112 // Try slices=auto with a version that doesn't support it, which should fail
118113 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 ));
120115 assertEquals ("Slices set as \" auto\" are not supported before version [6.1.0]. Found version [6.0.0-alpha1]" , e .getMessage ());
121116
122117 // Try regular slices with a version that doesn't support slices=auto, which should succeed
123- tripped = new DeleteByQueryRequest ();
124118 delete .setSlices (between (1 , Integer .MAX_VALUE ));
125- roundTrip ( Version . V_6_0_0_alpha1 , delete , tripped );
119+ tripped = new DeleteByQueryRequest ( toInputByteStream ( delete ) );
126120 assertRequestEquals (delete , tripped );
127121 }
128122
@@ -198,23 +192,24 @@ public void testRethrottleRequest() throws IOException {
198192 request .setTaskId (new TaskId (randomAlphaOfLength (5 ), randomLong ()));
199193 }
200194 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 ));
202197 assertEquals (request .getRequestsPerSecond (), tripped .getRequestsPerSecond (), 0.00001 );
203198 assertArrayEquals (request .getActions (), tripped .getActions ());
204199 assertEquals (request .getTaskId (), tripped .getTaskId ());
205200 }
206201
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 );
209204 }
210205
211- private void roundTrip (Version version , Streamable example , Streamable empty ) throws IOException {
206+ private StreamInput toInputByteStream (Version version , Streamable example ) throws IOException {
212207 BytesStreamOutput out = new BytesStreamOutput ();
213208 out .setVersion (version );
214209 example .writeTo (out );
215210 StreamInput in = out .bytes ().streamInput ();
216211 in .setVersion (version );
217- empty . readFrom ( in ) ;
212+ return in ;
218213 }
219214
220215 private Script randomScript () {
0 commit comments