Search in sources :

Example 11 with Endpoint

use of io.gravitee.definition.model.Endpoint in project gravitee-gateway by gravitee-io.

the class EndpointStatusDecoratorTest method testEndpointStatus_transitionallyDown.

@Test
public void testEndpointStatus_transitionallyDown() {
    Endpoint endpoint = createEndpoint();
    EndpointStatusDecorator manager = new EndpointStatusDecorator(endpoint);
    manager.updateStatus(true);
    manager.updateStatus(false);
    Assert.assertEquals(Endpoint.Status.TRANSITIONALLY_DOWN, endpoint.getStatus());
}
Also used : Endpoint(io.gravitee.definition.model.Endpoint) HttpEndpoint(io.gravitee.definition.model.endpoint.HttpEndpoint) Test(org.junit.Test)

Example 12 with Endpoint

use of io.gravitee.definition.model.Endpoint in project gravitee-gateway by gravitee-io.

the class EndpointStatusDecoratorTest method testEndpointStatus_scenario.

@Test
public void testEndpointStatus_scenario() {
    Endpoint endpoint = createEndpoint();
    EndpointStatusDecorator manager = new EndpointStatusDecorator(endpoint);
    Assert.assertEquals(Endpoint.Status.UP, endpoint.getStatus());
    manager.updateStatus(false);
    Assert.assertEquals(Endpoint.Status.TRANSITIONALLY_DOWN, endpoint.getStatus());
    manager.updateStatus(false);
    Assert.assertEquals(Endpoint.Status.TRANSITIONALLY_DOWN, endpoint.getStatus());
    manager.updateStatus(false);
    Assert.assertEquals(Endpoint.Status.DOWN, endpoint.getStatus());
    manager.updateStatus(true);
    Assert.assertEquals(Endpoint.Status.TRANSITIONALLY_UP, endpoint.getStatus());
    manager.updateStatus(false);
    Assert.assertEquals(Endpoint.Status.DOWN, endpoint.getStatus());
    manager.updateStatus(true);
    Assert.assertEquals(Endpoint.Status.TRANSITIONALLY_UP, endpoint.getStatus());
    manager.updateStatus(true);
    Assert.assertEquals(Endpoint.Status.UP, endpoint.getStatus());
    manager.updateStatus(false);
    Assert.assertEquals(Endpoint.Status.TRANSITIONALLY_DOWN, endpoint.getStatus());
}
Also used : Endpoint(io.gravitee.definition.model.Endpoint) HttpEndpoint(io.gravitee.definition.model.endpoint.HttpEndpoint) Test(org.junit.Test)

Example 13 with Endpoint

use of io.gravitee.definition.model.Endpoint in project gravitee-gateway by gravitee-io.

the class EndpointStatusDecoratorTest method testEndpointStatus_downAfterTransitionallyUp.

@Test
public void testEndpointStatus_downAfterTransitionallyUp() {
    Endpoint endpoint = createEndpoint();
    EndpointStatusDecorator manager = new EndpointStatusDecorator(endpoint);
    manager.updateStatus(false);
    manager.updateStatus(false);
    manager.updateStatus(false);
    Assert.assertEquals(Endpoint.Status.DOWN, endpoint.getStatus());
    manager.updateStatus(true);
    Assert.assertEquals(Endpoint.Status.TRANSITIONALLY_UP, endpoint.getStatus());
}
Also used : Endpoint(io.gravitee.definition.model.Endpoint) HttpEndpoint(io.gravitee.definition.model.endpoint.HttpEndpoint) Test(org.junit.Test)

Example 14 with Endpoint

use of io.gravitee.definition.model.Endpoint in project gravitee-gateway by gravitee-io.

the class EndpointStatusDecoratorTest method testEndpointStatus_noHealthCheckDone.

