mirror of https://github.com/grpc/grpc-java.git
Use a realistic Executor in BinderServerTransportTest (#10979)
This commit is contained in:
parent
85e52cd113
commit
d894c8385d
|
|
@ -27,6 +27,7 @@ android {
|
||||||
withJavadocJar()
|
withJavadocJar()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
testFixtures { enable true }
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
|
@ -70,6 +71,8 @@ dependencies {
|
||||||
androidTestImplementation libraries.androidx.lifecycle.service
|
androidTestImplementation libraries.androidx.lifecycle.service
|
||||||
androidTestImplementation libraries.guava.testlib
|
androidTestImplementation libraries.guava.testlib
|
||||||
androidTestImplementation testFixtures(project(':grpc-core'))
|
androidTestImplementation testFixtures(project(':grpc-core'))
|
||||||
|
|
||||||
|
testFixturesImplementation libraries.guava.testlib
|
||||||
}
|
}
|
||||||
|
|
||||||
import net.ltgt.gradle.errorprone.CheckSeverity
|
import net.ltgt.gradle.errorprone.CheckSeverity
|
||||||
|
|
@ -123,3 +126,8 @@ publishing {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
afterEvaluate {
|
||||||
|
components.release.withVariantsFromConfiguration(configurations.releaseTestFixturesVariantReleaseApiPublication) { skip() }
|
||||||
|
components.release.withVariantsFromConfiguration(configurations.releaseTestFixturesVariantReleaseRuntimePublication) { skip() }
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat;
|
||||||
import static com.google.common.util.concurrent.MoreExecutors.directExecutor;
|
import static com.google.common.util.concurrent.MoreExecutors.directExecutor;
|
||||||
import static org.robolectric.Shadows.shadowOf;
|
import static org.robolectric.Shadows.shadowOf;
|
||||||
|
|
||||||
|
import io.grpc.binder.internal.MainThreadScheduledExecutorService;
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
|
|
||||||
|
|
@ -22,15 +22,17 @@ import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.ArgumentMatchers.isNull;
|
import static org.mockito.ArgumentMatchers.isNull;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
import static org.robolectric.Shadows.shadowOf;
|
||||||
import static org.robolectric.annotation.LooperMode.Mode.PAUSED;
|
import static org.robolectric.annotation.LooperMode.Mode.PAUSED;
|
||||||
|
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
import android.os.Looper;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.util.concurrent.testing.TestingExecutors;
|
|
||||||
import io.grpc.Attributes;
|
import io.grpc.Attributes;
|
||||||
import io.grpc.Metadata;
|
import io.grpc.Metadata;
|
||||||
import io.grpc.Status;
|
import io.grpc.Status;
|
||||||
|
import io.grpc.binder.internal.MainThreadScheduledExecutorService;
|
||||||
import io.grpc.internal.FixedObjectPool;
|
import io.grpc.internal.FixedObjectPool;
|
||||||
import io.grpc.internal.ServerStream;
|
import io.grpc.internal.ServerStream;
|
||||||
import io.grpc.internal.ServerTransportListener;
|
import io.grpc.internal.ServerTransportListener;
|
||||||
|
|
@ -56,8 +58,7 @@ public final class BinderServerTransportTest {
|
||||||
|
|
||||||
@Rule public MockitoRule mocks = MockitoJUnit.rule();
|
@Rule public MockitoRule mocks = MockitoJUnit.rule();
|
||||||
|
|
||||||
private final ScheduledExecutorService executorService =
|
private final ScheduledExecutorService executorService = new MainThreadScheduledExecutorService();
|
||||||
TestingExecutors.sameThreadScheduledExecutor();
|
|
||||||
private final TestTransportListener transportListener = new TestTransportListener();
|
private final TestTransportListener transportListener = new TestTransportListener();
|
||||||
|
|
||||||
@Mock IBinder mockBinder;
|
@Mock IBinder mockBinder;
|
||||||
|
|
@ -83,6 +84,7 @@ public final class BinderServerTransportTest {
|
||||||
|
|
||||||
// Now shut it down.
|
// Now shut it down.
|
||||||
transport.shutdownNow(Status.UNKNOWN.withDescription("reasons"));
|
transport.shutdownNow(Status.UNKNOWN.withDescription("reasons"));
|
||||||
|
shadowOf(Looper.getMainLooper()).idle();
|
||||||
|
|
||||||
assertThat(transportListener.terminated).isTrue();
|
assertThat(transportListener.terminated).isTrue();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.grpc.binder;
|
package io.grpc.binder.internal;
|
||||||
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
|
@ -37,7 +37,7 @@ import java.util.concurrent.TimeoutException;
|
||||||
*
|
*
|
||||||
* <p>Use {@link org.robolectric.shadows.ShadowLooper#idle()} to run queued work.
|
* <p>Use {@link org.robolectric.shadows.ShadowLooper#idle()} to run queued work.
|
||||||
*/
|
*/
|
||||||
class MainThreadScheduledExecutorService extends AbstractExecutorService
|
public class MainThreadScheduledExecutorService extends AbstractExecutorService
|
||||||
implements ScheduledExecutorService {
|
implements ScheduledExecutorService {
|
||||||
|
|
||||||
private final Handler handler = new Handler(Looper.getMainLooper());
|
private final Handler handler = new Handler(Looper.getMainLooper());
|
||||||
Loading…
Reference in New Issue