Skip to content

Commit

Permalink
gh-13 Make infinispan-arquillian-container work with JBossAS 7.1.0.Be…
Browse files Browse the repository at this point in the history
…ta1+
  • Loading branch information
mgencur authored and maniksurtani committed Nov 28, 2011
1 parent 874631b commit d2cbefa
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 58 deletions.
4 changes: 0 additions & 4 deletions examples/embedded-infinispan/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,3 @@ pom files by changing version of the following artifact:
<scope>test</scope>
<version>${version.infinispan_core}</version>
</dependency>

The testng example contains certain test that fail at the moment (those taking a
Method parameter. This is happening because of a bug in Arquillian which has been recently
fixed and will appear in the next release (version 1.0.0.CR6 or Final).
6 changes: 6 additions & 0 deletions infinispan-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-controller-client</artifactId>
<version>${version.jboss.as.controller.client}</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2009, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.infinispan.arquillian.core;

import static org.jboss.as.arquillian.container.Authentication.getCallbackHandler;

import java.net.InetAddress;
import java.net.UnknownHostException;

import org.infinispan.arquillian.model.HotRodEndpoint;
import org.infinispan.arquillian.model.MemCachedEndpoint;
import org.infinispan.arquillian.model.RESTEndpoint;
import org.infinispan.arquillian.model.RemoteInfinispanCacheManager;
import org.infinispan.arquillian.utils.MBeanObjectsProvider;
import org.infinispan.arquillian.utils.MBeanServerConnectionProvider;
import org.infinispan.arquillian.utils.MBeanObjectsProvider.Domain;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.controller.client.ModelControllerClient;

/**
* The implementation of {@link RemoteInfinispanServer}. An instance of this
* class can be injected into a testcase and provide information about caches,
* cache managers and server module endpoints (hotrod, memcached, REST).
*
* There are always all endpoints available simultaneously:
*
* <ul>
* <li>hotrod</li>
* <li>memcached</li>
* <li>REST</li>
* </ul>
*
* @see RemoteInfinispanServer
*
*
* @author <a href="mailto:mgencur@redhat.com">Martin Gencur</a>
*
*/
public class EDGServer implements RemoteInfinispanServer
{
private MBeanServerConnectionProvider provider;

private MBeanObjectsProvider mBeans;

private ManagementClient managementClient;

public EDGServer(InetAddress managementAddress, int managementPort)
{
this.mBeans = new MBeanObjectsProvider(Domain.EDG);

ModelControllerClient modelControllerClient = ModelControllerClient.Factory.create(
managementAddress,
managementPort,
getCallbackHandler());

this.managementClient = new ManagementClient(modelControllerClient, managementAddress.getHostAddress());
}

@Override
public RemoteInfinispanCacheManager getDefaultCacheManager()
{
return new RemoteInfinispanCacheManager(getMBeanServerConnectionProvider(), mBeans, "default");
}

@Override
public RemoteInfinispanCacheManager getCacheManager(String cacheManagerName)
{
return new RemoteInfinispanCacheManager(getMBeanServerConnectionProvider(), mBeans, cacheManagerName);
}

@Override
public HotRodEndpoint getHotrodEndpoint()
{
return new HotRodEndpoint(getMBeanServerConnectionProvider(), mBeans);
}

@Override
public MemCachedEndpoint getMemcachedEndpoint()
{
return new MemCachedEndpoint(getMBeanServerConnectionProvider(), mBeans);
}

@Override
public RESTEndpoint getRESTEndpoint()
{
return new RESTEndpoint(getMBeanServerConnectionProvider(), mBeans);
}

private MBeanServerConnectionProvider getMBeanServerConnectionProvider()
{
if (provider == null)
{
String jmxSubsystem = "jmx";
InetAddress host = InfinispanConfigurator.getInetAddress(managementClient.getSubSystemURI(jmxSubsystem).getHost());
int port = managementClient.getSubSystemURI(jmxSubsystem).getPort();
provider = new MBeanServerConnectionProvider(host, port);
}
return provider;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
*/
package org.infinispan.arquillian.core;

import static org.jboss.as.arquillian.container.Authentication.getCallbackHandler;

import java.net.InetAddress;
import java.net.UnknownHostException;

import org.infinispan.arquillian.container.managed.InfinispanConfiguration;
import org.infinispan.arquillian.utils.MBeanObjectsProvider;
import org.infinispan.arquillian.utils.MBeanObjectsProvider.Domain;
Expand All @@ -31,6 +36,8 @@
import org.jboss.arquillian.core.api.annotation.Observes;
import org.jboss.arquillian.test.spi.annotation.SuiteScoped;
import org.jboss.as.arquillian.container.CommonContainerConfiguration;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.controller.client.ModelControllerClient;

/**
* A creator of {@link RemoteInfinispanServer} objects. Creates a single instance of
Expand Down Expand Up @@ -95,7 +102,7 @@ public void configureInfinispan(@Observes SetupContainer event)
try
{
conf = (InfinispanConfiguration) event.getContainer().createDeployableConfiguration();
server = new RemoteInfinispanServerImpl(conf.getHost(), conf.getJmxPort(), new MBeanObjectsProvider(Domain.STANDALONE));
server = new StandaloneInfinispanServer(getInetAddress(conf.getHost()), conf.getJmxPort());
}
catch (Exception e)
{
Expand All @@ -108,7 +115,7 @@ public void configureInfinispan(@Observes SetupContainer event)
try
{
conf = (CommonContainerConfiguration) event.getContainer().createDeployableConfiguration();
server = new RemoteInfinispanServerImpl(conf.getBindAddress().getHostName(), conf.getJmxPort(), new MBeanObjectsProvider(Domain.EDG));
server = new EDGServer(conf.getManagementAddress(), conf.getManagementPort());
}
catch (Exception e)
{
Expand All @@ -118,4 +125,16 @@ public void configureInfinispan(@Observes SetupContainer event)

infinispanContext.get().add(RemoteInfinispanServer.class, event.getContainer().getContainerConfiguration().getContainerName(), server);
}

protected static InetAddress getInetAddress(String name)
{
try
{
return InetAddress.getByName(name);
}
catch (UnknownHostException e)
{
throw new IllegalArgumentException("Unknown host: " + name);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
package org.infinispan.arquillian.core;

import java.net.InetAddress;
import java.net.UnknownHostException;

import org.infinispan.arquillian.model.HotRodEndpoint;
import org.infinispan.arquillian.model.MemCachedEndpoint;
Expand All @@ -35,54 +34,38 @@
/**
* The implementation of {@link RemoteInfinispanServer}. An instance of this class can
* be injected into a testcase and provide information about caches, cache managers and server
* module endpoints (hotrod, memcached, REST).
* module endpoints (hotrod, memcached).
*
* When using standalone Infinispan server, there's always only one of the following server modules
* There's always only one of the following server modules
* available at any time:
*
* <ul>
* <li>hotrod</li>
* <li>memcached</li>
* </ul>
*
* When using JBoss AS with Infinispan embedded, there are always all endpoints
* available simultaneously:
*
* <ul>
* <li>hotrod</li>
* <li>memcached</li>
* <li>REST</li>
* </ul>
*
* @see RemoteInfinispanServer
*
*
* @author <a href="mailto:mgencur@redhat.com">Martin Gencur</a>
*
*/
public class RemoteInfinispanServerImpl implements RemoteInfinispanServer
public class StandaloneInfinispanServer implements RemoteInfinispanServer
{
private MBeanServerConnectionProvider provider;

private MBeanObjectsProvider mBeans;

public RemoteInfinispanServerImpl(String host, int jmxPort, MBeanObjectsProvider mBeans)
public StandaloneInfinispanServer(InetAddress address, int jmxPort)
{
this.provider = new MBeanServerConnectionProvider(getInetAddress(host), jmxPort);
this.mBeans = mBeans;
this.provider = new MBeanServerConnectionProvider(address, jmxPort);
this.mBeans = new MBeanObjectsProvider(Domain.STANDALONE);
}

@Override
public RemoteInfinispanCacheManager getDefaultCacheManager()
{
if (mBeans.getDomain().equals(Domain.EDG))
{
return new RemoteInfinispanCacheManager(provider, mBeans, "default");
}
else
{
return new RemoteInfinispanCacheManager(provider, mBeans, "DefaultCacheManager");
}
return new RemoteInfinispanCacheManager(provider, mBeans, "DefaultCacheManager");
}

@Override
Expand All @@ -106,25 +89,6 @@ public MemCachedEndpoint getMemcachedEndpoint()
@Override
public RESTEndpoint getRESTEndpoint()
{
if (mBeans.getDomain().equals(Domain.EDG))
{
return new RESTEndpoint(provider, mBeans);
}
else
{
throw new RuntimeException("Could not retrieve REST endpoint -> not applicable for standalone Infinispan Server");
}
}

protected static InetAddress getInetAddress(String name)
{
try
{
return InetAddress.getByName(name);
}
catch (UnknownHostException e)
{
throw new IllegalArgumentException("Unknown host: " + name);
}
throw new RuntimeException("Could not retrieve REST endpoint -> not applicable for standalone Infinispan Server");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
*/
public class RESTEndpoint
{
private final String contextPath = "/datagrid";
private final String contextPath = "/rest";

private MBeanServerConnectionProvider provider;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,14 @@ public void shouldFindEDGServerInContext() throws Exception
when(def.getContainerProperties()).thenReturn(properties);
when(def.getContainerName()).thenReturn(containerName);
when(container.getContainerConfiguration()).thenReturn(def);
when(conf.getJmxPort()).thenReturn(1091);
when(conf.getManagementPort()).thenReturn(9999);
InetAddress addr = InetAddress.getByName("localhost");
when(conf.getBindAddress()).thenReturn(addr);
when(conf.getManagementAddress()).thenReturn(addr);
when(container.createDeployableConfiguration()).thenReturn(conf);

fire(new SetupContainer(container));
InfinispanContext ctx = getManager().getContext(SuiteContext.class).getObjectStore().get(InfinispanContext.class);

Assert.assertNotNull(ctx.get(RemoteInfinispanServer.class, containerName));
Assert.assertEquals("Expected context path configured", "/datagrid", ((RemoteInfinispanServer) ctx.get(RemoteInfinispanServer.class, containerName)).getRESTEndpoint().getContextPath());
}
}
9 changes: 5 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@

<!-- Properties -->
<properties>
<version.arquillian_core>1.0.0.CR5</version.arquillian_core>
<version.infinispan_core>5.1.0.BETA3</version.infinispan_core>
<version.infinispan_core_tests>5.1.0.BETA3</version.infinispan_core_tests>
<version.arquillian_core>1.0.0.Final-SNAPSHOT</version.arquillian_core>
<version.infinispan_core>5.1.0.BETA4</version.infinispan_core>
<version.infinispan_core_tests>5.1.0.BETA4</version.infinispan_core_tests>
<version.junit>4.8.1</version.junit>
<version.testng>5.14.6</version.testng>
<version.mockito>1.8.3</version.mockito>
<version.maven.compiler.plugin>2.3.2</version.maven.compiler.plugin>
<version.maven.surefire.plugin>2.9</version.maven.surefire.plugin>
<version.jboss.as.arquillian>7.0.0.Final</version.jboss.as.arquillian>
<version.jbossjta>4.15.1.Final</version.jbossjta>
<version.jboss.as.arquillian>7.1.0.Beta1</version.jboss.as.arquillian>
<version.jboss.as.controller.client>7.1.0.Beta1</version.jboss.as.controller.client>
</properties>

<dependencyManagement>
Expand Down

0 comments on commit d2cbefa

Please sign in to comment.