@Override public long resetStateAndGetFreshTimestamp() { long freshTimestamp = currentDelegate.get().resetStateAndGetFreshTimestamp(); currentDelegate.set(SimpleCoordinationResource.create(txManager)); return freshTimestamp; } }
private void assertTransactionsSchemaVersionIsNow(int expectedVersion) { assertThat(coordinationResource.getTransactionsSchemaVersion(coordinationResource.getFreshTimestamp())) .isEqualTo(expectedVersion); } }
@Test public void transactionOnKnownVersionFailsOnValueWithUnknownVersion() { coordinationResource.forceInstallNewTransactionsSchemaVersion(NEW_VERSION); assertTransactionsSchemaVersionIsNow(NEW_VERSION); assertThat(coordinationResource.doTransactionAndReportOutcome()).isFalse(); coordinationResource.forceInstallNewTransactionsSchemaVersion(VERSION_ONE); assertTransactionsSchemaVersionIsNow(VERSION_ONE); // This must still determine whether the transaction that started under a NEW_VERSION regime committed // or not, when performing conflict checking. We can't tell, hence we must fail. assertThat(coordinationResource.doTransactionAndReportOutcome()).isFalse(); }
@Test public void tryInstallNewVersionDoesNotForceImmediateChangeover() { coordinationResource.tryInstallNewTransactionsSchemaVersion(NEW_VERSION); assertTransactionsSchemaVersionIsNow(VERSION_ONE); assertThat(coordinationResource.doTransactionAndReportOutcome()).isTrue(); }
@Test public void defaultTransactionsSchemaVersionIsOne() { assertThat(coordinationResource.getTransactionsSchemaVersion(lowerBoundOnTimestamps)).isEqualTo(1); }
@Test public void transactionSucceedsUnderKnownSchemaVersion() { assertTransactionsSchemaVersionIsNow(VERSION_ONE); assertThat(coordinationResource.doTransactionAndReportOutcome()).isTrue(); }
@Test public void transactionFailsUnderUnknownSchemaVersion() { coordinationResource.forceInstallNewTransactionsSchemaVersion(NEW_VERSION); assertTransactionsSchemaVersionIsNow(NEW_VERSION); assertThat(coordinationResource.doTransactionAndReportOutcome()).isFalse(); }
@Test public void transactionOnKnownVersionAndFreshCellSucceedsEvenIfWePassedThroughAnUnknownVersion() { coordinationResource.forceInstallNewTransactionsSchemaVersion(NEW_VERSION); assertTransactionsSchemaVersionIsNow(NEW_VERSION); coordinationResource.forceInstallNewTransactionsSchemaVersion(VERSION_ONE); assertTransactionsSchemaVersionIsNow(VERSION_ONE); assertThat(coordinationResource.doTransactionAndReportOutcome()).isTrue(); }
@Before public void setUp() { lowerBoundOnTimestamps = coordinationResource.resetStateAndGetFreshTimestamp(); }