本文整理匯總了Java中com.netflix.loadbalancer.Server類的典型用法代碼示例。如果您正苦於以下問題:Java Server類的具體用法?Java Server怎麽用?Java Server使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Server類屬於com.netflix.loadbalancer包,在下文中一共展示了Server類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: choose
import com.netflix.loadbalancer.Server; //導入依賴的package包/類
@Override
public Server choose(Object key) {
//使用一致性哈希進行分發
//TODO 此處使用了GUAVA中簡單的一致性哈希算法選擇服務,但這裏存在性能缺陷:當reachableServers中間某一個服務節點失效了
//那麽後續節點的一致性哈希結果將會不匹配,後續需要使用更完善的哈希環 加上 虛擬節點 的形式解決本問題
List<Server> reachableServers = getLoadBalancer().getReachableServers();
if(reachableServers != null && reachableServers.size() != 0){
int serverSeq = Hashing.consistentHash(Thread.currentThread().getId(), reachableServers.size());
return reachableServers.get(serverSeq);
} else {
return super.choose(key);
}
}
示例2: getInitialListOfServers
import com.netflix.loadbalancer.Server; //導入依賴的package包/類
@Override
public List<Server> getInitialListOfServers() {
DiscoveryContext context = new DiscoveryContext();
context.setInputParameters(serviceId);
VersionedCache serversVersionedCache = discoveryTree.discovery(context,
RegistryUtils.getAppId(),
serviceId,
DefinitionConst.VERSION_RULE_ALL);
Map<String, MicroserviceInstance> servers = serversVersionedCache.data();
List<Server> instances = new ArrayList<>(servers.size());
for (MicroserviceInstance s : servers.values()) {
for (String endpoint : s.getEndpoints()) {
URIEndpointObject uri = new URIEndpointObject(endpoint);
instances.add(new Server(uri.getHostOrIp(), uri.getPort()));
}
}
return instances;
}
示例3: choose
import com.netflix.loadbalancer.Server; //導入依賴的package包/類
@Override
public Server choose(Object key) {
if (lastServer == null) {
return chooseInitialServer(key);
}
if (isTimeOut()) {
LOG.warn("session timeout. choose another server.");
return chooseServerWhenTimeout(key);
} else {
this.lastAccessedTime = System.currentTimeMillis();
}
if (isErrorThresholdMet()) {
LOG.warn("reached max error. choose another server.");
errorThresholdMet = true;
return chooseServerErrorThresholdMet(key);
}
return lastServer;
}
示例4: testLoadBalancerFullOperationWithoutException
import com.netflix.loadbalancer.Server; //導入依賴的package包/類
@Test
public void testLoadBalancerFullOperationWithoutException() {
List<Server> newServers = new ArrayList<>();
Server server = Mockito.mock(Server.class);
newServers.add(server);
loadBalancer.setServerList(newServers);
loadBalancer.chooseServer();
Object key = Mockito.mock(Object.class);
loadBalancer.chooseServer(key);
loadBalancer.getAllServers();
loadBalancer.getServerList(true);
loadBalancer.getServerList(false);
loadBalancer.getLoadBalancerStats();
loadBalancer.getReachableServers();
assertNotNull(loadBalancer.getAllServers());
}
示例5: testAddServerException
import com.netflix.loadbalancer.Server; //導入依賴的package包/類
@Test
public void testAddServerException() {
boolean status = true;
List<Server> newServers = new ArrayList<>();
Server server = Mockito.mock(Server.class);
newServers.add(server);
try {
loadBalancer.addServers(newServers);
} catch (Exception e) {
status = false;
Assert.assertEquals("Not implemented.", e.getMessage());
}
Assert.assertFalse(status);
}
示例6: testServerListException
import com.netflix.loadbalancer.Server; //導入依賴的package包/類
@Test
public void testServerListException() {
boolean status = true;
List<Server> newServers = new ArrayList<>();
Server server = Mockito.mock(Server.class);
newServers.add(server);
try {
loadBalancer.getServerList(ServerGroup.ALL);
} catch (Exception e) {
status = false;
Assert.assertEquals("Not implemented.", e.getMessage());
}
Assert.assertFalse(status);
}
示例7: testMarkServerDownException
import com.netflix.loadbalancer.Server; //導入依賴的package包/類
@Test
public void testMarkServerDownException() {
boolean status = true;
List<Server> newServers = new ArrayList<>();
Server server = Mockito.mock(Server.class);
newServers.add(server);
try {
loadBalancer.markServerDown(server);
} catch (Exception e) {
status = false;
Assert.assertEquals("Not implemented.", e.getMessage());
}
Assert.assertFalse(status);
}
示例8: testSetIsolationFilter
import com.netflix.loadbalancer.Server; //導入依賴的package包/類
@Test
public void testSetIsolationFilter() {
Invocation invocation = Mockito.mock(Invocation.class);
Mockito.when(invocation.getMicroserviceName()).thenReturn("test");
LoadbalanceHandler lbHandler = new LoadbalanceHandler();
LoadBalancer myLB = new LoadBalancer("loadBalancerName", rule);
lbHandler.setIsolationFilter(myLB, "abc");
Assert.assertEquals(1, myLB.getFilterSize());
Mockito.when(invocation.getMicroserviceName()).thenReturn("abc");
myLB = new LoadBalancer("loadBalancerName", rule);
lbHandler.setIsolationFilter(myLB, "abc");
myLB.setInvocation(invocation);
Assert.assertEquals(1, myLB.getFilterSize());
Map<String, ServerListFilterExt> filters = Deencapsulation.getField(myLB, "filters");
List<Server> servers = new ArrayList<>();
servers.add(new Server(null));
Assert.assertEquals(servers.size(),
filters.get("org.apache.servicecomb.loadbalance.filter.IsolationServerListFilter")
.getFilteredListOfServers(servers)
.size());
}
示例9: testRuleFullOperation
import com.netflix.loadbalancer.Server; //導入依賴的package包/類
@Test
public void testRuleFullOperation() {
SessionStickinessRule rule = new SessionStickinessRule();
LoadBalancer mockedLb = mock(LoadBalancer.class);
Transport transport = mock(Transport.class);
CseServer mockedServer = new CseServer(transport, new CacheEndpoint("rest:127.0.0.1:8889", null));
Object key = Mockito.mock(Object.class);
LoadBalancerStats stats = mock(LoadBalancerStats.class);
Mockito.when(mockedLb.getLoadBalancerStats()).thenReturn(stats);
Deencapsulation.invoke(rule, "chooseServerWhenTimeout", key);
mockedServer.setAlive(true);
mockedServer.setReadyToServe(true);
List<Server> allServers = Arrays.asList(mockedServer);
when(mockedLb.getReachableServers()).thenReturn(allServers);
when(mockedLb.getAllServers()).thenReturn(allServers);
rule.setLoadBalancer(mockedLb);
Assert.assertEquals(rule.getLoadBalancer(), mockedLb);
Server s = rule.choose("default");
Assert.assertEquals(s, mockedServer);
s = rule.choose("default");
Assert.assertEquals(s, mockedServer);
}
示例10: testServerWithActualServerObj
import com.netflix.loadbalancer.Server; //導入依賴的package包/類
@Test
public void testServerWithActualServerObj() {
boolean status = true;
SessionStickinessRule ss = new SessionStickinessRule();
Object key = new Object();
Server s = new Server("test");
Deencapsulation.setField(ss, "lastServer", s);
try {
ss.choose(key);
} catch (Exception e) {
status = false;
}
Assert.assertTrue(status);
}
示例11: testGetFilteredListOfServers
import com.netflix.loadbalancer.Server; //導入依賴的package包/類
@Test
public void testGetFilteredListOfServers() {
Invocation invocation = Mockito.mock(Invocation.class);
CseServer testServer = Mockito.mock(CseServer.class);
Mockito.when(invocation.getMicroserviceName()).thenReturn("microserviceName");
Mockito.when(testServer.getLastVisitTime()).thenReturn(System.currentTimeMillis());
List<Server> serverList = new ArrayList<>();
serverList.add(testServer);
IsolationServerListFilter.setLoadBalancerStats(loadBalancerStats);
IsolationServerListFilter.setInvocation(invocation);
List<Server> returnedServerList = IsolationServerListFilter.getFilteredListOfServers(serverList);
Assert.assertEquals(returnedServerList.size(), 1);
loadBalancerStats.incrementNumRequests(testServer);
loadBalancerStats.incrementNumRequests(testServer);
loadBalancerStats.incrementNumRequests(testServer);
loadBalancerStats.incrementSuccessiveConnectionFailureCount(testServer);
returnedServerList = IsolationServerListFilter.getFilteredListOfServers(serverList);
Assert.assertEquals(returnedServerList.size(), 0);
}
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:22,代碼來源:TestIsolationServerListFilter.java
示例12: testGetFilteredListOfServersOnContinuousFailureReachesThreshold
import com.netflix.loadbalancer.Server; //導入依賴的package包/類
@Test
public void testGetFilteredListOfServersOnContinuousFailureReachesThreshold() {
((AbstractConfiguration) DynamicPropertyFactory.getBackingConfigurationSource())
.addProperty("cse.loadbalance.isolation.continuousFailureThreshold",
"3");
Invocation invocation = Mockito.mock(Invocation.class);
CseServer testServer = Mockito.mock(CseServer.class);
Mockito.when(invocation.getMicroserviceName()).thenReturn("microserviceName");
Mockito.when(testServer.getCountinuousFailureCount()).thenReturn(3);
Mockito.when(testServer.getLastVisitTime()).thenReturn(System.currentTimeMillis());
for (int i = 0; i < 3; ++i) {
loadBalancerStats.incrementNumRequests(testServer);
}
List<Server> serverList = new ArrayList<>();
serverList.add(testServer);
IsolationServerListFilter.setLoadBalancerStats(loadBalancerStats);
IsolationServerListFilter.setInvocation(invocation);
List<Server> returnedServerList = IsolationServerListFilter.getFilteredListOfServers(serverList);
Assert.assertEquals(0, returnedServerList.size());
}
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:23,代碼來源:TestIsolationServerListFilter.java
示例13: testGetFilteredListOfServersOnContinuousFailureIsBelowThreshold
import com.netflix.loadbalancer.Server; //導入依賴的package包/類
@Test
public void testGetFilteredListOfServersOnContinuousFailureIsBelowThreshold() {
((AbstractConfiguration) DynamicPropertyFactory.getBackingConfigurationSource())
.addProperty("cse.loadbalance.isolation.continuousFailureThreshold",
"3");
Invocation invocation = Mockito.mock(Invocation.class);
CseServer testServer = Mockito.mock(CseServer.class);
Mockito.when(invocation.getMicroserviceName()).thenReturn("microserviceName");
Mockito.when(testServer.getCountinuousFailureCount()).thenReturn(2);
Mockito.when(testServer.getLastVisitTime()).thenReturn(System.currentTimeMillis());
for (int i = 0; i < 3; ++i) {
loadBalancerStats.incrementNumRequests(testServer);
}
List<Server> serverList = new ArrayList<>();
serverList.add(testServer);
IsolationServerListFilter.setLoadBalancerStats(loadBalancerStats);
IsolationServerListFilter.setInvocation(invocation);
List<Server> returnedServerList = IsolationServerListFilter.getFilteredListOfServers(serverList);
Assert.assertEquals(1, returnedServerList.size());
}
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:23,代碼來源:TestIsolationServerListFilter.java
示例14: doApply
import com.netflix.loadbalancer.Server; //導入依賴的package包/類
/**
* {@inheritDoc}
*/
@Override
protected boolean doApply(PredicateKey input) {
Server server = input.getServer();
String expected = current().get(zoneEntryKey);
String actual = server.getZone();
boolean accept = expected != null && expected.equals(actual);
log.trace("Expected [{}={}] vs {}:{}[zone={}] => {}",
zoneEntryKey,
expected,
server.getHostPort(),
server.getMetaInfo().getAppName(),
actual,
accept);
return accept;
}
示例15: updateLoadBalancer
import com.netflix.loadbalancer.Server; //導入依賴的package包/類
private void updateLoadBalancer(List<Server> newServers) {
if (serviceServers == null) {
serviceServers = new HashSet<Server>();
}
if (newServers == null) {
newServers = new ArrayList<Server>();
}
//return if nothing changed
if ((serviceServers.isEmpty() && newServers.isEmpty())
|| (newServers.size() == serviceServers.size() && serviceServers.containsAll(newServers))) {
return;
}
serviceServers = new HashSet<Server>(newServers);
loadBalancerModificationLock.writeLock().lock();
if (loadBalancer != null) {
loadBalancer.shutdown();
}
loadBalancer = LoadBalancerBuilder.newBuilder().buildFixedServerListLoadBalancer(newServers);
for (EndpointClientCollection<?> lb : endpointMap.values()) {
lb.updateServers(newServers);
}
loadBalancerModificationLock.writeLock().unlock();
}