@@ -185,16 +185,51 @@ public void testPublishCheckPointFail() throws Exception {
185
185
}
186
186
187
187
public void testPrimaryStopped_ReplicaPromoted () throws Exception {
188
- final String primary = internalCluster ().startDataOnlyNode ();
188
+ Settings mockNodeSetting = Settings .builder ()
189
+ .put (TransportReplicationAction .REPLICATION_RETRY_TIMEOUT .getKey (), TimeValue .timeValueSeconds (0 ))
190
+ .build ();
191
+
192
+ final String primary = internalCluster ().startDataOnlyNode (mockNodeSetting );
189
193
createIndex (INDEX_NAME );
190
194
ensureYellowAndNoInitializingShards (INDEX_NAME );
191
- final String replica = internalCluster ().startDataOnlyNode ();
195
+ final String replica = internalCluster ().startDataOnlyNode (mockNodeSetting );
192
196
ensureGreen (INDEX_NAME );
193
197
198
+ MockTransportService replicaTransportService = ((MockTransportService ) internalCluster ().getInstance (
199
+ TransportService .class ,
200
+ replica
201
+ ));
202
+ AtomicBoolean mockReplicaReceivePublishCheckpointException = new AtomicBoolean (true );
203
+ replicaTransportService .addRequestHandlingBehavior (
204
+ PublishCheckpointAction .ACTION_NAME + TransportReplicationAction .REPLICA_ACTION_SUFFIX ,
205
+ (handler , request , channel , task ) -> {
206
+ if (mockReplicaReceivePublishCheckpointException .get ()) {
207
+ logger .info ("mock remote transport exception" );
208
+ throw new RemoteTransportException ("mock remote transport exception" , new OpenSearchRejectedExecutionException ());
209
+ }
210
+ logger .info ("replica receive publish checkpoint request" );
211
+ handler .messageReceived (request , channel , task );
212
+ }
213
+ );
214
+
194
215
client ().prepareIndex (INDEX_NAME ).setId ("1" ).setSource ("foo" , "bar" ).setRefreshPolicy (WriteRequest .RefreshPolicy .IMMEDIATE ).get ();
195
216
refresh (INDEX_NAME );
217
+ logger .info ("ensure publish checkpoint request can be process" );
218
+ mockReplicaReceivePublishCheckpointException .set (false );
196
219
197
220
waitForSearchableDocs (1 , primary , replica );
221
+ replicaTransportService .clearAllRules ();
222
+
223
+ assertAcked (
224
+ client ().admin ()
225
+ .indices ()
226
+ .prepareUpdateSettings (INDEX_NAME )
227
+ .setSettings (
228
+ Settings .builder ()
229
+ .put (IndexSettings .INDEX_PUBLISH_CHECKPOINT_INTERVAL_SETTING .getKey (), TimeValue .timeValueSeconds (3 ))
230
+ .put (IndexSettings .INDEX_LAG_TIME_BEFORE_RESEND_CHECKPOINT_SETTING .getKey (), TimeValue .timeValueSeconds (3 ))
231
+ )
232
+ );
198
233
199
234
// index another doc but don't refresh, we will ensure this is searchable once replica is promoted.
200
235
client ().prepareIndex (INDEX_NAME ).setId ("2" ).setSource ("bar" , "baz" ).setRefreshPolicy (WriteRequest .RefreshPolicy .IMMEDIATE ).get ();
0 commit comments