io.fabric8.kubernetes.api.model.Probe Java Examples

The following examples show how to use io.fabric8.kubernetes.api.model.Probe. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ThorntailV2HealthCheckEnricher.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
private Probe discoverThorntailHealthCheck(int initialDelay) {
    if (getContext().hasDependency(IO_THORNTAIL, "thorntail-kernel")) {
        // if there's thorntail-kernel, it's Thorntail v4
        return null;
    }

    if (getContext().hasDependency(IO_THORNTAIL, "monitor")
            || getContext().hasDependency(IO_THORNTAIL, "microprofile-health")) {
        Integer port = getPort();
        // scheme must be in upper case in k8s
        String scheme = getScheme().toUpperCase();
        String path = getPath();

        return new ProbeBuilder()
                 .withNewHttpGet().withNewPort(port).withPath(path).withScheme(scheme).endHttpGet()
                 .withFailureThreshold(getFailureThreshold())
                 .withSuccessThreshold(getSuccessThreshold())
                 .withInitialDelaySeconds(initialDelay).build();
    }
    return null;
}
 
Example #2
Source File: QuarkusHealthCheckEnricher.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
private Probe discoverQuarkusHealthCheck(int initialDelay) {
    if (!getContext().hasDependency("io.quarkus", "quarkus-smallrye-health")) {
        return null;
    }

    return new ProbeBuilder()
        .withNewHttpGet()
          .withNewPort(asInteger(getConfig(Config.port)))
          .withPath(getConfig(Config.path))
          .withScheme(getConfig(Config.scheme))
        .endHttpGet()
        .withFailureThreshold(asInteger(getConfig(Config.failureThreshold)))
        .withSuccessThreshold(asInteger(getConfig(Config.successThreshold)))
        .withInitialDelaySeconds(initialDelay)
        .build();
}
 
Example #3
Source File: AbstractHealthCheckEnricher.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
private String describe(Probe probe) {
    StringBuilder desc = new StringBuilder("probe");
    if (probe.getHttpGet() != null) {
        desc.append(" on port ");
        desc.append(probe.getHttpGet().getPort().getIntVal());
        desc.append(", path='");
        desc.append(probe.getHttpGet().getPath());
        desc.append("'");
        desc.append(", scheme='");
        desc.append(probe.getHttpGet().getScheme());
        desc.append("'");
    }
    if (probe.getInitialDelaySeconds() != null) {
        desc.append(", with initial delay ");
        desc.append(probe.getInitialDelaySeconds());
        desc.append(" seconds");
    }
    if (probe.getPeriodSeconds() != null) {
        desc.append(", with period ");
        desc.append(probe.getPeriodSeconds());
        desc.append(" seconds");
    }
    return desc.toString();
}
 
Example #4
Source File: ProbeCreator.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 6 votes vote down vote up
Probe create() {
	HTTPGetActionBuilder httpGetActionBuilder = new HTTPGetActionBuilder()
			.withPath(getProbePath())
			.withNewPort(getPort());

	List<HTTPHeader> httpHeaders = getHttpHeaders();

	if (!httpHeaders.isEmpty()) {
		httpGetActionBuilder.withHttpHeaders(httpHeaders);
	}

	return new ProbeBuilder()
			.withHttpGet(httpGetActionBuilder.build())
			.withTimeoutSeconds(getTimeout())
			.withInitialDelaySeconds(getInitialDelay())
			.withPeriodSeconds(getPeriod())
			.build();
}
 
Example #5
Source File: AbstractSpringBootHealthCheckEnricherTestSupport.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testDefaultInitialDelayForLivenessAndReadiness() {
    SpringBootHealthCheckEnricher enricher = new SpringBootHealthCheckEnricher(context);
    withProjectProperties(new Properties());

    new Expectations(){{
        context.getProjectClassLoaders();
        result = new ProjectClassLoaders(
                new URLClassLoader(new URL[0], AbstractSpringBootHealthCheckEnricherTestSupport.class.getClassLoader())) {
            @Override
            public boolean isClassInCompileClasspath(boolean all, String... clazz) {
                return true;
            }
        };
    }};


    Probe probe = enricher.getReadinessProbe();
    assertNotNull(probe);
    assertEquals(10, probe.getInitialDelaySeconds().intValue());

    probe = enricher.getLivenessProbe();
    assertNotNull(probe);
    assertEquals(180, probe.getInitialDelaySeconds().intValue());
}
 
