Search in sources :

Example 1 with Supplier

use of com.tencent.polaris.api.plugin.Supplier in project polaris-java by polarismesh.

the class APIFactoryTest method testInitContextByConfig.

@Test
public void testInitContextByConfig() {
    SDKContext sdkContext = null;
    try {
        sdkContext = APIFactory.initContextByConfig(TestUtils.createSimpleConfiguration(8888));
        Supplier plugins = sdkContext.getPlugins();
        Plugin plugin = plugins.getPlugin(PluginTypes.LOAD_BALANCER.getBaseType(), LoadBalanceConfig.LOAD_BALANCE_WEIGHTED_RANDOM);
        Assert.assertNotNull(plugin);
    } catch (PolarisException e) {
        Assert.fail(e.getMessage());
    } finally {
        if (null != sdkContext) {
            sdkContext.destroy();
        }
    }
}
Also used : SDKContext(com.tencent.polaris.client.api.SDKContext) PolarisException(com.tencent.polaris.api.exception.PolarisException) Supplier(com.tencent.polaris.api.plugin.Supplier) Plugin(com.tencent.polaris.api.plugin.Plugin) Test(org.junit.Test)

Example 2 with Supplier

use of com.tencent.polaris.api.plugin.Supplier in project polaris-java by polarismesh.

the class APIFactoryTest method testInitContextByFile.

@Test
public void testInitContextByFile() {
    InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream("conf/default.yaml");
    SDKContext sdkContext = null;
    try {
        sdkContext = APIFactory.initContextByFile(resourceAsStream);
        Supplier plugins = sdkContext.getPlugins();
        Plugin plugin = plugins.getPlugin(PluginTypes.CIRCUIT_BREAKER.getBaseType(), DefaultPlugins.CIRCUIT_BREAKER_ERROR_COUNT);
        Assert.assertNotNull(plugin);
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    } finally {
        if (null != sdkContext) {
            sdkContext.destroy();
        }
    }
}
Also used : SDKContext(com.tencent.polaris.client.api.SDKContext) InputStream(java.io.InputStream) Supplier(com.tencent.polaris.api.plugin.Supplier) PolarisException(com.tencent.polaris.api.exception.PolarisException) Plugin(com.tencent.polaris.api.plugin.Plugin) Test(org.junit.Test)

Aggregations

PolarisException (com.tencent.polaris.api.exception.PolarisException)2 Plugin (com.tencent.polaris.api.plugin.Plugin)2 Supplier (com.tencent.polaris.api.plugin.Supplier)2 SDKContext (com.tencent.polaris.client.api.SDKContext)2 Test (org.junit.Test)2 InputStream (java.io.InputStream)1