### Question:
IteratorImpl { public void setErrorAndRollback(final long ntail, final Status st) { Requires.requireTrue(ntail > 0, "Invalid ntail=" + ntail); if (this.currEntry == null || this.currEntry.getType() != EnumOutter.EntryType.ENTRY_TYPE_DATA) { this.currentIndex -= ntail; } else { this.currentIndex -= ntail - 1; } this.currEntry = null; getOrCreateError().setType(EnumOutter.ErrorType.ERROR_TYPE_STATE_MACHINE); getOrCreateError().getStatus().setError(RaftError.ESTATEMACHINE, "StateMachine meet critical error when applying one or more tasks since index=%d, %s", this.currentIndex, st != null ? st.toString() : "none"); } IteratorImpl(final StateMachine fsm, final LogManager logManager, final List<Closure> closures,
                        final long firstClosureIndex, final long lastAppliedIndex, final long committedIndex,
                        final AtomicLong applyingIndex); @Override String toString(); LogEntry entry(); RaftException getError(); boolean isGood(); boolean hasError(); void next(); long getIndex(); Closure done(); void setErrorAndRollback(final long ntail, final Status st);  }### Answer:
@Test public void testSetErrorAndRollback() { testNext(); assertFalse(iter.hasError()); this.iter.setErrorAndRollback(5, new Status(-1, "test")); assertTrue(iter.hasError()); Assert.assertEquals(EnumOutter.ErrorType.ERROR_TYPE_STATE_MACHINE, iter.getError().getType()); Assert.assertEquals(RaftError.ESTATEMACHINE.getNumber(), iter.getError().getStatus().getCode()); Assert .assertEquals( "StateMachine meet critical error when applying one or more tasks since index=6, Status[UNKNOWN<-1>: test]", iter.getError().getStatus().getErrorMsg()); assertEquals(6, iter.getIndex()); }
@Test(expected = IllegalArgumentException.class) public void testSetErrorAndRollbackInvalid() { this.iter.setErrorAndRollback(-1, null); }