Example #6
Source File: AbstractSpringBootHealthCheckEnricherTestSupport.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testWithServerPortAndManagementPortAndManagementContextPathAndServletPathAndActuatorDefaultBasePath() {
    SpringBootHealthCheckEnricher enricher = new SpringBootHealthCheckEnricher(context);
    Properties props = new Properties();
    props.put(propertyHelper.getServerPortPropertyKey(), "8282");
    props.put(propertyHelper.getManagementPortPropertyKey(), "8383");
    props.put(propertyHelper.getServerContextPathPropertyKey(), "/p1");
    props.put(propertyHelper.getManagementContextPathPropertyKey(), "/p2");
    props.put(propertyHelper.getServletPathPropertyKey(), "/servlet");
    props.put(propertyHelper.getActuatorBasePathPropertyKey(), "/p3");

    Probe probe = enricher.buildProbe(props, 10, null, null, 3, 1);
    assertNotNull(probe);
    assertNotNull(probe.getHttpGet());
    assertEquals("/p2/p3" + "/health", probe.getHttpGet().getPath());
    assertEquals(8383, probe.getHttpGet().getPort().getIntVal().intValue());
}
 
Example #7
Source File: WebAppHealthCeckEnricherTest.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void noEnrichmentIfNoPath() {

    // given

    WebAppHealthCheckEnricher enricher = new WebAppHealthCheckEnricher(context);
    setupExpectations(new HashMap<>());

    // when

    Probe probeLiveness = enricher.getLivenessProbe();
    Probe probeReadiness = enricher.getReadinessProbe();

    // then
    assertThat(probeLiveness).isNull();
    assertThat(probeReadiness).isNull();
}
 
Example #8
Source File: ContainerHandler.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
List<Container> getContainers(ResourceConfig config, List<ImageConfiguration> images)  {
    List<Container> ret = new ArrayList<>();

    for (ImageConfiguration imageConfig : images) {
        if (imageConfig.getBuildConfiguration() != null) {
            Probe livenessProbe = probeHandler.getProbe(config.getLiveness());
            Probe readinessProbe = probeHandler.getProbe(config.getReadiness());

            Container container = new ContainerBuilder()
                .withName(KubernetesResourceUtil.extractContainerName(this.groupArtifactVersion, imageConfig))
                .withImage(getImageName(imageConfig))
                .withImagePullPolicy(getImagePullPolicy(config))
                .withEnv(getEnvVars(config))
                .withSecurityContext(createSecurityContext(config))
                .withPorts(getContainerPorts(imageConfig))
                .withVolumeMounts(getVolumeMounts(config))
                .withLivenessProbe(livenessProbe)
                .withReadinessProbe(readinessProbe)
                .build();
            ret.add(container);
        }
    }
    return ret;
}
 
Example #9
Source File: VertxHealthCheckEnricherTest.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testDefaultConfiguration_Enabled() {
    VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);

    final Properties props = new Properties();
    props.put("vertx.health.path", "/ping");
    setupExpectations(props);

    Probe probe = enricher.getLivenessProbe();
    assertNotNull(probe);
    assertNull(probe.getHttpGet().getHost());
    assertEquals(probe.getHttpGet().getScheme(), "HTTP");
    assertEquals(probe.getHttpGet().getPort().getIntVal().intValue(), 8080);
    assertEquals(probe.getHttpGet().getPath(), "/ping");

    probe = enricher.getReadinessProbe();
    assertNotNull(probe);
    assertEquals(probe.getHttpGet().getScheme(), "HTTP");
    assertNull(probe.getHttpGet().getHost());
    assertEquals(probe.getHttpGet().getPort().getIntVal().intValue(), 8080);
    assertEquals(probe.getHttpGet().getPath(), "/ping");
}
 
Example #10
Source File: VertxHealthCheckEnricherTest.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testWithCustomConfigurationComingFromConf() {

    final Map<String, Object> config = createFakeConfig("{\"path\":\"health\",\"port\":\"1234\",\"scheme\":\"https\"}");

    setupExpectations(config);

    VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);

    Probe probe = enricher.getLivenessProbe();
    assertNotNull(probe);
    assertNull(probe.getHttpGet().getHost());
    assertEquals(probe.getHttpGet().getScheme(), "HTTPS");
    assertEquals(probe.getHttpGet().getPort().getIntVal().intValue(), 1234);
    assertEquals(probe.getHttpGet().getPath(), "/health");

    probe = enricher.getReadinessProbe();
    assertNotNull(probe);
    assertEquals(probe.getHttpGet().getScheme(), "HTTPS");
    assertNull(probe.getHttpGet().getHost());
    assertEquals(probe.getHttpGet().getPort().getIntVal().intValue(), 1234);
    assertEquals(probe.getHttpGet().getPath(), "/health");
}
 
