mardi 20 octobre 2015

Android test out of storage space

I wrote an android app that (among other things) writes files to the disk. Now I wonder what's gonna happen when the file system runs out of storage space. I guess that e.g. java.io.FileOutputStream.write() will throw an IOException that I'll have to catch.

The thing is, I don't want to rely on my super ninja powers - I might have forgotten to put a try-catch somewhere or don't handle it correctly. Thus I want to test this scenario.

Sadly I couldn't find any word about a good practice on doing so - not even on SO.

Of course I cold manually stuff the filesystem with something like this, I guess:

size = N
dir = /some/path
data = generateDataForSize(size)
while( write(data, dir) );
while( round(size/=2) > 1 )
    write(generateDataForSize(size), dir)

Where write()will either generate distinct files or append to a single one. There might be some issues with generateDataForSize() and large sizes but let's put that aside for now.

What's itching me is that I'll have to put this somewhere into my app plus I'll have to clean that $%#! up manually. Okay, if I put it inside its own directory I can just discard the whole thing with a single line on the adb shell.

Anyhow, is there any easier way to go for this that I'm missing? Does android provide any mechanics for this like temporarily limiting the storage space available per app? Any integrated soltions for unit tests or android sdk tools? How do other people (you) do this?

TL;DR: How to test writing to fs if fs is full.

Aucun commentaire:

Enregistrer un commentaire