Search in sources :

Example 1 with HaProvider

use of org.apache.knox.gateway.ha.provider.HaProvider in project knox by apache.

the class ServiceSchemeFunctionProcessorTest method setUp.

@Before
public void setUp() {
    reg = EasyMock.createNiceMock(ServiceRegistry.class);
    EasyMock.expect(reg.lookupServiceURL("test-cluster", "test-service")).andReturn("test-scheme://test-host:777/test-path").anyTimes();
    svc = EasyMock.createNiceMock(GatewayServices.class);
    EasyMock.expect(svc.getService(GatewayServices.SERVICE_REGISTRY_SERVICE)).andReturn(reg).anyTimes();
    env = EasyMock.createNiceMock(UrlRewriteEnvironment.class);
    EasyMock.expect(env.getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE)).andReturn(svc).anyTimes();
    EasyMock.expect(env.getAttribute(GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE)).andReturn("test-cluster").anyTimes();
    ctx = EasyMock.createNiceMock(UrlRewriteContext.class);
    desc = EasyMock.createNiceMock(ServiceSchemeFunctionDescriptor.class);
    HaProvider haProvider = EasyMock.createNiceMock(HaProvider.class);
    EasyMock.expect(env.getAttribute(HaServletContextListener.PROVIDER_ATTRIBUTE_NAME)).andReturn(haProvider).anyTimes();
    EasyMock.expect(haProvider.isHaEnabled(EasyMock.anyObject(String.class))).andReturn(Boolean.FALSE).anyTimes();
    EasyMock.replay(reg, svc, env, desc, ctx, haProvider);
}
Also used : UrlRewriteEnvironment(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteEnvironment) GatewayServices(org.apache.knox.gateway.services.GatewayServices) ServiceSchemeFunctionDescriptor(org.apache.knox.gateway.svcregfunc.api.ServiceSchemeFunctionDescriptor) ServiceRegistry(org.apache.knox.gateway.services.registry.ServiceRegistry) UrlRewriteContext(org.apache.knox.gateway.filter.rewrite.spi.UrlRewriteContext) HaProvider(org.apache.knox.gateway.ha.provider.HaProvider) Before(org.junit.Before)

Example 2 with HaProvider

use of org.apache.knox.gateway.ha.provider.HaProvider in project knox by apache.

the class ServiceAddressFunctionProcessorTest method setUp.

@Before
public void setUp() {
    reg = EasyMock.createNiceMock(ServiceRegistry.class);
    EasyMock.expect(reg.lookupServiceURL("test-cluster", "test-service")).andReturn("test-scheme://test-host:777/test-path").anyTimes();
    svc = EasyMock.createNiceMock(GatewayServices.class);
    EasyMock.expect(svc.getService(GatewayServices.SERVICE_REGISTRY_SERVICE)).andReturn(reg).anyTimes();
    env = EasyMock.createNiceMock(UrlRewriteEnvironment.class);
    EasyMock.expect(env.getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE)).andReturn(svc).anyTimes();
    EasyMock.expect(env.getAttribute(GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE)).andReturn("test-cluster").anyTimes();
    ctx = EasyMock.createNiceMock(UrlRewriteContext.class);
    desc = EasyMock.createNiceMock(ServiceAddressFunctionDescriptor.class);
    HaProvider haProvider = EasyMock.createNiceMock(HaProvider.class);
    EasyMock.expect(env.getAttribute(HaServletContextListener.PROVIDER_ATTRIBUTE_NAME)).andReturn(haProvider).anyTimes();
    EasyMock.expect(haProvider.isHaEnabled(EasyMock.anyObject(String.class))).andReturn(Boolean.FALSE).anyTimes();
    EasyMock.replay(reg, svc, env, desc, ctx, haProvider);
}
Also used : UrlRewriteEnvironment(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteEnvironment) ServiceAddressFunctionDescriptor(org.apache.knox.gateway.svcregfunc.api.ServiceAddressFunctionDescriptor) GatewayServices(org.apache.knox.gateway.services.GatewayServices) ServiceRegistry(org.apache.knox.gateway.services.registry.ServiceRegistry) UrlRewriteContext(org.apache.knox.gateway.filter.rewrite.spi.UrlRewriteContext) HaProvider(org.apache.knox.gateway.ha.provider.HaProvider) Before(org.junit.Before)