Example #11
Source File: VertxHealthCheckEnricherTest.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testWithCustomConfigurationForLivenessAndReadinessComingFromConf() {
    final Map<String, Object> config = createFakeConfig(
            "{\"path\":\"health\",\"port\":\"1234\",\"scheme\":\"https\",\"readiness\":{\"path\":\"/ready\"}}");

    setupExpectations(config);

    VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);

    Probe probe = enricher.getLivenessProbe();
    assertNotNull(probe);
    assertNull(probe.getHttpGet().getHost());
    assertEquals(probe.getHttpGet().getScheme(), "HTTPS");
    assertEquals(probe.getHttpGet().getPort().getIntVal().intValue(), 1234);
    assertEquals(probe.getHttpGet().getPath(), "/health");

    probe = enricher.getReadinessProbe();
    assertNotNull(probe);
    assertEquals(probe.getHttpGet().getScheme(), "HTTPS");
    assertNull(probe.getHttpGet().getHost());
    assertEquals(probe.getHttpGet().getPort().getIntVal().intValue(), 1234);
    assertEquals(probe.getHttpGet().getPath(), "/ready");
}
 
Example #12
Source File: VertxHealthCheckEnricherTest.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testWithHttpHeaders() {
    final Map<String, Object> config = createFakeConfig("{\"path\":\"health\",\"headers\":{\"X-Header\":\"X\",\"Y-Header\":\"Y\"}}");

    setupExpectations(config);

    VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);

    Probe probe = enricher.getLivenessProbe();
    assertNotNull(probe);
    assertEquals(probe.getHttpGet().getPath(), "/health");
    assertThat(probe.getHttpGet().getPort().getIntVal()).isEqualTo(8080);
    assertThat(probe.getHttpGet().getHttpHeaders()).hasSize(2)
            .contains(new HTTPHeader("X-Header", "X"), new HTTPHeader("Y-Header", "Y"));

    probe = enricher.getReadinessProbe();
    assertNotNull(probe);
    assertEquals(probe.getHttpGet().getPath(), "/health");
    assertThat(probe.getHttpGet().getPort().getIntVal()).isEqualTo(8080);
    assertThat(probe.getHttpGet().getHttpHeaders()).hasSize(2)
            .contains(new HTTPHeader("X-Header", "X"), new HTTPHeader("Y-Header", "Y"));
}
 
Example #13
Source File: VertxHealthCheckEnricherTest.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testReadinessDisabledUsingConfig() {

    final Map<String, Object> config = createFakeConfig(
            "{\"readiness\":{\"path\":\"\"},\"path\":\"/ping\"}");

    setupExpectations(config);

    VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);

    Probe probe = enricher.getLivenessProbe();
    assertNotNull(probe);
    assertEquals(probe.getHttpGet().getPath(), "/ping");
    probe = enricher.getReadinessProbe();
    assertNull(probe);
}
 
Example #14
Source File: VertxHealthCheckEnricherTest.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testTCPSocketUsingConfig() {
    VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);

    final Map<String, Object> config = createFakeConfig(
            "{\"type\":\"tcp\",\"liveness\":{\"port\":\"1234\"},\"readiness\":{\"port\":\"1235\"}}");

    setupExpectations(config);

    Probe probe = enricher.getLivenessProbe();
    assertNotNull(probe);
    assertEquals(probe.getTcpSocket().getPort().getIntVal().intValue(), 1234);
    probe = enricher.getReadinessProbe();
    assertNotNull(probe);
    assertEquals(probe.getTcpSocket().getPort().getIntVal().intValue(), 1235);
}
 
