Skip to content

Commit

Permalink
[WFLY-11944] Some clustering test cases do not close JNDI context bet…
Browse files Browse the repository at this point in the history
…ween tests.
  • Loading branch information
rachmatowicz committed Apr 4, 2019
1 parent c1cd4db commit 7aca80c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 23 deletions.
Expand Up @@ -36,9 +36,9 @@
import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.AfterClass; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.BeforeClass; import org.junit.Before;


/** /**
* @author Ondrej Chaloupka * @author Ondrej Chaloupka
Expand All @@ -49,8 +49,8 @@ public abstract class RemoteEJBClientStatefulFailoverTestBase extends AbstractCl
protected static final String MODULE_NAME = RemoteEJBClientStatefulFailoverTestBase.class.getSimpleName(); protected static final String MODULE_NAME = RemoteEJBClientStatefulFailoverTestBase.class.getSimpleName();
protected static final String MODULE_NAME_SINGLE = MODULE_NAME + "-single"; protected static final String MODULE_NAME_SINGLE = MODULE_NAME + "-single";


protected static EJBDirectory singletonDirectory; protected EJBDirectory singletonDirectory;
protected static EJBDirectory directory; protected EJBDirectory directory;


protected static Archive<?> createDeploymentSingleton() { protected static Archive<?> createDeploymentSingleton() {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, MODULE_NAME_SINGLE + ".jar"); final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, MODULE_NAME_SINGLE + ".jar");
Expand All @@ -69,14 +69,14 @@ public void afterTestMethod() {
undeploy(TWO_DEPLOYMENT_HELPERS); undeploy(TWO_DEPLOYMENT_HELPERS);
} }


@BeforeClass @Before
public static void beforeClass() throws NamingException { public void beforeTest() throws NamingException {
directory = new RemoteEJBDirectory(MODULE_NAME); directory = new RemoteEJBDirectory(MODULE_NAME);
singletonDirectory = new RemoteEJBDirectory(MODULE_NAME_SINGLE); singletonDirectory = new RemoteEJBDirectory(MODULE_NAME_SINGLE);
} }


@AfterClass @After
public static void destroy() throws Exception { public void afterTest() throws Exception {
directory.close(); directory.close();
singletonDirectory.close(); singletonDirectory.close();
} }
Expand Down
Expand Up @@ -39,9 +39,9 @@
import org.jboss.as.test.clustering.ejb.RemoteEJBDirectory; import org.jboss.as.test.clustering.ejb.RemoteEJBDirectory;
import org.jboss.ejb.client.EJBClientContext; import org.jboss.ejb.client.EJBClientContext;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import org.junit.AfterClass; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.BeforeClass; import org.junit.Before;


/** /**
* Base class for passivation tests on EJB2 beans. * Base class for passivation tests on EJB2 beans.
Expand All @@ -52,15 +52,15 @@ public abstract class ClusterPassivationTestBase {
private static Logger log = Logger.getLogger(ClusterPassivationTestBase.class); private static Logger log = Logger.getLogger(ClusterPassivationTestBase.class);
public static final String MODULE_NAME = ClusterPassivationTestBase.class.getSimpleName(); public static final String MODULE_NAME = ClusterPassivationTestBase.class.getSimpleName();


protected static EJBDirectory directory; protected EJBDirectory directory;


@BeforeClass @Before
public static void beforeClass() throws NamingException { public void beforeTest() throws NamingException {
directory = new RemoteEJBDirectory(MODULE_NAME); directory = new RemoteEJBDirectory(MODULE_NAME);
} }


@AfterClass @After
public static void destroy() throws Exception { public void afterTest() throws Exception {
directory.close(); directory.close();
} }


Expand Down
Expand Up @@ -49,8 +49,9 @@
import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.AfterClass; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
Expand All @@ -64,8 +65,6 @@
@RunWith(Arquillian.class) @RunWith(Arquillian.class)
public class RemoteStatelessFailoverTestCase { public class RemoteStatelessFailoverTestCase {
private static final Logger log = Logger.getLogger(RemoteStatelessFailoverTestCase.class); private static final Logger log = Logger.getLogger(RemoteStatelessFailoverTestCase.class);
private static EJBDirectory directoryAnnotation;
private static EJBDirectory directoryDD;


private static final String MODULE_NAME = RemoteStatelessFailoverTestCase.class.getSimpleName(); private static final String MODULE_NAME = RemoteStatelessFailoverTestCase.class.getSimpleName();
private static final String MODULE_NAME_DD = MODULE_NAME + "dd"; private static final String MODULE_NAME_DD = MODULE_NAME + "dd";
Expand All @@ -74,11 +73,11 @@ public class RemoteStatelessFailoverTestCase {
private static final Map<String, Boolean> started = new HashMap<String, Boolean>(); private static final Map<String, Boolean> started = new HashMap<String, Boolean>();
private static final Map<String, List<String>> container2deployment = new HashMap<String, List<String>>(); private static final Map<String, List<String>> container2deployment = new HashMap<String, List<String>>();


private EJBDirectory directoryAnnotation;
private EJBDirectory directoryDD;

@BeforeClass @BeforeClass
public static void init() throws NamingException { public static void init() throws NamingException {
directoryAnnotation = new RemoteEJBDirectory(MODULE_NAME);
directoryDD = new RemoteEJBDirectory(MODULE_NAME_DD);

deployed.put(DEPLOYMENT_1, false); deployed.put(DEPLOYMENT_1, false);
deployed.put(DEPLOYMENT_2, false); deployed.put(DEPLOYMENT_2, false);
deployed.put(DEPLOYMENT_HELPER_1, false); deployed.put(DEPLOYMENT_HELPER_1, false);
Expand All @@ -96,8 +95,15 @@ public static void init() throws NamingException {
container2deployment.put(NODE_2, deployments2); container2deployment.put(NODE_2, deployments2);
} }


@AfterClass
public static void destroy() throws Exception { @Before
public void beforeTest() throws Exception {
directoryAnnotation = new RemoteEJBDirectory(MODULE_NAME);
directoryDD = new RemoteEJBDirectory(MODULE_NAME_DD);
}

@After
public void afterTest() throws Exception {
directoryAnnotation.close(); directoryAnnotation.close();
directoryDD.close(); directoryDD.close();
} }
Expand Down
Expand Up @@ -29,6 +29,12 @@


/** /**
* {@link EJBDirectory} that uses remote JNDI. * {@link EJBDirectory} that uses remote JNDI.
*
* NOTE:
* if you hold a static reference to this class, it causes any JNDI lookups across different tests to use the same discovered node registry (DNR).
* This can cause server starts and stops in one test to contaminate other tests and produce incorrect results.
* It is adviseable to use one instance per test by defining a @Before and @After method to create and dispose of the instance on a per test basis.
*
* @author Paul Ferraro * @author Paul Ferraro
*/ */
public class RemoteEJBDirectory extends NamingEJBDirectory { public class RemoteEJBDirectory extends NamingEJBDirectory {
Expand Down

0 comments on commit 7aca80c

Please sign in to comment.