@Override protected void performOneCall() { long timestamp = timestampService.getFreshTimestamp(); Preconditions.checkState(timestamp > 0); } }
@Test public void canRequestMoreTimestampsThanAreAllocatedAtOnce() { for (int i = 0; i < ONE_MILLION / ONE_THOUSAND; i++) { timestampService.getFreshTimestamps(ONE_THOUSAND); } Assertions.assertThat(timestampService.getFreshTimestamp()).isGreaterThanOrEqualTo(ONE_MILLION + 1); }
@Override public long getAsLong() { if (timestampService == null) { throwNotInitializedException(); } return timestampService.getFreshTimestamp(); }
@Test public void canReturnManyUniqueTimestampsInParallel() throws InterruptedException, TimeoutException { Set<Long> uniqueTimestamps = new ConcurrentSkipListSet<>(); repeat(ONE_MILLION, () -> uniqueTimestamps.add(timestampService.getFreshTimestamp())); Assertions.assertThat(uniqueTimestamps.size()).isEqualTo((int) ONE_MILLION); }
@Test public void willNotHandOutTimestampsEarlierThanAFastForward() { timestampManagementService.fastForwardTimestamp(TWO_MILLION); Assertions.assertThat(timestampService.getFreshTimestamp()).isGreaterThan(TWO_MILLION); }
@Override public void forceInstallNewTransactionsSchemaVersion(int newVersion) { while (transactionSchemaManager.getTransactionsSchemaVersion( timestampService.getFreshTimestamp()) != newVersion) { transactionSchemaManager.tryInstallNewTransactionsSchemaVersion(newVersion); advanceOneHundredMillionTimestamps(); } }
@Test public void testGetFreshTimestampDefersToTimestampService() { managedTimestampService.getFreshTimestamp(); verify(timestampService, times(1)).getFreshTimestamp(); }
@Test public void shouldExposeATimestampManagementServer() { TimestampService timestampClient = EteSetup.createClientToAllNodes(TimestampService.class); TimestampManagementService timestampManagementClient = EteSetup.createClientToAllNodes(TimestampManagementService.class); assertThat(timestampClient.getFreshTimestamp(), is(not(nullValue()))); long newts = timestampClient.getFreshTimestamp() + 10000000; timestampManagementClient.fastForwardTimestamp(newts); assertThat(timestampClient.getFreshTimestamp(), is(greaterThan(newts))); } }
@Test public void syncInitTimestampServiceSynchronous() { TimestampService timestampService = factory.createTimestampService(null, Optional.empty(), false); assertThat(timestampService.isInitialized()).isTrue(); assertThat(timestampService.getFreshTimestamp()).isEqualTo(1L); }
@Test public void syncInitTimestampServiceSynchronous() { TimestampService timestampService = factory.createTimestampService(null, Optional.empty(), false); assertThat(timestampService.isInitialized()).isTrue(); assertThat(timestampService.getFreshTimestamp()).isEqualTo(1L); }
@Test public void shouldExposeATimestampServer() { TimestampService timestampClient = EteSetup.createClientToAllNodes(TimestampService.class); assertThat(timestampClient.getFreshTimestamp(), is(not(nullValue()))); }
@Test public void asyncInitTimestampServiceSynchronous() { KeyValueService kvs = createRawKeyValueService(true); TimestampService timestampService = factory.createTimestampService(kvs, Optional.empty(), true); assertThat(timestampService.isInitialized()).isTrue(); assertThat(timestampService.getFreshTimestamp()).isEqualTo(1L); }
@Override public long resetStateAndGetFreshTimestamp() { forceInstallNewTransactionsSchemaVersion(1); KeyValueService kvs = transactionManager.getKeyValueService(); kvs.truncateTable(AtlasDbConstants.COORDINATION_TABLE); kvs.createTable(TEST_TABLE, AtlasDbConstants.GENERIC_TABLE_METADATA); kvs.truncateTable(TEST_TABLE); return timestampService.getFreshTimestamp(); }
@Test public void setupMigratorCommitsOneTransaction() { KeyValueServiceMigrators.setupMigrator(migratorSpec); ArgumentCaptor<Long> startTimestampCaptor = ArgumentCaptor.forClass(Long.class); ArgumentCaptor<Long> commitTimestampCaptor = ArgumentCaptor.forClass(Long.class); verify(toServices.getTransactionService()).putUnlessExists( startTimestampCaptor.capture(), commitTimestampCaptor.capture()); assertThat(startTimestampCaptor.getValue()).isLessThan(commitTimestampCaptor.getValue()); assertThat(commitTimestampCaptor.getValue()).isLessThan(toServices.getTimestampService().getFreshTimestamp()); }
@Test public void delegatesCallToTimestampServiceIfSet() { TimestampService timestampService = mock(TimestampService.class); adapter.setTimestampService(timestampService); adapter.getAsLong(); verify(timestampService, times(1)).getFreshTimestamp(); verifyNoMoreInteractions(timestampService); }
@Test public void testPuncherDurability() throws Exception { Long stored = timestampService.getFreshTimestamp(); asyncPuncher.punch(stored); Long retrieved = Long.MIN_VALUE; for (int i = 0; i < MAX_INTERVALS_TO_WAIT && retrieved < stored; i++) { Thread.sleep(ASYNC_PUNCHER_INTERVAL); retrieved = asyncPuncher.getTimestampSupplier().get(); } assertEquals(stored, retrieved); }
private static void checkFastForward(long target, long expected) throws Exception { InMemoryTestRunner runner = makeRunnerWithTargetTimestamp(target); AtlasDbServices atlasDbServices = runner.connect(moduleFactory); String response = runner.run(); // Unintuitive, but is consistent with existing CLI behaviour. assertThat(response).contains("Timestamp successfully fast-forwarded to " + target); assertThat(atlasDbServices.getTimestampService().getFreshTimestamp()).isEqualTo(expected + 1); }
@Test(expected = ServiceNotAvailableException.class) public void throwsAserviceNotAvailableExceptionIfThereAreMultipleServersRunning() { timestampBoundStore.pretendMultipleServersAreRunning(); getTimestampService().getFreshTimestamp(); }
@Test public void setupMigratorFastForwardsTimestamp() { KeyValueServiceMigrators.getTimestampManagementService(fromServices).fastForwardTimestamp(FUTURE_TIMESTAMP); assertThat(toServices.getTimestampService().getFreshTimestamp()).isLessThan(FUTURE_TIMESTAMP); KeyValueServiceMigrators.setupMigrator(migratorSpec); assertThat(toServices.getTimestampService().getFreshTimestamp()).isGreaterThanOrEqualTo(FUTURE_TIMESTAMP); }
@Test public void testSweepNonExistingTable() throws Exception { try (SingleBackendCliTestRunner runner = makeRunner( paramsWithDryRunSet(SWEEP_COMMAND, "-t", NON_EXISTING_TABLE.getQualifiedName()))) { TestAtlasDbServices services = runner.connect(moduleFactory); long ts5 = services.getTimestampService().getFreshTimestamp(); String stdout = sweep(runner, ts5); Assert.assertFalse(stdout.contains("Swept from")); Assert.assertTrue(stdout.contains( String.format("The table %s passed in to sweep does not exist", NON_EXISTING_TABLE))); } }