88
99import org .elasticsearch .ElasticsearchStatusException ;
1010import org .elasticsearch .ExceptionsHelper ;
11- import org .elasticsearch .action .ActionListener ;
1211import org .elasticsearch .action .DocWriteResponse ;
1312import org .elasticsearch .action .delete .DeleteResponse ;
1413import org .elasticsearch .action .search .SearchResponse ;
1716import org .elasticsearch .cluster .service .ClusterService ;
1817import org .elasticsearch .common .lucene .Lucene ;
1918import org .elasticsearch .common .util .BigArrays ;
20- import org .elasticsearch .core .SuppressForbidden ;
2119import org .elasticsearch .core .TimeValue ;
2220import org .elasticsearch .rest .RestStatus ;
2321import org .elasticsearch .search .SearchHits ;
3432import org .junit .After ;
3533import org .junit .Before ;
3634
37- import java .lang .reflect .Field ;
38- import java .lang .reflect .Method ;
3935import java .util .Map ;
4036
4137import static org .hamcrest .Matchers .instanceOf ;
@@ -115,23 +111,16 @@ public void testBuildSucceedsIfAnotherThreadHoldsRef() {
115111 * When the in-memory MutableSearchResponse has been released (tryIncRef == false),
116112 * the task falls back to the async-search store and returns the persisted response (200 OK).
117113 */
118- @ SuppressForbidden (reason = "access violation required in order to read private field for this test" )
119114 public void testFallbackToStoreWhenInMemoryResponseReleased () throws Exception {
120115 // Create an AsyncSearchTask
121116 AsyncSearchTask task = createAsyncSearchTask ();
122117 assertNotNull (task );
123118
124- // Get response instance and method from task
125- Field f = AsyncSearchTask .class .getDeclaredField ("searchResponse" );
126- f .setAccessible (true );
127- Method getResponse = AsyncSearchTask .class .getDeclaredMethod ("getResponse" , boolean .class , ActionListener .class );
128- getResponse .setAccessible (true );
129-
130119 // Build a SearchResponse (ssr refCount -> 1) to be stored in the index
131120 SearchResponse storedSearchResponse = createSearchResponse (totalShards , totalShards , skippedShards );
132121
133122 // Take a ref - (msr refCount -> 1, ssr refCount -> 2)
134- MutableSearchResponse msr = ( MutableSearchResponse ) f . get ( task );
123+ MutableSearchResponse msr = task . getSearchResponse ( );
135124 msr .updateShardsAndClusters (totalShards , skippedShards , /*clusters*/ null );
136125 msr .updateFinalResponse (storedSearchResponse , /*ccsMinimizeRoundtrips*/ false );
137126
@@ -168,7 +157,7 @@ public void testFallbackToStoreWhenInMemoryResponseReleased() throws Exception {
168157 msr .decRef ();
169158
170159 PlainActionFuture <AsyncSearchResponse > future = new PlainActionFuture <>();
171- getResponse . invoke ( task , true , future );
160+ task . getResponse ( future );
172161
173162 AsyncSearchResponse resp = future .actionGet ();
174163 assertNotNull ("Expected response loaded from store" , resp );
@@ -183,18 +172,11 @@ public void testFallbackToStoreWhenInMemoryResponseReleased() throws Exception {
183172 * When both the in-memory MutableSearchResponse has been released AND the stored
184173 * document has been deleted or not found, the task returns GONE (410).
185174 */
186- @ SuppressForbidden (reason = "access violation required in order to read private field for this test" )
187175 public void testGoneWhenInMemoryReleasedAndStoreMissing () throws Exception {
188176 AsyncSearchTask task = createAsyncSearchTask ();
189177
190- Field f = AsyncSearchTask .class .getDeclaredField ("searchResponse" );
191- f .setAccessible (true );
192- Method getResponse = AsyncSearchTask .class .getDeclaredMethod ("getResponse" , boolean .class , ActionListener .class );
193- getResponse .setAccessible (true );
194-
195178 SearchResponse searchResponse = createSearchResponse (totalShards , totalShards , skippedShards );
196-
197- MutableSearchResponse msr = (MutableSearchResponse ) f .get (task );
179+ MutableSearchResponse msr = task .getSearchResponse ();
198180 msr .updateShardsAndClusters (totalShards , skippedShards , null );
199181 msr .updateFinalResponse (searchResponse , false );
200182
@@ -223,9 +205,10 @@ public void testGoneWhenInMemoryReleasedAndStoreMissing() throws Exception {
223205 del .actionGet ();
224206
225207 // Now the task must surface GONE
226- PlainActionFuture <AsyncSearchResponse > fut = new PlainActionFuture <>();
227- getResponse .invoke (task , /*restoreHeaders*/ true , fut );
228- Exception ex = expectThrows (Exception .class , fut ::actionGet );
208+ PlainActionFuture <AsyncSearchResponse > future = new PlainActionFuture <>();
209+ task .getResponse (future );
210+
211+ Exception ex = expectThrows (Exception .class , future ::actionGet );
229212 Throwable cause = ExceptionsHelper .unwrapCause (ex );
230213 assertThat (cause , instanceOf (ElasticsearchStatusException .class ));
231214 assertThat (ExceptionsHelper .status (cause ), is (RestStatus .GONE ));
0 commit comments