Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISPN-9002 LocalModeNoPassivationTest.testValuesWithEvictedEntries random #5957

Merged
merged 1 commit into from
May 4, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.infinispan.persistence.util;

import java.lang.invoke.MethodHandles;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Executor;
Expand All @@ -20,6 +21,8 @@
import org.infinispan.util.concurrent.TimeoutException;
import org.infinispan.util.concurrent.WithinThreadExecutor;
import org.infinispan.util.function.CloseableSupplier;
import org.infinispan.util.logging.Log;
import org.infinispan.util.logging.LogFactory;

/**
* A closeable supplier that provides a way to supply cache entries from a given persistence manager. On the first
Expand All @@ -30,6 +33,9 @@
* @since 8.0
*/
public class PersistenceManagerCloseableSupplier<K, V> implements CloseableSupplier<CacheEntry<K, V>> {
private static final Log log = LogFactory.getLog(MethodHandles.lookup().lookupClass());
private static final boolean trace = log.isTraceEnabled();

private final Executor executor;
private final PersistenceManager manager;
private final KeyFilter<K> filter;
Expand Down Expand Up @@ -126,7 +132,7 @@ public CacheEntry<K, V> get() throws TimeoutException {
closeLock.lock();
try {
// If is possible that someone inserted a value and then acquired the close lock - thus we must recheck
if (closed || (entry = queue.poll()) != null) {
if ((entry = queue.poll()) != null || closed) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I stared for 5 minutes at this code yesterday without realizing what switching the evaluation order would do...
I saw it when I looked again today, but may I suggest not mixing complex if conditions and assignments? :)

break;
}
long targetTime = System.nanoTime() + unit.toNanos(timeout);
Expand All @@ -145,6 +151,9 @@ public CacheEntry<K, V> get() throws TimeoutException {
if (interrupted) {
Thread.currentThread().interrupt();
}
if (trace) {
log.tracef("Returning entry: " + entry);
}
return entry;
}

Expand Down