3232
3333package org .opensearch .cluster .coordination ;
3434
35- import java .util .Arrays ;
36- import java .util .Collection ;
37- import java .util .concurrent .atomic .AtomicBoolean ;
3835import org .opensearch .action .admin .cluster .health .ClusterHealthResponse ;
3936import org .opensearch .cluster .ClusterChangedEvent ;
4037import org .opensearch .cluster .ClusterStateApplier ;
5451import org .opensearch .test .store .MockFSIndexStore ;
5552import org .opensearch .test .transport .MockTransportService ;
5653import org .opensearch .test .transport .StubbableTransport ;
57- import org .opensearch .transport .*;
54+ import org .opensearch .transport .Transport ;
55+ import org .opensearch .transport .TransportChannel ;
56+ import org .opensearch .transport .TransportConnectionListener ;
57+ import org .opensearch .transport .TransportRequest ;
58+ import org .opensearch .transport .TransportRequestHandler ;
59+ import org .opensearch .transport .TransportService ;
60+
61+ import java .util .Arrays ;
62+ import java .util .Collection ;
63+ import java .util .concurrent .atomic .AtomicBoolean ;
5864
59- import static org .hamcrest .Matchers .is ;
6065import static org .opensearch .cluster .coordination .FollowersChecker .FOLLOWER_CHECK_ACTION_NAME ;
66+ import static org .hamcrest .Matchers .is ;
6167
6268@ ClusterScope (scope = Scope .TEST , numDataNodes = 0 )
6369public class NodeJoinLeftIT extends OpenSearchIntegTestCase {
@@ -99,7 +105,7 @@ public void testTransientErrorsDuringRecovery1AreRetried() throws Exception {
99105 .put (FollowersChecker .FOLLOWER_CHECK_RETRY_COUNT_SETTING .getKey (), 1 )
100106 .build ();
101107 // start a cluster-manager node
102- final String cm =internalCluster ().startNode (nodeSettings );
108+ final String cm = internalCluster ().startNode (nodeSettings );
103109
104110 System .out .println ("--> spawning node t1" );
105111 final String blueNodeName = internalCluster ().startNode (
@@ -126,8 +132,10 @@ public void testTransientErrorsDuringRecovery1AreRetried() throws Exception {
126132 .get ();
127133 System .out .println ("--> done creating index" );
128134 MockTransportService cmTransportService = (MockTransportService ) internalCluster ().getInstance (TransportService .class , cm );
129- MockTransportService redTransportService =
130- (MockTransportService ) internalCluster ().getInstance (TransportService .class , redNodeName );
135+ MockTransportService redTransportService = (MockTransportService ) internalCluster ().getInstance (
136+ TransportService .class ,
137+ redNodeName
138+ );
131139
132140 ClusterService cmClsService = internalCluster ().getInstance (ClusterService .class , cm );
133141 // simulate a slow applier on the cm
@@ -147,82 +155,79 @@ public void applyClusterState(ClusterChangedEvent event) {
147155
148156 @ Override
149157 public void onConnectionOpened (Transport .Connection connection ) {
150- // try {
151- // Thread.sleep(500);
152- // } catch (InterruptedException e) {
153- // throw new RuntimeException(e);
154- // }
158+ // try {
159+ // Thread.sleep(500);
160+ // } catch (InterruptedException e) {
161+ // throw new RuntimeException(e);
162+ // }
155163
156164 }
157165
158166 @ Override
159167 public void onNodeConnected (DiscoveryNode node , Transport .Connection connection ) {
160- // if (node.getName().equals("node_t2")) {
161- // try {
162- // Thread.sleep(250);
163- // } catch (InterruptedException e) {
164- // throw new RuntimeException(e);
165- // }
166- // }
168+ // if (node.getName().equals("node_t2")) {
169+ // try {
170+ // Thread.sleep(250);
171+ // } catch (InterruptedException e) {
172+ // throw new RuntimeException(e);
173+ // }
174+ // }
167175 }
168176
169- // @Override
170- // public void onNodeDisconnected(DiscoveryNode node, Transport.Connection connection) {
171- // try {
172- // Thread.sleep(5000);
173- // } catch (InterruptedException e) {
174- // throw new RuntimeException(e);
175- // }
176- // }
177+ // @Override
178+ // public void onNodeDisconnected(DiscoveryNode node, Transport.Connection connection) {
179+ // try {
180+ // Thread.sleep(5000);
181+ // } catch (InterruptedException e) {
182+ // throw new RuntimeException(e);
183+ // }
184+ // }
177185 });
178186 AtomicBoolean bb = new AtomicBoolean ();
179187 // simulate followerchecker failure
180188
181- ConnectionDelay handlingBehavior = new ConnectionDelay (
182- FOLLOWER_CHECK_ACTION_NAME ,
183- ()->{
184- if (bb .get ()) {
185- return ;
186- }
187- try {
188- Thread .sleep (10 );
189- } catch (InterruptedException e ) {
190- throw new RuntimeException (e );
191- }
192- throw new NodeHealthCheckFailureException ("non writable exception" );
193- });
189+ ConnectionDelay handlingBehavior = new ConnectionDelay (FOLLOWER_CHECK_ACTION_NAME , () -> {
190+ if (bb .get ()) {
191+ return ;
192+ }
193+ try {
194+ Thread .sleep (10 );
195+ } catch (InterruptedException e ) {
196+ throw new RuntimeException (e );
197+ }
198+ throw new NodeHealthCheckFailureException ("non writable exception" );
199+ });
194200 redTransportService .addRequestHandlingBehavior (FOLLOWER_CHECK_ACTION_NAME , handlingBehavior );
195201
196-
197- // for (int i=0 ;i < 1; i++) {
198- // //cmTransportService.disconnectFromNode(redTransportService.getLocalDiscoNode());
199- // System.out.println("--> follower check, iteration: " + i);
200- // bb.set(true); // pass followerchecker
201- // System.out.println("--> setting bb to true, sleeping for 1500ms, iteration: " + i);
202- // Thread.sleep(1500);
203- // bb.set(false); // fail followerchecker
204- // System.out.println("--> setting bb to false, iteration: " + i);
205- // System.out.println("--> checking cluster health 2 nodes, iteration: " + i);
206- // ClusterHealthResponse response1 = client().admin().cluster().prepareHealth().setWaitForNodes("2").get();
207- // assertThat(response1.isTimedOut(), is(false));
208- // System.out.println("--> completed checking cluster health 2 nodes, iteration: " + i);
209- // //internalCluster().stopRandomNode(InternalTestCluster.nameFilter(blueNodeName));
210- // System.out.println("--> checking cluster health 3 nodes, iteration: " + i);
211- // ClusterHealthResponse response2 = client().admin().cluster().prepareHealth().setWaitForNodes("3").get();
212- // assertThat(response2.isTimedOut(), is(false));
213- // System.out.println("--> completed checking cluster health 3 nodes, iteration: " + i);
214- // }
215- // for (int i=0 ;i < 1; i++) {
216- //
217- // bb.set(true); // pass followerchecker
218- //
219- // Thread.sleep(1500);
220- // System.out.println("--> manually disconnecting node, iteration: " + i);
221- // cmTransportService.disconnectFromNode(redTransportService.getLocalDiscoNode());
222- // }
202+ // for (int i=0 ;i < 1; i++) {
203+ // //cmTransportService.disconnectFromNode(redTransportService.getLocalDiscoNode());
204+ // System.out.println("--> follower check, iteration: " + i);
205+ // bb.set(true); // pass followerchecker
206+ // System.out.println("--> setting bb to true, sleeping for 1500ms, iteration: " + i);
207+ // Thread.sleep(1500);
208+ // bb.set(false); // fail followerchecker
209+ // System.out.println("--> setting bb to false, iteration: " + i);
210+ // System.out.println("--> checking cluster health 2 nodes, iteration: " + i);
211+ // ClusterHealthResponse response1 = client().admin().cluster().prepareHealth().setWaitForNodes("2").get();
212+ // assertThat(response1.isTimedOut(), is(false));
213+ // System.out.println("--> completed checking cluster health 2 nodes, iteration: " + i);
214+ // //internalCluster().stopRandomNode(InternalTestCluster.nameFilter(blueNodeName));
215+ // System.out.println("--> checking cluster health 3 nodes, iteration: " + i);
216+ // ClusterHealthResponse response2 = client().admin().cluster().prepareHealth().setWaitForNodes("3").get();
217+ // assertThat(response2.isTimedOut(), is(false));
218+ // System.out.println("--> completed checking cluster health 3 nodes, iteration: " + i);
219+ // }
220+ // for (int i=0 ;i < 1; i++) {
221+ //
222+ // bb.set(true); // pass followerchecker
223+ //
224+ // Thread.sleep(1500);
225+ // System.out.println("--> manually disconnecting node, iteration: " + i);
226+ // cmTransportService.disconnectFromNode(redTransportService.getLocalDiscoNode());
227+ // }
223228
224229 // FAILS WITHOUT CODE CHANGES
225- for (int i = 0 ; i < 10 ; i ++) {
230+ for (int i = 0 ; i < 10 ; i ++) {
226231 bb .set (false ); // fail followerchecker by force to trigger node disconnect
227232 System .out .println ("--> disconnecting from red node, iteration: " + i );
228233 // cmTransportService.disconnectFromNode(redTransportService.getLocalDiscoNode());
@@ -261,15 +266,13 @@ public void onNodeConnected(DiscoveryNode node, Transport.Connection connection)
261266 response = client ().admin ().cluster ().prepareHealth ().setWaitForNodes ("3" ).get ();
262267 assertThat (response .isTimedOut (), is (false ));
263268 }
269+
264270 private class ConnectionDelay implements StubbableTransport .RequestHandlingBehavior <TransportRequest > {
265271
266272 private final String actionName ;
267273 private final Runnable connectionBreaker ;
268274
269- private ConnectionDelay (
270- String actionName ,
271- Runnable connectionBreaker
272- ) {
275+ private ConnectionDelay (String actionName , Runnable connectionBreaker ) {
273276 this .actionName = actionName ;
274277 this .connectionBreaker = connectionBreaker ;
275278 }
@@ -282,7 +285,6 @@ public void messageReceived(
282285 Task task
283286 ) throws Exception {
284287
285-
286288 connectionBreaker .run ();
287289 handler .messageReceived (request , channel , task );
288290 }
0 commit comments