本文整理了Java中bolts.Task.isFaulted()
方法的一些代码示例,展示了Task.isFaulted()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Task.isFaulted()
方法的具体详情如下:
包路径:bolts.Task
类名称:Task
方法名:isFaulted
暂无
代码示例来源:origin: facebook/facebook-android-sdk
@Suppress
public void testUrlWithNoAppLinkData() {
String testNoAppLinkUrlString = "https://fb.me/732873156764191_no_app_link";
Uri testNoAppLinkUrl = Uri.parse(testNoAppLinkUrlString);
try {
executeResolverOnBlockerThread(new FacebookAppLinkResolver(), testNoAppLinkUrl);
getTestBlocker().waitForSignals(1);
assertNotNull(resolveTask);
Task<AppLink> singleUrlResolveTask = (Task<AppLink>)resolveTask;
assertTrue(singleUrlResolveTask.isCompleted() &&
!singleUrlResolveTask.isCancelled() &&
!singleUrlResolveTask.isFaulted());
AppLink appLink = singleUrlResolveTask.getResult();
assertNull(appLink);
} catch (Exception e) {
// Forcing the test to fail with details
assertNull(e);
}
}
代码示例来源:origin: parse-community/Parse-SDK-Android
@Override
public Task<Void> then(Task<Void> ignore) {
synchronized (tasksLock) {
// It might be better to return an aggregate error here.
for (Task<Void> task : tasks) {
if (task.isFaulted() || task.isCancelled()) {
return task;
}
}
tasks.clear();
return Task.forResult(null);
}
}
});
代码示例来源:origin: parse-community/Parse-SDK-Android
@Override
public Task<Void> then(Task<Void> task) {
if (task.isFaulted()) {
return Task.forResult(null);
} else {
return store.updateDataForObjectAsync(ParseObject.this);
}
}
});
代码示例来源:origin: parse-community/Parse-SDK-Android
@Override
public Task<Void> then(Task<ParsePin> task) {
if (task.isFaulted()) {
return task.makeVoid();
}
ParsePin pin = task.getResult();
return unpinAsync(pin, db);
}
});
代码示例来源:origin: parse-community/Parse-SDK-Android
@Override
public Task<Void> then(Task<Void> task) {
synchronized (mutex) {
if (task.isFaulted() || task.isCancelled()) {
removeAuthData(authType);
restoreAnonymity(oldAnonymousData);
return task;
}
return synchronizeAuthDataAsync(authType);
}
}
});
代码示例来源:origin: parse-community/Parse-SDK-Android
@Override
public Task<Void> then(Task<Boolean> task) {
boolean success = !task.isFaulted() && task.getResult();
if (!success) {
return unlinkFromInBackground(authType);
}
return task.makeVoid();
}
});
代码示例来源:origin: parse-community/Parse-SDK-Android
@Override
public T then(Task<List<T>> task) throws Exception {
if (task.isFaulted()) {
throw task.getError();
}
if (task.getResult() != null && task.getResult().size() > 0) {
return task.getResult().get(0);
}
throw new ParseException(ParseException.OBJECT_NOT_FOUND, "no results found for query");
}
});
代码示例来源:origin: parse-community/Parse-SDK-Android
@Test
public void testCallFunctionInBackgroundFailure() throws Exception {
// TODO(mengyan): Remove once we no longer rely on retry logic.
ParseRequest.setDefaultInitialRetryDelay(1L);
ParseHttpClient restClient = mock(ParseHttpClient.class);
when(restClient.execute(any(ParseHttpRequest.class))).thenThrow(new IOException());
ParseCloudCodeController controller = new ParseCloudCodeController(restClient);
Task<String> cloudCodeTask =
controller.callFunctionInBackground("test", new HashMap<String, Object>(), "sessionToken");
// Do not use ParseTaskUtils.wait() since we do not want to throw the exception
cloudCodeTask.waitForCompletion();
// TODO(mengyan): Abstract out command runner so we don't have to account for retries.
verify(restClient, times(5)).execute(any(ParseHttpRequest.class));
assertTrue(cloudCodeTask.isFaulted());
Exception error = cloudCodeTask.getError();
assertThat(error, instanceOf(ParseException.class));
assertEquals(ParseException.CONNECTION_FAILED, ((ParseException) error).getCode());
}
代码示例来源:origin: parse-community/Parse-SDK-Android
@Test
public void testSubscribeInBackgroundFail() throws Exception {
ParsePushChannelsController controller = mock(ParsePushChannelsController.class);
ParseException exception = new ParseException(ParseException.OTHER_CAUSE, "error");
when(controller.subscribeInBackground(anyString())).thenReturn(Task.<Void>forError(exception));
ParseCorePlugins.getInstance().registerPushChannelsController(controller);
Task<Void> pushTask = ParsePush.subscribeInBackground("test");
pushTask.waitForCompletion();
verify(controller, times(1)).subscribeInBackground("test");
assertTrue(pushTask.isFaulted());
assertSame(exception, pushTask.getError());
}
代码示例来源:origin: parse-community/Parse-SDK-Android
@Test
public void testUnsubscribeInBackgroundFail() throws Exception {
ParsePushChannelsController controller = mock(ParsePushChannelsController.class);
ParseException exception = new ParseException(ParseException.OTHER_CAUSE, "error");
when(controller.unsubscribeInBackground(anyString()))
.thenReturn(Task.<Void>forError(exception));
ParseCorePlugins.getInstance().registerPushChannelsController(controller);
Task<Void> pushTask = ParsePush.unsubscribeInBackground("test");
pushTask.waitForCompletion();
verify(controller, times(1)).unsubscribeInBackground("test");
assertTrue(pushTask.isFaulted());
assertSame(exception, pushTask.getError());
}
代码示例来源:origin: parse-community/Parse-SDK-Android
@Test
public void testGetAsyncFailureWithConnectionFailure() throws Exception {
// TODO(mengyan): Remove once we no longer rely on retry logic.
ParseRequest.setDefaultInitialRetryDelay(1L);
// Make ParseConfigController and call getAsync
ParseHttpClient restClient = mock(ParseHttpClient.class);
when(restClient.execute(any(ParseHttpRequest.class))).thenThrow(new IOException());
ParseCurrentConfigController currentConfigController = mockParseCurrentConfigController();
ParseConfigController configController =
new ParseConfigController(restClient, currentConfigController);
Task<ParseConfig> configTask = configController.getAsync(null);
// Do not use ParseTaskUtils.wait() since we do not want to throw the exception
configTask.waitForCompletion();
// Verify httpClient is tried enough times
// TODO(mengyan): Abstract out command runner so we don't have to account for retries.
verify(restClient, times(5)).execute(any(ParseHttpRequest.class));
assertTrue(configTask.isFaulted());
Exception error = configTask.getError();
assertThat(error, instanceOf(ParseException.class));
assertEquals(ParseException.CONNECTION_FAILED, ((ParseException) error).getCode());
// Verify currentConfigController is not called
verify(currentConfigController, times(0)).setCurrentConfigAsync(any(ParseConfig.class));
}
代码示例来源:origin: parse-community/Parse-SDK-Android
@Test
public void testPermanentFailures() throws Exception {
JSONObject json = new JSONObject();
json.put("code", 1337);
json.put("error", "mock error");
ParseHttpResponse response = newMockParseHttpResponse(400, json);
ParseHttpClient client = mock(ParseHttpClient.class);
when(client.execute(any(ParseHttpRequest.class))).thenReturn(response);
ParseRESTCommand command = new ParseRESTCommand.Builder()
.method(ParseHttpRequest.Method.GET)
.installationId("fake_installation_id")
.build();
Task<JSONObject> task = command.executeAsync(client);
task.waitForCompletion();
verify(client, times(1)).execute(any(ParseHttpRequest.class));
assertTrue(task.isFaulted());
assertEquals(1337, ((ParseException) task.getError()).getCode());
assertEquals("mock error", task.getError().getMessage());
}
代码示例来源:origin: parse-community/Parse-SDK-Android
@Test
public void testSendInBackgroundFailWithIOException() throws Exception {
// TODO(mengyan): Remove once we no longer rely on retry logic.
ParseRequest.setDefaultInitialRetryDelay(1L);
ParseHttpClient restClient = mock(ParseHttpClient.class);
when(restClient.execute(any(ParseHttpRequest.class))).thenThrow(new IOException());
ParsePushController controller = new ParsePushController(restClient);
JSONObject data = new JSONObject();
data.put(ParsePush.KEY_DATA_MESSAGE, "hello world");
ParsePush.State state = new ParsePush.State.Builder()
.data(data)
.build();
Task<Void> pushTask = controller.sendInBackground(state, "sessionToken");
// Do not use ParseTaskUtils.wait() since we do not want to throw the exception
pushTask.waitForCompletion();
// Verify httpClient is tried enough times
// TODO(mengyan): Abstract out command runner so we don't have to account for retries.
verify(restClient, times(5)).execute(any(ParseHttpRequest.class));
assertTrue(pushTask.isFaulted());
Exception error = pushTask.getError();
assertThat(error, instanceOf(ParseException.class));
assertEquals(ParseException.CONNECTION_FAILED, ((ParseException) error).getCode());
}
代码示例来源:origin: parse-community/Parse-SDK-Android
@Test
public void testSaveAsyncFailureWithByteArray() throws Exception {
// TODO(grantland): Remove once we no longer rely on retry logic.
ParseRequest.setDefaultInitialRetryDelay(1L);
ParseHttpClient restClient = mock(ParseHttpClient.class);
when(restClient.execute(any(ParseHttpRequest.class))).thenThrow(new IOException());
File root = temporaryFolder.getRoot();
ParseFileController controller = new ParseFileController(restClient, root);
byte[] data = "hello".getBytes();
ParseFile.State state = new ParseFile.State.Builder()
.build();
Task<ParseFile.State> task = controller.saveAsync(state, data, null, null, null);
task.waitForCompletion();
// TODO(grantland): Abstract out command runner so we don't have to account for retries.
verify(restClient, times(5)).execute(any(ParseHttpRequest.class));
assertTrue(task.isFaulted());
Exception error = task.getError();
assertThat(error, instanceOf(ParseException.class));
assertEquals(ParseException.CONNECTION_FAILED, ((ParseException) error).getCode());
assertEquals(0, root.listFiles().length);
}
代码示例来源:origin: parse-community/Parse-SDK-Android
/**
* Test to verify that handle 401 unauthorized
*/
@Test
public void test401Unauthorized() throws Exception {
JSONObject json = new JSONObject();
json.put("error", "unauthorized");
ParseHttpResponse response = newMockParseHttpResponse(401, json);
ParseHttpClient client = mock(ParseHttpClient.class);
when(client.execute(any(ParseHttpRequest.class))).thenReturn(response);
ParseRESTCommand command = new ParseRESTCommand.Builder()
.method(ParseHttpRequest.Method.GET)
.installationId("fake_installation_id")
.build();
Task<JSONObject> task = command.executeAsync(client);
task.waitForCompletion();
verify(client, times(1)).execute(any(ParseHttpRequest.class));
assertTrue(task.isFaulted());
assertEquals(0, ((ParseException) task.getError()).getCode());
assertEquals("unauthorized", task.getError().getMessage());
}
代码示例来源:origin: parse-community/Parse-SDK-Android
@Test
public void testSaveAsyncFailureWithFile() throws Exception {
// TODO(grantland): Remove once we no longer rely on retry logic.
ParseRequest.setDefaultInitialRetryDelay(1L);
ParseHttpClient restClient = mock(ParseHttpClient.class);
when(restClient.execute(any(ParseHttpRequest.class))).thenThrow(new IOException());
File root = temporaryFolder.getRoot();
ParseFileController controller = new ParseFileController(restClient, root);
File file = temporaryFolder.newFile("test");
ParseFile.State state = new ParseFile.State.Builder()
.build();
Task<ParseFile.State> task = controller.saveAsync(state, file, null, null, null);
task.waitForCompletion();
// TODO(grantland): Abstract out command runner so we don't have to account for retries.
verify(restClient, times(5)).execute(any(ParseHttpRequest.class));
assertTrue(task.isFaulted());
Exception error = task.getError();
assertThat(error, instanceOf(ParseException.class));
assertEquals(ParseException.CONNECTION_FAILED, ((ParseException) error).getCode());
// Make sure the original file is not deleted and there is no cache file in the folder
assertEquals(1, root.listFiles().length);
assertTrue(file.exists());
}
代码示例来源:origin: parse-community/Parse-SDK-Android
@Test
public void testSaveAsyncNotDirty() throws Exception {
ParseHttpClient restClient = mock(ParseHttpClient.class);
ParseFileController controller = new ParseFileController(restClient, null);
ParseFile.State state = new ParseFile.State.Builder()
.url("http://example.com")
.build();
Task<ParseFile.State> task = controller.saveAsync(state, (byte[]) null, null, null, null);
task.waitForCompletion();
verify(restClient, times(0)).execute(any(ParseHttpRequest.class));
assertFalse(task.isFaulted());
assertFalse(task.isCancelled());
assertSame(state, task.getResult());
}
代码示例来源:origin: parse-community/Parse-SDK-Android
@Test
public void testFetchAsyncFailure() throws Exception {
// TODO(grantland): Remove once we no longer rely on retry logic.
ParseRequest.setDefaultInitialRetryDelay(1L);
ParseHttpClient fileClient = mock(ParseHttpClient.class);
when(fileClient.execute(any(ParseHttpRequest.class))).thenThrow(new IOException());
File root = temporaryFolder.getRoot();
ParseFileController controller = new ParseFileController(null, root).fileClient(fileClient);
// We need to set url to make getTempFile() work and check it
ParseFile.State state = new ParseFile.State.Builder()
.url("test")
.build();
Task<File> task = controller.fetchAsync(state, null, null, null);
task.waitForCompletion();
// TODO(grantland): Abstract out command runner so we don't have to account for retries.
verify(fileClient, times(5)).execute(any(ParseHttpRequest.class));
assertTrue(task.isFaulted());
Exception error = task.getError();
assertThat(error, instanceOf(ParseException.class));
assertEquals(ParseException.CONNECTION_FAILED, ((ParseException) error).getCode());
assertEquals(0, root.listFiles().length);
assertFalse(controller.getTempFile(state).exists());
}
代码示例来源:origin: parse-community/Parse-SDK-Android
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public void test4XXThrowsException() throws Exception {
ParseRequest.setDefaultInitialRetryDelay(1L);
InputStream mockInputStream = new ByteArrayInputStream(
"An Error occurred while saving".getBytes());
ParseHttpResponse mockResponse = new ParseHttpResponse.Builder()
.setStatusCode(400)
.setTotalSize(0L)
.setReasonPhrase("Bad Request")
.setContent(mockInputStream)
.build();
ParseHttpClient mockHttpClient = mock(ParseHttpClient.class);
when(mockHttpClient.execute(any(ParseHttpRequest.class))).thenReturn(mockResponse);
ParseFileRequest request =
new ParseFileRequest(ParseHttpRequest.Method.GET, "http://parse.com", null);
Task<Void> task = request.executeAsync(mockHttpClient);
task.waitForCompletion();
assertTrue(task.isFaulted());
assertTrue(task.getError() instanceof ParseException);
ParseException error = (ParseException) task.getError();
assertEquals(error.getCode(), ParseException.CONNECTION_FAILED);
assertTrue(error.getMessage().contains("Download from file server"));
}
}
代码示例来源:origin: parse-community/Parse-SDK-Android
@Test
public void testDownloadProgress() throws Exception {
ParseHttpResponse mockResponse = new ParseHttpResponse.Builder()
.setStatusCode(200)
.setTotalSize((long) data.length)
.setContent(new ByteArrayInputStream(data))
.build();
ParseHttpClient mockHttpClient = mock(ParseHttpClient.class);
when(mockHttpClient.execute(any(ParseHttpRequest.class))).thenReturn(mockResponse);
File tempFile = temporaryFolder.newFile("test");
ParseFileRequest request =
new ParseFileRequest(ParseHttpRequest.Method.GET, "localhost", tempFile);
TestProgressCallback downloadProgressCallback = new TestProgressCallback();
Task<Void> task = request.executeAsync(mockHttpClient, null, downloadProgressCallback);
task.waitForCompletion();
assertFalse("Download failed: " + task.getError(), task.isFaulted());
assertEquals(data.length, ParseFileUtils.readFileToByteArray(tempFile).length);
assertProgressCompletedSuccessfully(downloadProgressCallback);
}
内容来源于网络,如有侵权,请联系作者删除!