mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 11:49:04 +01:00
KeyRotatorImpl looks a *lot* like DatabaseCleanerImpl.
This commit is contained in:
53
test/net/sf/briar/db/KeyRotatorImplTest.java
Normal file
53
test/net/sf/briar/db/KeyRotatorImplTest.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package net.sf.briar.db;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import net.sf.briar.BriarTestCase;
|
||||
import net.sf.briar.api.db.DbException;
|
||||
import net.sf.briar.db.KeyRotator.Callback;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class KeyRotatorImplTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testCleanerRunsPeriodically() throws Exception {
|
||||
final CountDownLatch latch = new CountDownLatch(5);
|
||||
Callback callback = new Callback() {
|
||||
|
||||
public void rotateKeys() throws DbException {
|
||||
latch.countDown();
|
||||
}
|
||||
};
|
||||
KeyRotatorImpl cleaner = new KeyRotatorImpl();
|
||||
// Start the rotator
|
||||
cleaner.startRotating(callback, 10L);
|
||||
// The keys should be rotated five times (allow 5 secs for system load)
|
||||
assertTrue(latch.await(5, TimeUnit.SECONDS));
|
||||
// Stop the rotator
|
||||
cleaner.stopRotating();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoppingCleanerWakesItUp() throws Exception {
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
Callback callback = new Callback() {
|
||||
|
||||
public void rotateKeys() throws DbException {
|
||||
latch.countDown();
|
||||
}
|
||||
};
|
||||
KeyRotatorImpl cleaner = new KeyRotatorImpl();
|
||||
long start = System.currentTimeMillis();
|
||||
// Start the rotator
|
||||
cleaner.startRotating(callback, 10L * 1000L);
|
||||
// The keys should be rotated once at startup
|
||||
assertTrue(latch.await(5, TimeUnit.SECONDS));
|
||||
// Stop the rotator (it should be waiting between rotations)
|
||||
cleaner.stopRotating();
|
||||
long end = System.currentTimeMillis();
|
||||
// Check that much less than 10 seconds expired
|
||||
assertTrue(end - start < 10L * 1000L);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user