KubernetesGCPServiceAccountSecretManager { @VisibleForTesting static long smearedEpoch(long nowMillis, String serviceAccount) { final long offset = Math.abs(serviceAccount.hashCode()) % DEFAULT_SECRET_EPOCH_PERIOD.toMillis(); return (nowMillis + offset) / DEFAULT_SECRET_EPOCH_PERIOD.toMillis(); } KubernetesGCPServiceAccountSecretManager(
      Fabric8KubernetesClient client,
      ServiceAccountKeyManager keyManager,
      Stats stats,
      EpochProvider epochProvider,
      Clock clock);   KubernetesGCPServiceAccountSecretManager(
      Fabric8KubernetesClient client,
      ServiceAccountKeyManager keyManager,
      Stats stats); void cleanup();  }
@Test public void shouldSmearRotationWeekly() { final long hours = Duration.ofDays(7).toHours(); final int[] rotationsPerHour = new int[(int) hours]; final int n = 10000; for (int i = 0; i < n; i++) { for (int hour = 0; hour < hours; hour++) { final long nowMillis = TimeUnit.HOURS.toMillis(hour); final long epoch = KubernetesGCPServiceAccountSecretManager.smearedEpoch( nowMillis, "sa" + i + "@example.com"); if (epoch != 0) { rotationsPerHour[hour]++; break; } } } final IntSummaryStatistics stats = IntStream.of(rotationsPerHour).summaryStatistics(); final double expectedMeanRotationsPerHour = n / hours; assertThat(stats.getAverage(), is(closeTo(expectedMeanRotationsPerHour, expectedMeanRotationsPerHour / 2))); assertThat((double) stats.getMax(), is(lessThan(expectedMeanRotationsPerHour * 2))); }