Example #15
Source File: VertxHealthCheckEnricherTest.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testCustomConfiguration() {
    VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);

    final Properties props = new Properties();
    props.put("vertx.health.path", "/health");
    props.put("vertx.health.port", " 8081 ");
    props.put("vertx.health.scheme", " https");

    setupExpectations(props);

    Probe probe = enricher.getLivenessProbe();
    assertNotNull(probe);
    assertNull(probe.getHttpGet().getHost());
    assertThat(probe.getHttpGet().getScheme()).isEqualToIgnoringCase("https");
    assertEquals(probe.getHttpGet().getPort().getIntVal().intValue(), 8081);
    assertEquals(probe.getHttpGet().getPath(), "/health");

    probe = enricher.getReadinessProbe();
    assertNotNull(probe);
    assertThat(probe.getHttpGet().getScheme()).isEqualToIgnoringCase("https");
    assertNull(probe.getHttpGet().getHost());
    assertEquals(probe.getHttpGet().getPort().getIntVal().intValue(), 8081);
    assertEquals(probe.getHttpGet().getPath(), "/health");
}
 
Example #16
Source File: VertxHealthCheckEnricherTest.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testThatSpecificUserPropertiesOverrideGenericUserProperties() {
    VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);

    final Map<String, Object> config = createFakeConfig(
            "{\"path\":\"/ping\",\"type\":\"http\"}");
    Properties properties = new Properties();
    properties.put("vertx.health.readiness.type", "tcp");
    properties.put("vertx.health.readiness.port", "1234");
    properties.put("vertx.health.port", "1235");
    properties.put("vertx.health.liveness.type", "tcp");
    properties.put("vertx.health.liveness.port", "1236");
    setupExpectations(properties, config);

    Probe probe = enricher.getReadinessProbe();
    assertThat(probe).isNotNull();
    assertThat(probe.getTcpSocket()).isNotNull();
    assertThat(probe.getHttpGet()).isNull();
    assertThat(probe.getTcpSocket().getPort().getIntVal()).isEqualTo(1234);

    probe = enricher.getLivenessProbe();
    assertThat(probe).isNotNull();
    assertThat(probe.getHttpGet()).isNull();
    assertThat(probe.getTcpSocket()).isNotNull();
    assertThat(probe.getTcpSocket().getPort().getIntVal()).isEqualTo(1236);
}
 
Example #17
Source File: VertxHealthCheckEnricherTest.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testThatSpecificConfigOverrideGenericConfig() {
    VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);

    final Map<String, Object> config = createFakeConfig(
            "{\"liveness\":{\"path\":\"/live\"}," +
                    "\"readiness\":{\"path\":\"/ping\",\"port-name\":\"ready\"}," +
                    "\"path\":\"/health\",\"port-name\":\"health\"}");

    setupExpectations(config);

    Probe probe = enricher.getReadinessProbe();
    assertThat(probe).isNotNull();
    assertThat(probe.getHttpGet()).isNotNull();
    assertThat(probe.getHttpGet().getPort().getStrVal()).isEqualTo("ready");
    assertThat(probe.getHttpGet().getPath()).isEqualTo("/ping");

    probe = enricher.getLivenessProbe();
    assertThat(probe).isNotNull();
    assertThat(probe.getHttpGet()).isNotNull();
    assertThat(probe.getHttpGet().getPort().getStrVal()).isEqualTo("health");
    assertThat(probe.getHttpGet().getPath()).isEqualTo("/live");
}
 
Example #18
Source File: VertxHealthCheckEnricherTest.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testThatGenericUserPropertiesOverrideGenericConfig() {
    VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);

    final Map<String, Object> config = createFakeConfig(
            "{\"type\":\"exec\",\"command\":{\"arg\":\"ls\"}}"
    );
    Properties properties = new Properties();
    properties.put("vertx.health.type", "tcp");
    properties.put("vertx.health.port", "1234");

    setupExpectations(properties,config);

    Probe probe = enricher.getReadinessProbe();
    assertThat(probe).isNotNull();
    assertThat(probe.getTcpSocket()).isNotNull();
    assertThat(probe.getExec()).isNull();
    assertThat(probe.getTcpSocket().getPort().getIntVal()).isEqualTo(1234);

    probe = enricher.getLivenessProbe();
    assertThat(probe).isNotNull();
    assertThat(probe.getTcpSocket()).isNotNull();
    assertThat(probe.getExec()).isNull();
    assertThat(probe.getTcpSocket().getPort().getIntVal()).isEqualTo(1234);
}
 
