3434
3535public class ShardGetServiceTests extends IndexShardTestCase {
3636
37+ private GetResult getForUpdate (IndexShard indexShard , String id , long ifSeqNo , long ifPrimaryTerm ) throws IOException {
38+ return indexShard .getService ().getForUpdate (id , ifSeqNo , ifPrimaryTerm , new String [] { RoutingFieldMapper .NAME });
39+ }
40+
3741 public void testGetForUpdate () throws IOException {
3842 Settings settings = indexSettings (IndexVersion .current (), 1 , 1 ).build ();
3943 IndexMetadata metadata = IndexMetadata .builder ("test" ).putMapping ("""
@@ -44,7 +48,7 @@ public void testGetForUpdate() throws IOException {
4448 long translogInMemorySegmentCountExpected = 0 ;
4549 Engine .IndexResult test = indexDoc (primary , "test" , "0" , "{\" foo\" : \" bar\" }" );
4650 assertTrue (primary .getEngine ().refreshNeeded ());
47- GetResult testGet = primary . getService (). getForUpdate ("0" , UNASSIGNED_SEQ_NO , UNASSIGNED_PRIMARY_TERM );
51+ GetResult testGet = getForUpdate (primary , "0" , UNASSIGNED_SEQ_NO , UNASSIGNED_PRIMARY_TERM );
4852 assertFalse (testGet .getFields ().containsKey (RoutingFieldMapper .NAME ));
4953 assertEquals (testGet .sourceRef ().utf8ToString (), "{\" foo\" : \" bar\" }" );
5054 assertEquals (translogInMemorySegmentCountExpected , translogInMemorySegmentCount .getAsLong ());
@@ -54,7 +58,7 @@ public void testGetForUpdate() throws IOException {
5458
5559 Engine .IndexResult test1 = indexDoc (primary , "1" , "{\" foo\" : \" baz\" }" , XContentType .JSON , "foobar" );
5660 assertTrue (primary .getEngine ().refreshNeeded ());
57- GetResult testGet1 = primary . getService (). getForUpdate ("1" , UNASSIGNED_SEQ_NO , UNASSIGNED_PRIMARY_TERM );
61+ GetResult testGet1 = getForUpdate (primary , "1" , UNASSIGNED_SEQ_NO , UNASSIGNED_PRIMARY_TERM );
5862 assertEquals (testGet1 .sourceRef ().utf8ToString (), "{\" foo\" : \" baz\" }" );
5963 assertTrue (testGet1 .getFields ().containsKey (RoutingFieldMapper .NAME ));
6064 assertEquals ("foobar" , testGet1 .getFields ().get (RoutingFieldMapper .NAME ).getValue ());
@@ -70,19 +74,19 @@ public void testGetForUpdate() throws IOException {
7074 // now again from the reader
7175 Engine .IndexResult test2 = indexDoc (primary , "1" , "{\" foo\" : \" baz\" }" , XContentType .JSON , "foobar" );
7276 assertTrue (primary .getEngine ().refreshNeeded ());
73- testGet1 = primary . getService (). getForUpdate ("1" , UNASSIGNED_SEQ_NO , UNASSIGNED_PRIMARY_TERM );
77+ testGet1 = getForUpdate (primary , "1" , UNASSIGNED_SEQ_NO , UNASSIGNED_PRIMARY_TERM );
7478 assertEquals (testGet1 .sourceRef ().utf8ToString (), "{\" foo\" : \" baz\" }" );
7579 assertTrue (testGet1 .getFields ().containsKey (RoutingFieldMapper .NAME ));
7680 assertEquals ("foobar" , testGet1 .getFields ().get (RoutingFieldMapper .NAME ).getValue ());
7781 assertEquals (translogInMemorySegmentCountExpected , translogInMemorySegmentCount .getAsLong ());
7882
7983 final long primaryTerm = primary .getOperationPrimaryTerm ();
80- testGet1 = primary . getService (). getForUpdate ("1" , test2 .getSeqNo (), primaryTerm );
84+ testGet1 = getForUpdate (primary , "1" , test2 .getSeqNo (), primaryTerm );
8185 assertEquals (testGet1 .sourceRef ().utf8ToString (), "{\" foo\" : \" baz\" }" );
8286 assertEquals (translogInMemorySegmentCountExpected , translogInMemorySegmentCount .getAsLong ());
8387
84- expectThrows (VersionConflictEngineException .class , () -> primary . getService (). getForUpdate ("1" , test2 .getSeqNo () + 1 , primaryTerm ));
85- expectThrows (VersionConflictEngineException .class , () -> primary . getService (). getForUpdate ("1" , test2 .getSeqNo (), primaryTerm + 1 ));
88+ expectThrows (VersionConflictEngineException .class , () -> getForUpdate (primary , "1" , test2 .getSeqNo () + 1 , primaryTerm ));
89+ expectThrows (VersionConflictEngineException .class , () -> getForUpdate (primary , "1" , test2 .getSeqNo (), primaryTerm + 1 ));
8690 closeShards (primary );
8791 }
8892
@@ -183,7 +187,7 @@ private void runGetFromTranslogWithOptions(
183187 Engine .IndexResult res = indexDoc (primary , "test" , "0" , docToIndex );
184188 assertTrue (res .isCreated ());
185189 assertTrue (primary .getEngine ().refreshNeeded ());
186- GetResult testGet = primary . getService (). getForUpdate ("0" , UNASSIGNED_SEQ_NO , UNASSIGNED_PRIMARY_TERM );
190+ GetResult testGet = getForUpdate (primary , "0" , UNASSIGNED_SEQ_NO , UNASSIGNED_PRIMARY_TERM );
187191 assertFalse (testGet .getFields ().containsKey (RoutingFieldMapper .NAME ));
188192 assertFalse (testGet .getFields ().containsKey ("foo" ));
189193 assertFalse (testGet .getFields ().containsKey ("bar" ));
@@ -194,7 +198,7 @@ private void runGetFromTranslogWithOptions(
194198
195199 indexDoc (primary , "1" , docToIndex , XContentType .JSON , "foobar" );
196200 assertTrue (primary .getEngine ().refreshNeeded ());
197- GetResult testGet1 = primary . getService (). getForUpdate ("1" , UNASSIGNED_SEQ_NO , UNASSIGNED_PRIMARY_TERM );
201+ GetResult testGet1 = getForUpdate (primary , "1" , UNASSIGNED_SEQ_NO , UNASSIGNED_PRIMARY_TERM );
198202 assertEquals (testGet1 .sourceRef () == null ? "" : testGet1 .sourceRef ().utf8ToString (), expectedResult );
199203 assertTrue (testGet1 .getFields ().containsKey (RoutingFieldMapper .NAME ));
200204 assertFalse (testGet .getFields ().containsKey ("foo" ));
@@ -252,7 +256,7 @@ public void testTypelessGetForUpdate() throws IOException {
252256 Engine .IndexResult indexResult = indexDoc (shard , "some_type" , "0" , "{\" foo\" : \" bar\" }" );
253257 assertTrue (indexResult .isCreated ());
254258
255- GetResult getResult = shard . getService (). getForUpdate ("0" , UNASSIGNED_SEQ_NO , UNASSIGNED_PRIMARY_TERM );
259+ GetResult getResult = getForUpdate (shard , "0" , UNASSIGNED_SEQ_NO , UNASSIGNED_PRIMARY_TERM );
256260 assertTrue (getResult .isExists ());
257261
258262 closeShards (shard );
0 commit comments