Reduce Thread.sleep to Jvm.pause, delays >= 1s to 500 ms, and remove "throws Exception" from tests

This commit is contained in:
Peter Lawrey
2016-04-12 12:08:14 +01:00
parent ceab61fd85
commit ffff33bed1
16 changed files with 22 additions and 22 deletions
@@ -1501,7 +1501,7 @@ public final class ChronicleMapBuilder<K, V> implements
// truncated between length() and read() calls, then continue to wait
}
try {
Thread.sleep(100);
Jvm.pause(100);
} catch (InterruptedException e) {
if (recover) {
break;
@@ -144,7 +144,7 @@ public class CHMLatencyTestMain {
public void run() {
while (running) {
try {
Thread.sleep(1);
Jvm.pause(1);
} catch (InterruptedException e) {
e.printStackTrace();
break;
@@ -233,7 +233,7 @@ public class CHMTest5 {
long elapsedTime;
while ((elapsedTime = System.currentTimeMillis() - start) < pause) {
try {
Thread.sleep(pause - elapsedTime);
Jvm.pause(pause - elapsedTime);
} catch (InterruptedException e) {
}
}
@@ -115,7 +115,7 @@ public class CHMUseCasesTest {
if (map1.equals(map2))
break;
try {
Thread.sleep(1);
Jvm.pause(1);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
@@ -107,7 +107,7 @@ public class ChronicleMapSanityCheckTest {
}, 0, consumerPeriod, consumerTimeUnit);
Thread.sleep(totalTestTimeMS);
Jvm.pause(totalTestTimeMS);
consumerExecutor.shutdown();
try {
@@ -45,7 +45,7 @@ public class Issue62ChronicleClient {
cityPostalCodesMapBuilder.createPersistedTo(MAP_FILE_B)) {
LOGGER.info("Starting");
Thread.sleep(3000);
Jvm.pause(3000);
for (Entry<String, Long> entry : map.entrySet()) {
LOGGER.info("{} : {}", entry.getKey(), entry.getValue());
@@ -63,7 +63,7 @@ public class Issue62ChronicleServer {
}
LOGGER.info("Map created");
Thread.sleep(15000);
Jvm.pause(15000);
}
@@ -39,7 +39,7 @@ import static org.junit.Assert.assertEquals;
public class Issue63Test {
@Test
public void issue63Test() throws Exception {
public void issue63test() {
Path path = Paths.get(System.getProperty("java.io.tmpdir") + "/test-vectors1.dat");
if (Files.exists(path)) Files.delete(path);
File mapFile = path.toFile();
@@ -148,7 +148,7 @@ public class Issue63Test {
new Issue63Test().testChronicleMap();
}
void testChronicleMap() throws Exception {
void testChronicleMap() {
int num = 1_000_000;
testChronicleMap(System.getProperty("java.io.tmpdir"), num, num);
ThreadLocalRandom random = ThreadLocalRandom.current();
@@ -307,7 +307,7 @@ public class Issue63Test {
}
@Test
public void testKnownItems() throws Exception {
public void testKnownItems() {
ArrayList<CharSequence> averageKnownItems = new ArrayList<>();
for (int i = 0; i < 100; i++) {
@@ -157,7 +157,7 @@ public class LargeEntriesTest {
sb.append(thisThread).append("\n");
try {
while (!Thread.currentThread().isInterrupted()) {
Thread.sleep(50);
Jvm.pause(50);
StackTraceElement[] stackTrace = thisThread.getStackTrace();
for (int i = 0; i < 4 && i < stackTrace.length; i++)
sb.append("\tat ").append(stackTrace[i]).append("\n");
@@ -60,7 +60,7 @@ public class ProcessInstanceLimiterMain implements Runnable {
ProcessInstanceLimiterMain limiter = new ProcessInstanceLimiterMain("test", callback);
limiter.setMaxNumberOfProcessesOfType("x", 2);
limiter.startingProcessOfType("x");
Thread.sleep(60L * 1000L);
Jvm.pause(60L * 1000L);
}
public static void pause(long pause) {
@@ -68,7 +68,7 @@ public class ProcessInstanceLimiterMain implements Runnable {
long elapsedTime;
while ((elapsedTime = System.currentTimeMillis() - start) < pause) {
try {
Thread.sleep(pause - elapsedTime);
Jvm.pause(pause - elapsedTime);
} catch (InterruptedException e) {
}
}
@@ -92,7 +92,7 @@ public class ReplicationCheckingMap<K, V> implements ChronicleMap<K, V> {
if (i > 30) {
try {
Thread.sleep(i);
Jvm.pause(i);
} catch (InterruptedException e) {
e.printStackTrace();
}
@@ -101,7 +101,7 @@ public class PointListSerializationTest {
}
@Test
public void testComplexSerialization() throws Exception {
public void testComplexSerialization() {
try (ChronicleMap<String, A> map = ChronicleMapBuilder
.of(String.class, A.class)
.valueMarshaller(AMarshaller.INSTANCE)
@@ -153,7 +153,7 @@ public class JSR166TestCase {
long ns = millis * 1000 * 1000;
for (; ; ) {
if (millis > 0L)
Thread.sleep(millis);
Jvm.pause(millis);
else // too short to sleep
Thread.yield();
long d = ns - (System.nanoTime() - startTime);
@@ -97,7 +97,7 @@ public class MapCheck {
mainTest(key, absent);
if ((rep & 3) == 3 && rep < numTests - 1) {
shuffle(key);
// Thread.sleep(10);
// Jvm.pause(10);
}
}
@@ -151,7 +151,7 @@ public class ProcessInstanceLimiter implements Runnable {
public static void main(String[] args) throws IOException, InterruptedException {
ProcessInstanceLimiter.limitTo(2);
Thread.sleep(60L * 1000L);
Jvm.pause(60L * 1000L);
}
/**
@@ -224,7 +224,7 @@ public class ProcessInstanceLimiter implements Runnable {
long elapsedTime;
while ((elapsedTime = System.currentTimeMillis() - start) < pause) {
try {
Thread.sleep(pause - elapsedTime);
Jvm.pause(pause - elapsedTime);
} catch (InterruptedException e) {
}
}
@@ -336,7 +336,7 @@ public class ProcessInstanceLimiter implements Runnable {
this.callback.tooManyProcessesOfType(processType);
return;
}
//try {Thread.sleep(60L*1000L);} catch (InterruptedException e) {}
//try {Jvm.pause(60L*1000L);} catch (InterruptedException e) {}
//we've got the lock, now copy the array
try {
for (int i = 0; i < times1.length; i++) {
@@ -59,14 +59,14 @@ public class Builder {
// not map1.equals(map2), the reason is described above
if (map1.equals(map2)) {
numberOfTimesTheSame++;
Thread.sleep(1);
Jvm.pause(1);
if (numberOfTimesTheSame == 10) {
System.out.println("same");
break;
}
}
Thread.sleep(1);
Jvm.pause(1);
if (System.currentTimeMillis() - startTime > timeOutMs)
break;
}