Adding a unit test

This commit is contained in:
Joshua Kim 2020-07-27 19:17:27 -04:00
parent cadbc0503b
commit 15c45d2029
2 changed files with 21 additions and 8 deletions

View file

@ -81,14 +81,16 @@ public class LeaseCleanupManager {
* {@link LeaseCleanupManager#leaseCleanupIntervalMillis}
*/
public void start() {
log.debug("Starting lease cleanup thread.");
completedLeaseStopwatch.start();
garbageLeaseStopwatch.start();
deletionThreadPool.scheduleAtFixedRate(new LeaseCleanupThread(), INITIAL_DELAY, leaseCleanupIntervalMillis,
TimeUnit.MILLISECONDS);
isRunning = true;
if (!isRunning) {
log.debug("Starting lease cleanup thread.");
completedLeaseStopwatch.reset().start();
garbageLeaseStopwatch.reset().start();
deletionThreadPool.scheduleAtFixedRate(new LeaseCleanupThread(), INITIAL_DELAY, leaseCleanupIntervalMillis,
TimeUnit.MILLISECONDS);
isRunning = true;
} else {
log.debug("Lease cleanup thread already running, no need to start.");
}
}
/**

View file

@ -15,6 +15,7 @@
package software.amazon.kinesis.leases;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -83,6 +84,16 @@ public class LeaseCleanupManagerTest {
when(leaseCoordinator.updateLease(any(Lease.class), any(UUID.class), any(String.class), any(String.class))).thenReturn(true);
}
/**
* Tests subsequent calls to start {@link LeaseCleanupManager}.
*/
@Test
public final void testSubsequentStarts() {
leaseCleanupManager.start();
Assert.assertTrue(leaseCleanupManager.isRunning());
leaseCleanupManager.start();
}
/**
* Tests that when both child shard leases are present, we are able to delete the parent shard for the completed
* shard case.