Skip to content

Commit

Permalink
Reduce Thread.sleep to Jvm.pause, delays >= 1s to 500 ms, and remove …
Browse files Browse the repository at this point in the history
…"throws Exception" from tests
  • Loading branch information
peter-lawrey committed Apr 12, 2016
1 parent ceab61f commit ffff33b
Show file tree
Hide file tree
Showing 16 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1501,7 +1501,7 @@ private int waitUntilReady(RandomAccessFile raf, boolean recover) throws IOExcep
// truncated between length() and read() calls, then continue to wait
}
try {
Thread.sleep(100);
Jvm.pause(100);
} catch (InterruptedException e) {
if (recover) {
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ static class Monitor implements Runnable {
public void run() {
while (running) {
try {
Thread.sleep(1);
Jvm.pause(1);
} catch (InterruptedException e) {
e.printStackTrace();
break;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/net/openhft/chronicle/map/CHMTest5.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public static void pause(long pause) {
long elapsedTime;
while ((elapsedTime = System.currentTimeMillis() - start) < pause) {
try {
Thread.sleep(pause - elapsedTime);
Jvm.pause(pause - elapsedTime);
} catch (InterruptedException e) {
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private void waitTillEqual(final int timeOutMs) {
if (map1.equals(map2))
break;
try {
Thread.sleep(1);
Jvm.pause(1);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void testSanity1() throws IOException, InterruptedException

}, 0, consumerPeriod, consumerTimeUnit);

Thread.sleep(totalTestTimeMS);
Jvm.pause(totalTestTimeMS);

consumerExecutor.shutdown();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static void main(String[] args) throws Exception {
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static void main(String[] args) throws Exception {
}

LOGGER.info("Map created");
Thread.sleep(15000);
Jvm.pause(15000);

}

Expand Down
6 changes: 3 additions & 3 deletions src/test/java/net/openhft/chronicle/map/Issue63Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
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();
Expand Down Expand Up @@ -148,7 +148,7 @@ public static void main(String[] args) throws Exception {
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();
Expand Down Expand Up @@ -307,7 +307,7 @@ public void addKnownItems(ChronicleMap<CharSequence, List<CharSequence>> knownIt
}

@Test
public void testKnownItems() throws Exception {
public void testKnownItems() {

ArrayList<CharSequence> averageKnownItems = new ArrayList<>();
for (int i = 0; i < 100; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void run() {
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ public void noDefinitionForProcessesOfType(String processType) {
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) {
long start = System.currentTimeMillis();
long elapsedTime;
while ((elapsedTime = System.currentTimeMillis() - start) < pause) {
try {
Thread.sleep(pause - elapsedTime);
Jvm.pause(pause - elapsedTime);
} catch (InterruptedException e) {
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public <R> R check(Call instance) {

if (i > 30) {
try {
Thread.sleep(i);
Jvm.pause(i);
} catch (InterruptedException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void writeMarshallable(Bytes out) {
}

@Test
public void testComplexSerialization() throws Exception {
public void testComplexSerialization() {
try (ChronicleMap<String, A> map = ChronicleMapBuilder
.of(String.class, A.class)
.valueMarshaller(AMarshaller.INSTANCE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ static void delay(long millis) throws InterruptedException {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ else if (et.startsWith("d"))
mainTest(key, absent);
if ((rep & 3) == 3 && rep < numTests - 1) {
shuffle(key);
// Thread.sleep(10);
// Jvm.pause(10);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public ProcessInstanceLimiter(String sharedMapPath, Callback callback) throws IO

public static void main(String[] args) throws IOException, InterruptedException {
ProcessInstanceLimiter.limitTo(2);
Thread.sleep(60L * 1000L);
Jvm.pause(60L * 1000L);
}

/**
Expand Down Expand Up @@ -224,7 +224,7 @@ public static void pause(long pause) {
long elapsedTime;
while ((elapsedTime = System.currentTimeMillis() - start) < pause) {
try {
Thread.sleep(pause - elapsedTime);
Jvm.pause(pause - elapsedTime);
} catch (InterruptedException e) {
}
}
Expand Down Expand Up @@ -336,7 +336,7 @@ public void startingProcessOfType(String processType) {
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++) {
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/net/openhft/chronicle/set/Builder.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ public static void waitTillEqual(Map map1, Map map2, int timeOutMs) throws Inter
// 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;
}
Expand Down

0 comments on commit ffff33b

Please sign in to comment.