Database refactoring to fix injection problems.

This commit is contained in:
akwizgran
2011-09-23 18:52:56 +01:00
parent 4b0e91f52c
commit 98ab523092
10 changed files with 88 additions and 34 deletions

View File

@@ -25,17 +25,15 @@ public class DatabaseCleanerImplTest extends TestCase {
return false;
}
};
// Configure the cleaner to wait for 30 seconds between sweeps
DatabaseCleanerImpl cleaner =
new DatabaseCleanerImpl(callback, 30 * 1000);
DatabaseCleanerImpl cleaner = new DatabaseCleanerImpl();
long start = System.currentTimeMillis();
// Start the cleaner and check that shouldCheckFreeSpace() is called
cleaner.startCleaning();
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 < 10 * 1000);
assertTrue(end - start < 10L * 1000L);
}
}

View File

@@ -96,7 +96,9 @@ public abstract class DatabaseComponentTest extends TestCase {
allowing(database).commitTransaction(txn);
// open(false)
oneOf(database).open(false);
oneOf(cleaner).startCleaning();
oneOf(cleaner).startCleaning(
with(any(DatabaseCleaner.Callback.class)),
with(any(long.class)));
// getRating(authorId)
oneOf(database).getRating(txn, authorId);
will(returnValue(Rating.UNRATED));