### Question:
RetryNTimes implements RetryPolicy { @Override public RetryDecision onWriteTimeout(Statement stmnt, ConsistencyLevel cl, WriteType wt, int requiredResponses, int receivedResponses, int wTime) { if (wTime < writeAttempts) { LOG.info(String.format("Retrying on WriteTimeout: stmnt %s, " + "consistency %s, writeType %s, requiredResponse %d, " + "receivedResponse %d, rTime %d", stmnt, cl, wt.toString(), requiredResponses, receivedResponses, wTime)); return RetryDecision.retry(cl); } return RetryDecision.rethrow(); } RetryNTimes(int readAttempts, int writeAttempts, int unavailableAttempts); @Override RetryDecision onReadTimeout(Statement stmnt, ConsistencyLevel cl,
                                       int requiredResponses, int receivedResponses,
                                       boolean dataReceived, int rTime); @Override RetryDecision onWriteTimeout(Statement stmnt, ConsistencyLevel cl,
                                        WriteType wt, int requiredResponses,
                                        int receivedResponses, int wTime); @Override RetryDecision onUnavailable(Statement stmnt, ConsistencyLevel cl,
                                       int requiredResponses, int receivedResponses, int uTime); @Override RetryDecision onRequestError(Statement statement, ConsistencyLevel cl, DriverException e, int nbRetry); @Override void init(Cluster cluster); @Override void close();  }### Answer:
@Test public void firstTimeRetryOnWriteTimeout_shouldRetry() throws Exception { RetryNTimes retryPolicy = new RetryNTimes(3, 3, 3); Statement mockStatement = mock( Statement.class ); RetryPolicy.RetryDecision retryResult = retryPolicy.onWriteTimeout(mockStatement, ConsistencyLevel.LOCAL_ONE, WriteType.BATCH, 1, 0, 0); RetryPolicy.RetryDecision retryExpected = RetryPolicy.RetryDecision.retry(ConsistencyLevel.LOCAL_ONE); assertRetryDecisionEquals(retryExpected, retryResult); }
@Test public void maxTimeRetryOnWriteTimeout_shouldRethrow() throws Exception { RetryNTimes retryPolicy = new RetryNTimes(3, 3, 3); Statement mockStatement = mock( Statement.class ); RetryPolicy.RetryDecision retryResult = retryPolicy.onWriteTimeout(mockStatement, ConsistencyLevel.LOCAL_ONE, WriteType.BATCH, 1, 0, 3); RetryPolicy.RetryDecision retryExpected = RetryPolicy.RetryDecision.rethrow(); assertRetryDecisionEquals(retryExpected, retryResult); }