mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 13:19:52 +01:00
Changed the root package from net.sf.briar to org.briarproject.
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
package org.briarproject.db;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import org.briarproject.BriarTestCase;
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.system.SystemTimer;
|
||||
import org.briarproject.api.system.Timer;
|
||||
import org.briarproject.db.DatabaseCleaner.Callback;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
// FIXME: Use a mock timer
|
||||
public class DatabaseCleanerImplTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testCleanerRunsPeriodically() throws Exception {
|
||||
final CountDownLatch latch = new CountDownLatch(5);
|
||||
Callback callback = new Callback() {
|
||||
|
||||
public void checkFreeSpaceAndClean() throws DbException {
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
public boolean shouldCheckFreeSpace() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
Timer timer = new SystemTimer();
|
||||
DatabaseCleanerImpl cleaner = new DatabaseCleanerImpl(timer);
|
||||
// Start the cleaner
|
||||
cleaner.startCleaning(callback, 10);
|
||||
// The database should be cleaned five times (allow 5s for system load)
|
||||
assertTrue(latch.await(5, SECONDS));
|
||||
// Stop the cleaner
|
||||
cleaner.stopCleaning();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoppingCleanerWakesItUp() throws Exception {
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
Callback callback = new Callback() {
|
||||
|
||||
public void checkFreeSpaceAndClean() throws DbException {
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
public boolean shouldCheckFreeSpace() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
Timer timer = new SystemTimer();
|
||||
DatabaseCleanerImpl cleaner = new DatabaseCleanerImpl(timer);
|
||||
long start = System.currentTimeMillis();
|
||||
// Start the cleaner
|
||||
cleaner.startCleaning(callback, 10 * 1000);
|
||||
// The database should be cleaned once at startup
|
||||
assertTrue(latch.await(5, SECONDS));
|
||||
// Stop the cleaner (it should be waiting between sweeps)
|
||||
cleaner.stopCleaning();
|
||||
long end = System.currentTimeMillis();
|
||||
// Check that much less than 10 seconds expired
|
||||
assertTrue(end - start < 10 * 1000);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user