Example #19
Source File: VertxHealthCheckEnricherTest.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testThatWeCanUSeDifferentTypesForLivenessAndReadiness() {
    VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);

    final Map<String, Object> config = createFakeConfig(
            "{\"liveness\":{" +
                    "\"type\":\"exec\",\"command\":{\"arg\":\"ls\"}" +
                    "},\"readiness\":{\"path\":\"/ping\"}}");
    setupExpectations(config);

    Probe probe = enricher.getLivenessProbe();
    assertNotNull(probe);
    assertNotNull(probe.getExec());
    probe = enricher.getReadinessProbe();
    assertNotNull(probe);
    assertNotNull(probe.getHttpGet());
}
 
Example #20
Source File: AbstractSpringBootHealthCheckEnricherTestSupport.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testWithServerPortAndManagementPortAndManagementContextPathAndActuatorDefaultBasePathSlash() {
    SpringBootHealthCheckEnricher enricher = new SpringBootHealthCheckEnricher(context);
    Properties props = new Properties();
    props.put(propertyHelper.getServerPortPropertyKey(), "8282");
    props.put(propertyHelper.getManagementPortPropertyKey(), "8383");
    props.put(propertyHelper.getServerContextPathPropertyKey(), "/p1");
    props.put(propertyHelper.getManagementContextPathPropertyKey(), "/");
    props.put(propertyHelper.getActuatorBasePathPropertyKey(), "/");

    Probe probe = enricher.buildProbe(props, 10, null, null, 3, 1);
    assertNotNull(probe);
    assertNotNull(probe.getHttpGet());
    assertEquals("/health", probe.getHttpGet().getPath());
    assertEquals(8383, probe.getHttpGet().getPort().getIntVal().intValue());
}
 
Example #21
Source File: VertxHealthCheckEnricherTest.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testExecUsingConfigReadinessDisabled() {
    VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);

    final Map<String, Object> config = createFakeConfig(
            "{\"type\":\"exec\"," +
                    "\"liveness\":{" +
                    "\"command\": {\"arg\":[\"/bin/sh\", \"-c\",\"touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 600\"]}}," +
                    "\"readiness\":{}" +
                    "}");

    setupExpectations(config);

    Probe probe = enricher.getLivenessProbe();
    assertThat(probe.getExec().getCommand()).hasSize(3);
    assertNotNull(probe);
    probe = enricher.getReadinessProbe();
    assertNull(probe);
}
 
Example #22
Source File: VertxHealthCheckEnricherTest.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testExecUsingConfigLivenessDisabled() {
    VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);

    final Map<String, Object> config = createFakeConfig(
            "{\"type\":\"exec\"," +
                    "\"readiness\":{" +
                    "\"command\": {\"arg\":[\"/bin/sh\", \"-c\",\"touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 600\"]}}," +
                    "\"liveness\":{}" +
                    "}");

    setupExpectations(config);

    Probe probe = enricher.getLivenessProbe();
    assertNull(probe);
    probe = enricher.getReadinessProbe();
    assertNotNull(probe);
    assertThat(probe.getExec().getCommand()).hasSize(3);
}
 
Example #23
Source File: VertxHealthCheckEnricherTest.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testExecUsingConfig() {
    VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);

    final Map<String, Object> config = createFakeConfig(
            "{\"type\":\"exec\"," +
                    "\"command\": {\"arg\":[\"/bin/sh\", \"-c\",\"touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 600\"]}" +
                    "}");
    setupExpectations(config);

    Probe probe = enricher.getLivenessProbe();
    assertNotNull(probe);
    assertThat(probe.getExec().getCommand()).hasSize(3);
    probe = enricher.getReadinessProbe();
    assertNotNull(probe);
    assertThat(probe.getExec().getCommand()).hasSize(3);
}
 
Example #24
Source File: KubeUtil.java    From enmasse with Apache License 2.0 6 votes vote down vote up
private static void applyDesiredProbeSettings(Probe actualProbe, Probe desiredProbe) {
    if (actualProbe != null && desiredProbe != null) {
        if (desiredProbe.getInitialDelaySeconds() != null) {
            actualProbe.setInitialDelaySeconds(desiredProbe.getInitialDelaySeconds());
        }

        if (desiredProbe.getPeriodSeconds() != null) {
            actualProbe.setPeriodSeconds(desiredProbe.getPeriodSeconds());
        }

        if (desiredProbe.getTimeoutSeconds() != null) {
            actualProbe.setTimeoutSeconds(desiredProbe.getTimeoutSeconds());
        }

        if (desiredProbe.getSuccessThreshold() != null) {
            actualProbe.setSuccessThreshold(desiredProbe.getSuccessThreshold());
        }

        if (desiredProbe.getFailureThreshold() != null) {
            actualProbe.setFailureThreshold(desiredProbe.getFailureThreshold());
        }
    }
}
 
