@@ -190,7 +190,6 @@ public class TestStressNRTReplication extends LuceneTestCase {
190
190
final Set <Integer > crashingNodes = Collections .synchronizedSet (new HashSet <>());
191
191
192
192
@ Nightly
193
- @ SuppressForbidden (reason = "Thread sleep" )
194
193
public void test () throws Exception {
195
194
196
195
Node .globalStartNS = System .nanoTime ();
@@ -215,7 +214,7 @@ public void test() throws Exception {
215
214
numNodes = NUM_NODES ;
216
215
}
217
216
218
- System . out . println ("TEST: using " + numNodes + " nodes" );
217
+ message ("TEST: using " + numNodes + " nodes" );
219
218
220
219
transLogPath = createTempDir ("NRTReplication" ).resolve ("translog" );
221
220
transLog = new SimpleTransLog (transLogPath );
@@ -232,7 +231,7 @@ public void test() throws Exception {
232
231
}
233
232
234
233
Thread [] indexers = new Thread [TestUtil .nextInt (random (), 1 , 3 )];
235
- System . out . println ("TEST: launch " + indexers .length + " indexer threads" );
234
+ message ("TEST: launch " + indexers .length + " indexer threads" );
236
235
for (int i = 0 ; i < indexers .length ; i ++) {
237
236
indexers [i ] = new IndexThread ();
238
237
indexers [i ].setName ("indexer" + i );
@@ -241,7 +240,7 @@ public void test() throws Exception {
241
240
}
242
241
243
242
Thread [] searchers = new Thread [TestUtil .nextInt (random (), 1 , 3 )];
244
- System . out . println ("TEST: launch " + searchers .length + " searcher threads" );
243
+ message ("TEST: launch " + searchers .length + " searcher threads" );
245
244
for (int i = 0 ; i < searchers .length ; i ++) {
246
245
searchers [i ] = new SearchThread ();
247
246
searchers [i ].setName ("searcher" + i );
@@ -261,7 +260,7 @@ public void test() throws Exception {
261
260
runTimeSec = RANDOM_MULTIPLIER * TestUtil .nextInt (random (), 20 , 60 );
262
261
}
263
262
264
- System . out . println ("TEST: will run for " + runTimeSec + " sec" );
263
+ message ("TEST: will run for " + runTimeSec + " sec" );
265
264
266
265
long endTime = System .nanoTime () + runTimeSec * 1000000000L ;
267
266
@@ -270,7 +269,7 @@ public void test() throws Exception {
270
269
while (failed .get () == false && System .nanoTime () < endTime ) {
271
270
272
271
// Wait a bit:
273
- Thread . sleep (TestUtil .nextInt (random (), Math .min (runTimeSec * 4 , 200 ), runTimeSec * 4 ));
272
+ pause (TestUtil .nextInt (random (), Math .min (runTimeSec * 4 , 200 ), runTimeSec * 4 ));
274
273
if (primary != null && random ().nextBoolean ()) {
275
274
NodeProcess curPrimary = primary ;
276
275
if (curPrimary != null ) {
@@ -350,7 +349,7 @@ public void test() throws Exception {
350
349
restarter .join ();
351
350
352
351
// Close replicas before primary so we cancel any in-progress replications:
353
- System . out . println ("TEST: top: now close replicas" );
352
+ message ("TEST: top: now close replicas" );
354
353
List <Closeable > toClose = new ArrayList <>();
355
354
for (NodeProcess node : nodes ) {
356
355
if (node != primary && node != null ) {
@@ -673,7 +672,7 @@ NodeProcess startNode(final int id, Path indexPath, boolean isPrimary, long forc
673
672
return null ;
674
673
} else {
675
674
try {
676
- Thread . sleep (10 );
675
+ pause (10 );
677
676
} catch (InterruptedException ie ) {
678
677
throw new ThreadInterruptedException (ie );
679
678
}
@@ -723,7 +722,7 @@ NodeProcess startNode(final int id, Path indexPath, boolean isPrimary, long forc
723
722
() -> {
724
723
while (System .nanoTime () < deadline && p .isAlive ()) {
725
724
try {
726
- Thread . sleep (250 );
725
+ pause (250 );
727
726
} catch (
728
727
@ SuppressWarnings ("unused" )
729
728
InterruptedException e ) {
@@ -815,6 +814,11 @@ NodeProcess startNode(final int id, Path indexPath, boolean isPrimary, long forc
815
814
subprocessKiller );
816
815
}
817
816
817
+ @ SuppressForbidden (reason = "Thread sleep" )
818
+ private static void pause (int millis ) throws InterruptedException {
819
+ Thread .sleep (millis );
820
+ }
821
+
818
822
private void nodeClosed (int id ) {
819
823
NodeProcess oldNode = nodes [id ];
820
824
if (primary != null && oldNode == primary ) {
@@ -896,7 +900,7 @@ void addTransLogLoc(long version, long loc) {
896
900
}
897
901
898
902
// Periodically wakes up and starts up any down nodes:
899
- @ SuppressForbidden ( reason = "Thread sleep" )
903
+
900
904
private class RestartThread extends Thread {
901
905
@ Override
902
906
public void run () {
@@ -905,7 +909,7 @@ public void run() {
905
909
906
910
try {
907
911
while (stop .get () == false ) {
908
- Thread . sleep (TestUtil .nextInt (random (), 50 , 500 ));
912
+ pause (TestUtil .nextInt (random (), 50 , 500 ));
909
913
// message("top: restarter cycle");
910
914
911
915
// Randomly crash full cluster:
@@ -915,7 +919,7 @@ public void run() {
915
919
if (starting [i ]) {
916
920
message ("N" + i + ": top: wait for startup so we can crash..." );
917
921
while (starting [i ]) {
918
- Thread . sleep (10 );
922
+ pause (10 );
919
923
}
920
924
message ("N" + i + ": top: done wait for startup" );
921
925
}
@@ -994,26 +998,26 @@ public void run() {
994
998
} finally {
995
999
starting [idx ] = false ;
996
1000
startupThreads .remove (Thread .currentThread ());
1001
+ message ("N" + idx + ": top: removed thread" );
997
1002
}
998
1003
}
999
1004
};
1005
+ startupThreads .add (t );
1000
1006
t .setName ("start R" + idx );
1001
1007
t .start ();
1002
- startupThreads .add (t );
1003
1008
}
1004
1009
} else {
1005
1010
message ("node " + idx + " still starting" );
1006
1011
}
1007
1012
}
1008
1013
}
1009
1014
1010
- System .out .println (
1011
- "Restarter: now stop: join " + startupThreads .size () + " startup threads" );
1015
+ message ("Restarter: now stop: join " + startupThreads .size () + " startup threads" );
1012
1016
1013
- while (startupThreads .size () > 0 ) {
1014
- Thread .sleep (10 );
1017
+ while (!startupThreads .isEmpty ()) {
1018
+ pause (1000 );
1019
+ message ("Waiting for startup threads to terminate." );
1015
1020
}
1016
-
1017
1021
} catch (Throwable t ) {
1018
1022
failed .set (true );
1019
1023
stop .set (true );
@@ -1023,7 +1027,6 @@ public void run() {
1023
1027
}
1024
1028
1025
1029
/** Randomly picks a node and runs a search against it */
1026
- @ SuppressForbidden (reason = "Thread sleep" )
1027
1030
private class SearchThread extends Thread {
1028
1031
1029
1032
@ Override
@@ -1074,7 +1077,7 @@ public void run() {
1074
1077
if (node .isOpen == false ) {
1075
1078
throw new IOException ("node closed" );
1076
1079
}
1077
- Thread . sleep (1 );
1080
+ pause (1 );
1078
1081
}
1079
1082
version = c .in .readVLong ();
1080
1083
@@ -1085,7 +1088,7 @@ public void run() {
1085
1088
if (node .isOpen == false ) {
1086
1089
throw new IOException ("node closed" );
1087
1090
}
1088
- Thread . sleep (1 );
1091
+ pause (1 );
1089
1092
}
1090
1093
int hitCount = c .in .readVInt ();
1091
1094
@@ -1161,7 +1164,7 @@ && random().nextInt(10) == 7) {
1161
1164
if (node .isOpen == false ) {
1162
1165
throw new IOException ("node died" );
1163
1166
}
1164
- Thread . sleep (1 );
1167
+ pause (1 );
1165
1168
}
1166
1169
1167
1170
version = c .in .readVLong ();
@@ -1173,7 +1176,7 @@ && random().nextInt(10) == 7) {
1173
1176
if (node .isOpen == false ) {
1174
1177
throw new IOException ("node died" );
1175
1178
}
1176
- Thread . sleep (1 );
1179
+ pause (1 );
1177
1180
}
1178
1181
1179
1182
int hitCount = c .in .readVInt ();
@@ -1208,7 +1211,7 @@ && random().nextInt(10) == 7) {
1208
1211
}
1209
1212
}
1210
1213
1211
- Thread . sleep (10 );
1214
+ pause (10 );
1212
1215
1213
1216
} catch (Throwable t ) {
1214
1217
failed .set (true );
@@ -1223,7 +1226,6 @@ && random().nextInt(10) == 7) {
1223
1226
}
1224
1227
}
1225
1228
1226
- @ SuppressForbidden (reason = "Thread sleep" )
1227
1229
private class IndexThread extends Thread {
1228
1230
1229
1231
@ Override
@@ -1248,7 +1250,7 @@ public void run() {
1248
1250
1249
1251
try {
1250
1252
while (stop .get () == false && curPrimary == null ) {
1251
- Thread . sleep (10 );
1253
+ pause (10 );
1252
1254
curPrimary = primary ;
1253
1255
if (curPrimary != null ) {
1254
1256
c = new Connection (curPrimary .tcpPort );
@@ -1318,14 +1320,14 @@ public void run() {
1318
1320
}
1319
1321
1320
1322
if (random ().nextInt (sleepChance ) == 0 ) {
1321
- Thread . sleep (10 );
1323
+ pause (10 );
1322
1324
}
1323
1325
1324
1326
if (random ().nextInt (100 ) == 17 ) {
1325
1327
int pauseMS = TestUtil .nextInt (random (), 500 , 2000 );
1326
- System . out . println ("Indexer: now pause for " + pauseMS + " ms..." );
1327
- Thread . sleep (pauseMS );
1328
- System . out . println ("Indexer: done pause for a bit..." );
1328
+ message ("Indexer: now pause for " + pauseMS + " ms..." );
1329
+ pause (pauseMS );
1330
+ message ("Indexer: done pause for a bit..." );
1329
1331
}
1330
1332
}
1331
1333
if (curPrimary != null ) {
0 commit comments