FileDocCategorySizeDatePackage
DatabaseStressTest.javaAPI DocAndroid 1.5 API3163Wed May 06 22:42:02 BST 2009com.android.unit_tests

DatabaseStressTest

public class DatabaseStressTest extends android.test.AndroidTestCase

Fields Summary
private static final String
TAG
private static final int
CURRENT_DATABASE_VERSION
private SQLiteDatabase
mDatabase
private File
mDatabaseFile
Constructors Summary
Methods Summary
protected voidsetUp()

    
    
         
        super.setUp();
        Context c = getContext();
        
        mDatabaseFile = c.getDatabasePath("database_test.db");
        if (mDatabaseFile.exists()) {
            mDatabaseFile.delete();
        }
                
        mDatabase = c.openOrCreateDatabase("database_test.db", 0, null);            
       
        assertNotNull(mDatabase);
        mDatabase.setVersion(CURRENT_DATABASE_VERSION);
        
        mDatabase.execSQL("CREATE TABLE IF NOT EXISTS test (_id INTEGER PRIMARY KEY, data TEXT);");

    
protected voidtearDown()

        mDatabase.close();
        mDatabaseFile.delete();
        super.tearDown();
    
public voidtestOutOfSpace()
use fillup -p 90 before run the test and when disk run out start delete some fillup files and see if db recover

        int i = 0;
        char[] ch = new char[100000];
        String str = new String(ch);
        String[] strArr = new String[1];
        strArr[0] = str;
        for (; i < 10000; ++i) {
            try {
                mDatabase.execSQL("INSERT INTO test (data) VALUES (?)", strArr);
            } catch (Exception e) {
                Log.e(TAG, "exception " + e.getMessage());                
            }
        }        
    
public voidtestSingleThreadInsertDelete()

        
        int i = 0;
        char[] ch = new char[100000];
        String str = new String(ch);
        String[] strArr = new String[1];
        strArr[0] = str;
        for (; i < 10000; ++i) {
            try {
                mDatabase.execSQL("INSERT INTO test (data) VALUES (?)", strArr);
                mDatabase.execSQL("delete from test;");
            } catch (Exception e) {
                Log.e(TAG, "exception " + e.getMessage());                
            }
        }