ClientLocalHistory extends AbstractClientHistory implements AutoCloseable { @Override AbstractTransactionCommitCohort onTransactionReady(final ClientTransaction tx, final AbstractTransactionCommitCohort cohort) { final State local = state(); switch (local) { case CLOSED: return super.onTransactionReady(tx, cohort); case IDLE: throw new IllegalStateException(String.format("Local history %s is idle when readying transaction %s", this, tx.getIdentifier())); case TX_OPEN: updateState(local, State.IDLE); return super.onTransactionReady(tx, cohort); default: throw new IllegalStateException(String.format("Local history %s in unhandled state %s", this, local)); } } ClientLocalHistory(final AbstractDataStoreClientBehavior client, final LocalHistoryIdentifier historyId); @Override void close();  }
@Override @Test public void testOnTransactionComplete() { final ClientTransaction tx = object().createTransaction(); object().onTransactionReady(tx, cohort); Assert.assertEquals(AbstractClientHistory.State.IDLE, object.state()); object().onTransactionComplete(tx.getIdentifier()); Assert.assertEquals(AbstractClientHistory.State.IDLE, object.state()); }
@Override @Test public void testOnTransactionReady() { final AbstractTransactionCommitCohort result = object().onTransactionReady( object().createTransaction(), cohort); Assert.assertEquals(result, cohort); }
@Override @Test(expected = IllegalStateException.class) public void testOnTransactionReadyDuplicate() { final ClientTransaction tx = object().createTransaction(); object().onTransactionReady(tx, cohort); object().onTransactionReady(tx, cohort); }
@Test public void testOnTransactionReadyAndComplete() { object().updateState(AbstractClientHistory.State.IDLE, AbstractClientHistory.State.TX_OPEN); final AbstractTransactionCommitCohort transactionCommitCohort = object().onTransactionReady(transaction, cohort); Assert.assertEquals(cohort, transactionCommitCohort); }
@Test public void testOnTransactionReadyAndCompleteStateClosed() { object().updateState(AbstractClientHistory.State.IDLE, AbstractClientHistory.State.CLOSED); final AbstractTransactionCommitCohort transactionCommitCohort = object().onTransactionReady(transaction, cohort); Assert.assertEquals(cohort, transactionCommitCohort); }
@Test(expected = IllegalStateException.class) public void testOnTransactionReadyAndCompleteIdleFail() { object().onTransactionReady(transaction, cohort); }