use of org.apache.servicecomb.foundation.common.exceptions.ServiceCombException in project java-chassis by ServiceComb.
the class ZoneAwareDiscoveryFilter method findChildName.
@Override
protected String findChildName(DiscoveryContext context, DiscoveryTreeNode parent) {
String key = context.getContextParameter(KEY_ZONE_AWARE_STEP);
if (key == null) {
key = GROUP_RegionAndAZMatch;
context.pushRerunFilter();
} else if (GROUP_RegionAndAZMatch.equals(key)) {
key = GROUP_InstancesAZMatch;
context.pushRerunFilter();
} else if (GROUP_InstancesAZMatch.equals(key)) {
key = GROUP_InstancesNoMatch;
context.pushRerunFilter();
} else if (GROUP_InstancesNoMatch.equals(key)) {
key = GROUP_Instances_All;
} else {
throw new ServiceCombException("not possible happen, maybe a bug.");
}
context.putContextParameter(KEY_ZONE_AWARE_STEP, key);
return key;
}
use of org.apache.servicecomb.foundation.common.exceptions.ServiceCombException in project java-chassis by ServiceComb.
the class QpsControllerManager method chooseStrategy.
private AbstractQpsStrategy chooseStrategy(String configKey, Long limit, Long bucket, String strategyName) {
if (StringUtils.isEmpty(strategyName)) {
strategyName = "FixedWindow";
}
AbstractQpsStrategy strategy = null;
List<IStrategyFactory> strategyFactories = SPIServiceUtils.getOrLoadSortedService(IStrategyFactory.class);
for (IStrategyFactory strategyFactory : strategyFactories) {
strategy = strategyFactory.createStrategy(strategyName);
if (strategy != null) {
break;
}
}
if (strategy == null) {
throw new ServiceCombException("the qps strategy name " + strategyName + " is not exist , please check.");
}
strategy.setKey(configKey);
strategy.setQpsLimit(limit);
strategy.setBucketLimit(bucket);
return strategy;
}
use of org.apache.servicecomb.foundation.common.exceptions.ServiceCombException in project java-chassis by ServiceComb.
the class TestInvocationToHttpServletRequest method testGetPathInfoException.
@Test
public void testGetPathInfoException(@Mocked URLPathBuilder builder) throws Exception {
new Expectations() {
{
swaggerOperation.getPathBuilder();
result = builder;
builder.createPathString(args);
result = new Exception("error");
}
};
try {
request.getPathInfo();
Assert.fail("must throw exception");
} catch (ServiceCombException e) {
Assert.assertEquals("Failed to get path info.", e.getMessage());
Assert.assertEquals("error", e.getCause().getMessage());
}
}
use of org.apache.servicecomb.foundation.common.exceptions.ServiceCombException in project incubator-servicecomb-java-chassis by apache.
the class TestMicroservicePaths method testAddResourceStaticDuplicatedHttpMethod.
@Test
public void testAddResourceStaticDuplicatedHttpMethod() {
RestOperationMeta staticResPost = UnitTestRestUtils.createRestOperationMeta("POST", "/static");
MicroservicePaths paths = new MicroservicePaths();
paths.addResource(staticResPost);
try {
paths.addResource(staticResPost);
Assert.fail("must throw exception");
} catch (ServiceCombException e) {
Assert.assertEquals("operation with url /static, method POST is duplicated.", e.getMessage());
}
}
use of org.apache.servicecomb.foundation.common.exceptions.ServiceCombException in project incubator-servicecomb-java-chassis by apache.
the class TestInvocationToHttpServletRequest method testGetPathInfoException.
@Test
public void testGetPathInfoException(@Mocked URLPathBuilder builder) throws Exception {
new Expectations() {
{
swaggerOperation.getPathBuilder();
result = builder;
builder.createPathString(args);
result = new Exception("error");
}
};
try {
request.getPathInfo();
Assert.fail("must throw exception");
} catch (ServiceCombException e) {
Assert.assertEquals("Failed to get path info.", e.getMessage());
Assert.assertEquals("error", e.getCause().getMessage());
}
}
Aggregations