Example 3 with HaProvider

use of org.apache.knox.gateway.ha.provider.HaProvider in project knox by apache.

the class ServiceMappedAddressFunctionProcessorTest method setUp.

@Before
public void setUp() {
    hm = EasyMock.createNiceMock(HostMapper.class);
    EasyMock.expect(hm.resolveInboundHostName("test-host")).andReturn("test-internal-host").anyTimes();
    hms = EasyMock.createNiceMock(HostMapperService.class);
    EasyMock.expect(hms.getHostMapper("test-cluster")).andReturn(hm).anyTimes();
    reg = EasyMock.createNiceMock(ServiceRegistry.class);
    EasyMock.expect(reg.lookupServiceURL("test-cluster", "test-service")).andReturn("test-scheme://test-host:777/test-path").anyTimes();
    svc = EasyMock.createNiceMock(GatewayServices.class);
    EasyMock.expect(svc.getService(GatewayServices.SERVICE_REGISTRY_SERVICE)).andReturn(reg).anyTimes();
    EasyMock.expect(svc.getService(GatewayServices.HOST_MAPPING_SERVICE)).andReturn(hms).anyTimes();
    env = EasyMock.createNiceMock(UrlRewriteEnvironment.class);
    EasyMock.expect(env.getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE)).andReturn(svc).anyTimes();
    EasyMock.expect(env.getAttribute(GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE)).andReturn("test-cluster").anyTimes();
    ctx = EasyMock.createNiceMock(UrlRewriteContext.class);
    EasyMock.expect(ctx.getDirection()).andReturn(UrlRewriter.Direction.IN).anyTimes();
    desc = EasyMock.createNiceMock(ServiceMappedAddressFunctionDescriptor.class);
    HaProvider haProvider = EasyMock.createNiceMock(HaProvider.class);
    EasyMock.expect(env.getAttribute(HaServletContextListener.PROVIDER_ATTRIBUTE_NAME)).andReturn(haProvider).anyTimes();
    EasyMock.expect(haProvider.isHaEnabled(EasyMock.anyObject(String.class))).andReturn(Boolean.FALSE).anyTimes();
    EasyMock.replay(hm, hms, reg, svc, env, desc, ctx, haProvider);
}
Also used : UrlRewriteEnvironment(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteEnvironment) GatewayServices(org.apache.knox.gateway.services.GatewayServices) HostMapper(org.apache.knox.gateway.services.hostmap.HostMapper) ServiceMappedAddressFunctionDescriptor(org.apache.knox.gateway.svcregfunc.api.ServiceMappedAddressFunctionDescriptor) ServiceRegistry(org.apache.knox.gateway.services.registry.ServiceRegistry) HostMapperService(org.apache.knox.gateway.services.hostmap.HostMapperService) UrlRewriteContext(org.apache.knox.gateway.filter.rewrite.spi.UrlRewriteContext) HaProvider(org.apache.knox.gateway.ha.provider.HaProvider) Before(org.junit.Before)

Example 4 with HaProvider

use of org.apache.knox.gateway.ha.provider.HaProvider in project knox by apache.

the class ServiceMappedUrlFunctionProcessorTest method setUp.

