Search in sources :

Example 16 with HaProvider

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

the class DefaultHaProviderTest method testActiveUrl.

@Test
public void testActiveUrl() {
    HaDescriptor descriptor = new DefaultHaDescriptor();
    HaProvider provider = new DefaultHaProvider(descriptor);
    ArrayList<String> urls = new ArrayList<String>();
    String url1 = "http://host1";
    urls.add(url1);
    String url2 = "http://host2";
    urls.add(url2);
    String url3 = "http://host3";
    urls.add(url3);
    String serviceName = "foo";
    provider.addHaService(serviceName, urls);
    assertEquals(url1, provider.getActiveURL(serviceName));
    provider.markFailedURL(serviceName, url1);
    assertEquals(url2, provider.getActiveURL(serviceName));
    provider.markFailedURL(serviceName, url2);
    assertEquals(url3, provider.getActiveURL(serviceName));
    provider.markFailedURL(serviceName, url3);
    assertEquals(url1, provider.getActiveURL(serviceName));
    provider.setActiveURL(serviceName, url3);
    assertEquals(url3, provider.getActiveURL(serviceName));
    provider.setActiveURL(serviceName, url2);
    assertEquals(url2, provider.getActiveURL(serviceName));
}
Also used : ArrayList(java.util.ArrayList) 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