Skip to content

Commit

Permalink
Add distributed TimerService test case that uses infinispan-server fo…
Browse files Browse the repository at this point in the history
…r timer persistence.
  • Loading branch information
pferraro committed Mar 8, 2022
1 parent 6c3bd58 commit cddac7d
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 21 deletions.
2 changes: 2 additions & 0 deletions testsuite/integration/clustering/pom.xml
Expand Up @@ -669,6 +669,7 @@
<exclude>${test-group}/**/group/*TestCase.java</exclude>
<exclude>${test-group}/**/jms/*TestCase.java</exclude>
<!-- These are run by ts.clustering.cluster.ha-infinispan-server.profile -->
<exclude>${test-group}/**/ejb/timer/remote/*TestCase.java</exclude>
<exclude>${test-group}/**/web/remote/*TestCase.java</exclude>
<exclude>${test-group}/**/sso/remote/*TestCase.java</exclude>
<!-- These are run by ts.clustering.cluster.byteman.profile -->
Expand Down Expand Up @@ -735,6 +736,7 @@
<runOrder>alphabetical</runOrder>
<!-- Tests to execute. -->
<includes>
<include>${test-group}/**/ejb/timer/remote/*TestCase.java</include>
<include>${test-group}/**/web/remote/*TestCase.java</include>
<include>${test-group}/**/sso/remote/*TestCase.java</include>
</includes>
Expand Down
Expand Up @@ -43,9 +43,7 @@
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.utils.DateUtils;
import org.apache.http.impl.client.CloseableHttpClient;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.OperateOnDeployment;
import org.jboss.arquillian.container.test.api.TargetsContainer;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.test.clustering.cluster.AbstractClusteringTestCase;
Expand All @@ -67,36 +65,29 @@
* @author Paul Ferraro
*/
@RunWith(Arquillian.class)
public class DistributedTimerServiceTestCase extends AbstractClusteringTestCase {
private static final String MODULE_NAME = DistributedTimerServiceTestCase.class.getSimpleName();
public class AbstractTimerServiceTestCase extends AbstractClusteringTestCase {

@Deployment(name = DEPLOYMENT_1, managed = false, testable = false)
@TargetsContainer(NODE_1)
public static Archive<?> deployment0() {
return createArchive();
}

@Deployment(name = DEPLOYMENT_2, managed = false, testable = false)
@TargetsContainer(NODE_2)
public static Archive<?> deployment1() {
return createArchive();
}

private static Archive<?> createArchive() {
return ShrinkWrap.create(WebArchive.class, MODULE_NAME + ".war")
protected static Archive<?> createArchive(Class<? extends AbstractTimerServiceTestCase> testClass) {
return ShrinkWrap.create(WebArchive.class, testClass.getSimpleName() + ".war")
.addPackage(TimerServlet.class.getPackage())
.addPackage(EJBDirectory.class.getPackage())
.addPackage(TimerBean.class.getPackage())
.addAsWebInfResource(DistributedTimerServiceTestCase.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml")
.addAsWebInfResource(testClass.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml")
;
}

private final String moduleName;

protected AbstractTimerServiceTestCase() {
this.moduleName = this.getClass().getSimpleName();
}

@Test
public void test(@ArquillianResource(TimerServlet.class) @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1, @ArquillianResource(TimerServlet.class) @OperateOnDeployment(DEPLOYMENT_2) URL baseURL2) throws IOException, URISyntaxException {

Map<String, URI> uris = new TreeMap<>();
uris.put(NODE_1, TimerServlet.createURI(baseURL1, MODULE_NAME));
uris.put(NODE_2, TimerServlet.createURI(baseURL2, MODULE_NAME));
uris.put(NODE_1, TimerServlet.createURI(baseURL1, this.moduleName));
uris.put(NODE_2, TimerServlet.createURI(baseURL2, this.moduleName));

try (CloseableHttpClient client = TestHttpClientUtils.promiscuousCookieHttpClient()) {

Expand Down
@@ -0,0 +1,49 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2022, Red Hat, Inc., 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.jboss.as.test.clustering.cluster.ejb.timer;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.TargetsContainer;
import org.jboss.shrinkwrap.api.Archive;

/**
* @author Paul Ferraro
*/
public class DistributedTimerTestCase extends AbstractTimerServiceTestCase {

@Deployment(name = DEPLOYMENT_1, managed = false, testable = false)
@TargetsContainer(NODE_1)
public static Archive<?> deployment0() {
return createArchive();
}

@Deployment(name = DEPLOYMENT_2, managed = false, testable = false)
@TargetsContainer(NODE_2)
public static Archive<?> deployment1() {
return createArchive();
}

private static Archive<?> createArchive() {
return createArchive(DistributedTimerTestCase.class);
}
}
@@ -0,0 +1,73 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2022, Red Hat, Inc., 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.jboss.as.test.clustering.cluster.ejb.timer.remote;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.TargetsContainer;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.test.clustering.cluster.ejb.timer.AbstractTimerServiceTestCase;
import org.jboss.as.test.shared.CLIServerSetupTask;
import org.jboss.shrinkwrap.api.Archive;
import org.junit.ClassRule;
import org.junit.rules.TestRule;

/**
* @author Paul Ferraro
*/
@ServerSetup({ InfinispanServerSetupTask.class, HotRodPersistentTimerServiceTestCase.ServerSetupTask.class })
public class HotRodPersistentTimerServiceTestCase extends AbstractTimerServiceTestCase {

@ClassRule
public static final TestRule INFINISPAN_SERVER_RULE = infinispanServerTestRule();

@Deployment(name = DEPLOYMENT_1, managed = false, testable = false)
@TargetsContainer(NODE_1)
public static Archive<?> deployment0() {
return createArchive();
}

@Deployment(name = DEPLOYMENT_2, managed = false, testable = false)
@TargetsContainer(NODE_2)
public static Archive<?> deployment1() {
return createArchive();
}

private static Archive<?> createArchive() {
return createArchive(HotRodPersistentTimerServiceTestCase.class);
}

static class ServerSetupTask extends CLIServerSetupTask {
ServerSetupTask() {
this.builder.node(THREE_NODES)
.setup("/subsystem=infinispan/cache-container=ejb/invalidation-cache=hotrod-persistent:add")
.setup("/subsystem=infinispan/cache-container=ejb/invalidation-cache=hotrod-persistent/component=expiration:add(interval=0)")
.setup("/subsystem=infinispan/cache-container=ejb/invalidation-cache=hotrod-persistent/component=locking:add(isolation=REPEATABLE_READ)")
.setup("/subsystem=infinispan/cache-container=ejb/invalidation-cache=hotrod-persistent/component=transaction:add(mode=BATCH)")
.setup("/subsystem=infinispan/cache-container=ejb/invalidation-cache=hotrod-persistent/store=hotrod:add(remote-cache-container=ejb, cache-configuration=default, fetch-state=false, purge=false, passivation=false, shared=true)")
.setup("/subsystem=distributable-ejb/infinispan-timer-management=hotrod:add(cache-container=ejb, cache=hotrod-persistent)")
.teardown("/subsystem=distributable-ejb/infinispan-timer-management=hotrod:remove")
.teardown("/subsystem=infinispan/cache-container=ejb/invalidation-cache=hotrod-persistent:remove")
;
}
}
}
@@ -0,0 +1,47 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., 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.jboss.as.test.clustering.cluster.ejb.timer.remote;

import static org.jboss.as.test.clustering.cluster.AbstractClusteringTestCase.INFINISPAN_APPLICATION_PASSWORD;
import static org.jboss.as.test.clustering.cluster.AbstractClusteringTestCase.INFINISPAN_APPLICATION_USER;
import static org.jboss.as.test.clustering.cluster.AbstractClusteringTestCase.INFINISPAN_SERVER_ADDRESS;
import static org.jboss.as.test.clustering.cluster.AbstractClusteringTestCase.INFINISPAN_SERVER_PORT;

import org.jboss.as.test.clustering.cluster.AbstractClusteringTestCase;
import org.jboss.as.test.shared.CLIServerSetupTask;

/**
* Server setup task that configures a hotrod client to connect to an Infinispan server.
* @author Paul Ferraro
*/
public class InfinispanServerSetupTask extends CLIServerSetupTask {
public InfinispanServerSetupTask() {
this.builder.node(AbstractClusteringTestCase.THREE_NODES)
.setup("/socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=infinispan-server:add(port=%d,host=%s)", INFINISPAN_SERVER_PORT, INFINISPAN_SERVER_ADDRESS)
.setup("/subsystem=infinispan/remote-cache-container=ejb:add(default-remote-cluster=infinispan-server-cluster, tcp-keep-alive=true, marshaller=PROTOSTREAM, module=org.wildfly.clustering.ejb.infinispan, properties={infinispan.client.hotrod.auth_username=%s, infinispan.client.hotrod.auth_password=%s}, statistics-enabled=true)", INFINISPAN_APPLICATION_USER, INFINISPAN_APPLICATION_PASSWORD)
.setup("/subsystem=infinispan/remote-cache-container=ejb/remote-cluster=infinispan-server-cluster:add(socket-bindings=[infinispan-server])")
.teardown("/subsystem=infinispan/remote-cache-container=ejb:remove")
.teardown("/socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=infinispan-server:remove")
;
}
}
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<jboss:ejb-jar xmlns:jboss="http://www.jboss.com/xml/ns/javaee"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:t="urn:timer-service:2.0"
xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-ejb3-2_0.xsd
http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd
http://www.jboss.org/j2ee/schema/jboss_5_0.xsd"
version="3.1"
impl-version="2.0">
<assembly-descriptor>
<t:timer-service>
<ejb-name>*</ejb-name>
<t:persistent-timer-management>hotrod</t:persistent-timer-management>
</t:timer-service>
</assembly-descriptor>
</jboss:ejb-jar>

0 comments on commit cddac7d

Please sign in to comment.