yigit / android-priority-jobqueue

A Job Queue specifically written for Android to easily schedule jobs (tasks) that run in the background, improving UX and application stability.
3.4k stars 395 forks source link

Provide a way to delete underlying database files #10

Open yigit opened 9 years ago

yigit commented 9 years ago

From @daj on July 24, 2014 22:7

I create a separate instance of the JobManager for each of my automated tests. In the setUp() for each test I set the ID to be a unique String based on System.currentTimeMillis():

mJobManagerName = MyTestUtil.getUniqueID();
Configuration configuration = new Configuration.Builder(context)
            .id(mJobManagerName)
            <snip>
            .build();
mJobManager = new JobManager(context, configuration);

Then in my tearDown() I stop and clear the job manager:

mJobManager.stop();    
mJobManager.clear();

Unfortunately I can see that lots of database files are leftover after running my test suite, e.g.

-rw-rw---- u0_a49   u0_a49      20480 2014-07-24 22:04 db_1406228676565
-rw------- u0_a49   u0_a49      24072 2014-07-24 22:04 db_1406228676565-journal

This isn't causing an issue right now as the files are small, but we need a reliable way to remove them. Perhaps .clear() should tidy them up?

In the short term I will probably workaround this by deleting the files in my test tearDown(), e.g.

File dbFile = getContext().getDatabasePath("db_" + mJobManagerName);
File journalFile = getContext().getDatabasePath("db_" + mJobManagerName + "-journal");

Copied from original issue: path/android-priority-jobqueue#56

yigit commented 9 years ago

We should add a test mode where sqlite databases are created memory only.

coltin commented 9 years ago

Database creation could be injected/provided to the JobManager, and an in memory DB could be provided when testing? But I could see a flag being cleaner, depending on what it looks like to enable in memory only sqlite.

ApoorvKhatreja commented 7 years ago

@yigit Was the test mode ever implemented? I'm trying to write some unit tests for a migration of jobs from v1 of this library to v2, and being able to do this in test mode would be very helpful.