Search in sources :

Example 1 with SynchronizationContext

use of io.grpc.SynchronizationContext in project grpc-java by grpc.

the class ClusterResolverLoadBalancerProviderTest method providesLoadBalancer.

@Test
public void providesLoadBalancer() {
    Helper helper = mock(Helper.class);
    SynchronizationContext syncContext = new SynchronizationContext(new Thread.UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread t, Throwable e) {
            throw new AssertionError(e);
        }
    });
    FakeClock fakeClock = new FakeClock();
    NameResolverRegistry nsRegistry = new NameResolverRegistry();
    NameResolver.Args args = NameResolver.Args.newBuilder().setDefaultPort(8080).setProxyDetector(GrpcUtil.NOOP_PROXY_DETECTOR).setSynchronizationContext(syncContext).setServiceConfigParser(mock(ServiceConfigParser.class)).setChannelLogger(mock(ChannelLogger.class)).build();
    when(helper.getNameResolverRegistry()).thenReturn(nsRegistry);
    when(helper.getNameResolverArgs()).thenReturn(args);
    when(helper.getSynchronizationContext()).thenReturn(syncContext);
    when(helper.getScheduledExecutorService()).thenReturn(fakeClock.getScheduledExecutorService());
    when(helper.getAuthority()).thenReturn("api.google.com");
    LoadBalancerProvider provider = new ClusterResolverLoadBalancerProvider();
    LoadBalancer loadBalancer = provider.newLoadBalancer(helper);
    assertThat(loadBalancer).isInstanceOf(ClusterResolverLoadBalancer.class);
}
Also used : FakeClock(io.grpc.internal.FakeClock) LoadBalancer(io.grpc.LoadBalancer) NameResolverRegistry(io.grpc.NameResolverRegistry) Helper(io.grpc.LoadBalancer.Helper) SynchronizationContext(io.grpc.SynchronizationContext) LoadBalancerProvider(io.grpc.LoadBalancerProvider) ServiceConfigParser(io.grpc.NameResolver.ServiceConfigParser) NameResolver(io.grpc.NameResolver) Test(org.junit.Test)

Example 2 with SynchronizationContext

use of io.grpc.SynchronizationContext in project grpc-java by grpc.

the class CdsLoadBalancerProviderTest method providesLoadBalancer.

@Test
public void providesLoadBalancer() {
    Helper helper = mock(Helper.class);
    SynchronizationContext syncContext = new SynchronizationContext(new Thread.UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread t, Throwable e) {
            throw new AssertionError(e);
        }
    });
    when(helper.getSynchronizationContext()).thenReturn(syncContext);
    LoadBalancerProvider provider = new CdsLoadBalancerProvider();
    LoadBalancer loadBalancer = provider.newLoadBalancer(helper);
    assertThat(loadBalancer).isInstanceOf(CdsLoadBalancer2.class);
}
Also used : Helper(io.grpc.LoadBalancer.Helper) SynchronizationContext(io.grpc.SynchronizationContext) LoadBalancerProvider(io.grpc.LoadBalancerProvider) LoadBalancer(io.grpc.LoadBalancer) Test(org.junit.Test)

Example 3 with SynchronizationContext

use of io.grpc.SynchronizationContext in project grpc-java by grpc.

the class LbPolicyConfigurationTest method setUp.

@Before
public void setUp() {
    doReturn(mock(ChannelLogger.class)).when(helper).getChannelLogger();
    doReturn(new SynchronizationContext(new UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread t, Throwable e) {
            throw new AssertionError(e);
        }
    })).when(helper).getSynchronizationContext();
    doReturn(mock(LoadBalancer.class)).when(lbProvider).newLoadBalancer(any(Helper.class));
    doReturn(ConfigOrError.fromConfig(new Object())).when(lbProvider).parseLoadBalancingPolicyConfig(ArgumentMatchers.<Map<String, ?>>any());
}
Also used : Helper(io.grpc.LoadBalancer.Helper) ChildPolicyReportingHelper(io.grpc.rls.LbPolicyConfiguration.ChildPolicyWrapper.ChildPolicyReportingHelper) SynchronizationContext(io.grpc.SynchronizationContext) LoadBalancer(io.grpc.LoadBalancer) ChannelLogger(io.grpc.ChannelLogger) UncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler) Before(org.junit.Before)

Aggregations

LoadBalancer (io.grpc.LoadBalancer)3 Helper (io.grpc.LoadBalancer.Helper)3 SynchronizationContext (io.grpc.SynchronizationContext)3 LoadBalancerProvider (io.grpc.LoadBalancerProvider)2 Test (org.junit.Test)2 ChannelLogger (io.grpc.ChannelLogger)1 NameResolver (io.grpc.NameResolver)1 ServiceConfigParser (io.grpc.NameResolver.ServiceConfigParser)1 NameResolverRegistry (io.grpc.NameResolverRegistry)1 FakeClock (io.grpc.internal.FakeClock)1 ChildPolicyReportingHelper (io.grpc.rls.LbPolicyConfiguration.ChildPolicyWrapper.ChildPolicyReportingHelper)1 UncaughtExceptionHandler (java.lang.Thread.UncaughtExceptionHandler)1 Before (org.junit.Before)1