@Test public void testPutOk() throws Exception { when(persistentEngine.put("key", "value")).thenReturn("secret"); when(persistentEngine.isExists("key")).thenReturn(false); String result = underTest.put("key", "value"); verify(metricService, times(1)).submit(eq(MetricType.VAULT_READ), anyDouble()); verify(persistentEngine, times(1)).put(eq("key"), eq("value")); verify(metricService, times(1)).submit(eq(MetricType.VAULT_WRITE), anyDouble()); verify(metricService, times(1)).incrementMetricCounter(any(Metric.class)); Assert.assertEquals("secret", result); }
public String put(String key, String value) throws Exception { long start = System.currentTimeMillis(); boolean exists = vaultRetryService.tryReadingVault(() -> persistentEngine.isExists(key)); long duration = System.currentTimeMillis() - start; metricService.submit(MetricType.VAULT_READ, duration); LOGGER.trace("Secret read took {} ms", duration); if (exists) { throw new InvalidKeyException(format("Key: %s already exists!", key)); } start = System.currentTimeMillis(); String secret = vaultRetryService.tryWritingVault(() -> persistentEngine.put(key, value)); duration = System.currentTimeMillis() - start; metricService.submit(MetricType.VAULT_WRITE, duration); LOGGER.trace("Secret write took {} ms", duration); metricService.incrementMetricCounter(() -> "secret.write." + convertSecretToMetric(secret)); return secret; }
SecretService { public String put(String key, String value) throws Exception { long start = System.currentTimeMillis(); boolean exists = vaultRetryService.tryReadingVault(() -> persistentEngine.isExists(key)); long duration = System.currentTimeMillis() - start; metricService.submit(MetricType.VAULT_READ, duration); LOGGER.trace("Secret read took {} ms", duration); if (exists) { throw new InvalidKeyException(format("Key: %s already exists!", key)); } start = System.currentTimeMillis(); String secret = vaultRetryService.tryWritingVault(() -> persistentEngine.put(key, value)); duration = System.currentTimeMillis() - start; metricService.submit(MetricType.VAULT_WRITE, duration); LOGGER.trace("Secret write took {} ms", duration); metricService.incrementMetricCounter(() -> "secret.write." + convertSecretToMetric(secret)); return secret; } }
SecretService { public String put(String key, String value) throws Exception { long start = System.currentTimeMillis(); boolean exists = vaultRetryService.tryReadingVault(() -> persistentEngine.isExists(key)); long duration = System.currentTimeMillis() - start; metricService.submit(MetricType.VAULT_READ, duration); LOGGER.trace("Secret read took {} ms", duration); if (exists) { throw new InvalidKeyException(format("Key: %s already exists!", key)); } start = System.currentTimeMillis(); String secret = vaultRetryService.tryWritingVault(() -> persistentEngine.put(key, value)); duration = System.currentTimeMillis() - start; metricService.submit(MetricType.VAULT_WRITE, duration); LOGGER.trace("Secret write took {} ms", duration); metricService.incrementMetricCounter(() -> "secret.write." + convertSecretToMetric(secret)); return secret; } SecretService(MetricService metricService, List<SecretEngine> engines, VaultRetryService vaultRetryService); }
SecretService { public String put(String key, String value) throws Exception { long start = System.currentTimeMillis(); boolean exists = vaultRetryService.tryReadingVault(() -> persistentEngine.isExists(key)); long duration = System.currentTimeMillis() - start; metricService.submit(MetricType.VAULT_READ, duration); LOGGER.trace("Secret read took {} ms", duration); if (exists) { throw new InvalidKeyException(format("Key: %s already exists!", key)); } start = System.currentTimeMillis(); String secret = vaultRetryService.tryWritingVault(() -> persistentEngine.put(key, value)); duration = System.currentTimeMillis() - start; metricService.submit(MetricType.VAULT_WRITE, duration); LOGGER.trace("Secret write took {} ms", duration); metricService.incrementMetricCounter(() -> "secret.write." + convertSecretToMetric(secret)); return secret; } SecretService(MetricService metricService, List<SecretEngine> engines, VaultRetryService vaultRetryService); @PostConstruct void init(); String put(String key, String value); String get(String secret); String getByResponse(SecretResponse secretResponse); void delete(String secret); List<String> listEntries(String secretPathPrefix); void cleanup(String pathPrefix); boolean isSecret(String secret); SecretResponse convertToExternal(String secret); }
SecretService { public String put(String key, String value) throws Exception { long start = System.currentTimeMillis(); boolean exists = vaultRetryService.tryReadingVault(() -> persistentEngine.isExists(key)); long duration = System.currentTimeMillis() - start; metricService.submit(MetricType.VAULT_READ, duration); LOGGER.trace("Secret read took {} ms", duration); if (exists) { throw new InvalidKeyException(format("Key: %s already exists!", key)); } start = System.currentTimeMillis(); String secret = vaultRetryService.tryWritingVault(() -> persistentEngine.put(key, value)); duration = System.currentTimeMillis() - start; metricService.submit(MetricType.VAULT_WRITE, duration); LOGGER.trace("Secret write took {} ms", duration); metricService.incrementMetricCounter(() -> "secret.write." + convertSecretToMetric(secret)); return secret; } SecretService(MetricService metricService, List<SecretEngine> engines, VaultRetryService vaultRetryService); @PostConstruct void init(); String put(String key, String value); String get(String secret); String getByResponse(SecretResponse secretResponse); void delete(String secret); List<String> listEntries(String secretPathPrefix); void cleanup(String pathPrefix); boolean isSecret(String secret); SecretResponse convertToExternal(String secret);  }