Skip to content

Commit

Permalink
Mitigate race condition in hz-cluster unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
sikeoka committed Dec 13, 2018
1 parent 8252045 commit 2469eca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@


import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.google.common.util.concurrent.ThreadFactoryBuilder;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.RejectedExecutionException;
Expand All @@ -34,7 +33,7 @@ public class ReloadHzSynchronizer extends HzSynchronizer {
/** lock during reload */ /** lock during reload */
protected AtomicBoolean eventLock = new AtomicBoolean(); protected AtomicBoolean eventLock = new AtomicBoolean();


final ExecutorService reloadService; final ThreadPoolExecutor reloadService;


public ReloadHzSynchronizer(HzCluster cluster, GeoServer gs) { public ReloadHzSynchronizer(HzCluster cluster, GeoServer gs) {
super(cluster, gs); super(cluster, gs);
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.SynchronousQueue; import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import org.geoserver.catalog.DataStoreInfo; import org.geoserver.catalog.DataStoreInfo;
import org.geoserver.catalog.FeatureTypeInfo; import org.geoserver.catalog.FeatureTypeInfo;
import org.geoserver.catalog.LayerInfo; import org.geoserver.catalog.LayerInfo;
Expand Down Expand Up @@ -143,10 +144,16 @@ private void expectGeoServerReload() throws Exception {
@Override @Override
protected void waitForSync() throws Exception { protected void waitForSync() throws Exception {
super.waitForSync(); super.waitForSync();
// Add a small delay to reload calls to mitigate a race condition. // Wait up to 5 seconds for the executor to be ready for the next reload.
try { ThreadPoolExecutor executor = ((ReloadHzSynchronizer) sync).reloadService;
Thread.sleep(200); for (int i = 0; i < 200; i++) {
} catch (InterruptedException e) { if (executor.getActiveCount() == 0) {
return;
}
try {
Thread.sleep(25);
} catch (InterruptedException e) {
}
} }
} }
} }

0 comments on commit 2469eca

Please sign in to comment.