This is an automated email from the ASF dual-hosted git repository.
svenmeier pushed a commit to branch WICKET-6563
in repository https://gitbox.apache.org/repos/asf/wicket.git
The following commit(s) were added to refs/heads/WICKET-6563 by this push:
new 4d49a21 WICKET-6563 added tests for maxBytes
4d49a21 is described below
commit 4d49a21f9dcfc81de12add9cbb4c47ecd0497f47
Author: Sven Meier <[email protected]>
AuthorDate: Wed Jan 23 09:57:13 2019 +0100
WICKET-6563 added tests for maxBytes
and check for page in remove()
---
.../apache/wicket/pageStore/InMemoryPageStore.java | 19 +++++------
.../wicket/pageStore/InSessionPageStore.java | 14 ++++----
.../wicket/pageStore/AbstractPageStoreTest.java | 37 +++++++++++++++-------
.../pageStore/InMemoryPageStoreSizeTest.java | 31 ++++++++++++++++++
.../pageStore/InSessionPageStoreSizeTest.java | 32 +++++++++++++++++++
5 files changed, 105 insertions(+), 28 deletions(-)
diff --git
a/wicket-core/src/main/java/org/apache/wicket/pageStore/InMemoryPageStore.java
b/wicket-core/src/main/java/org/apache/wicket/pageStore/InMemoryPageStore.java
index 4764018..e8bca9c 100644
---
a/wicket-core/src/main/java/org/apache/wicket/pageStore/InMemoryPageStore.java
+++
b/wicket-core/src/main/java/org/apache/wicket/pageStore/InMemoryPageStore.java
@@ -231,10 +231,10 @@ public class InMemoryPageStore extends
AbstractPersistentPageStore
return page;
}
- protected void removeFirst() {
- Iterator<IManageablePage> iterator =
pages.values().iterator();
- iterator.next();
- iterator.remove();
+ protected void removeOldest() {
+ IManageablePage page = pages.values().iterator().next();
+
+ remove(page.getPageId());
}
}
@@ -258,7 +258,7 @@ public class InMemoryPageStore extends
AbstractPersistentPageStore
while (pages.size() > maxPages)
{
- removeFirst();
+ removeOldest();
}
}
}
@@ -294,7 +294,7 @@ public class InMemoryPageStore extends
AbstractPersistentPageStore
while (size > maxBytes.bytes())
{
- removeFirst();
+ removeOldest();
}
}
@@ -302,9 +302,10 @@ public class InMemoryPageStore extends
AbstractPersistentPageStore
public synchronized IManageablePage remove(int pageId)
{
SerializedPage page = (SerializedPage)
super.remove(pageId);
-
- size -= ((SerializedPage) page).getData().length;
-
+ if (page != null)
+ {
+ size -= ((SerializedPage)
page).getData().length;
+ }
return page;
}
diff --git
a/wicket-core/src/main/java/org/apache/wicket/pageStore/InSessionPageStore.java
b/wicket-core/src/main/java/org/apache/wicket/pageStore/InSessionPageStore.java
index c880ce0..81d1060 100644
---
a/wicket-core/src/main/java/org/apache/wicket/pageStore/InSessionPageStore.java
+++
b/wicket-core/src/main/java/org/apache/wicket/pageStore/InSessionPageStore.java
@@ -212,13 +212,11 @@ public class InSessionPageStore extends
DelegatingPageStore
pages.add(page);
}
- public synchronized IManageablePage removeFirst()
+ protected synchronized void removeOldest()
{
IManageablePage page = pages.get(0);
remove(page.getPageId());
-
- return page;
}
public synchronized IManageablePage remove(int pageId)
@@ -311,7 +309,7 @@ public class InSessionPageStore extends DelegatingPageStore
while (pages.size() > maxPages)
{
- removeFirst();
+ removeOldest();
}
}
}
@@ -347,7 +345,7 @@ public class InSessionPageStore extends DelegatingPageStore
while (size > maxBytes.bytes())
{
- removeFirst();
+ removeOldest();
}
}
@@ -355,8 +353,10 @@ public class InSessionPageStore extends DelegatingPageStore
public synchronized IManageablePage remove(int pageId)
{
SerializedPage page = (SerializedPage)
super.remove(pageId);
-
- size -= ((SerializedPage) page).getData().length;
+ if (page != null)
+ {
+ size -= ((SerializedPage)
page).getData().length;
+ }
return page;
}
diff --git
a/wicket-core/src/test/java/org/apache/wicket/pageStore/AbstractPageStoreTest.java
b/wicket-core/src/test/java/org/apache/wicket/pageStore/AbstractPageStoreTest.java
index 038b830..37f4e64 100644
---
a/wicket-core/src/test/java/org/apache/wicket/pageStore/AbstractPageStoreTest.java
+++
b/wicket-core/src/test/java/org/apache/wicket/pageStore/AbstractPageStoreTest.java
@@ -31,7 +31,17 @@ public abstract class AbstractPageStoreTest
{
protected final String sessionId = "1234567890";
protected final int pageId = 123;
+
+ /**
+ * Maximum entries in store.
+ */
protected int maxEntries = 1;
+
+ /**
+ * Data for stored pages.
+ */
+ protected byte[] pageData = new byte[1];
+
protected IPageStore pageStore = null;
@BeforeEach
@@ -60,7 +70,7 @@ public abstract class AbstractPageStoreTest
{
IPageContext context = new DummyPageContext(sessionId);
- pageStore.addPage(context, new SerializedPage(pageId, new
byte[0]));
+ pageStore.addPage(context, new SerializedPage(pageId,
pageData));
assertNotNull(pageStore.getPage(context, pageId));
}
@@ -78,12 +88,12 @@ public abstract class AbstractPageStoreTest
pageStore = createPageStore(maxEntries);
- pageStore.addPage(context, new SerializedPage(pageId, new
byte[0]));
- pageStore.addPage(context, new SerializedPage(pageId, new
byte[0]));
+ pageStore.addPage(context, new SerializedPage(pageId,
pageData));
+ pageStore.addPage(context, new SerializedPage(pageId,
pageData));
assertNotNull(pageStore.getPage(context, pageId));
- pageStore.removePage(context, new SerializedPage(pageId, new
byte[0]));
+ pageStore.removePage(context, new SerializedPage(pageId,
pageData));
assertNull(pageStore.getPage(context, pageId));
}
@@ -93,13 +103,16 @@ public abstract class AbstractPageStoreTest
{
IPageContext context = new DummyPageContext(sessionId);
- pageStore.addPage(context, new SerializedPage(pageId, new
byte[0]));
+ pageStore.addPage(context, new SerializedPage(pageId,
pageData));
assertNotNull(pageStore.getPage(context, pageId));
- pageStore.removePage(context, new SerializedPage(pageId, new
byte[0]));
+ pageStore.removePage(context, new SerializedPage(pageId,
pageData));
assertNull(pageStore.getPage(context, pageId));
+
+ int pageId2 = 234;
+ pageStore.removePage(context, new SerializedPage(pageId2,
pageData));
}
@Test
@@ -135,7 +148,7 @@ public abstract class AbstractPageStoreTest
}
};
- pageStore.removePage(context, new SerializedPage(0, new
byte[0]));
+ pageStore.removePage(context, new SerializedPage(0, pageData));
}
@Test
@@ -143,7 +156,7 @@ public abstract class AbstractPageStoreTest
{
IPageContext context = new DummyPageContext(sessionId);
- pageStore.addPage(context, new SerializedPage(pageId, new
byte[0]));
+ pageStore.addPage(context, new SerializedPage(pageId,
pageData));
assertNotNull(pageStore.getPage(context, pageId));
@@ -160,12 +173,12 @@ public abstract class AbstractPageStoreTest
{
IPageContext context = new DummyPageContext(sessionId);
- pageStore.addPage(context, new SerializedPage(pageId, new
byte[0]));
+ pageStore.addPage(context, new SerializedPage(pageId,
pageData));
assertNotNull(pageStore.getPage(context, pageId));
int pageId2 = 234;
- pageStore.addPage(context, new SerializedPage(pageId2, new
byte[0]));
+ pageStore.addPage(context, new SerializedPage(pageId2,
pageData));
assertNull(pageStore.getPage(context, pageId));
assertNotNull(pageStore.getPage(context, pageId2));
}
@@ -180,11 +193,11 @@ public abstract class AbstractPageStoreTest
IPageContext context = new DummyPageContext(sessionId);
IPageContext context2 = new DummyPageContext("0987654321");
- pageStore.addPage(context, new SerializedPage(pageId, new
byte[0]));
+ pageStore.addPage(context, new SerializedPage(pageId,
pageData));
assertNotNull(pageStore.getPage(context, pageId));
- pageStore.addPage(context2, new SerializedPage(pageId, new
byte[0]));
+ pageStore.addPage(context2, new SerializedPage(pageId,
pageData));
assertNotNull(pageStore.getPage(context, pageId));
assertNotNull(pageStore.getPage(context2, pageId));
diff --git
a/wicket-core/src/test/java/org/apache/wicket/pageStore/InMemoryPageStoreSizeTest.java
b/wicket-core/src/test/java/org/apache/wicket/pageStore/InMemoryPageStoreSizeTest.java
new file mode 100644
index 0000000..b4f7301
--- /dev/null
+++
b/wicket-core/src/test/java/org/apache/wicket/pageStore/InMemoryPageStoreSizeTest.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.pageStore;
+
+import org.apache.wicket.util.lang.Bytes;
+
+/**
+ * Tests for {@link InMemoryPageStore} with maximum size.
+ */
+public class InMemoryPageStoreSizeTest extends AbstractPageStoreTest
+{
+ @Override
+ protected IPageStore createPageStore(int maxEntries)
+ {
+ return new InMemoryPageStore("test",
Bytes.bytes(pageData.length * maxEntries));
+ }
+}
diff --git
a/wicket-core/src/test/java/org/apache/wicket/pageStore/InSessionPageStoreSizeTest.java
b/wicket-core/src/test/java/org/apache/wicket/pageStore/InSessionPageStoreSizeTest.java
new file mode 100644
index 0000000..f0697bd
--- /dev/null
+++
b/wicket-core/src/test/java/org/apache/wicket/pageStore/InSessionPageStoreSizeTest.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.pageStore;
+
+import org.apache.wicket.util.lang.Bytes;
+
+/**
+ * Test for {@link InSessionPageStore} with maximum size.
+ */
+public class InSessionPageStoreSizeTest extends AbstractPageStoreTest
+{
+ @Override
+ protected IPageStore createPageStore(int maxEntries)
+ {
+ return new InSessionPageStore(new NoopPageStore(),
Bytes.bytes(pageData.length * maxEntries));
+ }
+
+}