TestFileRscLimitpublic 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 | LIMITShorthand for the global file limit. | static final int | SUITEThe suite name used when creating files. | static final int | EXTThe file extension used when creating files. | RecordStoreFile[] | rsfAn array of open RecordStoreFile objects. |
Methods Summary |
---|
java.lang.String | makeName(int i)Makes a filename.
return "TestFileRscLimit" + i;
| public void | runTests()Run all tests.
declare("testFileHandlesRscLimit");
testFileHandlesRscLimit();
| public void | setUp()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 void | tearDown()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);
}
}
| void | testFileHandlesRscLimit()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();
}
|
|