Skip to content

Commit

Permalink
assert + doc
Browse files Browse the repository at this point in the history
  • Loading branch information
tlrx committed Oct 19, 2021
1 parent 66b1e07 commit 174954f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ protected void closeInternal() {
private volatile FileChannelReference channelRef;

/**
* Indicates if the file has already been created.
* This is useful to pass the right options when opening the file.
* Indicates if the file should be created when it is open for the first time.
* This is required to pass the right options for sparse file support.
*/
private volatile boolean created;

Expand All @@ -145,6 +145,7 @@ private CacheFile(CacheKey cacheKey, SparseFileTracker tracker, Path file, Modif
this.tracker = Objects.requireNonNull(tracker);
this.file = Objects.requireNonNull(file);
this.listener = Objects.requireNonNull(listener);
assert fileExists == Files.exists(file) : file + " exists? " + fileExists;
this.created = fileExists;
assert invariant();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@ public void onCacheFileDelete(CacheFile cacheFile) {}
private static final CacheKey CACHE_KEY = new CacheKey("_snap_uuid", "_snap_index", new ShardId("_name", "_uuid", 0), "_filename");

public void testGetCacheKey() throws Exception {
final Path file = createTempDir().resolve("file.new");
final CacheKey cacheKey = new CacheKey(
UUIDs.randomBase64UUID(random()),
randomAlphaOfLength(5).toLowerCase(Locale.ROOT),
new ShardId(randomAlphaOfLength(5).toLowerCase(Locale.ROOT), UUIDs.randomBase64UUID(random()), randomInt(5)),
randomAlphaOfLength(105).toLowerCase(Locale.ROOT)
);

final CacheFile cacheFile = new CacheFile(cacheKey, randomLongBetween(1, 100), createTempFile(), NOOP);
final CacheFile cacheFile = new CacheFile(cacheKey, randomLongBetween(1, 100), file, NOOP);
assertThat(cacheFile.getCacheKey(), sameInstance(cacheKey));
}

Expand Down

0 comments on commit 174954f

Please sign in to comment.