Wait one second between checks in swap test

This commit is contained in:
Shane Kilkelly 2021-01-22 15:32:34 +00:00
parent b010622442
commit 465a39c564

View file

@ -83,13 +83,17 @@ public class SwapJobImplTest {
}
}
private void waitASecond() {
try { Thread.sleep(1 * 1000); } catch (Exception _e) {}
}
@Test
public void startingTimerAlwaysCausesASwap() {
swapJob.lowWatermarkBytes = 16384;
swapJob.interval = Duration.ofHours(1);
assertEquals(0, swapJob.swaps.get());
swapJob.start();
while (swapJob.swaps.get() <= 0);
do { waitASecond(); } while (swapJob.swaps.get() <= 0);
assertTrue(swapJob.swaps.get() > 0);
}
@ -98,7 +102,7 @@ public class SwapJobImplTest {
swapJob.lowWatermarkBytes = 16384;
assertEquals(0, swapJob.swaps.get());
swapJob.start();
while (swapJob.swaps.get() <= 1);
do { waitASecond(); } while (swapJob.swaps.get() <= 1);
assertTrue(swapJob.swaps.get() > 1);
}
@ -107,7 +111,7 @@ public class SwapJobImplTest {
swapJob.highWatermarkBytes = 65536;
assertEquals(2, dbStore.getNumUnswappedProjects());
swapJob.start();
while (swapJob.swaps.get() < 1);
do { waitASecond(); } while (swapJob.swaps.get() < 1);
assertEquals(2, dbStore.getNumUnswappedProjects());
}
@ -118,14 +122,14 @@ public class SwapJobImplTest {
assertEquals(2, dbStore.getNumUnswappedProjects());
assertEquals("proj2", dbStore.getOldestUnswappedProject());
swapJob.start();
while (swapJob.swaps.get() < 1);
do { waitASecond(); } while (swapJob.swaps.get() < 1);
assertEquals(1, dbStore.getNumUnswappedProjects());
assertEquals("proj1", dbStore.getOldestUnswappedProject());
assertEquals("bzip2", dbStore.getSwapCompression("proj2"));
swapJob.restore("proj2");
assertEquals(null, dbStore.getSwapCompression("proj2"));
int numSwaps = swapJob.swaps.get();
while (swapJob.swaps.get() <= numSwaps);
do { waitASecond(); } while (swapJob.swaps.get() <= numSwaps);
assertEquals(1, dbStore.getNumUnswappedProjects());
assertEquals("proj2", dbStore.getOldestUnswappedProject());
}
@ -147,14 +151,14 @@ public class SwapJobImplTest {
assertEquals(2, dbStore.getNumUnswappedProjects());
assertEquals("proj2", dbStore.getOldestUnswappedProject());
swapJob.start();
while (swapJob.swaps.get() < 1);
do { waitASecond(); } while (swapJob.swaps.get() < 1);
assertEquals(1, dbStore.getNumUnswappedProjects());
assertEquals("proj1", dbStore.getOldestUnswappedProject());
assertEquals("gzip", dbStore.getSwapCompression("proj2"));
swapJob.restore("proj2");
assertEquals(null, dbStore.getSwapCompression("proj2"));
int numSwaps = swapJob.swaps.get();
while (swapJob.swaps.get() <= numSwaps);
do { waitASecond(); } while (swapJob.swaps.get() <= numSwaps);
assertEquals(1, dbStore.getNumUnswappedProjects());
assertEquals("proj2", dbStore.getOldestUnswappedProject());
}