@Test
public void testEndpointStatus_noHealthCheckDone() {
    Endpoint endpoint = createEndpoint();
    Assert.assertEquals(Endpoint.Status.UP, endpoint.getStatus());
}
Also used : Endpoint(io.gravitee.definition.model.Endpoint) HttpEndpoint(io.gravitee.definition.model.endpoint.HttpEndpoint) Test(org.junit.Test)

Example 15 with Endpoint

use of io.gravitee.definition.model.Endpoint in project gravitee-gateway by gravitee-io.

the class HttpEndpointRuleHandlerTest method shouldValidateFromRoot.

@Test
public void shouldValidateFromRoot(TestContext context) throws InterruptedException {
    // Prepare HTTP endpoint
    stubFor(get(urlEqualTo("/")).willReturn(aResponse().withStatus(200).withBody("{\"status\": \"green\"}")));
    // Prepare
    EndpointRule rule = mock(EndpointRule.class);
    Endpoint endpoint = createEndpoint();
    endpoint.setTarget(endpoint.getTarget() + "/additional-but-unused-path-for-hc");
    when(rule.endpoint()).thenReturn(endpoint);
    io.gravitee.definition.model.services.healthcheck.Step step = new io.gravitee.definition.model.services.healthcheck.Step();
    Request request = new Request();
    request.setPath("/");
    request.setFromRoot(true);
    request.setMethod(HttpMethod.GET);
    step.setRequest(request);
    Response response = new Response();
    response.setAssertions(Collections.singletonList(Response.DEFAULT_ASSERTION));
    step.setResponse(response);
    when(rule.steps()).thenReturn(Collections.singletonList(step));
    HttpEndpointRuleHandler runner = new HttpEndpointRuleHandler(vertx, rule);
    Async async = context.async();
    // Verify
    runner.setStatusHandler(new Handler<EndpointStatus>() {

        @Override
        public void handle(EndpointStatus status) {
            Assert.assertTrue(status.isSuccess());
            async.complete();
        }
    });
    // Run
    runner.handle(null);
    // Wait until completion
    async.awaitSuccess();
}
Also used : EndpointRule(io.gravitee.gateway.services.healthcheck.EndpointRule) Request(io.gravitee.definition.model.services.healthcheck.Request) Step(io.gravitee.reporter.api.health.Step) Response(io.gravitee.definition.model.services.healthcheck.Response) EndpointStatus(io.gravitee.reporter.api.health.EndpointStatus) Endpoint(io.gravitee.definition.model.Endpoint) HttpEndpoint(io.gravitee.definition.model.endpoint.HttpEndpoint) Async(io.vertx.ext.unit.Async) Test(org.junit.Test)

Aggregations

Endpoint (io.gravitee.definition.model.Endpoint)17 HttpEndpoint (io.gravitee.definition.model.endpoint.HttpEndpoint)12 Test (org.junit.Test)10 DiscoveredEndpoint (io.gravitee.gateway.services.endpoint.discovery.consul.endpoint.DiscoveredEndpoint)3 URL (java.net.URL)3 Api (io.gravitee.gateway.handlers.api.definition.Api)2 List (java.util.List)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Event (io.gravitee.common.event.Event)1 EventListener (io.gravitee.common.event.EventListener)1 EventManager (io.gravitee.common.event.EventManager)1 GraviteeMapper (io.gravitee.definition.jackson.datatype.GraviteeMapper)1 Api (io.gravitee.definition.model.Api)1 EndpointType (io.gravitee.definition.model.EndpointType)1 HttpClientOptions (io.gravitee.definition.model.HttpClientOptions)1 EndpointDiscoveryProvider (io.gravitee.definition.model.services.discovery.EndpointDiscoveryProvider)1 EndpointDiscoveryService (io.gravitee.definition.model.services.discovery.EndpointDiscoveryService)1 ConsulEndpointDiscoveryConfiguration (io.gravitee.definition.model.services.discovery.consul.ConsulEndpointDiscoveryConfiguration)1 HealthCheckService (io.gravitee.definition.model.services.healthcheck.HealthCheckService)1 Request (io.gravitee.definition.model.services.healthcheck.Request)1