本文整理匯總了Java中io.grpc.LoadBalancer.Helper類的典型用法代碼示例。如果您正苦於以下問題:Java Helper類的具體用法?Java Helper怎麽用?Java Helper使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Helper類屬於io.grpc.LoadBalancer包,在下文中一共展示了Helper類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: loadBalancerThrowsInHandleResolvedAddresses
import io.grpc.LoadBalancer.Helper; //導入依賴的package包/類
@Test
public void loadBalancerThrowsInHandleResolvedAddresses() {
RuntimeException ex = new RuntimeException("simulated");
// Delay the success of name resolution until allResolved() is called
FakeNameResolverFactory nameResolverFactory = new FakeNameResolverFactory(false);
createChannel(nameResolverFactory, NO_INTERCEPTOR);
verify(mockLoadBalancerFactory).newLoadBalancer(any(Helper.class));
doThrow(ex).when(mockLoadBalancer).handleResolvedAddressGroups(
Matchers.<List<EquivalentAddressGroup>>anyObject(), any(Attributes.class));
// NameResolver returns addresses.
nameResolverFactory.allResolved();
// The LoadBalancer will receive the error that it has thrown.
verify(mockLoadBalancer).handleNameResolutionError(statusCaptor.capture());
Status status = statusCaptor.getValue();
assertSame(Status.Code.INTERNAL, status.getCode());
assertSame(ex, status.getCause());
}
示例2: getState_withRequestConnect
import io.grpc.LoadBalancer.Helper; //導入依賴的package包/類
@Test
public void getState_withRequestConnect() {
createChannel(
new FakeNameResolverFactory(false), NO_INTERCEPTOR, false /* requestConnection */,
ManagedChannelImpl.IDLE_TIMEOUT_MILLIS_DISABLE);
assertEquals(IDLE, channel.getState(false));
verify(mockLoadBalancerFactory, never()).newLoadBalancer(any(Helper.class));
// call getState() with requestConnection = true
assertEquals(IDLE, channel.getState(true));
ArgumentCaptor<Helper> helperCaptor = ArgumentCaptor.forClass(null);
verify(mockLoadBalancerFactory).newLoadBalancer(helperCaptor.capture());
helper = helperCaptor.getValue();
helper.updateBalancingState(CONNECTING, mockPicker);
assertEquals(CONNECTING, channel.getState(false));
assertEquals(CONNECTING, channel.getState(true));
verifyNoMoreInteractions(mockLoadBalancerFactory);
}
示例3: idleTimeoutAndReconnect
import io.grpc.LoadBalancer.Helper; //導入依賴的package包/類
@Test
public void idleTimeoutAndReconnect() {
long idleTimeoutMillis = 2000L;
createChannel(
new FakeNameResolverFactory(true), NO_INTERCEPTOR, true /* request connection*/,
idleTimeoutMillis);
timer.forwardNanos(TimeUnit.MILLISECONDS.toNanos(idleTimeoutMillis));
assertEquals(IDLE, channel.getState(true /* request connection */));
ArgumentCaptor<Helper> helperCaptor = ArgumentCaptor.forClass(Helper.class);
// Two times of requesting connection will create loadBalancer twice.
verify(mockLoadBalancerFactory, times(2)).newLoadBalancer(helperCaptor.capture());
Helper helper2 = helperCaptor.getValue();
// Updating on the old helper (whose balancer has been shutdown) does not change the channel
// state.
helper.updateBalancingState(CONNECTING, mockPicker);
assertEquals(IDLE, channel.getState(false));
helper2.updateBalancingState(CONNECTING, mockPicker);
assertEquals(CONNECTING, channel.getState(false));
}
示例4: updateSubchannelAddresses_newAddressConnects
import io.grpc.LoadBalancer.Helper; //導入依賴的package包/類
@Test
public void updateSubchannelAddresses_newAddressConnects() {
ClientCall<String, Integer> call = channel.newCall(method, CallOptions.DEFAULT);
call.start(mockCallListener, new Metadata()); // Create LB
ArgumentCaptor<Helper> helperCaptor = ArgumentCaptor.forClass(null);
verify(mockLoadBalancerFactory).newLoadBalancer(helperCaptor.capture());
Helper helper = helperCaptor.getValue();
Subchannel subchannel = helper.createSubchannel(servers.get(0), Attributes.EMPTY);
subchannel.requestConnection();
MockClientTransportInfo t0 = newTransports.poll();
t0.listener.transportReady();
helper.updateSubchannelAddresses(subchannel, servers.get(1));
subchannel.requestConnection();
MockClientTransportInfo t1 = newTransports.poll();
t1.listener.transportReady();
}
示例5: updateSubchannelAddresses_existingAddressDoesNotConnect
import io.grpc.LoadBalancer.Helper; //導入依賴的package包/類
@Test
public void updateSubchannelAddresses_existingAddressDoesNotConnect() {
ClientCall<String, Integer> call = channel.newCall(method, CallOptions.DEFAULT);
call.start(mockCallListener, new Metadata()); // Create LB
ArgumentCaptor<Helper> helperCaptor = ArgumentCaptor.forClass(null);
verify(mockLoadBalancerFactory).newLoadBalancer(helperCaptor.capture());
Helper helper = helperCaptor.getValue();
Subchannel subchannel = helper.createSubchannel(servers.get(0), Attributes.EMPTY);
subchannel.requestConnection();
MockClientTransportInfo t0 = newTransports.poll();
t0.listener.transportReady();
List<SocketAddress> changedList = new ArrayList<SocketAddress>(servers.get(0).getAddresses());
changedList.add(new FakeSocketAddress("aDifferentServer"));
helper.updateSubchannelAddresses(subchannel, new EquivalentAddressGroup(changedList));
subchannel.requestConnection();
assertNull(newTransports.poll());
}
示例6: updateOobChannelAddresses_newAddressConnects
import io.grpc.LoadBalancer.Helper; //導入依賴的package包/類
@Test
public void updateOobChannelAddresses_newAddressConnects() {
ClientCall<String, Integer> call = channel.newCall(method, CallOptions.DEFAULT);
call.start(mockCallListener, new Metadata()); // Create LB
ArgumentCaptor<Helper> helperCaptor = ArgumentCaptor.forClass(null);
verify(mockLoadBalancerFactory).newLoadBalancer(helperCaptor.capture());
Helper helper = helperCaptor.getValue();
ManagedChannel oobChannel = helper.createOobChannel(servers.get(0), "localhost");
oobChannel.newCall(method, CallOptions.DEFAULT).start(mockCallListener, new Metadata());
MockClientTransportInfo t0 = newTransports.poll();
t0.listener.transportReady();
helper.updateOobChannelAddresses(oobChannel, servers.get(1));
oobChannel.newCall(method, CallOptions.DEFAULT).start(mockCallListener, new Metadata());
MockClientTransportInfo t1 = newTransports.poll();
t1.listener.transportReady();
}
示例7: updateOobChannelAddresses_existingAddressDoesNotConnect
import io.grpc.LoadBalancer.Helper; //導入依賴的package包/類
@Test
public void updateOobChannelAddresses_existingAddressDoesNotConnect() {
ClientCall<String, Integer> call = channel.newCall(method, CallOptions.DEFAULT);
call.start(mockCallListener, new Metadata()); // Create LB
ArgumentCaptor<Helper> helperCaptor = ArgumentCaptor.forClass(null);
verify(mockLoadBalancerFactory).newLoadBalancer(helperCaptor.capture());
Helper helper = helperCaptor.getValue();
ManagedChannel oobChannel = helper.createOobChannel(servers.get(0), "localhost");
oobChannel.newCall(method, CallOptions.DEFAULT).start(mockCallListener, new Metadata());
MockClientTransportInfo t0 = newTransports.poll();
t0.listener.transportReady();
List<SocketAddress> changedList = new ArrayList<SocketAddress>(servers.get(0).getAddresses());
changedList.add(new FakeSocketAddress("aDifferentServer"));
helper.updateOobChannelAddresses(oobChannel, new EquivalentAddressGroup(changedList));
oobChannel.newCall(method, CallOptions.DEFAULT).start(mockCallListener, new Metadata());
assertNull(newTransports.poll());
}
示例8: GrpclbState
import io.grpc.LoadBalancer.Helper; //導入依賴的package包/類
GrpclbState(
Helper helper,
TimeProvider time,
ScheduledExecutorService timerService,
LogId logId) {
this.helper = checkNotNull(helper, "helper");
this.time = checkNotNull(time, "time provider");
this.timerService = checkNotNull(timerService, "timerService");
this.serviceName = checkNotNull(helper.getAuthority(), "helper returns null authority");
this.logId = checkNotNull(logId, "logId");
}
示例9: fallbackTestVerifyUseOfBalancerBackendLists
import io.grpc.LoadBalancer.Helper; //導入依賴的package包/類
private List<Subchannel> fallbackTestVerifyUseOfBalancerBackendLists(
InOrder inOrder, Helper helper, List<ServerEntry> servers) {
ArrayList<EquivalentAddressGroup> addrs = new ArrayList<EquivalentAddressGroup>();
ArrayList<String> tokens = new ArrayList<String>();
for (ServerEntry server : servers) {
addrs.add(new EquivalentAddressGroup(server.addr));
tokens.add(server.token);
}
return fallbackTestVerifyUseOfBackendLists(inOrder, helper, addrs, tokens);
}
示例10: setUp
import io.grpc.LoadBalancer.Helper; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
expectedUri = new URI(target);
when(mockLoadBalancerFactory.newLoadBalancer(any(Helper.class))).thenReturn(mockLoadBalancer);
transports = TestUtils.captureTransports(mockTransportFactory);
when(mockTransportFactory.getScheduledExecutorService())
.thenReturn(timer.getScheduledExecutorService());
when(executorPool.getObject()).thenReturn(executor.getScheduledExecutorService());
when(oobExecutorPool.getObject()).thenReturn(oobExecutor.getScheduledExecutorService());
}
示例11: nameResolverReturnsEmptySubLists
import io.grpc.LoadBalancer.Helper; //導入依賴的package包/類
@Test
public void nameResolverReturnsEmptySubLists() {
String errorDescription = "NameResolver returned an empty list";
// Pass a FakeNameResolverFactory with an empty list
createChannel(new FakeNameResolverFactory(), NO_INTERCEPTOR);
// LoadBalancer received the error
verify(mockLoadBalancerFactory).newLoadBalancer(any(Helper.class));
verify(mockLoadBalancer).handleNameResolutionError(statusCaptor.capture());
Status status = statusCaptor.getValue();
assertSame(Status.Code.UNAVAILABLE, status.getCode());
assertEquals(errorDescription, status.getDescription());
}
示例12: channelsAndSubchannels_instrumented_state
import io.grpc.LoadBalancer.Helper; //導入依賴的package包/類
@Test
public void channelsAndSubchannels_instrumented_state() throws Exception {
createChannel(new FakeNameResolverFactory(true), NO_INTERCEPTOR);
ArgumentCaptor<Helper> helperCaptor = ArgumentCaptor.forClass(null);
verify(mockLoadBalancerFactory).newLoadBalancer(helperCaptor.capture());
helper = helperCaptor.getValue();
assertEquals(IDLE, getStats(channel).state);
helper.updateBalancingState(CONNECTING, mockPicker);
assertEquals(CONNECTING, getStats(channel).state);
AbstractSubchannel subchannel =
(AbstractSubchannel) helper.createSubchannel(addressGroup, Attributes.EMPTY);
assertEquals(IDLE, getStats(subchannel).state);
subchannel.requestConnection();
assertEquals(CONNECTING, getStats(subchannel).state);
MockClientTransportInfo transportInfo = transports.poll();
assertEquals(CONNECTING, getStats(subchannel).state);
transportInfo.listener.transportReady();
assertEquals(READY, getStats(subchannel).state);
assertEquals(CONNECTING, getStats(channel).state);
helper.updateBalancingState(READY, mockPicker);
assertEquals(READY, getStats(channel).state);
channel.shutdownNow();
assertEquals(SHUTDOWN, getStats(channel).state);
assertEquals(SHUTDOWN, getStats(subchannel).state);
}
示例13: newCallExitsIdleness
import io.grpc.LoadBalancer.Helper; //導入依賴的package包/類
@Test
public void newCallExitsIdleness() throws Exception {
ClientCall<String, Integer> call = channel.newCall(method, CallOptions.DEFAULT);
call.start(mockCallListener, new Metadata());
verify(mockLoadBalancerFactory).newLoadBalancer(any(Helper.class));
verify(mockNameResolver).start(nameResolverListenerCaptor.capture());
// Simulate new address resolved to make sure the LoadBalancer is correctly linked to
// the NameResolver.
nameResolverListenerCaptor.getValue().onAddresses(servers, Attributes.EMPTY);
verify(mockLoadBalancer).handleResolvedAddressGroups(servers, Attributes.EMPTY);
}
示例14: newCallRefreshesIdlenessTimer
import io.grpc.LoadBalancer.Helper; //導入依賴的package包/類
@Test
public void newCallRefreshesIdlenessTimer() throws Exception {
// First call to exit the initial idleness, then immediately cancel the call.
ClientCall<String, Integer> call = channel.newCall(method, CallOptions.DEFAULT);
call.start(mockCallListener, new Metadata());
call.cancel("For testing", null);
// Verify that we have exited the idle mode
verify(mockLoadBalancerFactory).newLoadBalancer(any(Helper.class));
assertFalse(channel.inUseStateAggregator.isInUse());
// Move closer to idleness, but not yet.
timer.forwardTime(IDLE_TIMEOUT_SECONDS - 1, TimeUnit.SECONDS);
verify(mockLoadBalancer, never()).shutdown();
assertFalse(channel.inUseStateAggregator.isInUse());
// A new call would refresh the timer
call = channel.newCall(method, CallOptions.DEFAULT);
call.start(mockCallListener, new Metadata());
call.cancel("For testing", null);
assertFalse(channel.inUseStateAggregator.isInUse());
// ... so that passing the same length of time will not trigger idle mode
timer.forwardTime(IDLE_TIMEOUT_SECONDS - 1, TimeUnit.SECONDS);
verify(mockLoadBalancer, never()).shutdown();
assertFalse(channel.inUseStateAggregator.isInUse());
// ... until the time since last call has reached the timeout
timer.forwardTime(1, TimeUnit.SECONDS);
verify(mockLoadBalancer).shutdown();
assertFalse(channel.inUseStateAggregator.isInUse());
// Drain the app executor, which runs the call listeners
verify(mockCallListener, never()).onClose(any(Status.class), any(Metadata.class));
assertEquals(2, executor.runDueTasks());
verify(mockCallListener, times(2)).onClose(any(Status.class), any(Metadata.class));
}
示例15: newLoadBalancer
import io.grpc.LoadBalancer.Helper; //導入依賴的package包/類
@Override
public LoadBalancer newLoadBalancer(Helper helper) {
return new GrpcRoundRobinLoadBalancer(helper);
}