Search in sources :

Example 6 with BaseJob

use of com.path.android.jobqueue.BaseJob in project android-priority-jobqueue by path.

the class SqliteJobQueueTest method testCustomSerializer.

@Test
public void testCustomSerializer() throws Exception {
    final CountDownLatch calledForSerialize = new CountDownLatch(1);
    final CountDownLatch calledForDeserialize = new CountDownLatch(1);
    SqliteJobQueue.JobSerializer jobSerializer = new SqliteJobQueue.JavaSerializer() {

        @Override
        public byte[] serialize(Object object) throws IOException {
            calledForSerialize.countDown();
            return super.serialize(object);
        }

        @Override
        public <T extends BaseJob> T deserialize(byte[] bytes) throws IOException, ClassNotFoundException {
            calledForDeserialize.countDown();
            return super.deserialize(bytes);
        }
    };
    SqliteJobQueue jobQueue = new SqliteJobQueue(Robolectric.application, System.nanoTime(), "__" + System.nanoTime(), jobSerializer);
    jobQueue.insert(createNewJobHolder(new Params(0)));
    calledForSerialize.await(1, TimeUnit.SECONDS);
    MatcherAssert.assertThat("custom serializer should be called for serialize", (int) calledForSerialize.getCount(), CoreMatchers.equalTo(0));
    MatcherAssert.assertThat("custom serializer should NOT be called for deserialize", (int) calledForDeserialize.getCount(), CoreMatchers.equalTo(1));
    jobQueue.nextJobAndIncRunCount(true, null);
    MatcherAssert.assertThat("custom serializer should be called for deserialize", (int) calledForDeserialize.getCount(), CoreMatchers.equalTo(0));
}
Also used : SqliteJobQueue(com.path.android.jobqueue.persistentQueue.sqlite.SqliteJobQueue) BaseJob(com.path.android.jobqueue.BaseJob) Params(com.path.android.jobqueue.Params) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

BaseJob (com.path.android.jobqueue.BaseJob)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 JobManager (com.path.android.jobqueue.JobManager)4 Params (com.path.android.jobqueue.Params)4 Test (org.junit.Test)4 DummyJob (com.path.android.jobqueue.test.jobs.DummyJob)3 JobHolder (com.path.android.jobqueue.JobHolder)2 Configuration (com.path.android.jobqueue.config.Configuration)2 DependencyInjector (com.path.android.jobqueue.di.DependencyInjector)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 AsyncAddCallback (com.path.android.jobqueue.AsyncAddCallback)1 Job (com.path.android.jobqueue.Job)1 JobQueue (com.path.android.jobqueue.JobQueue)1 CustomLogger (com.path.android.jobqueue.log.CustomLogger)1 SqliteJobQueue (com.path.android.jobqueue.persistentQueue.sqlite.SqliteJobQueue)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1