mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 12:49:55 +01:00
40 lines
1.1 KiB
Java
40 lines
1.1 KiB
Java
package net.sf.briar.db;
|
|
|
|
import java.util.concurrent.CountDownLatch;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
import junit.framework.TestCase;
|
|
import net.sf.briar.api.db.DbException;
|
|
import net.sf.briar.db.DatabaseCleaner.Callback;
|
|
|
|
import org.junit.Test;
|
|
|
|
public class DatabaseCleanerImplTest extends TestCase {
|
|
|
|
@Test
|
|
public void testStoppingCleanerWakesItUp() throws Exception {
|
|
final CountDownLatch latch = new CountDownLatch(1);
|
|
Callback callback = new Callback() {
|
|
|
|
public void checkFreeSpaceAndClean() throws DbException {
|
|
throw new IllegalStateException();
|
|
}
|
|
|
|
public boolean shouldCheckFreeSpace() {
|
|
latch.countDown();
|
|
return false;
|
|
}
|
|
};
|
|
DatabaseCleanerImpl cleaner = new DatabaseCleanerImpl();
|
|
long start = System.currentTimeMillis();
|
|
// Start the cleaner and check that shouldCheckFreeSpace() is called
|
|
cleaner.startCleaning(callback, 30L * 1000L);
|
|
assertTrue(latch.await(5, TimeUnit.SECONDS));
|
|
// Stop the cleaner (it should be waiting between sweeps)
|
|
cleaner.stopCleaning();
|
|
long end = System.currentTimeMillis();
|
|
// Check that much less than 30 seconds expired
|
|
assertTrue(end - start < 10L * 1000L);
|
|
}
|
|
}
|