Reputation: 7075
After updating the App Engine SDK to 1.7.0 some of our unit test started to fail.
In SDK 1.6.x I asserted that a blob was deleted like this:
try {
fileService.getBlobFile(blobKey);
Assert.fail("Blob not deleted: " + blobKey);
} catch (FileNotFoundException expected) {
// OK
}
In SDK 1.7.0 getBlobFile() is not throwing FileNotFoundException anymore.
I tried to provoke an exception, but it did not work out (no exception is thrown):
try {
AppEngineFile blobFile = fileService.getBlobFile(blobKey);
boolean readable = blobFile.isReadable();
FileReadChannel channel = fileService.openReadChannel(blobFile, false);
channel.position(1);
try {
channel.close();
} catch (Exception e) {
// Silent
}
Assert.fail("Blob not deleted: " + blobKey);
} catch (Exception expected) {
// OK
}
The blob should be deleted, but it's possible to open a channel for it...
So, any ideas how to check deletion was successful in unit testing?
Upvotes: 1
Views: 187
Reputation: 7054
Try using blobstoreService.fetchData to retrieve the first byte of the file.
It will throw if the file does not exist.
Upvotes: 1