[arquillian-issues] [JBoss JIRA] (ARQ-1937) Class loading issue with injected deployer

Aslak Knutsen (JIRA) issues at jboss.org
Mon Mar 23 07:32:19 EDT 2015


    [ https://issues.jboss.org/browse/ARQ-1937?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13052535#comment-13052535 ] 

Aslak Knutsen commented on ARQ-1937:
------------------------------------

It's not technically wrong what you're doing, it's just not what you expected.. :)

The confusing scenario here I guess is that you can OperateOnDeployment which is not deployed, by which means RunAsClient. The deployment has a DeploymentScope/Context regardless of being deployed or not, but since it's not deployed it can only RunAsClient... we could make that Illegal unless you also explicitly specify RunAsClient. 

{code}
@Test @OperatesOnDeployment("X") // iIlegal
public void shouldX() {
  deployer.deploy("x")
}

@Test @OperatesOnDeployment("X") @RunAsClient // legal
public void shouldX() {
  deployer.deploy("x")
}

{code}

> Class loading issue with injected deployer 
> -------------------------------------------
>
>                 Key: ARQ-1937
>                 URL: https://issues.jboss.org/browse/ARQ-1937
>             Project: Arquillian
>          Issue Type: Bug
>    Affects Versions: 1.1.1.Final
>            Reporter: Martin Gencur
>
> Steps to reproduce:
> 1) inject a Deployer via @ArquillianResource
> 2) declare a deployment as managed=false, use the deployer to deploy artifacts to a managed container
> 3) run a test method that operates on the deployment
> 4) check that classes inside the test method have the same classloader as the test class itself (see the code below where I call cache.getClass().getClassLoader())
> 5) this does not happen when the deployment is managed=true and deployer API is NOT used. In this case, the classes have a different class loader
> In the test below, I tried to load different versions of Infinispan in two deployments and test backward compatibility. However, due to this class loading issue the Infinispan classes are of the latest version regardless of libraries bundled in the WAR. This is probably due to the fact that the Maven test module has the latest Infinispan libraries defined in <dependencies> while the older version is downloaded separately via Maven dependency plugin.
> {code}
> package com.jboss.datagrid.test.backwardcompatibility;
> @RunWith(Arquillian.class)
> public class SingleFileStoreBackwardCompatibilityIT {
>     private DefaultCacheManager dfc;
>     private String cacheName = "testCache";
>     private static final String OLD_ISPN = "dep1_with_old_ispn";
>     private static final String NEW_ISPN = "dep2_with_new_ispn";
>     private static Map<String, String> storedMap;
>     @ArquillianResource
>     Deployer deployer;
>     @Deployment(name = OLD_ISPN, testable = true, managed = true, order=1)
>     @TargetsContainer("container1")
>     public static WebArchive createDeploymentOld() {
>         WebArchive jar = DeploymentBuilder.createTestArchiveWithPreviousJDG("test1.war", "previous");
>         System.out.println("ClassLoader: " + SingleFileStoreBackwardCompatibilityIT.class.getClassLoader());
>         return jar;
>     }
>     @Deployment(name = NEW_ISPN, testable = true, managed = true, order=2)
>     @TargetsContainer("container2")
>     public static WebArchive createDeploymentNew() {
>         WebArchive jar = DeploymentBuilder.createTestArchive("test2.war", "current");
>         return jar;
>     }
>     private DefaultCacheManager configureCacheManager(boolean clearCacheStore) throws Exception {
>         GlobalConfiguration glob = new GlobalConfigurationBuilder().nonClusteredDefault()
>                 .globalJmxStatistics().allowDuplicateDomains(true).
>                         build();
>         ConfigurationBuilder c = new ConfigurationBuilder();
>         c.clustering().cacheMode(CacheMode.LOCAL);
>         File tmpStore = new File("/tmp/cache/" + cacheName + ".dat");
>         if (clearCacheStore && tmpStore.exists()) {
>             tmpStore.delete();
>         }
>         c.persistence().passivation(false).addSingleFileStore().purgeOnStartup(false).location("/tmp/cache/");
>         Configuration cnf = c.build();
>         DefaultCacheManager manager = new DefaultCacheManager(glob);
>         manager.defineConfiguration(cacheName, cnf);
>         return manager;
>     }
>     @Test
>     @OperateOnDeployment(OLD_ISPN)
>     @InSequence(1)
>     public void testStoreWithOldJDG() throws Exception {
>         deployer.deploy(OLD_ISPN);
>         dfc = configureCacheManager(true);
>         dfc.start();
>         Cache<Object, Object> cache = dfc.getCache(cacheName);
>         System.out.println("Version: " + cache.getVersion());
>         System.out.println("ClassLoader: " + cache.getClass().getClassLoader());
>         storedMap = new HashMap<String, String>();
>         storedMap.put("k", "v");
>         cache.put("mapKey", storedMap);
>         dfc.stop();
>         deployer.undeploy(OLD_ISPN);
>     }
>     @Test
>     @OperateOnDeployment(NEW_ISPN)
>     @InSequence(2)
>     public void testReadWithNewJDG() throws Exception {
>         deployer.deploy(NEW_ISPN);
>         dfc = configureCacheManager(false);
>         dfc.start();
>         Cache<Object, Object> cache = dfc.getCache(cacheName);
>         System.out.println("ClassLoader: " + cache.getClass().getClassLoader());
>         System.out.println("Version: " + cache.getVersion());
>         assertEquals(storedMap, cache.get("mapKey"));
>         dfc.stop();
>         deployer.undeploy(NEW_ISPN);
>     }
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.11#6341)


More information about the arquillian-issues mailing list