if (!this.retryContextCache.containsKey(key)) { RetryContext context = this.retryContextCache.get(key); if (context == null) { if (this.retryContextCache.containsKey(key)) { throw new RetryException( "Inconsistent state for failed item: no history found. "
private void registerContext(RetryContext context, RetryState state) { if (state != null) { Object key = state.getKey(); if (key != null) { if (context.getRetryCount() > 1 && !this.retryContextCache.containsKey(key)) { throw new RetryException( "Inconsistent state for failed item key: cache key has changed. " + "Consider whether equals() or hashCode() for the key might be inconsistent, " + "or if you need to supply a better key"); } this.retryContextCache.put(key, context); } } }
/** * Clean up the cache if necessary and close the context provided (if the flag * indicates that processing was successful). * * @param retryPolicy the {@link RetryPolicy} * @param context the {@link RetryContext} * @param state the {@link RetryState} * @param succeeded whether the close succeeded */ protected void close(RetryPolicy retryPolicy, RetryContext context, RetryState state, boolean succeeded) { if (state != null) { if (succeeded) { if (!context.hasAttribute(GLOBAL_STATE)) { this.retryContextCache.remove(state.getKey()); } retryPolicy.close(context); context.setAttribute(RetryContext.CLOSED, true); } } else { retryPolicy.close(context); context.setAttribute(RetryContext.CLOSED, true); } }
ArgumentCaptor getCaptor = ArgumentCaptor.forClass(Object.class); ArgumentCaptor removeCaptor = ArgumentCaptor.forClass(Object.class); verify(cache, times(2)).put(putCaptor.capture(), any(RetryContext.class)); verify(cache, times(2)).get(getCaptor.capture()); verify(cache, atLeast(2)).remove(removeCaptor.capture()); verify(cache, atMost(4)).remove(removeCaptor.capture()); logger.debug("puts:" + putCaptor.getAllValues()); logger.debug("gets:" + putCaptor.getAllValues());
ArgumentCaptor getCaptor = ArgumentCaptor.forClass(Object.class); ArgumentCaptor removeCaptor = ArgumentCaptor.forClass(Object.class); verify(cache, times(6)).put(putCaptor.capture(), any(RetryContext.class)); verify(cache, times(6)).get(getCaptor.capture()); verify(cache, atLeast(2)).remove(removeCaptor.capture()); verify(cache, atMost(4)).remove(removeCaptor.capture()); logger.debug("puts:" + putCaptor.getAllValues()); logger.debug("gets:" + putCaptor.getAllValues());
private void registerContext(RetryContext context, RetryState state) { if (state != null) { Object key = state.getKey(); if (key != null) { if (context.getRetryCount() > 1 && !this.retryContextCache.containsKey(key)) { throw new RetryException( "Inconsistent state for failed item key: cache key has changed. " + "Consider whether equals() or hashCode() for the key might be inconsistent, " + "or if you need to supply a better key"); } this.retryContextCache.put(key, context); } } }
if (!this.retryContextCache.containsKey(key)) { RetryContext context = this.retryContextCache.get(key); if (context == null) { if (this.retryContextCache.containsKey(key)) { throw new RetryException( "Inconsistent state for failed item: no history found. "
context.setAttribute(RetryContext.EXHAUSTED, true); if (state != null && !context.hasAttribute(GLOBAL_STATE)) { this.retryContextCache.remove(state.getKey());
/** * Clean up the cache if necessary and close the context provided (if the flag * indicates that processing was successful). * * @param retryPolicy the {@link RetryPolicy} * @param context the {@link RetryContext} * @param state the {@link RetryState} * @param succeeded whether the close succeeded */ protected void close(RetryPolicy retryPolicy, RetryContext context, RetryState state, boolean succeeded) { if (state != null) { if (succeeded) { if (!context.hasAttribute(GLOBAL_STATE)) { this.retryContextCache.remove(state.getKey()); } retryPolicy.close(context); context.setAttribute(RetryContext.CLOSED, true); } } else { retryPolicy.close(context); context.setAttribute(RetryContext.CLOSED, true); } }
context.setAttribute(RetryContext.EXHAUSTED, true); if (state != null && !context.hasAttribute(GLOBAL_STATE)) { this.retryContextCache.remove(state.getKey());