use of org.apache.servicecomb.foundation.common.Holder in project java-chassis by ServiceComb.
the class DelayFaultTest method injectFaultSystemDelay.
@Test
public void injectFaultSystemDelay() throws InterruptedException {
ArchaiusUtils.setProperty("servicecomb.governance.Consumer._global.policy.fault.protocols.rest.delay.fixedDelay", "10");
ArchaiusUtils.setProperty("servicecomb.governance.Consumer._global.policy.fault.protocols.rest.delay.percent", "100");
assertEquals("10", DynamicProperty.getInstance("servicecomb.governance.Consumer._global.policy.fault.protocols.rest.delay.fixedDelay").getString());
assertEquals("100", DynamicProperty.getInstance("servicecomb.governance.Consumer._global.policy.fault.protocols.rest.delay.percent").getString());
DelayFault delayFault = new DelayFault();
FaultParam faultParam = new FaultParam(1);
Holder<String> resultHolder = new Holder<>();
CountDownLatch latch = new CountDownLatch(1);
delayFault.injectFault(invocation, faultParam, response -> {
resultHolder.value = response.getResult();
latch.countDown();
});
latch.await(10, TimeUnit.SECONDS);
AtomicLong count = FaultInjectionUtil.getOperMetTotalReq("restMicroserviceQualifiedName12");
assertEquals(1, count.get());
assertEquals("success", resultHolder.value);
}
use of org.apache.servicecomb.foundation.common.Holder in project java-chassis by ServiceComb.
the class TestFaultInjectHandler method testFaultInjectHandlerConfigChangeEvent1.
/**
* Tests the fault injection handler functionality with configuration change event for global level config.
*/
@Test
public void testFaultInjectHandlerConfigChangeEvent1() throws Exception {
System.setProperty("servicecomb.governance.Consumer._global.policy.fault.protocols.rest.delay.fixedDelay", "1");
System.setProperty("servicecomb.governance.Consumer._global.policy.fault.protocols.rest.delay.percent", "100");
System.setProperty("servicecomb.governance.Consumer._global.policy.fault.protocols.rest.abort.percent", "100");
System.setProperty("servicecomb.governance.Consumer._global.policy.fault.protocols.rest.abort.httpStatus", "420");
Mockito.when(invocation.getMicroserviceQualifiedName()).thenReturn("MicroserviceQualifiedName7");
Mockito.when(invocation.getTransport()).thenReturn(transport);
Mockito.when(transport.getName()).thenReturn("rest");
Mockito.when(invocation.getOperationName()).thenReturn("sayBye1");
Mockito.when(invocation.getSchemaId()).thenReturn("testSchema1");
Mockito.when(invocation.getMicroserviceName()).thenReturn("carts1");
boolean validAssert;
List<Fault> faultInjectionFeatureList = Arrays.asList(delayFault, abortFault);
handler.setFaultFeature(faultInjectionFeatureList);
try {
validAssert = true;
handler.handle(invocation, ar);
} catch (Exception e) {
validAssert = false;
}
Assert.assertTrue(validAssert);
ArchaiusUtils.setProperty("servicecomb.governance.Consumer._global.policy.fault.protocols.rest.delay.fixedDelay", 500);
ArchaiusUtils.setProperty("servicecomb.governance.Consumer._global.policy.fault.protocols.rest.abort.httpStatus", 421);
Holder<Boolean> isAsserted = new Holder<>(false);
handler.handle(invocation, ar -> {
isAsserted.value = true;
assertTrue(response.isFailed());
});
Assert.assertTrue(isAsserted.value);
System.getProperties().remove("servicecomb.governance.Consumer._global.policy.fault.protocols.rest.delay.fixedDelay");
System.getProperties().remove("servicecomb.governance.Consumer._global.policy.fault.protocols.rest.delay.percent");
System.getProperties().remove("servicecomb.governance.Consumer._global.policy.fault.protocols.rest.abort.percent");
System.getProperties().remove("servicecomb.governance.Consumer._global.policy.fault.protocols.rest.abort.httpStatus");
AtomicLong count = FaultInjectionUtil.getOperMetTotalReq("restMicroserviceQualifiedName7");
assertEquals(3, count.get());
}
use of org.apache.servicecomb.foundation.common.Holder in project java-chassis by ServiceComb.
the class TestCseClientHttpRequest method testNormal.
@Test
public void testNormal() {
Holder<Invocation> holder = new Holder<>();
CseClientHttpRequest client = new CseClientHttpRequest(URI.create("cse://defaultMicroservice/" + SpringmvcImpl.class.getSimpleName() + "/bytes"), HttpMethod.POST) {
/**
* {@inheritDoc}
*/
@Override
protected Response doInvoke(Invocation invocation) {
holder.value = invocation;
return Response.ok("result");
}
};
byte[] body = "abc".getBytes();
HttpHeaders headers = new HttpHeaders();
headers.add("token", "123");
client.setRequestBody(body);
client.setHttpHeaders(headers);
client.execute();
Assert.assertArrayEquals(body, (byte[]) holder.value.getInvocationArguments().get("input"));
Assert.assertEquals("123", holder.value.getInvocationArguments().get("token"));
}
use of org.apache.servicecomb.foundation.common.Holder in project java-chassis by ServiceComb.
the class TestInstanceCacheCheckerMock method createFindServiceInstancesResult.
private Holder<MicroserviceInstances> createFindServiceInstancesResult() {
MicroserviceInstances microserviceInstances = new MicroserviceInstances();
microserviceInstances.setNeedRefresh(true);
microserviceInstances.setRevision("first");
FindInstancesResponse findInstancesResponse = new FindInstancesResponse();
findInstancesResponse.setInstances(new ArrayList<>());
microserviceInstances.setInstancesResponse(findInstancesResponse);
Holder<MicroserviceInstances> findHolder = new Holder<>();
findHolder.value = microserviceInstances;
return findHolder;
}
use of org.apache.servicecomb.foundation.common.Holder in project java-chassis by ServiceComb.
the class HighwayServerInvoke 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;
sendResponse(header.getContext(), response);
});
} catch (Exception e) {
LOGGER.error("failed to execute ProviderQpsFlowControlHandler", e);
qpsFlowControlReject.value = true;
sendResponse(header.getContext(), Response.providerFailResp(e));
}
}
return qpsFlowControlReject;
}
Aggregations