Make InMemoryRepository pack names globally unique

It was easy to create multiple packs with exactly the same name and
same DfsRepositoryDescription in a test, which can poison the
DfsBlockCache. The javadoc for DfsObjDatabase.newPack() explicitly
says pack names should be unique within an entire DFS, so do this by
making the packId AtomicInteger static.

Arguably, test writers shouldn't be doing things like putting
'new DfsRepositoryDescription("test")' in a setUp() method, but that's
a natural thing to do, and we don't document this restriction
anywhere.

Change-Id: I9477413ab3950d83b7d17e173fbc0a3e064896e3
This commit is contained in:
Dave Borowitz 2012-06-27 13:55:25 -07:00
parent 2d1124b89b
commit dc23a7cc42
1 changed files with 2 additions and 1 deletions

View File

@ -26,6 +26,8 @@
* is garbage collected. Closing the repository has no impact on its memory.
*/
public class InMemoryRepository extends DfsRepository {
private static final AtomicInteger packId = new AtomicInteger();
private final DfsObjDatabase objdb;
private final DfsRefDatabase refdb;
@ -60,7 +62,6 @@ public DfsRefDatabase getRefDatabase() {
}
private class MemObjDatabase extends DfsObjDatabase {
private final AtomicInteger packId = new AtomicInteger();
private List<DfsPackDescription> packs = new ArrayList<DfsPackDescription>();
MemObjDatabase(DfsRepository repo) {