FileDocCategorySizeDatePackage
TestFileRscLimit.javaAPI DocphoneME MR2 API (J2ME)3925Wed May 02 18:00:12 BST 2007com.sun.midp.rms

TestFileRscLimit

public class TestFileRscLimit extends TestCase
Test the global file resource limit by opening files up to and then past the limit. To open files, this test uses the RecordStoreFile class, which is a Java-based interface that's reasonably close to direct file access. RecordStoreFile is a private class inside com.sun.midp.rms, so that's why this test resides in that package.

Fields Summary
static final int
LIMIT
Shorthand for the global file limit.
static final int
SUITE
The suite name used when creating files.
static final int
EXT
The file extension used when creating files.
RecordStoreFile[]
rsf
An array of open RecordStoreFile objects.
Constructors Summary
Methods Summary
java.lang.StringmakeName(int i)
Makes a filename.

param
i a small integer used in creating the filename
return
the filename just created


                           
       
        return "TestFileRscLimit" + i;
    
public voidrunTests()
Run all tests.

        declare("testFileHandlesRscLimit");
        testFileHandlesRscLimit();
    
public voidsetUp()
Creates rsf, an array of LIMIT+1 RecordStoreFile objects and opens files up to LIMIT, leaving one slot unused.

        rsf = new RecordStoreFile[LIMIT + 1];
        for (int i = 0; i < LIMIT; i++) {
            rsf[i] = new RecordStoreFile(SUITE, makeName(i), EXT);
        }
    
public voidtearDown()
Closes and deletes any RecordStoreFile objects found in the rsf array. Ignores any errors that might occur.

        for (int i = 0; i < rsf.length; i++) {
            if (rsf[i] != null) {
                try {
                    rsf[i].close();
                } catch (IOException ioe) { }
                RecordStoreUtil.quietDeleteFile(SUITE, makeName(i), EXT);
            }
        }
    
voidtestFileHandlesRscLimit()
Opens one more file than the global file resource limit and checks to see that the last one throws an exception.

        try {
            boolean exceptionThrown = false;

            setUp();
            try {
                // The following line should hit the resource limit
                // and therefore throw IOException.
                rsf[LIMIT] = new RecordStoreFile(SUITE, makeName(LIMIT), EXT);
            } catch (IOException ioe) {
                exceptionThrown = true;
            }
            assertTrue(exceptionThrown);
        } finally {
            tearDown();
        }