Search in sources :

Example 1 with Operation

use of com.android.calendar.AsyncQueryService.Operation in project Etar-Calendar by Etar-Group.

the class AsyncQueryServiceHelper method getLastCancelableOperation.

/**
     * Gets the last delayed operation. It is typically used for canceling.
     *
     * @return Operation object which contains of the last cancelable operation
     */
public static Operation getLastCancelableOperation() {
    long lastScheduleTime = Long.MIN_VALUE;
    Operation op = null;
    synchronized (sWorkQueue) {
        // Unknown order even for a PriorityQueue
        Iterator<OperationInfo> it = sWorkQueue.iterator();
        while (it.hasNext()) {
            OperationInfo info = it.next();
            if (info.delayMillis > 0 && lastScheduleTime < info.mScheduledTimeMillis) {
                if (op == null) {
                    op = new Operation();
                }
                op.token = info.token;
                op.op = info.op;
                op.scheduledExecutionTime = info.mScheduledTimeMillis;
                lastScheduleTime = info.mScheduledTimeMillis;
            }
        }
    }
    if (AsyncQueryService.localLOGV) {
        Log.d(TAG, "getLastCancelableOperation -> Operation:" + Operation.opToChar(op.op) + " token:" + op.token);
    }
    return op;
}
Also used : ContentProviderOperation(android.content.ContentProviderOperation) Operation(com.android.calendar.AsyncQueryService.Operation)

Example 2 with Operation

use of com.android.calendar.AsyncQueryService.Operation in project Etar-Calendar by Etar-Group.

the class AsyncQueryServiceTest method testCancel_cancelSecondToLast.

@LargeTest
public void testCancel_cancelSecondToLast() throws Exception {
    int index = 0;
    OperationInfo[] work = new OperationInfo[5];
    work[index++] = generateWork(MIN_DELAY * 2);
    work[index++] = generateWork(0);
    work[index++] = generateWork(MIN_DELAY);
    work[index++] = generateWork(0);
    work[index] = generateWork(MIN_DELAY * 3);
    // Not part of the expected as it will be canceled
    OperationInfo toBeCancelled1 = work[index];
    OperationInfo[] expected = new OperationInfo[4];
    // delay = 0
    expected[0] = work[1];
    // delay = 0
    expected[1] = work[3];
    // delay = MIN_DELAY
    expected[2] = work[2];
    // delay = MIN_DELAY * 3
    expected[3] = work[4];
    TestAsyncQueryService aqs = new TestAsyncQueryService(buildTestContext(expected), expected);
    startWork(aqs, work);
    // delay = 3
    Operation lastOne = aqs.getLastCancelableOperation();
    assertTrue("2) delay=3 is not last", toBeCancelled1.equivalent(lastOne));
    assertEquals("Can't cancel delay 2", 1, aqs.cancelOperation(work[0].token));
    assertEquals("Delay 2 should be gone", 0, aqs.cancelOperation(work[0].token));
    Log.d(TAG, "testCancel_cancelSecondToLast Waiting >>>>>>>>>>>");
    assertEquals("Not all operations were executed.", expected.length, aqs.waitForCompletion(BASE_TEST_WAIT_TIME));
    Log.d(TAG, "testCancel_cancelSecondToLast Done <<<<<<<<<<<<<<");
}
Also used : OperationInfo(com.android.calendar.AsyncQueryServiceHelper.OperationInfo) ContentProviderOperation(android.content.ContentProviderOperation) Operation(com.android.calendar.AsyncQueryService.Operation) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 3 with Operation

use of com.android.calendar.AsyncQueryService.Operation in project Etar-Calendar by Etar-Group.

the class AsyncQueryServiceTest method testCancel_simpleCancelLastTest.

