You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by sv...@apache.org on 2020/06/01 13:22:11 UTC

[wicket] branch master updated: WICKET-6793 remove pending from map too

This is an automated email from the ASF dual-hosted git repository.

svenmeier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/wicket.git


The following commit(s) were added to refs/heads/master by this push:
     new 96c9918  WICKET-6793 remove pending from map too
96c9918 is described below

commit 96c99181ac74607910795eefbb27c88a706e8f0d
Author: Sven Meier <sv...@apache.org>
AuthorDate: Mon Jun 1 11:18:12 2020 +0200

    WICKET-6793 remove pending from map too
---
 .../wicket/pageStore/AsynchronousPageStore.java    | 25 +++++----
 .../pageStore/AsynchronousPageStoreTest.java       | 59 +++++++++++++++++++++-
 2 files changed, 73 insertions(+), 11 deletions(-)

diff --git a/wicket-core/src/main/java/org/apache/wicket/pageStore/AsynchronousPageStore.java b/wicket-core/src/main/java/org/apache/wicket/pageStore/AsynchronousPageStore.java
index 735683c..fd55e40 100644
--- a/wicket-core/src/main/java/org/apache/wicket/pageStore/AsynchronousPageStore.java
+++ b/wicket-core/src/main/java/org/apache/wicket/pageStore/AsynchronousPageStore.java
@@ -242,18 +242,18 @@ public class AsynchronousPageStore extends DelegatingPageStore
 	{
 		private static final Logger log = LoggerFactory.getLogger(PageAddingRunnable.class);
 
-		private final BlockingQueue<PendingAdd> entries;
+		private final BlockingQueue<PendingAdd> queue;
 
-		private final ConcurrentMap<String, PendingAdd> addQueue;
+		private final ConcurrentMap<String, PendingAdd> map;
 
 		private final IPageStore delegate;
 
-		private PageAddingRunnable(IPageStore delegate, BlockingQueue<PendingAdd> entries,
-		                           ConcurrentMap<String, PendingAdd> entryMap)
+		private PageAddingRunnable(IPageStore delegate, BlockingQueue<PendingAdd> queue,
+		                           ConcurrentMap<String, PendingAdd> map)
 		{
 			this.delegate = delegate;
-			this.entries = entries;
-			this.addQueue = entryMap;
+			this.queue = queue;
+			this.map = map;
 		}
 
 		@Override
@@ -264,7 +264,7 @@ public class AsynchronousPageStore extends DelegatingPageStore
 				PendingAdd add = null;
 				try
 				{
-					add = entries.poll(POLL_WAIT, TimeUnit.MILLISECONDS);
+					add = queue.poll(POLL_WAIT, TimeUnit.MILLISECONDS);
 				}
 				catch (InterruptedException e)
 				{
@@ -276,7 +276,7 @@ public class AsynchronousPageStore extends DelegatingPageStore
 					log.debug("Saving asynchronously: {}...", add);
 					add.asynchronous = true;					
 					delegate.addPage(add, add.page);
-					addQueue.remove(add.getKey());
+					map.remove(add.getKey());
 				}
 			}
 		}
@@ -383,7 +383,14 @@ public class AsynchronousPageStore extends DelegatingPageStore
 			return;
 		}
 
-		queue.removeIf(add -> add.sessionId.equals(sessionId));
+		queue.removeIf(add -> {
+			if (add.sessionId.equals(sessionId)) {
+				queueMap.remove(add.getKey());
+				return true;
+			}
+			
+			return false;
+		});
 		
 		getDelegate().removeAllPages(context);
 	}
diff --git a/wicket-core/src/test/java/org/apache/wicket/pageStore/AsynchronousPageStoreTest.java b/wicket-core/src/test/java/org/apache/wicket/pageStore/AsynchronousPageStoreTest.java
index 3f72f98..ffd85e5 100644
--- a/wicket-core/src/test/java/org/apache/wicket/pageStore/AsynchronousPageStoreTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/pageStore/AsynchronousPageStoreTest.java
@@ -176,8 +176,6 @@ public class AsynchronousPageStoreTest
 	{
 		final Semaphore semaphore = new Semaphore(0);
 		
-		final AtomicBoolean got = new AtomicBoolean(false);
-		
 		IPageStore store = new MockPageStore() {
 			
 			@Override
@@ -224,6 +222,63 @@ public class AsynchronousPageStoreTest
 	}
 
 	/**
+	 * WICKET-6793
+	 *
+	 * @throws InterruptedException
+	 */
+	@Test
+	void dontKeepPendingPagesInMapIfSessionExpires() throws InterruptedException
+	{
+
+		final Semaphore semaphore = new Semaphore(0);
+		
+		IPageStore store = new NoopPageStore() {
+			
+			@Override
+			public synchronized void addPage(IPageContext context, IManageablePage page)
+			{
+				try
+				{
+					semaphore.acquire();
+				}
+				catch (InterruptedException e)
+				{
+				}
+			}
+			
+			@Override
+			public IManageablePage getPage(IPageContext context, int id)
+			{
+				return null;
+			}
+		};
+
+		IPageStore asyncPageStore = new AsynchronousPageStore(store, 100);
+
+		int pageId = 0;
+		
+		String sessionId = "sessionId";
+		
+		IPageContext context = new MockPageContext(sessionId);
+
+		SerializedPage page = new SerializedPage(pageId, "", new byte[0]);
+		// add twice so the first one clogs the queue and the second
+		// is still present in the queue
+		asyncPageStore.addPage(context, page);
+		asyncPageStore.addPage(context, page);
+
+		// clear the queue
+		asyncPageStore.removeAllPages(context);
+		
+		assertEquals(null, asyncPageStore.getPage(context, pageId));
+		
+		store.destroy();
+
+		semaphore.release();
+	}
+
+
+	/**
 	 * Store works fully asynchronous when number of pages handled never exceeds the
 	 * asynchronous-storage capacity.
 	 *