Skip to content

Commit

Permalink
AS7-4430 InterceptorContext.getTarget() returns null for PrePassivate…
Browse files Browse the repository at this point in the history
… and PostActivate methods
  • Loading branch information
stuartwdouglas committed Apr 9, 2012
1 parent 57aab58 commit 97e9c62
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ private Object execute(final Interceptor interceptor, final Method method, final
interceptorContext.putPrivateData(ComponentInstance.class, this);
interceptorContext.putPrivateData(InvokeMethodOnTargetInterceptor.PARAMETERS_KEY, parameters);
interceptorContext.setContextData(new HashMap<String, Object>());
interceptorContext.setTarget(getInstance());
try {
return interceptor.processInvocation(interceptorContext);
} catch (Error e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.jboss.as.test.integration.ejb.stateful.passivation;

import java.io.Serializable;

import javax.ejb.PostActivate;
import javax.ejb.PrePassivate;
import javax.interceptor.InvocationContext;

/**
* @author Stuart Douglas
*/
public class PassivationInterceptor implements Serializable {

private static volatile Object postActivateTarget, prePassivateTarget;

@PostActivate
public void postActivate(final InvocationContext ctx) throws Exception {
postActivateTarget = ctx.getTarget();
ctx.proceed();
}
@PrePassivate
public void prePassivate(final InvocationContext ctx) throws Exception {
prePassivateTarget = ctx.getTarget();
ctx.proceed();
}

public static void reset() {
postActivateTarget = prePassivateTarget = null;
}

public static Object getPostActivateTarget() {
return postActivateTarget;
}

public static Object getPrePassivateTarget() {
return prePassivateTarget;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ private static ModelNode getAddress() {

@Test
public void testPassivationMaxSize() throws Exception {
PassivationInterceptor.reset();
TestPassivationRemote remote1 = (TestPassivationRemote) ctx.lookup("java:module/"
+ TestPassivationBean.class.getSimpleName());
Assert.assertEquals("Returned remote1 result was not expected", TestPassivationRemote.EXPECTED_RESULT,
Expand Down Expand Up @@ -149,10 +150,13 @@ public void testPassivationMaxSize() throws Exception {

remote1.remove();
remote2.remove();
Assert.assertTrue(PassivationInterceptor.getPostActivateTarget() instanceof TestPassivationBean);
Assert.assertTrue(PassivationInterceptor.getPrePassivateTarget() instanceof TestPassivationBean);
}

@Test
public void testPassivationIdleTimeout() throws Exception {
PassivationInterceptor.reset();
// Lookup and create stateful instance
TestPassivationRemote remote = (TestPassivationRemote) ctx.lookup("java:module/"
+ TestPassivationBean.class.getSimpleName());
Expand All @@ -169,5 +173,7 @@ public void testPassivationIdleTimeout() throws Exception {
// Ensure that @PrePassivate was called during the client sleep
Assert.assertTrue("@PrePassivate not called, check CacheConfig and client sleep time", remote.hasBeenPassivated());
remote.remove();
Assert.assertTrue(PassivationInterceptor.getPostActivateTarget() instanceof TestPassivationBean);
Assert.assertTrue(PassivationInterceptor.getPrePassivateTarget() instanceof TestPassivationBean);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import javax.ejb.Remote;
import javax.ejb.Remove;
import javax.ejb.Stateful;
import javax.interceptor.Interceptors;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;
Expand All @@ -44,6 +45,7 @@
@Stateful
@Remote(TestPassivationRemote.class)
@Cache("passivating")
@Interceptors(PassivationInterceptor.class)
public class TestPassivationBean extends PassivationSuperClass implements TestPassivationRemote {
private static final Logger log = Logger.getLogger(TestPassivationBean.class);

Expand Down

0 comments on commit 97e9c62

Please sign in to comment.