提交 73b88a40 编写于 作者: J Jake Wharton

Throw normal IOException when canceled to match OkHttp.

上级 c342d650
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
package retrofit2.mock; package retrofit2.mock;
import java.io.IOException; import java.io.IOException;
import java.io.InterruptedIOException;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future; import java.util.concurrent.Future;
...@@ -59,7 +58,7 @@ final class BehaviorCall<T> implements Call<T> { ...@@ -59,7 +58,7 @@ final class BehaviorCall<T> implements Call<T> {
try { try {
Thread.sleep(sleepMs); Thread.sleep(sleepMs);
} catch (InterruptedException e) { } catch (InterruptedException e) {
callback.onFailure(new InterruptedIOException("canceled")); callback.onFailure(new IOException("canceled"));
return false; return false;
} }
} }
...@@ -68,7 +67,7 @@ final class BehaviorCall<T> implements Call<T> { ...@@ -68,7 +67,7 @@ final class BehaviorCall<T> implements Call<T> {
@Override public void run() { @Override public void run() {
if (canceled) { if (canceled) {
callback.onFailure(new InterruptedIOException("canceled")); callback.onFailure(new IOException("canceled"));
} else if (behavior.calculateIsFailure()) { } else if (behavior.calculateIsFailure()) {
if (delaySleep()) { if (delaySleep()) {
callback.onFailure(behavior.failureException()); callback.onFailure(behavior.failureException());
...@@ -114,7 +113,7 @@ final class BehaviorCall<T> implements Call<T> { ...@@ -114,7 +113,7 @@ final class BehaviorCall<T> implements Call<T> {
try { try {
latch.await(); latch.await();
} catch (InterruptedException e) { } catch (InterruptedException e) {
throw new InterruptedIOException("canceled"); throw new IOException("canceled");
} }
Response<T> response = responseRef.get(); Response<T> response = responseRef.get();
if (response != null) return response; if (response != null) return response;
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
package retrofit2.mock; package retrofit2.mock;
import java.io.IOException; import java.io.IOException;
import java.io.InterruptedIOException;
import java.util.Random; import java.util.Random;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
...@@ -222,8 +221,8 @@ public final class MockRetrofitTest { ...@@ -222,8 +221,8 @@ public final class MockRetrofitTest {
try { try {
call.execute(); call.execute();
fail(); fail();
} catch (InterruptedIOException e) { } catch (IOException e) {
assertThat(e).hasMessage("canceled"); assertThat(e).isExactlyInstanceOf(IOException.class).hasMessage("canceled");
} }
} }
...@@ -252,7 +251,7 @@ public final class MockRetrofitTest { ...@@ -252,7 +251,7 @@ public final class MockRetrofitTest {
call.cancel(); call.cancel();
assertTrue(latch.await(1, SECONDS)); assertTrue(latch.await(1, SECONDS));
assertThat(failureRef.get()).isInstanceOf(InterruptedIOException.class).hasMessage("canceled"); assertThat(failureRef.get()).isExactlyInstanceOf(IOException.class).hasMessage("canceled");
} }
@Test public void syncCanceledBeforeStart() throws IOException { @Test public void syncCanceledBeforeStart() throws IOException {
...@@ -266,8 +265,8 @@ public final class MockRetrofitTest { ...@@ -266,8 +265,8 @@ public final class MockRetrofitTest {
try { try {
call.execute(); call.execute();
fail(); fail();
} catch (InterruptedIOException e) { } catch (IOException e) {
assertThat(e).hasMessage("canceled"); assertThat(e).isExactlyInstanceOf(IOException.class).hasMessage("canceled");
} }
} }
...@@ -293,6 +292,6 @@ public final class MockRetrofitTest { ...@@ -293,6 +292,6 @@ public final class MockRetrofitTest {
}); });
assertTrue(latch.await(1, SECONDS)); assertTrue(latch.await(1, SECONDS));
assertThat(failureRef.get()).isInstanceOf(InterruptedIOException.class).hasMessage("canceled"); assertThat(failureRef.get()).isExactlyInstanceOf(IOException.class).hasMessage("canceled");
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册