@Override public Supplier<ManagedTimestampService> createTimestampService(String client, LeaderConfig leaderConfig) { ServiceDiscoveringAtlasSupplier atlasFactory = new ServiceDiscoveringAtlasSupplier( new MetricsManager(new MetricRegistry(), new DefaultTaggedMetricRegistry(), x -> false), kvsConfig, Optional.of(leaderConfig), Optional.empty(), Optional.of(AtlasDbConstants.TIMELOCK_TIMESTAMP_TABLE)); TimestampService timestampService = atlasFactory.getTimestampService(); Preconditions.checkArgument(TimestampManagementService.class.isInstance(timestampService), "The timestamp service is not a managed timestamp service."); return () -> new DelegatingManagedTimestampService(timestampService, (TimestampManagementService) timestampService); } }
@Test public void returnDifferentTimestampServicesOnSubsequentCalls() { // Need to get a newly-initialized timestamp service in case leadership changed between calls. ServiceDiscoveringAtlasSupplier supplier = new ServiceDiscoveringAtlasSupplier( metrics, kvsConfig, leaderConfig); AutoServiceAnnotatedAtlasDbFactory.nextTimestampServiceToReturn( mock(TimestampService.class), mock(TimestampService.class)); assertThat(supplier.getTimestampService(), is(not(sameObjectAs(supplier.getTimestampService())))); }
@Test public void delegateToFactoriesAnnotatedWithAutoServiceForCreatingTimestampServices() { ServiceDiscoveringAtlasSupplier atlasSupplier = new ServiceDiscoveringAtlasSupplier( metrics, kvsConfig, leaderConfig); TimestampService timestampService = mock(TimestampService.class); AutoServiceAnnotatedAtlasDbFactory.nextTimestampServiceToReturn(timestampService); assertThat( atlasSupplier.getTimestampService(), is(timestampService)); }