Skip to content

Commit

Permalink
ISPN-1200 - Nullpointer exception when calling channel.truncate(0); o…
Browse files Browse the repository at this point in the history
…n org.infinispan.loaders.file.FileCacheStore$BufferedFileSync.purge
  • Loading branch information
Sanne authored and Mircea Markus committed Jun 27, 2011
1 parent bc5d272 commit 655cb53
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,15 @@ public void purge(File f) throws IOException {
// cos any cached file channel write won't change the file's exists
// status. So, clear the file rather than delete it.
FileChannel channel = streams.get(f.getPath());
if (channel == null) {
channel = createChannel(f);
String path = f.getPath();
FileChannel existingChannel = streams.putIfAbsent(path, channel);
if (existingChannel != null) {
Util.close(channel);
channel = existingChannel;
}
}
channel.truncate(0);
// Apart from truncating, it's necessary to reset the position!
channel.position(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ public void testLoadAndStoreImmortal() throws CacheLoaderException {
assert cs.load("k").getMaxIdle() == -1;
assert !cs.load("k").isExpired();
assert cs.containsKey("k");

boolean removed = cs.remove("k2");
assert !removed;
}

public void testLoadAndStoreWithLifespan() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,22 @@ public void testBucketRemoval() throws Exception {
checkBucketExists(b);
}

public void testCacheStoreRebootable() throws Exception {
String key = "testCacheStoreRebootable";
InternalCacheEntry se = InternalEntryFactory.create(key, "initialValue");
fcs.store(se);
Bucket b = fcs.loadBucketContainingKey(key);

//stop and restart it:
fcs.stop();
fcs.start();

InternalCacheEntry entry = b.getEntry(key);
entry.setValue("updatedValue");
fcs.updateBucket(b);
"updatedValue".equals(fcs.load(key).getValue());
}

protected void checkBucketExists(Bucket b) {
File file = new File(fcs.root, b.getBucketIdAsString());
assert file.exists();
Expand Down

0 comments on commit 655cb53

Please sign in to comment.