use of com.android.calendar.AsyncQueryServiceHelper.OperationInfo in project Etar-Calendar by Etar-Group.
the class AsyncQueryServiceTest method testBatch.
@SmallTest
public void testBatch() throws Exception {
int index = 0;
final OperationInfo[] work = new OperationInfo[1];
work[index] = new OperationInfo();
work[index].op = Operation.EVENT_ARG_BATCH;
work[index].token = ++mId;
work[index].cookie = ++mId;
work[index].authority = AUTHORITY;
work[index].cpo = new ArrayList<ContentProviderOperation>();
work[index].cpo.add(ContentProviderOperation.newInsert(Uri.parse(AUTHORITY_URI + ++mId)).build());
work[index].delayMillis = 0;
ContentProviderResult[] resultArray = new ContentProviderResult[1];
resultArray[0] = new ContentProviderResult(++mId);
work[index].result = resultArray;
TestAsyncQueryService aqs = new TestAsyncQueryService(buildTestContext(work), work);
aqs.startBatch(work[index].token, work[index].cookie, work[index].authority, work[index].cpo, work[index].delayMillis);
Log.d(TAG, "testBatch Waiting >>>>>>>>>>>");
assertEquals("Not all operations were executed.", work.length, aqs.waitForCompletion(BASE_TEST_WAIT_TIME));
Log.d(TAG, "testBatch Done <<<<<<<<<<<<<<");
}
use of com.android.calendar.AsyncQueryServiceHelper.OperationInfo in project Etar-Calendar by Etar-Group.
the class AsyncQueryServiceTest method testDelete.
@SmallTest
public void testDelete() throws Exception {
int index = 0;
final OperationInfo[] work = new OperationInfo[1];
work[index] = new OperationInfo();
work[index].op = Operation.EVENT_ARG_DELETE;
work[index].token = ++mId;
work[index].cookie = ++mId;
work[index].uri = Uri.parse(AUTHORITY_URI + "blah");
work[index].selection = TEST_SELECTION;
work[index].selectionArgs = TEST_SELECTION_ARGS;
work[index].delayMillis = 0;
work[index].result = ++mId;
TestAsyncQueryService aqs = new TestAsyncQueryService(buildTestContext(work), work);
aqs.startDelete(work[index].token, work[index].cookie, work[index].uri, work[index].selection, work[index].selectionArgs, work[index].delayMillis);
Log.d(TAG, "testDelete Waiting >>>>>>>>>>>");
assertEquals("Not all operations were executed.", work.length, aqs.waitForCompletion(BASE_TEST_WAIT_TIME));
Log.d(TAG, "testDelete Done <<<<<<<<<<<<<<");
}
use of com.android.calendar.AsyncQueryServiceHelper.OperationInfo in project Etar-Calendar by Etar-Group.
the class AsyncQueryServiceTest method generateSortedWork.
OperationInfo[] generateSortedWork(OperationInfo[] work, int length) {
OperationInfo[] sorted = new OperationInfo[length];
System.arraycopy(work, 0, sorted, 0, length);
// Set the scheduled time so they get sorted properly
for (OperationInfo w : sorted) {
if (w != null) {
w.calculateScheduledTime();
}
}
// Stable sort by scheduled time
Arrays.sort(sorted);
Log.d(TAG, "Unsorted work: " + work.length);
for (OperationInfo w : work) {
if (w != null) {
Log.d(TAG, "Token#" + w.token + " delay=" + w.delayMillis);
}
}
Log.d(TAG, "Sorted work: " + sorted.length);
for (OperationInfo w : sorted) {
if (w != null) {
Log.d(TAG, "Token#" + w.token + " delay=" + w.delayMillis);
}
}
return sorted;
}
use of com.android.calendar.AsyncQueryServiceHelper.OperationInfo 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 <<<<<<<<<<<<<<");
}
use of com.android.calendar.AsyncQueryServiceHelper.OperationInfo in project Etar-Calendar by Etar-Group.
the class AsyncQueryService method startUpdate.
/**
* This method begins an asynchronous update. When the update operation is
* done {@link #onUpdateComplete} is called.
*
* @param token A token passed into {@link #onUpdateComplete} to identify
* the update operation.
* @param cookie An object that gets passed into {@link #onUpdateComplete}
* @param uri the Uri passed to the update operation.
* @param values the ContentValues parameter passed to the update operation.
* @param selection A filter declaring which rows to update, formatted as an
* SQL WHERE clause (excluding the WHERE itself). Passing null
* will update all rows for the given URI.
* @param selectionArgs You may include ?s in selection, which will be
* replaced by the values from selectionArgs, in the order that
* they appear in the selection. The values will be bound as
* Strings.
* @param delayMillis delay in executing the operation. This operation will
* execute before the delayed time when another operation is
* added. Useful for implementing single level undo.
*/
public void startUpdate(int token, Object cookie, Uri uri, ContentValues values, String selection, String[] selectionArgs, long delayMillis) {
OperationInfo info = new OperationInfo();
info.op = Operation.EVENT_ARG_UPDATE;
info.resolver = mContext.getContentResolver();
info.handler = mHandler;
info.token = token;
info.cookie = cookie;
info.uri = uri;
info.values = values;
info.selection = selection;
info.selectionArgs = selectionArgs;
info.delayMillis = delayMillis;
AsyncQueryServiceHelper.queueOperation(mContext, info);
}
Aggregations