package org.sagebionetworks.bridge.services.backfill;

import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import org.junit.Test;
import org.sagebionetworks.bridge.dao.DistributedLockDao;
import org.sagebionetworks.bridge.models.BackfillRecord;
import org.sagebionetworks.bridge.models.BackfillTask;

public class AsyncBackfillTemplateTest {

    @Test
    public void test() throws Exception {
        AsyncBackfillTemplate backfillTemplate = new TestBackfillService();
        DistributedLockDao lockDao = mock(DistributedLockDao.class);
        when(lockDao.acquireLock(TestBackfillService.class, TestBackfillService.class.getSimpleName()))
                .thenReturn("abc");
        backfillTemplate.setDistributedLockDao(lockDao);
        BackfillCallback callback = mock(BackfillCallback.class);
        backfillTemplate.backfill("test user", "test backfill", callback);
        Thread.sleep(1000L);
        verify(callback, times(1)).start(any(BackfillTask.class));
        verify(callback, times(1)).newRecords(any(BackfillRecord.class));
        verify(callback, times(1)).newRecords(any(BackfillRecord.class), any(BackfillRecord.class));
        verify(callback, times(1)).done();
    }
}

@@ -268,17 +268,134 @@
 rg.j
-unit.Test
+oda.time.DateTime;%0Aimport org.joda.time.DateTimeZone;%0Aimport org.junit.Test;%0Aimport org.sagebionetworks.bridge.dao.BackfillDao
 ;%0Aim
@@ -507,16 +507,73 @@
 Record;%0A
+import org.sagebionetworks.bridge.models.BackfillStatus;%0A
 import o
@@ -714,16 +714,17 @@
 ption %7B%0A
+%0A
         
@@ -1000,16 +1000,16 @@
 %22abc%22);%0A
-
         
@@ -1057,16 +1057,897 @@
 ckDao);%0A
+%0A        BackfillTask backfillTask = new BackfillTask() %7B%0A            @Override%0A            public String getId() %7B%0A                return %22taskId%22;%0A            %7D%0A            @Override%0A            public long getTimestamp() %7B%0A                return DateTime.now(DateTimeZone.UTC).getMillis();%0A            %7D%0A            @Override%0A            public String getName() %7B%0A                return %22test backfill%22;%0A            %7D%0A            @Override%0A            public String getUser() %7B%0A                return %22test user%22;%0A            %7D%0A            @Override%0A            public String getStatus() %7B%0A                return BackfillStatus.SUBMITTED.name();%0A            %7D%0A        %7D;%0A        BackfillDao backfillDao = mock(BackfillDao.class);%0A        when(backfillDao.createTask(%22test backfill%22, %22test user%22)).thenReturn(backfillTask);%0A        backfillTemplate.setBackfillDao(backfillDao);%0A%0A
         

Fix test failure