@Before
public void setUp() {
    hm = EasyMock.createNiceMock(HostMapper.class);
    EasyMock.expect(hm.resolveInboundHostName("test-host")).andReturn("test-internal-host").anyTimes();
    hms = EasyMock.createNiceMock(HostMapperService.class);
    EasyMock.expect(hms.getHostMapper("test-cluster")).andReturn(hm).anyTimes();
    reg = EasyMock.createNiceMock(ServiceRegistry.class);
    EasyMock.expect(reg.lookupServiceURL("test-cluster", "test-service")).andReturn("test-scheme://test-host:777/test-path").anyTimes();
    svc = EasyMock.createNiceMock(GatewayServices.class);
    EasyMock.expect(svc.getService(GatewayServices.SERVICE_REGISTRY_SERVICE)).andReturn(reg).anyTimes();
    EasyMock.expect(svc.getService(GatewayServices.HOST_MAPPING_SERVICE)).andReturn(hms).anyTimes();
    env = EasyMock.createNiceMock(UrlRewriteEnvironment.class);
    EasyMock.expect(env.getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE)).andReturn(svc).anyTimes();
    EasyMock.expect(env.getAttribute(GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE)).andReturn("test-cluster").anyTimes();
    ctx = EasyMock.createNiceMock(UrlRewriteContext.class);
    EasyMock.expect(ctx.getDirection()).andReturn(UrlRewriter.Direction.IN).anyTimes();
    desc = EasyMock.createNiceMock(ServiceMappedUrlFunctionDescriptor.class);
    HaProvider haProvider = EasyMock.createNiceMock(HaProvider.class);
    EasyMock.expect(env.getAttribute(HaServletContextListener.PROVIDER_ATTRIBUTE_NAME)).andReturn(haProvider).anyTimes();
    EasyMock.expect(haProvider.isHaEnabled(EasyMock.anyObject(String.class))).andReturn(Boolean.FALSE).anyTimes();
    EasyMock.replay(hm, hms, reg, svc, env, desc, ctx, haProvider);
}
Also used : UrlRewriteEnvironment(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteEnvironment) GatewayServices(org.apache.knox.gateway.services.GatewayServices) HostMapper(org.apache.knox.gateway.services.hostmap.HostMapper) ServiceMappedUrlFunctionDescriptor(org.apache.knox.gateway.svcregfunc.api.ServiceMappedUrlFunctionDescriptor) ServiceRegistry(org.apache.knox.gateway.services.registry.ServiceRegistry) HostMapperService(org.apache.knox.gateway.services.hostmap.HostMapperService) UrlRewriteContext(org.apache.knox.gateway.filter.rewrite.spi.UrlRewriteContext) HaProvider(org.apache.knox.gateway.ha.provider.HaProvider) Before(org.junit.Before)

Example 5 with HaProvider

use of org.apache.knox.gateway.ha.provider.HaProvider in project knox by apache.

the class DefaultHaProviderTest method testDescriptor.

@Test
public void testDescriptor() {
    try {
        new DefaultHaProvider(null);
        fail("provider construction should have failed with null descriptor");
    } catch (IllegalArgumentException e) {
    }
    HaDescriptor descriptor = new DefaultHaDescriptor();
    HaProvider provider = new DefaultHaProvider(descriptor);
    assertNotNull(provider.getHaDescriptor());
    descriptor.addServiceConfig(new DefaultHaServiceConfig("foo"));
    assertTrue(provider.isHaEnabled("foo"));
}
Also used : HaDescriptor(org.apache.knox.gateway.ha.provider.HaDescriptor) HaProvider(org.apache.knox.gateway.ha.provider.HaProvider) Test(org.junit.Test)

Aggregations

HaProvider (org.apache.knox.gateway.ha.provider.HaProvider)16 UrlRewriteEnvironment (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteEnvironment)9 UrlRewriteContext (org.apache.knox.gateway.filter.rewrite.spi.UrlRewriteContext)9 GatewayServices (org.apache.knox.gateway.services.GatewayServices)9 ServiceRegistry (org.apache.knox.gateway.services.registry.ServiceRegistry)9 Before (org.junit.Before)9 HaDescriptor (org.apache.knox.gateway.ha.provider.HaDescriptor)7 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 IOException (java.io.IOException)4 URI (java.net.URI)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 FilterConfig (javax.servlet.FilterConfig)4 ServletContext (javax.servlet.ServletContext)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)4 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)4 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)4 BasicHttpParams (org.apache.http.params.BasicHttpParams)4