use of org.apache.servicecomb.core.Invocation in project java-chassis by ServiceComb.
the class TestSessionSticknessRule method testRuleFullOperation.
@Test
public void testRuleFullOperation() {
SessionStickinessRule rule = new SessionStickinessRule();
LoadBalancer mockedLb = mock(LoadBalancer.class);
Transport transport = mock(Transport.class);
MicroserviceInstance instance1 = new MicroserviceInstance();
instance1.setInstanceId("1234");
ServiceCombServer mockedServer = new ServiceCombServer(null, transport, new CacheEndpoint("rest:127.0.0.1:8889", instance1));
Invocation invocation = mock(Invocation.class);
LoadBalancerStats stats = mock(LoadBalancerStats.class);
Mockito.when(mockedLb.getLoadBalancerStats()).thenReturn(stats);
Deencapsulation.invoke(rule, "chooseServerWhenTimeout", Arrays.asList(mockedServer), invocation);
mockedServer.setAlive(true);
mockedServer.setReadyToServe(true);
List<ServiceCombServer> allServers = Arrays.asList(mockedServer);
rule.setLoadBalancer(mockedLb);
Server s = rule.choose(allServers, invocation);
Assert.assertEquals(s, mockedServer);
s = rule.choose(allServers, invocation);
Assert.assertEquals(s, mockedServer);
}
use of org.apache.servicecomb.core.Invocation in project java-chassis by ServiceComb.
the class TestSessionSticknessRule method testServerWithoutTimeoutAndWithThreshold.
@Test
public void testServerWithoutTimeoutAndWithThreshold() {
boolean status = true;
SessionStickinessRule ss = new SessionStickinessRule();
Invocation invocation = mock(Invocation.class);
ServiceCombServer server = mock(ServiceCombServer.class);
List<ServiceCombServer> servers = new ArrayList<>();
servers.add(server);
Deencapsulation.setField(ss, "lastServer", server);
new MockUp<SessionStickinessRule>() {
@Mock
private boolean isTimeOut() {
return false;
}
};
new MockUp<SessionStickinessRule>() {
@Mock
private boolean isErrorThresholdMet() {
return true;
}
};
try {
ss.choose(servers, invocation);
} catch (Exception e) {
status = false;
}
Assert.assertTrue(status);
}
use of org.apache.servicecomb.core.Invocation in project java-chassis by ServiceComb.
the class ZipkinProviderDelegateTest method testGetterOnGetOtherContent.
@Test
public void testGetterOnGetOtherContent() {
Getter<Invocation, String> getter = Deencapsulation.getField(ZipkinProviderDelegate.class, "INVOCATION_STRING_GETTER");
Invocation invocation = Mockito.mock(Invocation.class);
Map<String, String> context = new HashMap<>();
Mockito.when(invocation.getContext()).thenReturn(context);
final String key = "key";
String value = getter.get(invocation, key);
Assert.assertNull(value);
final String expectedValue = "value";
context.put(key, expectedValue);
value = getter.get(invocation, key);
Assert.assertEquals(expectedValue, value);
}
use of org.apache.servicecomb.core.Invocation in project java-chassis by ServiceComb.
the class SlowInvocationLogger method onInvocationFinish.
@Subscribe
@AllowConcurrentEvents
public void onInvocationFinish(InvocationFinishEvent event) {
Invocation invocation = event.getInvocation();
OperationConfig operationConfig = invocation.getOperationMeta().getConfig();
if (!operationConfig.isSlowInvocationEnabled() || invocation.getInvocationStageTrace().calcTotalTime() < operationConfig.getNanoSlowInvocation()) {
return;
}
if (!invocation.isConsumer()) {
logSlowProducer(invocation, event.getResponse(), operationConfig);
return;
}
if (invocation.isEdge()) {
logSlowEdge(invocation, event.getResponse(), operationConfig);
return;
}
logSlowConsumer(invocation, event.getResponse(), operationConfig);
}
use of org.apache.servicecomb.core.Invocation in project java-chassis by ServiceComb.
the class TestVertxRestTransport method testSendException.
@Test
public void testSendException() {
boolean validAssert;
Invocation invocation = Mockito.mock(Invocation.class);
AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
URIEndpointObject endpoint = Mockito.mock(URIEndpointObject.class);
Endpoint end = Mockito.mock(Endpoint.class);
Mockito.when(invocation.getEndpoint()).thenReturn(end);
Mockito.when(invocation.getEndpoint().getAddress()).thenReturn(endpoint);
try {
validAssert = true;
instance.send(invocation, asyncResp);
} catch (Exception e) {
validAssert = false;
}
Assert.assertFalse(validAssert);
}
Aggregations