ProbeHandler { public Probe getProbe(ProbeConfig probeConfig) { if (probeConfig == null) { return null; } Probe probe = new Probe(); Integer initialDelaySeconds = probeConfig.getInitialDelaySeconds(); if (initialDelaySeconds != null) { probe.setInitialDelaySeconds(initialDelaySeconds); } Integer timeoutSeconds = probeConfig.getTimeoutSeconds(); if (timeoutSeconds != null) { probe.setTimeoutSeconds(timeoutSeconds); } Integer failureThreshold = probeConfig.getFailureThreshold(); if(failureThreshold != null) { probe.setFailureThreshold(failureThreshold); } Integer successThreshold = probeConfig.getSuccessThreshold(); if(successThreshold != null) { probe.setSuccessThreshold(successThreshold); } HTTPGetAction getAction = getHTTPGetAction(probeConfig.getGetUrl()); if (getAction != null) { probe.setHttpGet(getAction); return probe; } ExecAction execAction = getExecAction(probeConfig.getExec()); if (execAction != null) { probe.setExec(execAction); return probe; } TCPSocketAction tcpSocketAction = getTCPSocketAction(probeConfig.getGetUrl(), probeConfig.getTcpPort()); if (tcpSocketAction != null) { probe.setTcpSocket(tcpSocketAction); return probe; } return null; }  Probe getProbe(ProbeConfig probeConfig);  }
@Test public void getProbeEmptyTest() { probeConfig = null; probe = probeHandler.getProbe(probeConfig); assertNull(probe); }
@Test public void getProbeNullTest() { probeConfig = new ProbeConfig.Builder() .build(); probe = probeHandler.getProbe(probeConfig); assertNull(probe); }
@Test public void getHTTPProbeWithEmptyURLTest() { probeConfig = new ProbeConfig.Builder() .initialDelaySeconds(5).timeoutSeconds(5).getUrl(null) .build(); probe = probeHandler.getProbe(probeConfig); assertNull(probe); }
@Test public void getHTTPProbeWithHTTPURLTest() { probeConfig = new ProbeConfig.Builder() .initialDelaySeconds(5).timeoutSeconds(5).getUrl("http: .build(); probe = probeHandler.getProbe(probeConfig); assertNotNull(probe); assertEquals(5,probe.getInitialDelaySeconds().intValue()); assertEquals(5,probe.getTimeoutSeconds().intValue()); assertEquals("www.healthcheck.com",probe.getHttpGet().getHost()); assertEquals(null,probe.getHttpGet().getHttpHeaders()); assertEquals("/healthz",probe.getHttpGet().getPath()); assertEquals(8080,probe.getHttpGet().getPort().getIntVal().intValue()); assertEquals("HTTP",probe.getHttpGet().getScheme()); assertNull(probe.getExec()); assertNull(probe.getTcpSocket()); }
@Test public void getHTTPProbeWithoutHTTPURLTest() { probeConfig = new ProbeConfig.Builder() .initialDelaySeconds(5).timeoutSeconds(5).getUrl("www.healthcheck.com:8080/healthz") .build(); probe = probeHandler.getProbe(probeConfig); assertNull(probe); }
@Test(expected = IllegalArgumentException.class) public void getHTTPProbeWithInvalidURLTest() { probeConfig = new ProbeConfig.Builder() .initialDelaySeconds(5).timeoutSeconds(5).getUrl("httphealthcheck.com:8080/healthz") .build(); probe = probeHandler.getProbe(probeConfig); }
@Test public void getExecProbeWithEmptyExecTest() { probeConfig = new ProbeConfig.Builder() .initialDelaySeconds(5).timeoutSeconds(5).exec("") .build(); probe = probeHandler.getProbe(probeConfig); assertNull(probe); }
@Test public void getExecProbeWithExecTest() { probeConfig = new ProbeConfig.Builder() .initialDelaySeconds(5).timeoutSeconds(5).exec("cat /tmp/probe") .build(); probe = probeHandler.getProbe(probeConfig); assertNotNull(probe); assertEquals(5,probe.getInitialDelaySeconds().intValue()); assertEquals(5,probe.getTimeoutSeconds().intValue()); assertNotNull(probe.getExec()); assertEquals(2,probe.getExec().getCommand().size()); assertEquals("[cat, /tmp/probe]",probe.getExec().getCommand().toString()); assertNull(probe.getHttpGet()); assertNull(probe.getTcpSocket()); }
@Test public void getExecProbeWithInvalidExecTest() { probeConfig = new ProbeConfig.Builder() .initialDelaySeconds(5).timeoutSeconds(5).exec(" ") .build(); probe = probeHandler.getProbe(probeConfig); assertNull(probe); }
@Test public void getTCPProbeWithoutURLTest() { probeConfig = new ProbeConfig.Builder() .initialDelaySeconds(5).timeoutSeconds(5).tcpPort("80") .build(); probe = probeHandler.getProbe(probeConfig); assertNotNull(probe); assertNull(probe.getHttpGet()); assertNotNull(probe.getTcpSocket()); assertEquals(80,probe.getTcpSocket().getPort().getIntVal().intValue()); assertNull(probe.getTcpSocket().getHost()); assertNull(probe.getExec()); assertEquals(5,probe.getInitialDelaySeconds().intValue()); assertEquals(5,probe.getTimeoutSeconds().intValue()); }
@Test public void getTCPProbeWithHTTPURLAndPortTest() { probeConfig = new ProbeConfig.Builder() .initialDelaySeconds(5).timeoutSeconds(5) .getUrl("http: .build(); probe = probeHandler.getProbe(probeConfig); assertNotNull(probe); assertNotNull(probe.getHttpGet()); assertNull(probe.getTcpSocket()); assertNull(probe.getExec()); assertEquals(5,probe.getInitialDelaySeconds().intValue()); assertEquals(5,probe.getTimeoutSeconds().intValue()); assertEquals("www.healthcheck.com",probe.getHttpGet().getHost()); assertEquals(null,probe.getHttpGet().getHttpHeaders()); assertEquals("/healthz",probe.getHttpGet().getPath()); assertEquals(8080,probe.getHttpGet().getPort().getIntVal().intValue()); assertEquals("HTTP",probe.getHttpGet().getScheme()); }
@Test public void getTCPProbeWithNonHTTPURLTest() { probeConfig = new ProbeConfig.Builder() .initialDelaySeconds(5).timeoutSeconds(5) .failureThreshold(3).successThreshold(1) .getUrl("tcp: .build(); probe = probeHandler.getProbe(probeConfig); assertNotNull(probe); assertNull(probe.getHttpGet()); assertNotNull(probe.getTcpSocket()); assertNull(probe.getExec()); assertEquals(80,probe.getTcpSocket().getPort().getIntVal().intValue()); assertEquals("www.healthcheck.com",probe.getTcpSocket().getHost()); assertEquals(5,probe.getInitialDelaySeconds().intValue()); assertEquals(5,probe.getTimeoutSeconds().intValue()); assertEquals(3, probe.getFailureThreshold().intValue()); assertEquals(1, probe.getSuccessThreshold().intValue()); }
@Test public void getTCPProbeWithNonHTTPURLAndStringPortTest() { probeConfig = new ProbeConfig.Builder() .initialDelaySeconds(5).timeoutSeconds(5) .getUrl("tcp: .successThreshold(1) .failureThreshold(3) .build(); probe = probeHandler.getProbe(probeConfig); assertNotNull(probe); assertNull(probe.getHttpGet()); assertNotNull(probe.getTcpSocket()); assertNull(probe.getExec()); assertEquals("httpPort",probe.getTcpSocket().getPort().getStrVal()); assertEquals("www.healthcheck.com",probe.getTcpSocket().getHost()); assertEquals(5,probe.getInitialDelaySeconds().intValue()); assertEquals(5,probe.getTimeoutSeconds().intValue()); assertEquals(3, probe.getFailureThreshold().intValue()); assertEquals(1, probe.getSuccessThreshold().intValue()); }
@Test public void getTCPWithHTTPURLAndWithoutPort() { probeConfig = new ProbeConfig.Builder() .initialDelaySeconds(5).timeoutSeconds(5) .getUrl("http: .build(); probe = probeHandler.getProbe(probeConfig); assertNotNull(probe); assertNotNull(probe.getHttpGet()); assertNull(probe.getTcpSocket()); assertNull(probe.getExec()); assertEquals(5,probe.getInitialDelaySeconds().intValue()); assertEquals(5,probe.getTimeoutSeconds().intValue()); assertEquals("www.healthcheck.com",probe.getHttpGet().getHost()); assertEquals(null,probe.getHttpGet().getHttpHeaders()); assertEquals("/healthz",probe.getHttpGet().getPath()); assertEquals(8080,probe.getHttpGet().getPort().getIntVal().intValue()); assertEquals("HTTP",probe.getHttpGet().getScheme()); }
@Test public void getTCPProbeWithTCPURLTest() { probeConfig = new ProbeConfig.Builder() .initialDelaySeconds(5).timeoutSeconds(5) .getUrl("tcp: .build(); probe = probeHandler.getProbe(probeConfig); assertNull(probe); }
@Test(expected = IllegalArgumentException.class) public void getTCPProbeWithInvalidURLTest() { probeConfig = new ProbeConfig.Builder() .initialDelaySeconds(5).timeoutSeconds(5).getUrl("healthcheck.com:8080/healthz") .tcpPort("80") .build(); probe = probeHandler.getProbe(probeConfig); }