use of org.apache.servicecomb.foundation.common.Holder in project incubator-servicecomb-java-chassis by apache.
the class TestLoadbalanceHandler method send_failed.
@Test
public void send_failed(@Injectable LoadBalancer loadBalancer) {
MicroserviceInstance instance1 = new MicroserviceInstance();
instance1.setInstanceId("1234");
CacheEndpoint cacheEndpoint = new CacheEndpoint("rest://localhost:8080", instance1);
ServiceCombServer server = new ServiceCombServer(null, restTransport, cacheEndpoint);
LoadBalancerStats stats = new LoadBalancerStats("test");
new Expectations(loadBalancer) {
{
loadBalancer.chooseServer(invocation);
result = server;
loadBalancer.getLoadBalancerStats();
result = stats;
}
};
sendResponse = Response.consumerFailResp(new SocketException());
Holder<Throwable> result = new Holder<>();
Deencapsulation.invoke(handler, "send", invocation, (AsyncResponse) resp -> {
result.value = (Throwable) resp.getResult();
}, loadBalancer);
Assert.assertEquals(1, loadBalancer.getLoadBalancerStats().getSingleServerStat(server).getSuccessiveConnectionFailureCount());
Assert.assertEquals("InvocationException: code=490;msg=CommonExceptionData [message=Unexpected consumer error, please check logs for details]", result.value.getMessage());
}
use of org.apache.servicecomb.foundation.common.Holder in project incubator-servicecomb-java-chassis by apache.
the class TestLoadbalanceHandler method send_failed2.
@Test
public void send_failed2(@Injectable LoadBalancer loadBalancer) {
MicroserviceInstance instance1 = new MicroserviceInstance();
instance1.setInstanceId("1234");
CacheEndpoint cacheEndpoint = new CacheEndpoint("rest://localhost:8080", instance1);
ServiceCombServer server = new ServiceCombServer(null, restTransport, cacheEndpoint);
LoadBalancerStats stats = new LoadBalancerStats("test");
new Expectations(loadBalancer) {
{
loadBalancer.chooseServer(invocation);
result = server;
loadBalancer.getLoadBalancerStats();
result = stats;
}
};
sendResponse = Response.create(Status.BAD_REQUEST, "send failed");
Holder<Throwable> result = new Holder<>();
Deencapsulation.invoke(handler, "send", invocation, (AsyncResponse) resp -> {
result.value = (Throwable) resp.getResult();
}, loadBalancer);
// InvocationException is not taken as a failure
Assert.assertEquals(0, loadBalancer.getLoadBalancerStats().getSingleServerStat(server).getSuccessiveConnectionFailureCount());
Assert.assertEquals("InvocationException: code=400;msg=send failed", result.value.getMessage());
}
use of org.apache.servicecomb.foundation.common.Holder in project incubator-servicecomb-java-chassis by apache.
the class AbstractRestInvocation method checkQpsFlowControl.
private Holder<Boolean> checkQpsFlowControl(OperationMeta operationMeta) {
Holder<Boolean> qpsFlowControlReject = new Holder<>(false);
@SuppressWarnings("deprecation") Handler providerQpsFlowControlHandler = operationMeta.getProviderQpsFlowControlHandler();
if (null != providerQpsFlowControlHandler) {
try {
providerQpsFlowControlHandler.handle(invocation, response -> {
qpsFlowControlReject.value = true;
produceProcessor = ProduceProcessorManager.INSTANCE.findDefaultJsonProcessor();
sendResponse(response);
});
} catch (Throwable e) {
LOGGER.error("failed to execute ProviderQpsFlowControlHandler", e);
qpsFlowControlReject.value = true;
sendFailResponse(e);
}
}
return qpsFlowControlReject;
}
use of org.apache.servicecomb.foundation.common.Holder in project incubator-servicecomb-java-chassis by apache.
the class TestVertxServerRequestToHttpServletRequest method setBodyBuffer.
@Test
public void setBodyBuffer() {
Holder<Buffer> bodyHolder = new Holder<>();
context = new MockUp<RoutingContext>() {
@Mock
HttpServerRequest request() {
return vertxRequest;
}
@Mock
void setBody(Buffer body) {
bodyHolder.value = body;
}
}.getMockInstance();
request = new VertxServerRequestToHttpServletRequest(context);
Buffer bodyBuffer = Buffer.buffer();
request.setBodyBuffer(bodyBuffer);
Assert.assertSame(bodyBuffer, bodyHolder.value);
Assert.assertSame(bodyBuffer, request.getBodyBuffer());
}
use of org.apache.servicecomb.foundation.common.Holder in project incubator-servicecomb-java-chassis by apache.
the class TestVertxUtils method testGetOrCreateVertx.
@Test
public void testGetOrCreateVertx() throws InterruptedException {
Vertx vertx = VertxUtils.getOrCreateVertxByName("ut", null);
Holder<String> name = new Holder<>();
CountDownLatch latch = new CountDownLatch(1);
vertx.runOnContext(v -> {
name.value = Thread.currentThread().getName();
latch.countDown();
});
latch.await();
Assert.assertEquals(name.value, "ut-vert.x-eventloop-thread-0");
VertxUtils.blockCloseVertxByName("ut");
}
Aggregations