You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by br...@apache.org on 2022/03/01 00:20:01 UTC
[geode] branch feature/GEODE-10093 created (now f3c043f)
This is an automated email from the ASF dual-hosted git repository.
bross pushed a change to branch feature/GEODE-10093
in repository https://gitbox.apache.org/repos/asf/geode.git.
at f3c043f GEODE-10093 - Fixed attr issue in Delta Session
This branch includes the following new commits:
new f3c043f GEODE-10093 - Fixed attr issue in Delta Session
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[geode] 01/01: GEODE-10093 - Fixed attr issue in Delta Session
Posted by br...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
bross pushed a commit to branch feature/GEODE-10093
in repository https://gitbox.apache.org/repos/asf/geode.git
commit f3c043f89af8d4064ff6f8d86d02662caa85fcea
Author: Ben Ross <ro...@vmware.com>
AuthorDate: Mon Feb 28 16:07:24 2022 -0800
GEODE-10093 - Fixed attr issue in Delta Session
---
.../AbstractDeltaSessionIntegrationTest.java | 83 ++++++++++++++++++++--
.../modules/session/catalina/DeltaSession.java | 8 ++-
2 files changed, 84 insertions(+), 7 deletions(-)
diff --git a/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/AbstractDeltaSessionIntegrationTest.java b/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/AbstractDeltaSessionIntegrationTest.java
index 5008b17..1c3a270 100644
--- a/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/AbstractDeltaSessionIntegrationTest.java
+++ b/extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/AbstractDeltaSessionIntegrationTest.java
@@ -17,11 +17,8 @@ package org.apache.geode.modules.session.catalina;
import static org.apache.geode.cache.RegionShortcut.PARTITION;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.when;
+import static org.mockito.ArgumentMatchers.*;
+import static org.mockito.Mockito.*;
import java.io.IOException;
@@ -30,6 +27,8 @@ import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;
import org.apache.catalina.Context;
+import org.apache.geode.modules.session.catalina.internal.DeltaSessionDestroyAttributeEvent;
+import org.apache.geode.modules.session.catalina.internal.DeltaSessionUpdateAttributeEvent;
import org.apache.juli.logging.Log;
import org.junit.Before;
import org.junit.Rule;
@@ -41,6 +40,8 @@ import org.apache.geode.internal.util.BlobHelper;
import org.apache.geode.modules.session.catalina.callback.SessionExpirationCacheListener;
import org.apache.geode.modules.session.catalina.internal.DeltaSessionStatistics;
import org.apache.geode.test.junit.rules.ServerStarterRule;
+import org.mockito.InOrder;
+import org.mockito.Mockito;
public abstract class AbstractDeltaSessionIntegrationTest<DeltaSessionManagerT extends DeltaSessionManager<?>, DeltaSessionT extends DeltaSession> {
protected static final String KEY = "key1";
@@ -107,4 +108,76 @@ public abstract class AbstractDeltaSessionIntegrationTest<DeltaSessionManagerT e
verifyNoMoreInteractions(listener);
assertThat(event.getValue().getValue()).isEqualTo(value1);
}
+
+ @Test
+ public void setNewAttributeWithNullValueInvokesRemove() {
+ final HttpSessionAttributeListener listener = mock(HttpSessionAttributeListener.class);
+ when(context.getApplicationEventListeners()).thenReturn(new Object[] {listener});
+ when(manager.isBackingCacheAvailable()).thenReturn(true);
+
+ final DeltaSessionT session = spy(newSession(manager));
+ session.setId(KEY, false);
+ session.setValid(true);
+ session.setOwner(manager);
+
+ final String name = "attribute";
+ final Object nullValue = null;
+
+ session.setAttribute(name, nullValue);
+ assertThat(session.getAttributes().size()).isEqualTo(0);
+
+ //Mockito.inOrder
+ verify(session).queueAttributeEvent(any(DeltaSessionDestroyAttributeEvent.class), anyBoolean());
+ verify(session, times(0)).queueAttributeEvent(any(DeltaSessionUpdateAttributeEvent.class), anyBoolean());
+ verify(session).removeAttribute(eq(name));
+ }
+
+ @Test
+ public void setExistingAttributeWithNullValueInvokesRemove() {
+ final HttpSessionAttributeListener listener = mock(HttpSessionAttributeListener.class);
+ when(context.getApplicationEventListeners()).thenReturn(new Object[] {listener});
+ when(manager.isBackingCacheAvailable()).thenReturn(true);
+
+ final DeltaSessionT session = spy(newSession(manager));
+ session.setId(KEY, false);
+ session.setValid(true);
+ session.setOwner(manager);
+
+ final String name = "attribute";
+ final Object value = "value";
+ final Object nullValue = null;
+
+ session.setAttribute(name, value);
+ assertThat(session.getAttributes().size()).isEqualTo(1);
+
+ session.setAttribute(name, nullValue);
+ assertThat(session.getAttributes().size()).isEqualTo(0);
+
+
+ InOrder inOrder = Mockito.inOrder(session);
+ inOrder.verify(session).queueAttributeEvent(any(DeltaSessionUpdateAttributeEvent.class), anyBoolean());
+ inOrder.verify(session).removeAttribute(eq(name));
+ inOrder.verify(session).queueAttributeEvent(any(DeltaSessionDestroyAttributeEvent.class), anyBoolean());
+ }
+
+ @Test
+ public void getAttributeWithNullValueReturnsNull() throws IOException, ClassNotFoundException {
+ final HttpSessionAttributeListener listener = mock(HttpSessionAttributeListener.class);
+ when(context.getApplicationEventListeners()).thenReturn(new Object[] {listener});
+ when(manager.isBackingCacheAvailable()).thenReturn(true);
+
+ final DeltaSessionT session = spy(newSession(manager));
+ session.setId(KEY, false);
+ session.setValid(true);
+ session.setOwner(manager);
+
+ final String name = "attribute";
+ final Object value = null;
+
+ final byte[] serializedValue1 = BlobHelper.serializeToBlob(value);
+ // simulates initial deserialized state with serialized attribute values.
+ session.getAttributes().put(name, serializedValue1);
+
+ assertThat(session.getAttribute(name)).isNull();
+ }
}
diff --git a/extensions/geode-modules/src/main/java/org/apache/geode/modules/session/catalina/DeltaSession.java b/extensions/geode-modules/src/main/java/org/apache/geode/modules/session/catalina/DeltaSession.java
index e745ffe..c4661ca 100644
--- a/extensions/geode-modules/src/main/java/org/apache/geode/modules/session/catalina/DeltaSession.java
+++ b/extensions/geode-modules/src/main/java/org/apache/geode/modules/session/catalina/DeltaSession.java
@@ -266,7 +266,7 @@ public class DeltaSession extends StandardSession
super.setAttribute(name, serializedValue, true);
}
- if (serializedValue == null) {
+ if (value == null) {
return;
}
@@ -353,6 +353,10 @@ public class DeltaSession extends StandardSession
if (value instanceof byte[]) {
try {
final Object deserialized = BlobHelper.deserializeBlob((byte[]) value);
+ if(deserialized == null) {
+ removeAttributeInternal(name, false);
+ return null;
+ }
if (store) {
setAttributeInternal(name, deserialized);
}
@@ -478,7 +482,7 @@ public class DeltaSession extends StandardSession
}
}
- private void queueAttributeEvent(DeltaSessionAttributeEvent event,
+ void queueAttributeEvent(DeltaSessionAttributeEvent event,
boolean checkAddToCurrentGatewayDelta) {
// Add to current gateway delta if necessary
if (checkAddToCurrentGatewayDelta) {