@LargeTest
public void testCancel_simpleCancelLastTest() throws Exception {
    int index = 0;
    OperationInfo[] work = new OperationInfo[5];
    work[index++] = generateWork(MIN_DELAY * 2);
    work[index++] = generateWork(0);
    work[index++] = generateWork(MIN_DELAY);
    work[index++] = generateWork(0);
    work[index] = generateWork(MIN_DELAY * 3);
    // Not part of the expected as it will be canceled
    OperationInfo toBeCancelled1 = work[index];
    OperationInfo[] expected = generateSortedWork(work, work.length - 1);
    TestAsyncQueryService aqs = new TestAsyncQueryService(buildTestContext(expected), expected);
    startWork(aqs, work);
    Operation lastOne = aqs.getLastCancelableOperation();
    // Log.d(TAG, "lastOne = " + lastOne.toString());
    // Log.d(TAG, "toBeCancelled1 = " + toBeCancelled1.toString());
    assertTrue("1) delay=3 is not last", toBeCancelled1.equivalent(lastOne));
    assertEquals("Can't cancel delay 3", 1, aqs.cancelOperation(lastOne.token));
    Log.d(TAG, "testCancel_simpleCancelLastTest Waiting >>>>>>>>>>>");
    assertEquals("Not all operations were executed.", expected.length, aqs.waitForCompletion(BASE_TEST_WAIT_TIME));
    Log.d(TAG, "testCancel_simpleCancelLastTest Done <<<<<<<<<<<<<<");
}
Also used : OperationInfo(com.android.calendar.AsyncQueryServiceHelper.OperationInfo) ContentProviderOperation(android.content.ContentProviderOperation) Operation(com.android.calendar.AsyncQueryService.Operation) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 4 with Operation

use of com.android.calendar.AsyncQueryService.Operation in project Etar-Calendar by Etar-Group.

the class AsyncQueryServiceTest method testCancel_multipleCancels.

@LargeTest
public void testCancel_multipleCancels() throws Exception {
    int index = 0;
    OperationInfo[] work = new OperationInfo[5];
    work[index++] = generateWork(MIN_DELAY * 2);
    work[index++] = generateWork(0);
    work[index++] = generateWork(MIN_DELAY);
    work[index++] = generateWork(0);
    work[index] = generateWork(MIN_DELAY * 3);
    // Not part of the expected as it will be canceled
    OperationInfo[] expected = new OperationInfo[3];
    // delay = 0
    expected[0] = work[1];
    // delay = 0
    expected[1] = work[3];
    // delay = MIN_DELAY
    expected[2] = work[2];
    TestAsyncQueryService aqs = new TestAsyncQueryService(buildTestContext(expected), expected);
    startWork(aqs, work);
    // delay = 3
    Operation lastOne = aqs.getLastCancelableOperation();
    assertTrue("3) delay=3 is not last", work[4].equivalent(lastOne));
    assertEquals("Can't cancel delay 2", 1, aqs.cancelOperation(work[0].token));
    assertEquals("Delay 2 should be gone", 0, aqs.cancelOperation(work[0].token));
    assertEquals("Can't cancel delay 3", 1, aqs.cancelOperation(work[4].token));
    assertEquals("Delay 3 should be gone", 0, aqs.cancelOperation(work[4].token));
    Log.d(TAG, "testCancel_multipleCancels Waiting >>>>>>>>>>>");
    assertEquals("Not all operations were executed.", expected.length, aqs.waitForCompletion(BASE_TEST_WAIT_TIME));
    Log.d(TAG, "testCancel_multipleCancels Done <<<<<<<<<<<<<<");
}
Also used : OperationInfo(com.android.calendar.AsyncQueryServiceHelper.OperationInfo) ContentProviderOperation(android.content.ContentProviderOperation) Operation(com.android.calendar.AsyncQueryService.Operation) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Aggregations

ContentProviderOperation (android.content.ContentProviderOperation)4 Operation (com.android.calendar.AsyncQueryService.Operation)4 LargeTest (android.test.suitebuilder.annotation.LargeTest)3 OperationInfo (com.android.calendar.AsyncQueryServiceHelper.OperationInfo)3