### Question:
OcspCertificateChainValidationService implements Runnable { @Override public void run() { try { final Set<Certificate> certificatesSet = certificateService.getAllCertificates(); final double timestamp = DateTime.now(DateTimeZone.UTC).getMillis(); for (Certificate certificate: certificatesSet) { try { if (ocspCertificateChainValidityChecker.isValid(certificate)) { updateAGauge(ocspStatusGauge, certificate, VALID); updateAGauge(lastUpdatedGauge, certificate, timestamp); } else { updateAGauge(ocspStatusGauge, certificate, INVALID); } } catch (Exception e) { if (Objects.nonNull(certificate)) { LOG.warn(String.format("Unable to set certificates OCSP revocation status metrics for the certificate [issuer id: %s]", certificate.getIssuerEntityId()), e); } else { LOG.error("Unable to set certificates OCSP revocation status metrics.", e); } } } LOG.info("Updated Certificates OCSP Revocation Statuses Metrics."); } catch (Exception e) { LOG.error("Failed to update Certificates OCSP Revocation Statuses Metrics", e); } } OcspCertificateChainValidationService(final OCSPCertificateChainValidityChecker ocspCertificateChainValidityChecker,
                                                 final CertificateService certificateService,
                                                 final Gauge ocspStatusGauge,
                                                 final Gauge lastUpdatedGauge); @Override void run(); static final double VALID; static final double INVALID; }### Answer:
@Test public void gaugesAreUpdatedForCertsWithValidChains() throws Exception { Gauge ocspStatusGauge = Gauge.build("ocspStatusGauge", "whatever") .labelNames("entity_id", "use", "subject", "fingerprint", "serial") .create(); Gauge lastUpdatedGauge = Gauge.build("lastUpdatedGauge", "whatever") .labelNames("entity_id", "use", "subject", "fingerprint", "serial") .create(); OcspCertificateChainValidationService ocspCertificateChainValidationService = new OcspCertificateChainValidationService( ocspCertificateChainValidityChecker, certificateService, ocspStatusGauge, lastUpdatedGauge ); assertThat(getGaugeValue(ocspStatusGauge, cert1)).isEqualTo(0); assertThat(getGaugeValue(ocspStatusGauge, cert2)).isEqualTo(0); assertThat(getGaugeValue(ocspStatusGauge, cert3)).isEqualTo(0); assertThat(getGaugeValue(lastUpdatedGauge, cert1)).isEqualTo(0); assertThat(getGaugeValue(lastUpdatedGauge, cert2)).isEqualTo(0); assertThat(getGaugeValue(lastUpdatedGauge, cert3)).isEqualTo(0); when(certificateService.getAllCertificates()).thenReturn(Set.of(cert1, cert2, cert3)); when(ocspCertificateChainValidityChecker.isValid(cert1)).thenReturn(true); when(ocspCertificateChainValidityChecker.isValid(cert2)).thenReturn(true); when(ocspCertificateChainValidityChecker.isValid(cert3)).thenReturn(false); ocspCertificateChainValidationService.run(); assertThat(getGaugeValue(ocspStatusGauge, cert1)).isEqualTo(1); assertThat(getGaugeValue(ocspStatusGauge, cert2)).isEqualTo(1); assertThat(getGaugeValue(ocspStatusGauge, cert3)).isEqualTo(0); assertThat(getGaugeValue(lastUpdatedGauge, cert1)).isGreaterThan(0); assertThat(getGaugeValue(lastUpdatedGauge, cert2)).isGreaterThan(0); assertThat(getGaugeValue(lastUpdatedGauge, cert3)).isEqualTo(0); when(ocspCertificateChainValidityChecker.isValid(cert2)).thenReturn(false); ocspCertificateChainValidationService.run(); assertThat(getGaugeValue(ocspStatusGauge, cert1)).isEqualTo(1); assertThat(getGaugeValue(ocspStatusGauge, cert2)).isEqualTo(0); assertThat(getGaugeValue(ocspStatusGauge, cert3)).isEqualTo(0); assertThat(getGaugeValue(lastUpdatedGauge, cert1)).isGreaterThan(0); assertThat(getGaugeValue(lastUpdatedGauge, cert2)).isGreaterThan(0); assertThat(getGaugeValue(lastUpdatedGauge, cert3)).isEqualTo(0); }