Search in sources :

Example 6 with ServiceCombException

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;
}
Also used : ServiceCombException(org.apache.servicecomb.foundation.common.exceptions.ServiceCombException)

Example 7 with ServiceCombException

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;
}
Also used : AbstractQpsStrategy(org.apache.servicecomb.qps.strategy.AbstractQpsStrategy) IStrategyFactory(org.apache.servicecomb.qps.strategy.IStrategyFactory) ServiceCombException(org.apache.servicecomb.foundation.common.exceptions.ServiceCombException)

Example 8 with ServiceCombException

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());
    }
}
Also used : Expectations(mockit.Expectations) ServiceCombException(org.apache.servicecomb.foundation.common.exceptions.ServiceCombException) ServiceCombException(org.apache.servicecomb.foundation.common.exceptions.ServiceCombException) Test(org.junit.Test)

Example 9 with ServiceCombException

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());
    }
}
Also used : RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) ServiceCombException(org.apache.servicecomb.foundation.common.exceptions.ServiceCombException) Test(org.junit.Test)

Example 10 with ServiceCombException

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());
    }
}
Also used : Expectations(mockit.Expectations) ServiceCombException(org.apache.servicecomb.foundation.common.exceptions.ServiceCombException) ServiceCombException(org.apache.servicecomb.foundation.common.exceptions.ServiceCombException) Test(org.junit.Test)

Aggregations

ServiceCombException (org.apache.servicecomb.foundation.common.exceptions.ServiceCombException)10 Test (org.junit.Test)3 HTTPServer (io.prometheus.client.exporter.HTTPServer)2 IOException (java.io.IOException)2 InetSocketAddress (java.net.InetSocketAddress)2 Expectations (mockit.Expectations)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 RestOperationMeta (org.apache.servicecomb.common.rest.definition.RestOperationMeta)1 AbstractQpsStrategy (org.apache.servicecomb.qps.strategy.AbstractQpsStrategy)1 IStrategyFactory (org.apache.servicecomb.qps.strategy.IStrategyFactory)1