Example #25
Source File: VertxHealthCheckEnricherTest.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testTCPSocketUsingUserPropertiesAndPortName() {
    VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);

    final Properties props = new Properties();
    props.put("vertx.health.type", "tcp");
    props.put("vertx.health.port-name", "health");
    props.put("vertx.health.readiness.port-name", "ready");
    setupExpectations(props);

    Probe probe = enricher.getLivenessProbe();
    assertNotNull(probe);
    assertEquals(probe.getTcpSocket().getPort().getStrVal(), "health");
    probe = enricher.getReadinessProbe();
    assertNotNull(probe);
    assertEquals(probe.getTcpSocket().getPort().getStrVal(), "ready");
}
 
Example #26
Source File: VertxHealthCheckEnricherTest.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testTCPSocketUsingUserProperties() {
    VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);

    final Properties props = new Properties();
    props.put("vertx.health.type", "tcp");
    props.put("vertx.health.port", "1234");
    props.put("vertx.health.readiness.port", "1235");
    setupExpectations(props);

    Probe probe = enricher.getLivenessProbe();
    assertNotNull(probe);
    assertEquals(probe.getTcpSocket().getPort().getIntVal().intValue(), 1234);
    probe = enricher.getReadinessProbe();
    assertNotNull(probe);
    assertEquals(probe.getTcpSocket().getPort().getIntVal().intValue(), 1235);
}
 
Example #27
Source File: VertxHealthCheckEnricherTest.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testTCPSocketUsingConfigDisabled() {
    VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);

    final Map<String, Object> config = createFakeConfig(
        "{\"type\":\"tcp\"}");
    setupExpectations(config);

    Probe probe = enricher.getLivenessProbe();
    assertNull(probe);
    probe = enricher.getReadinessProbe();
    assertNull(probe);
}
 
Example #28
Source File: VertxHealthCheckEnricherTest.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testTCPSocketUsingConfigAndPortName() {
    VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);

    final Map<String, Object> config = createFakeConfig(
            "{\"type\":\"tcp\",\"liveness\":{\"port-name\":\"health\"},\"readiness\":{\"port-name\":\"ready\"}}");
    setupExpectations(config);

    Probe probe = enricher.getLivenessProbe();
    assertNotNull(probe);
    assertEquals(probe.getTcpSocket().getPort().getStrVal(), "health");
    probe = enricher.getReadinessProbe();
    assertNotNull(probe);
    assertEquals(probe.getTcpSocket().getPort().getStrVal(), "ready");
}
 
Example #29
Source File: VertxHealthCheckEnricherTest.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testTCPSocketUsingConfigReadinessDisabled() {
    VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);

    final Map<String, Object> config = createFakeConfig(
            "{\"type\":\"tcp\",\"liveness\":{\"port\":\"1235\"},\"readiness\":{\"port\":\"-1\"}}");

    setupExpectations(config);

    Probe probe = enricher.getLivenessProbe();
    assertEquals(probe.getTcpSocket().getPort().getIntVal().intValue(), 1235);
    assertNotNull(probe);
    probe = enricher.getReadinessProbe();
    assertNull(probe);
}
 
Example #30
Source File: AbstractSpringBootHealthCheckEnricherTestSupport.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testWithServerPortAndManagementPortAndServerContextPath() {
    SpringBootHealthCheckEnricher enricher = new SpringBootHealthCheckEnricher(context);
    Properties props = new Properties();
    props.put(propertyHelper.getServerPortPropertyKey(), "8282");
    props.put(propertyHelper.getManagementPortPropertyKey(), "8383");
    props.put(propertyHelper.getServerContextPathPropertyKey(), "/p1");

    Probe probe = enricher.buildProbe(props, 10, null, null, 3, 1);
    assertNotNull(probe);
    assertNotNull(probe.getHttpGet());
    assertEquals(propertyHelper.getActuatorDefaultBasePath() + "/health", probe.getHttpGet().getPath());
    assertEquals(8383, probe.getHttpGet().getPort().getIntVal().intValue());
}