Methods Summary |
---|
protected void | setUp()
super.setUp();
File parentDir = getContext().getFilesDir();
mDatabaseFile = new File(parentDir, "database_test.db");
if (mDatabaseFile.exists()) {
mDatabaseFile.delete();
}
mDatabase = SQLiteDatabase.openOrCreateDatabase(mDatabaseFile.getPath(), null);
assertNotNull(mDatabase);
|
private void | startDatabaseFairnessThread()
Thread thread = new DatabaseFairnessThread();
thread.start();
|
private void | startDatabaseLatencyThread()
Thread thread = new DatabaseLatencyThread();
thread.start();
|
protected void | tearDown()
mDatabase.close();
mDatabaseFile.delete();
super.tearDown();
|
public void | testLockFairness()
startDatabaseFairnessThread();
int previous = 0;
for (int i = 0; i < NUM_ITERATIONS; i++) {
mDatabase.beginTransaction();
int val = mCounter.get();
if (i == 0) {
previous = val - i;
}
assertTrue(previous == (val - i));
try {
Thread.currentThread().sleep(SLEEP_TIME);
} catch (InterruptedException e) {
// ignore
}
mDatabase.endTransaction();
}
|
public void | testLockLatency()
startDatabaseLatencyThread();
int previous = 0;
long sumTime = 0;
long maxTime = 0;
for (int i = 0; i < NUM_ITERATIONS; i++) {
long startTime = System.currentTimeMillis();
mDatabase.beginTransaction();
long endTime = System.currentTimeMillis();
long elapsedTime = endTime - startTime;
if (maxTime < elapsedTime) {
maxTime = elapsedTime;
}
sumTime += elapsedTime;
try {
Thread.currentThread().sleep(SLEEP_TIME);
} catch (InterruptedException e) {
// ignore
}
mDatabase.endTransaction();
}
long averageTime = sumTime/NUM_ITERATIONS;
Log.i("DatabaseLockLatency", "AverageTime: " + averageTime);
Log.i("DatabaseLockLatency", "MaxTime: " + maxTime);
assertTrue( (averageTime - SLEEP_TIME) <= MAX_ALLOWED_LATENCY_TIME);
|