repo
stringlengths
1
191
file
stringlengths
23
351
code
stringlengths
0
5.32M
file_length
int64
0
5.32M
avg_line_length
float64
0
2.9k
max_line_length
int64
0
288k
extension_type
stringclasses
1 value
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/single/infinispan/cdi/embedded/deployment/GreetingCacheManager.java
/* * 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.single.infinispan.cdi.embedded.deployment; import java.util.Collection; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import jakarta.inject.Named; import org.infinispan.Cache; /** * The greeting cache manager. This manager is used to collect information on the greeting cache and to clear its content if needed. * Adopted and adapted from Infinispan testsuite. * * @author Radoslav Husar * @author Kevin Pollet &lt;pollet.kevin@gmail.com&gt; (C) 2011 * @since 27 */ @Named @ApplicationScoped public class GreetingCacheManager { @Inject @GreetingCache private Cache<String, String> cache; public String getCacheName() { return cache.getName(); } public int getNumberOfEntries() { return cache.size(); } public long getMemorySize() { return cache.getCacheConfiguration().memory().maxCount(); } public long getExpirationLifespan() { return cache.getCacheConfiguration().expiration().lifespan(); } public String[] getCachedValues() { Collection<String> cachedValues = cache.values(); return cachedValues.toArray(new String[cachedValues.size()]); } // JCache: @CacheRemoveAll(cacheName = "greeting-cache") public void clearCache() { cache.clear(); } public void cacheResult(String name, String greeting) { cache.put(name, greeting); } }
2,485
30.468354
132
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/single/infinispan/query/ServerSetupTask.java
/* * 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.single.infinispan.query; 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.shared.ManagementServerSetupTask; /** * @author Radoslav Husar */ public class ServerSetupTask extends ManagementServerSetupTask { public ServerSetupTask() { super("default", createContainerConfigurationBuilder() .setupScript(createScriptBuilder() .startBatch() .add("/socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=infinispan-server:add(port=%d, host=%s)", INFINISPAN_SERVER_PORT, INFINISPAN_SERVER_ADDRESS) .add("/subsystem=infinispan/remote-cache-container=query:add(default-remote-cluster=infinispan-server-cluster, tcp-keep-alive=true, marshaller=PROTOSTREAM, modules=[org.infinispan.query.client], properties={infinispan.client.hotrod.auth_username=%s, infinispan.client.hotrod.auth_password=%s}, statistics-enabled=true)", INFINISPAN_APPLICATION_USER, INFINISPAN_APPLICATION_PASSWORD) .add("/subsystem=infinispan/remote-cache-container=query/remote-cluster=infinispan-server-cluster:add(socket-bindings=[infinispan-server])") .endBatch() .build() ) .tearDownScript(createScriptBuilder() .startBatch() .add("/subsystem=infinispan/remote-cache-container=query:remove") .add("/socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=infinispan-server:remove") .endBatch() .build()) .build() ); } }
3,153
56.345455
406
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/single/infinispan/query/HotRodClientTestCase.java
/* * 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.single.infinispan.query; 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.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import java.util.List; import java.util.ServiceLoader; import java.util.stream.Collectors; import org.infinispan.client.hotrod.RemoteCache; import org.infinispan.client.hotrod.RemoteCacheManager; import org.infinispan.client.hotrod.configuration.ConfigurationBuilder; import org.infinispan.commons.marshall.ProtoStreamMarshaller; import org.infinispan.protostream.GeneratedSchema; import org.infinispan.protostream.SerializationContextInitializer; import org.infinispan.query.remote.client.ProtobufMetadataManagerConstants; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.test.clustering.single.infinispan.query.data.Person; import org.jboss.as.test.clustering.single.infinispan.query.data.PersonSchema; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.jboss.shrinkwrap.descriptor.api.Descriptors; import org.jboss.shrinkwrap.descriptor.api.spec.se.manifest.ManifestDescriptor; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; /** * Test the Infinispan AS remote client module integration. * Adopted and adapted from Infinispan testsuite (HotRodClientIT). * * @author Radoslav Husar * @author Pedro Ruivo * @since 27 */ @RunWith(Arquillian.class) public class HotRodClientTestCase { private RemoteCache<String, Person> remoteCache; @Deployment public static Archive<?> deployment() { return ShrinkWrap.create(WebArchive.class, HotRodClientTestCase.class.getSimpleName() + ".war") .addClass(HotRodClientTestCase.class) .addPackage(Person.class.getPackage()) .addAsServiceProvider(SerializationContextInitializer.class.getName(), PersonSchema.class.getName() + "Impl") .setManifest(new StringAsset(Descriptors.create(ManifestDescriptor.class).attribute("Dependencies", "org.infinispan, org.infinispan.commons, org.infinispan.client.hotrod, org.infinispan.query, org.infinispan.protostream").exportAsString())) ; } @Before public void initialize() { List<GeneratedSchema> schemas = ServiceLoader.load(SerializationContextInitializer.class, this.getClass().getClassLoader()).stream().map(ServiceLoader.Provider::get).filter(GeneratedSchema.class::isInstance).map(GeneratedSchema.class::cast).collect(Collectors.toList()); ConfigurationBuilder config = new ConfigurationBuilder(); config.addServer().host(INFINISPAN_SERVER_ADDRESS); config.marshaller(new ProtoStreamMarshaller()); for (GeneratedSchema schema : schemas) { config.addContextInitializer(schema); } config.security().authentication().username(INFINISPAN_APPLICATION_USER).password(INFINISPAN_APPLICATION_PASSWORD); RemoteCacheManager remoteCacheManager = new RemoteCacheManager(config.build(), true); this.remoteCache = remoteCacheManager.getCache(); this.remoteCache.clear(); RemoteCache<String, String> schemaCache = this.remoteCache.getRemoteCacheContainer().getCache(ProtobufMetadataManagerConstants.PROTOBUF_METADATA_CACHE_NAME); for (GeneratedSchema schema : schemas) { schemaCache.put(schema.getProtoFileName(), schema.getProtoFile()); assertFalse(schemaCache.containsKey(ProtobufMetadataManagerConstants.ERRORS_KEY_SUFFIX)); } } @Test public void testPutGetCustomObject() { String key = "k1"; Person expected = new Person("Martin"); this.remoteCache.put(key, expected); Person result = this.remoteCache.get(key); assertNotNull(result); assertEquals(expected.getName(), result.getName()); } }
5,392
46.725664
278
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/single/infinispan/query/ContainerManagedHotRodClientTestCase.java
/* * 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.single.infinispan.query; import static org.junit.Assert.assertEquals; import jakarta.annotation.Resource; import org.infinispan.client.hotrod.RemoteCache; import org.infinispan.client.hotrod.RemoteCacheContainer; import org.infinispan.protostream.SerializationContextInitializer; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.test.clustering.single.infinispan.query.data.Person; import org.jboss.as.test.clustering.single.infinispan.query.data.PersonSchema; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.jboss.shrinkwrap.descriptor.api.Descriptors; import org.jboss.shrinkwrap.descriptor.api.spec.se.manifest.ManifestDescriptor; import org.junit.Test; import org.junit.runner.RunWith; /** * Variant of the {@link HotRodClientTestCase} using container-managed objects. * * @author Radoslav Husar * @since 27 */ @RunWith(Arquillian.class) @ServerSetup({ ServerSetupTask.class }) public class ContainerManagedHotRodClientTestCase { @Deployment public static Archive<?> deployment() { return ShrinkWrap .create(WebArchive.class, ContainerManagedHotRodClientTestCase.class.getSimpleName() + ".war") .addClass(ContainerManagedHotRodClientTestCase.class) .addPackage(PersonSchema.class.getPackage()) .addAsServiceProvider(SerializationContextInitializer.class.getName(), PersonSchema.class.getName() + "Impl") .setManifest(new StringAsset(Descriptors.create(ManifestDescriptor.class).attribute("Dependencies", "org.infinispan, org.infinispan.commons, org.infinispan.client.hotrod, org.infinispan.query, org.infinispan.protostream").exportAsString())) ; } @Resource(lookup = "java:jboss/infinispan/remote-container/query") private RemoteCacheContainer remoteCacheContainer; @Test public void testPutGetCustomObject() { RemoteCache<String, Person> cache = this.remoteCacheContainer.getCache(); cache.clear(); Person p = new Person("Martin"); cache.put("k1", p); assertEquals(p.getName(), cache.get("k1").getName()); } }
3,438
41.9875
256
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/single/infinispan/query/ContainerRemoteQueryTestCase.java
/* * 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.single.infinispan.query; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.util.List; import java.util.ServiceLoader; import java.util.stream.Collectors; import jakarta.annotation.Resource; import org.infinispan.client.hotrod.RemoteCache; import org.infinispan.client.hotrod.RemoteCacheContainer; import org.infinispan.client.hotrod.Search; import org.infinispan.commons.marshall.ProtoStreamMarshaller; import org.infinispan.protostream.GeneratedSchema; import org.infinispan.protostream.SerializationContext; import org.infinispan.protostream.SerializationContextInitializer; import org.infinispan.query.dsl.Query; import org.infinispan.query.dsl.QueryFactory; import org.infinispan.query.remote.client.ProtobufMetadataManagerConstants; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.test.clustering.single.infinispan.query.data.Book; import org.jboss.as.test.clustering.single.infinispan.query.data.BookSchema; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.jboss.shrinkwrap.descriptor.api.Descriptors; import org.jboss.shrinkwrap.descriptor.api.spec.se.manifest.ManifestDescriptor; import org.junit.Test; import org.junit.runner.RunWith; /** * Test for remote query using container-managed objects. * * @author Radoslav Husar * @since 27 */ @RunWith(Arquillian.class) @ServerSetup(ServerSetupTask.class) public class ContainerRemoteQueryTestCase { @Deployment public static Archive<?> deployment() { return ShrinkWrap .create(WebArchive.class, ContainerRemoteQueryTestCase.class.getSimpleName() + ".war") .addClasses(ContainerRemoteQueryTestCase.class) .addPackage(Book.class.getPackage()) .addAsServiceProvider(SerializationContextInitializer.class.getName(), BookSchema.class.getName() + "Impl") .setManifest(new StringAsset(Descriptors.create(ManifestDescriptor.class).attribute("Dependencies", "org.infinispan, org.infinispan.commons, org.infinispan.client.hotrod, org.infinispan.protostream, org.infinispan.query, org.infinispan.query.dsl, org.infinispan.query.client").exportAsString())) ; } @Resource(lookup = "java:jboss/infinispan/remote-container/query") private RemoteCacheContainer container; @Test public void testRemoteBookQuery() { RemoteCache<String, Book> cache = this.container.getCache(); cache.clear(); List<GeneratedSchema> schemas = ServiceLoader.load(SerializationContextInitializer.class, this.getClass().getClassLoader()).stream().map(ServiceLoader.Provider::get).filter(GeneratedSchema.class::isInstance).map(GeneratedSchema.class::cast).collect(Collectors.toList()); ProtoStreamMarshaller marshaller = (ProtoStreamMarshaller) cache.getRemoteCacheContainer().getMarshaller(); SerializationContext context = marshaller.getSerializationContext(); RemoteCache<String, String> schemaCache = this.container.getCache(ProtobufMetadataManagerConstants.PROTOBUF_METADATA_CACHE_NAME); for (GeneratedSchema schema : schemas) { schema.registerSchema(context); schema.registerMarshallers(context); schemaCache.put(schema.getProtoFileName(), schema.getProtoFile()); assertFalse(schemaCache.containsKey(ProtobufMetadataManagerConstants.ERRORS_KEY_SUFFIX)); } QueryFactory queryFactory = Search.getQueryFactory(cache); cache.put("A", new Book("A1", "A2", 2021)); cache.put("B", new Book("B1", "B2", 2022)); assertTrue(cache.containsKey("A")); Query<Book> query = queryFactory.create("FROM Book WHERE author='A2'"); List<Book> list = query.execute().list(); assertEquals(1, list.size()); assertEquals(Book.class, list.get(0).getClass()); assertEquals("A2", list.get(0).author); } }
5,265
44.396552
311
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/single/infinispan/query/RemoteQueryTestCase.java
/* * 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.single.infinispan.query; 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.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.util.List; import java.util.ServiceLoader; import java.util.stream.Collectors; import org.infinispan.client.hotrod.RemoteCache; import org.infinispan.client.hotrod.RemoteCacheManager; import org.infinispan.client.hotrod.Search; import org.infinispan.client.hotrod.configuration.ConfigurationBuilder; import org.infinispan.commons.configuration.StringConfiguration; import org.infinispan.commons.marshall.ProtoStreamMarshaller; import org.infinispan.protostream.GeneratedSchema; import org.infinispan.protostream.SerializationContextInitializer; import org.infinispan.query.dsl.Query; import org.infinispan.query.dsl.QueryFactory; import org.infinispan.query.remote.client.ProtobufMetadataManagerConstants; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.test.clustering.single.infinispan.query.data.Book; import org.jboss.as.test.clustering.single.infinispan.query.data.BookSchema; import org.jboss.as.test.clustering.single.infinispan.query.data.Person; import org.jboss.as.test.clustering.single.infinispan.query.data.PersonSchema; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.jboss.shrinkwrap.descriptor.api.Descriptors; import org.jboss.shrinkwrap.descriptor.api.spec.se.manifest.ManifestDescriptor; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * Test remote query. * Adopted and adapted from Infinispan testsuite (HotRodQueryIT). * * @author Radoslav Husar * @author Adrian Nistor * @since 27 */ @RunWith(Arquillian.class) public class RemoteQueryTestCase { @Deployment public static Archive<?> deployment() { return ShrinkWrap .create(WebArchive.class, RemoteQueryTestCase.class.getSimpleName() + ".war") .addClasses(RemoteQueryTestCase.class) .addPackage(Book.class.getPackage()) .addAsServiceProvider(SerializationContextInitializer.class.getName(), BookSchema.class.getName() + "Impl", PersonSchema.class.getName() + "Impl") .setManifest(new StringAsset(Descriptors.create(ManifestDescriptor.class).attribute("Dependencies", "org.infinispan, org.infinispan.commons, org.infinispan.client.hotrod, org.infinispan.protostream, org.infinispan.query, org.infinispan.query.dsl").exportAsString())); } @Test public void testIndexed() { try (RemoteCacheManager container = this.createRemoteCacheManager()) { String xmlConfig = "<local-cache name=\"books\">\n" + " <indexing path=\"${java.io.tmpdir}/index\">\n" + " <indexed-entities>\n" + " <indexed-entity>Book</indexed-entity>\n" + " </indexed-entities>\n" + " </indexing>\n" + "</local-cache>"; RemoteCache<Integer, Book> remoteCache = container.administration().getOrCreateCache("books", new StringConfiguration(xmlConfig)); remoteCache.clear(); // Add some Books Book book1 = new Book("Infinispan in Action", "Learn Infinispan by using it", 2015); Book book2 = new Book("Cloud-Native Applications with Java and Quarkus", "Build robust and reliable cloud applications", 2019); remoteCache.put(1, book1); remoteCache.put(2, book2); QueryFactory factory = Search.getQueryFactory(remoteCache); Query<Book> query = factory.create("FROM Book WHERE title:'java'"); List<Book> list = query.execute().list(); assertEquals(1, list.size()); } } @Test public void testRemoteQuery() throws Exception { try (RemoteCacheManager container = this.createRemoteCacheManager()) { RemoteCache<String, Person> cache = container.getCache(); cache.clear(); cache.put("Adrian", new Person("Adrian")); assertTrue(cache.containsKey("Adrian")); QueryFactory factory = Search.getQueryFactory(cache); Query<Person> query = factory.create("FROM Person WHERE name='Adrian'"); List<Person> list = query.execute().list(); assertNotNull(list); assertEquals(1, list.size()); assertEquals(Person.class, list.get(0).getClass()); assertEquals("Adrian", list.get(0).name); } } /** * Sorting on a field that does not contain DocValues so Hibernate Search is forced to uninvert it - ISPN-5729 */ @Test public void testUninverting() throws Exception { try (RemoteCacheManager container = this.createRemoteCacheManager()) { RemoteCache<String, Person> cache = container.getCache(); cache.clear(); QueryFactory factory = Search.getQueryFactory(cache); Query<Person> query = factory.create("FROM Person WHERE name='John' ORDER BY id"); Assert.assertEquals(0, query.execute().list().size()); } } private RemoteCacheManager createRemoteCacheManager() { List<GeneratedSchema> schemas = ServiceLoader.load(SerializationContextInitializer.class, this.getClass().getClassLoader()).stream().map(ServiceLoader.Provider::get).filter(GeneratedSchema.class::isInstance).map(GeneratedSchema.class::cast).collect(Collectors.toList()); ConfigurationBuilder builder = new ConfigurationBuilder(); builder.addServer().host(INFINISPAN_SERVER_ADDRESS); builder.marshaller(new ProtoStreamMarshaller()); for (GeneratedSchema schema : schemas) { builder.addContextInitializer(schema); } builder.security().authentication().username(INFINISPAN_APPLICATION_USER).password(INFINISPAN_APPLICATION_PASSWORD); RemoteCacheManager container = new RemoteCacheManager(builder.build()); RemoteCache<String, String> schemaCache = container.getCache(ProtobufMetadataManagerConstants.PROTOBUF_METADATA_CACHE_NAME); for (GeneratedSchema schema : schemas) { schemaCache.put(schema.getProtoFileName(), schema.getProtoFile()); assertFalse(schemaCache.containsKey(ProtobufMetadataManagerConstants.ERRORS_KEY_SUFFIX)); } return container; } }
8,028
47.36747
283
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/single/infinispan/query/data/Person.java
/* * 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.single.infinispan.query.data; import org.infinispan.protostream.annotations.ProtoField; /** * Adopted and adapted from Infinispan testsuite. * * @author Radoslav Husar * @since 27 */ public class Person { @ProtoField(1) public String name; @ProtoField(2) public Integer id; public Person() { } public Person(String name) { this.name = name; } public Person(String name, Integer id) { this.name = name; this.id = id; } public String getName() { return name; } public Integer getId() { return id; } }
1,670
26.393443
70
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/single/infinispan/query/data/Book.java
/* * 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.single.infinispan.query.data; import org.infinispan.protostream.annotations.ProtoDoc; import org.infinispan.protostream.annotations.ProtoFactory; import org.infinispan.protostream.annotations.ProtoField; /** * Adopted and adapted from Infinispan testsuite. * * @author Radoslav Husar * @since 27 */ @ProtoDoc("@Indexed") public class Book { @ProtoDoc("@Field(index=Index.YES, analyze = Analyze.YES, store = Store.NO)") @ProtoField(number = 1) public final String title; @ProtoDoc("@Field(index=Index.YES, analyze = Analyze.NO, store = Store.NO)") @ProtoField(number = 2) public final String author; @ProtoDoc("@Field(index=Index.YES, store = Store.NO)") @ProtoField(number = 3, defaultValue = "0") public final int publicationYear; @ProtoFactory public Book(String title, String author, int publicationYear) { this.title = title; this.author = author; this.publicationYear = publicationYear; } }
2,041
34.206897
81
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/single/infinispan/query/data/PersonSchema.java
/* * 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.single.infinispan.query.data; import org.infinispan.protostream.GeneratedSchema; import org.infinispan.protostream.annotations.AutoProtoSchemaBuilder; /** * @author Radoslav Husar */ @AutoProtoSchemaBuilder(includeClasses = { Person.class }, service = false) public interface PersonSchema extends GeneratedSchema { }
1,382
39.676471
75
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/single/infinispan/query/data/BookSchema.java
/* * 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.single.infinispan.query.data; import org.infinispan.protostream.GeneratedSchema; import org.infinispan.protostream.annotations.AutoProtoSchemaBuilder; /** * Adopted and adapted from Infinispan testsuite. * * @author Radoslav Husar * @since 27 */ @AutoProtoSchemaBuilder(includeClasses = { Book.class }, service = false) public interface BookSchema extends GeneratedSchema { }
1,444
38.054054
73
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/single/singleton/SingletonServiceTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2012, 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.single.singleton; import static org.jboss.as.test.clustering.cluster.AbstractClusteringTestCase.NODE_1; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import jakarta.servlet.http.HttpServletResponse; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.utils.HttpClientUtils; import org.apache.http.impl.client.CloseableHttpClient; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.test.clustering.cluster.singleton.service.NodeServiceActivator; import org.jboss.as.test.clustering.cluster.singleton.service.NodeServiceServlet; import org.jboss.as.test.http.util.TestHttpClientUtils; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * Validates that a singleton service works in a non-clustered environment. * @author Paul Ferraro */ @RunWith(Arquillian.class) public class SingletonServiceTestCase { private static final String MODULE_NAME = SingletonServiceTestCase.class.getSimpleName(); @Deployment(testable = false) public static Archive<?> deployment() { WebArchive war = ShrinkWrap.create(WebArchive.class, MODULE_NAME + ".war"); war.addPackage(NodeServiceServlet.class.getPackage()); war.setManifest(new StringAsset("Manifest-Version: 1.0\nDependencies: org.jboss.as.clustering.common\n")); war.addAsServiceProvider(org.jboss.msc.service.ServiceActivator.class, NodeServiceActivator.class); return war; } @Test public void testSingletonService(@ArquillianResource(NodeServiceServlet.class) URL baseURL) throws IOException, URISyntaxException { // URLs look like "http://IP:PORT/singleton/service" URI defaultURI = NodeServiceServlet.createURI(baseURL, NodeServiceActivator.DEFAULT_SERVICE_NAME); URI quorumURI = NodeServiceServlet.createURI(baseURL, NodeServiceActivator.QUORUM_SERVICE_NAME); try (CloseableHttpClient client = TestHttpClientUtils.promiscuousCookieHttpClient()) { HttpResponse response = client.execute(new HttpGet(defaultURI)); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertTrue(response.containsHeader(NodeServiceServlet.NODE_HEADER)); Assert.assertEquals(NODE_1, response.getFirstHeader(NodeServiceServlet.NODE_HEADER).getValue()); } finally { HttpClientUtils.closeQuietly(response); } // Service should be started regardless of whether a quorum was required. response = client.execute(new HttpGet(quorumURI)); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertTrue(response.containsHeader(NodeServiceServlet.NODE_HEADER)); Assert.assertEquals(NODE_1, response.getFirstHeader(NodeServiceServlet.NODE_HEADER).getValue()); } finally { HttpClientUtils.closeQuietly(response); } } } }
4,520
45.608247
136
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/AbstractClusteringTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, 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; import java.util.AbstractMap; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; import org.apache.http.Header; import org.apache.http.HttpResponse; import org.jboss.arquillian.container.spi.Container; import org.jboss.arquillian.container.spi.ContainerRegistry; import org.jboss.arquillian.container.test.api.Deployer; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.arquillian.api.WildFlyContainerController; import org.jboss.as.test.clustering.NodeUtil; import org.jboss.as.test.shared.TimeoutUtil; import org.jboss.logging.Logger; import org.junit.After; import org.junit.Before; /** * Base implementation for every clustering test which guarantees a framework contract as follows: * <ol> * <li>test case is constructed specifying nodes and deployments required</li> * <li>before every test method, first all containers that are not required in the test are stopped</li> * <li>before every test method, containers are started and deployments are deployed via {@link #beforeTestMethod()}</li> * <li>after every method execution the deployments are undeployed via {@link #afterTestMethod()}</li> * </ol> * Should the test demand different node and deployment handling, the {@link #beforeTestMethod()} and {@link #afterTestMethod()} * may be overridden. * <p> * Furthermore, this base class provides common constants for node/instance-id, deployment/deployment helpers, timeouts and provides * convenience methods for managing container and deployment lifecycle ({@link #start(String...)}, {@link #deploy(String...)}, etc). * * @author Radoslav Husar */ public abstract class AbstractClusteringTestCase { public static final String CONTAINER_SINGLE = "node-non-ha"; // Unified node and container names public static final String NODE_1 = "node-1"; public static final String NODE_2 = "node-2"; public static final String NODE_3 = "node-3"; public static final String NODE_4 = "node-4"; @Deprecated public static final String[] TWO_NODES = new String[] { NODE_1, NODE_2 }; @Deprecated public static final String[] THREE_NODES = new String[] { NODE_1, NODE_2, NODE_3 }; @Deprecated public static final String[] FOUR_NODES = new String[] { NODE_1, NODE_2, NODE_3, NODE_4 }; public static final Set<String> NODE_1_2 = Set.of(TWO_NODES); public static final Set<String> NODE_1_2_3 = Set.of(THREE_NODES); public static final Set<String> NODE_1_2_3_4 = Set.of(FOUR_NODES); public static final String NODE_NAME_PROPERTY = "jboss.node.name"; // Test deployment names public static final String DEPLOYMENT_1 = "deployment-1"; public static final String DEPLOYMENT_2 = "deployment-2"; public static final String DEPLOYMENT_3 = "deployment-3"; public static final String DEPLOYMENT_4 = "deployment-4"; @Deprecated public static final String[] TWO_DEPLOYMENTS = new String[] { DEPLOYMENT_1, DEPLOYMENT_2 }; @Deprecated public static final String[] THREE_DEPLOYMENTS = new String[] { DEPLOYMENT_1, DEPLOYMENT_2, DEPLOYMENT_3 }; @Deprecated public static final String[] FOUR_DEPLOYMENTS = new String[] { DEPLOYMENT_1, DEPLOYMENT_2, DEPLOYMENT_3, DEPLOYMENT_4 }; public static final Set<String> DEPLOYMENT_1_2 = Set.of(TWO_DEPLOYMENTS); public static final Set<String> DEPLOYMENT_1_2_3 = Set.of(THREE_DEPLOYMENTS); public static final Set<String> DEPLOYMENT_1_2_3_4 = Set.of(FOUR_DEPLOYMENTS); // Helper deployment names public static final String DEPLOYMENT_HELPER_1 = "deployment-helper-0"; public static final String DEPLOYMENT_HELPER_2 = "deployment-helper-1"; public static final String DEPLOYMENT_HELPER_3 = "deployment-helper-2"; public static final String DEPLOYMENT_HELPER_4 = "deployment-helper-3"; @Deprecated public static final String[] TWO_DEPLOYMENT_HELPERS = new String[] { DEPLOYMENT_HELPER_1, DEPLOYMENT_HELPER_2 }; @Deprecated public static final String[] FOUR_DEPLOYMENT_HELPERS = new String[] { DEPLOYMENT_HELPER_1, DEPLOYMENT_HELPER_2, DEPLOYMENT_HELPER_3, DEPLOYMENT_HELPER_4 }; public static final Set<String> DEPLOYMENT_HELPER_1_2 = Set.of(TWO_DEPLOYMENT_HELPERS); public static final Set<String> DEPLOYMENT_HELPER_1_2_3_4 = Set.of(FOUR_DEPLOYMENT_HELPERS); // Infinispan Server public static final String INFINISPAN_SERVER_HOME = System.getProperty("infinispan.server.home"); public static final String INFINISPAN_SERVER_PROFILE = System.getProperty("infinispan.server.profile"); public static final String INFINISPAN_SERVER_PROFILE_DEFAULT = "infinispan-14_0.xml"; public static final String INFINISPAN_SERVER_ADDRESS = "127.0.0.1"; public static final int INFINISPAN_SERVER_PORT = 11222; public static final String INFINISPAN_APPLICATION_USER = "testsuite-application-user"; public static final String INFINISPAN_APPLICATION_PASSWORD = "testsuite-application-password"; // Undertow-based WildFly load-balancer public static final String LOAD_BALANCER_1 = "load-balancer-1"; // H2 database public static final String DB_PORT = System.getProperty("dbport", "9092"); // Timeouts public static final int GRACE_TIME_TO_REPLICATE = TimeoutUtil.adjust(4000); public static final int GRACE_TIME_TOPOLOGY_CHANGE = TimeoutUtil.adjust(3000); public static final int GRACEFUL_SHUTDOWN_TIMEOUT = TimeoutUtil.adjust(15); public static final int GRACE_TIME_TO_MEMBERSHIP_CHANGE = TimeoutUtil.adjust(10000); public static final int WAIT_FOR_PASSIVATION_MS = TimeoutUtil.adjust(5); public static final int HTTP_REQUEST_WAIT_TIME_S = TimeoutUtil.adjust(5); // System Properties public static final String TESTSUITE_NODE0 = System.getProperty("node0", "127.0.0.1"); public static final String TESTSUITE_NODE1 = System.getProperty("node1", "127.0.0.1"); public static final String TESTSUITE_NODE2 = System.getProperty("node2", "127.0.0.1"); public static final String TESTSUITE_NODE3 = System.getProperty("node3", "127.0.0.1"); public static final String TESTSUITE_MCAST = System.getProperty("mcast", "230.0.0.4"); public static final String TESTSUITE_MCAST1 = System.getProperty("mcast1", "230.0.0.5"); public static final String TESTSUITE_MCAST2 = System.getProperty("mcast2", "230.0.0.6"); public static final String TESTSUITE_MCAST3 = System.getProperty("mcast3", "230.0.0.7"); protected static final Logger log = Logger.getLogger(AbstractClusteringTestCase.class); private static final Map<String, String> CONTAINER_TO_DEPLOYMENT = Map.of(NODE_1, DEPLOYMENT_1, NODE_2, DEPLOYMENT_2, NODE_3, DEPLOYMENT_3, NODE_4, DEPLOYMENT_4); protected static Map.Entry<String, String> parseSessionRoute(HttpResponse response) { Header setCookieHeader = response.getFirstHeader("Set-Cookie"); if (setCookieHeader == null) return null; String setCookieValue = setCookieHeader.getValue(); final String id = setCookieValue.substring(setCookieValue.indexOf('=') + 1, setCookieValue.indexOf(';')); final int index = id.indexOf('.'); return (index < 0) ? new AbstractMap.SimpleImmutableEntry<>(id, null) : new AbstractMap.SimpleImmutableEntry<>(id.substring(0, index), id.substring(index + 1)); } @ArquillianResource protected ContainerRegistry containerRegistry; @ArquillianResource protected WildFlyContainerController controller; @ArquillianResource protected Deployer deployer; private final Set<String> containers; private final Set<String> deployments; // Framework contract methods public AbstractClusteringTestCase() { this(NODE_1_2); } @Deprecated public AbstractClusteringTestCase(String[] nodes) { this(Set.of(nodes)); } public AbstractClusteringTestCase(Set<String> containers) { this(containers, toDeployments(containers)); } @Deprecated public AbstractClusteringTestCase(String[] nodes, String[] deployments) { this(Set.of(nodes), Set.of(deployments)); } public AbstractClusteringTestCase(Set<String> containers, Set<String> deployments) { this.containers = containers; this.deployments = deployments; } /** * Guarantees that prior to test method execution * (1) all containers that are not used in the test are stopped and, * (2) all requested containers are running and, * (3) all requested deployments are deployed thus allowing all necessary test resources injection. */ @Before public void beforeTestMethod() throws Exception { this.containerRegistry.getContainers().forEach(container -> { if (container.getState() == Container.State.STARTED && !this.containers.contains(container.getName())) { // Even though we should be able to just stop the container object this currently fails with: // WFARQ-47 Calling "container.stop();" always ends exceptionally "Caught exception closing ManagementClient: java.lang.NullPointerException" this.stop(container.getName()); log.debugf("Stopped container '%s' which was started but not requested for this test.", container.getName()); } }); this.start(); this.deploy(); } /** * Guarantees that all deployments are undeployed after the test method has been executed. */ @After public void afterTestMethod() throws Exception { this.start(); this.undeploy(); } // Node and deployment lifecycle management convenience methods @Deprecated protected void start(String... containers) { start(Set.of(containers)); } protected void start() { this.start(this.containers); } protected void start(String container) { NodeUtil.start(this.controller, container); } protected void start(Set<String> containers) { NodeUtil.start(this.controller, containers); } @Deprecated protected void stop(String... containers) { stop(Set.of(containers)); } protected void stop() { this.stop(this.containers); } protected void stop(String container) { NodeUtil.stop(this.controller, container); } protected void stop(Set<String> containers) { NodeUtil.stop(this.controller, containers); } protected boolean isStarted(String container) { return NodeUtil.isStarted(this.controller, container); } @Deprecated protected void stop(int timeout, String... containers) { stop(Set.of(containers), timeout); } protected void stop(String container, int timeout) { NodeUtil.stop(this.controller, container, timeout); } protected void stop(Set<String> containers, int timeout) { NodeUtil.stop(this.controller, containers, timeout); } @Deprecated protected void deploy(String... deployments) { deploy(Set.of(deployments)); } protected void deploy() { this.deploy(this.deployments); } protected void deploy(String deployment) { NodeUtil.deploy(this.deployer, deployment); } protected void deploy(Set<String> deployments) { NodeUtil.deploy(this.deployer, deployments); } @Deprecated protected void undeploy(String... deployments) { undeploy(Set.of(deployments)); } protected void undeploy() { this.undeploy(this.deployments); } protected void undeploy(String deployment) { NodeUtil.undeploy(this.deployer, deployment); } protected void undeploy(Set<String> deployments) { NodeUtil.undeploy(this.deployer, deployments); } protected static String findDeployment(String container) { String deployment = CONTAINER_TO_DEPLOYMENT.get(container); if (deployment == null) { throw new IllegalArgumentException(container); } return deployment; } public static int getPortOffsetForNode(String node) { switch (node) { case NODE_1: return 0; case NODE_2: return 100; case NODE_3: return 200; case NODE_4: return 300; default: throw new IllegalArgumentException(); } } static Set<String> toDeployments(Set<String> containers) { return containers.stream().map(AbstractClusteringTestCase::findDeployment).collect(Collectors.toSet()); } public interface Lifecycle { default void start(String container) { this.start(Set.of(container)); } default void stop(String container) { this.stop(Set.of(container)); } void start(Set<String> containers); void stop(Set<String> containers); } public class RestartLifecycle implements Lifecycle { @Override public void start(Set<String> containers) { AbstractClusteringTestCase.this.start(containers); } @Override public void stop(Set<String> containers) { AbstractClusteringTestCase.this.stop(containers); } } public class GracefulRestartLifecycle extends RestartLifecycle { @Override public void stop(Set<String> containers) { AbstractClusteringTestCase.this.stop(containers, GRACEFUL_SHUTDOWN_TIMEOUT); } } public class RedeployLifecycle implements Lifecycle { @Override public void start(Set<String> containers) { AbstractClusteringTestCase.this.deploy(toDeployments(containers)); } @Override public void stop(Set<String> containers) { AbstractClusteringTestCase.this.undeploy(toDeployments(containers)); } } }
14,922
40.33795
171
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/sso/ElytronSSOServerSetupTask.java
/* * 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.sso; import org.jboss.as.test.clustering.cluster.AbstractClusteringTestCase; import org.jboss.as.test.shared.CLIServerSetupTask; /** * @author Paul Ferraro */ public class ElytronSSOServerSetupTask extends CLIServerSetupTask { public ElytronSSOServerSetupTask() { NodeBuilder nb = this.builder.node(AbstractClusteringTestCase.TWO_NODES) .setup("/subsystem=elytron/filesystem-realm=sso:add(path=sso-realm, relative-to=jboss.server.data.dir)") .setup("/subsystem=elytron/security-domain=sso:add(default-realm=sso, permission-mapper=default-permission-mapper,realms=[{realm=sso, role-decoder=groups-to-roles}])") .setup("/subsystem=elytron/http-authentication-factory=sso:add(security-domain=sso, http-server-mechanism-factory=global, mechanism-configurations=[{mechanism-name=FORM}])"); // We already have an application-security-domain; need to reconfigure nb = nb.setup("/subsystem=undertow/application-security-domain=other:undefine-attribute(name=security-domain)") .setup("/subsystem=undertow/application-security-domain=other:write-attribute(name=http-authentication-factory,value=sso"); nb = nb.setup("/subsystem=elytron/key-store=sso:add(path=sso.keystore, relative-to=jboss.server.config.dir, credential-reference={clear-text=password}, type=PKCS12)") .setup("/subsystem=undertow/application-security-domain=other/setting=single-sign-on:add(key-store=sso, key-alias=localhost, credential-reference={clear-text=password})") .teardown("/subsystem=undertow/application-security-domain=other/setting=single-sign-on:remove()") .teardown("/subsystem=elytron/key-store=sso:remove()"); nb = nb.teardown("/subsystem=undertow/application-security-domain=other:undefine-attribute(name=http-authentication-factory)") .teardown("/subsystem=undertow/application-security-domain=other:write-attribute(name=security-domain,value=ApplicationDomain"); nb.teardown("/subsystem=elytron/http-authentication-factory=sso:remove()") .teardown("/subsystem=elytron/security-domain=sso:remove()") .teardown("/subsystem=elytron/filesystem-realm=sso:remove()") ; } }
3,354
60
190
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/sso/ReplicatedElytronSingleSignOnTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2018, 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.sso; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.TargetsContainer; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.test.integration.web.sso.SSOTestBase; import org.jboss.shrinkwrap.api.Archive; import org.junit.runner.RunWith; /** * @author Paul Ferraro */ @RunWith(Arquillian.class) @ServerSetup({ ElytronSSOServerSetupTask.class, IdentityServerSetupTask.class }) public class ReplicatedElytronSingleSignOnTestCase extends AbstractSingleSignOnTestCase { @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment1() { return createArchive(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment2() { return createArchive(); } private static Archive<?> createArchive() { return SSOTestBase.createSsoEar(); } }
2,128
37.017857
89
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/sso/HostSSOServerSetupTask.java
/* * 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.sso; import org.jboss.as.test.clustering.cluster.AbstractClusteringTestCase; import org.jboss.as.test.shared.CLIServerSetupTask; /** * @author Paul Ferraro */ public class HostSSOServerSetupTask extends CLIServerSetupTask { public HostSSOServerSetupTask() { this.builder.node(AbstractClusteringTestCase.TWO_NODES) .setup("/subsystem=undertow/server=default-server/host=default-host/setting=single-sign-on:add") .teardown("/subsystem=undertow/server=default-server/host=default-host/setting=single-sign-on:remove") ; } }
1,648
42.394737
118
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/sso/AbstractSingleSignOnTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.sso; import java.net.URL; import org.jboss.arquillian.container.test.api.OperateOnDeployment; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.test.clustering.cluster.AbstractClusteringTestCase; import org.jboss.as.test.integration.web.sso.LogoutServlet; import org.jboss.as.test.integration.web.sso.SSOTestBase; import org.jboss.logging.Logger; import org.junit.Test; /** * @author <a href="mailto:dpospisi@redhat.com">Dominik Pospisil</a> */ public abstract class AbstractSingleSignOnTestCase extends AbstractClusteringTestCase { private static Logger log = Logger.getLogger(AbstractSingleSignOnTestCase.class); /** * Test single sign-on across two web apps using form based auth */ @Test public void testFormAuthSingleSignOn( @ArquillianResource(LogoutServlet.class) @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1, @ArquillianResource(LogoutServlet.class) @OperateOnDeployment(DEPLOYMENT_2) URL baseURL2) throws Exception { log.trace("+++ testFormAuthSingleSignOn"); SSOTestBase.executeFormAuthSingleSignOnTest(new URL(baseURL1, "/"), new URL(baseURL2, "/"), log); } /** * Test single sign-on across two web apps using form based auth */ @Test public void testNoAuthSingleSignOn( @ArquillianResource(LogoutServlet.class) @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1, @ArquillianResource(LogoutServlet.class) @OperateOnDeployment(DEPLOYMENT_2) URL baseURL2) throws Exception { log.trace("+++ testNoAuthSingleSignOn"); SSOTestBase.executeNoAuthSingleSignOnTest(new URL(baseURL1, "/"), new URL(baseURL2, "/"), log); } /** * Test single sign-on is destroyed after session timeout * * Testing https://issues.jboss.org/browse/WFLY-5422 */ @Test public void testSessionTimeoutDestroysSSO( @ArquillianResource(LogoutServlet.class) @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1, @ArquillianResource(LogoutServlet.class) @OperateOnDeployment(DEPLOYMENT_2) URL baseURL2) throws Exception { log.trace("+++ testSessionTimeoutDestroysSSO"); SSOTestBase.executeFormAuthSSOTimeoutTest(new URL(baseURL1, "/"), new URL(baseURL2, "/"), log); } }
3,353
43.131579
120
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/sso/IdentityServerSetupTask.java
/* * 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.sso; import org.jboss.as.test.clustering.cluster.AbstractClusteringTestCase; import org.jboss.as.test.shared.CLIServerSetupTask; /** * @author Paul Ferraro */ public class IdentityServerSetupTask extends CLIServerSetupTask { public IdentityServerSetupTask() { this.builder.node(AbstractClusteringTestCase.TWO_NODES) .setup("/subsystem=elytron/filesystem-realm=sso:add-identity(identity=user1)") .setup("/subsystem=elytron/filesystem-realm=sso:add-identity-attribute(identity=user1, name=groups, value=[Users])") .setup("/subsystem=elytron/filesystem-realm=sso:set-password(identity=user1, clear={password=password1})") .teardown("/subsystem=elytron/filesystem-realm=sso:remove-identity(identity=user1)") ; } }
1,880
43.785714
132
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/sso/remote/RemoteElytronSingleSignOnTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2020, 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.sso.remote; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.TargetsContainer; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.test.clustering.cluster.sso.ElytronSSOServerSetupTask; import org.jboss.as.test.clustering.cluster.sso.IdentityServerSetupTask; import org.jboss.as.test.integration.web.sso.SSOTestBase; import org.jboss.as.test.shared.CLIServerSetupTask; import org.jboss.shrinkwrap.api.Archive; import org.junit.runner.RunWith; /** * @author Paul Ferraro */ @RunWith(Arquillian.class) @ServerSetup({ InfinispanServerSetupTask.class, RemoteElytronSingleSignOnTestCase.ServerSetupTask.class, ElytronSSOServerSetupTask.class, IdentityServerSetupTask.class }) public class RemoteElytronSingleSignOnTestCase extends AbstractRemoteSingleSignOnTestCase { @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment1() { return createArchive(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment2() { return createArchive(); } private static Archive<?> createArchive() { return SSOTestBase.createSsoEar(); } public static class ServerSetupTask extends CLIServerSetupTask { public ServerSetupTask() { this.builder.node(TWO_NODES) .setup("/subsystem=distributable-web/hotrod-single-sign-on-management=other:add(remote-cache-container=sso, cache-configuration=default)") .teardown("/subsystem=distributable-web/hotrod-single-sign-on-management=other:remove") ; } } }
2,870
41.220588
170
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/sso/remote/InfinispanServerSetupTask.java
/* * 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.sso.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; /** * @author Paul Ferraro */ public class InfinispanServerSetupTask extends CLIServerSetupTask { public InfinispanServerSetupTask() { this.builder.node(AbstractClusteringTestCase.TWO_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=sso:add(default-remote-cluster=infinispan-server-cluster, marshaller=PROTOSTREAM, modules=[org.wildfly.clustering.web.hotrod], properties={infinispan.client.hotrod.auth_username=%s, infinispan.client.hotrod.auth_password=%s})", INFINISPAN_APPLICATION_USER, INFINISPAN_APPLICATION_PASSWORD) .setup("/subsystem=infinispan/remote-cache-container=sso/remote-cluster=infinispan-server-cluster:add(socket-bindings=[infinispan-server])") .teardown("/subsystem=infinispan/remote-cache-container=sso:remove") .teardown("/socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=infinispan-server:remove") ; } }
2,799
58.574468
358
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/sso/remote/AbstractRemoteSingleSignOnTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2020, 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.sso.remote; import org.jboss.as.test.clustering.InfinispanServerUtil; import org.jboss.as.test.clustering.cluster.sso.AbstractSingleSignOnTestCase; import org.junit.ClassRule; import org.junit.rules.TestRule; /** * @author Radoslav Husar */ public abstract class AbstractRemoteSingleSignOnTestCase extends AbstractSingleSignOnTestCase { @ClassRule public static final TestRule INFINISPAN_SERVER_RULE = InfinispanServerUtil.infinispanServerTestRule(); }
1,536
38.410256
106
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/group/GroupListenerTestCase.java
/* * 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.group; import static org.junit.Assert.*; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.TargetsContainer; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.test.clustering.cluster.AbstractClusteringTestCase; import org.jboss.as.test.clustering.cluster.group.bean.ClusterTopology; import org.jboss.as.test.clustering.cluster.group.bean.ClusterTopologyRetriever; import org.jboss.as.test.clustering.cluster.group.bean.ClusterTopologyRetrieverBean; import org.jboss.as.test.clustering.ejb.EJBDirectory; import org.jboss.as.test.clustering.ejb.RemoteEJBDirectory; import org.jboss.as.test.shared.TimeoutUtil; import org.jboss.as.test.shared.integration.ejb.security.PermissionUtils; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; /** * Integration test for the listener facility of a {@link Group}. * @author Paul Ferraro */ @RunWith(Arquillian.class) public class GroupListenerTestCase extends AbstractClusteringTestCase { private static final String MODULE_NAME = GroupListenerTestCase.class.getSimpleName(); private static final long VIEW_CHANGE_WAIT = TimeoutUtil.adjust(2000); @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment1() { return createDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment2() { return createDeployment(); } private static Archive<?> createDeployment() { WebArchive war = ShrinkWrap.create(WebArchive.class, MODULE_NAME + ".war"); war.addPackage(ClusterTopologyRetriever.class.getPackage()); war.setWebXML(GroupListenerTestCase.class.getPackage(), "web.xml"); war.addAsManifestResource(PermissionUtils.createPermissionsXmlAsset(new RuntimePermission("getClassLoader")), "permissions.xml"); return war; } @Test public void test() throws Exception { try (EJBDirectory directory = new RemoteEJBDirectory(MODULE_NAME)) { ClusterTopologyRetriever bean = directory.lookupStateless(ClusterTopologyRetrieverBean.class, ClusterTopologyRetriever.class); ClusterTopology topology = bean.getClusterTopology(); assertEquals(topology.getCurrentMembers().toString(), 2, topology.getCurrentMembers().size()); assertTrue(topology.getCurrentMembers().toString(), topology.getCurrentMembers().contains(NODE_1)); assertTrue(topology.getCurrentMembers().toString(), topology.getCurrentMembers().contains(NODE_2)); stop(NODE_2); Thread.sleep(VIEW_CHANGE_WAIT); topology = bean.getClusterTopology(); assertEquals(topology.getCurrentMembers().toString(), 1, topology.getCurrentMembers().size()); assertTrue(topology.getCurrentMembers().toString(), topology.getCurrentMembers().contains(NODE_1)); assertEquals(topology.getPreviousMembers().toString(), 2, topology.getPreviousMembers().size()); assertTrue(topology.getPreviousMembers().toString(), topology.getPreviousMembers().contains(NODE_1)); assertTrue(topology.getPreviousMembers().toString(), topology.getPreviousMembers().contains(NODE_2)); start(NODE_2); Thread.sleep(VIEW_CHANGE_WAIT); topology = bean.getClusterTopology(); assertEquals(topology.getCurrentMembers().toString(), 2, topology.getCurrentMembers().size()); assertTrue(topology.getCurrentMembers().toString(), topology.getCurrentMembers().contains(NODE_1)); assertTrue(topology.getCurrentMembers().toString(), topology.getCurrentMembers().contains(NODE_2)); if (topology.getTargetMember().equals(NODE_1)) { assertEquals(topology.getPreviousMembers().toString(), 1, topology.getPreviousMembers().size()); assertTrue(topology.getPreviousMembers().toString(), topology.getPreviousMembers().contains(NODE_1)); } else { // Since node 2 was just started, its previous membership will be empty assertEquals(topology.getPreviousMembers().toString(), 0, topology.getPreviousMembers().size()); } stop(NODE_1); Thread.sleep(VIEW_CHANGE_WAIT); topology = bean.getClusterTopology(); assertEquals(topology.getCurrentMembers().toString(), 1, topology.getCurrentMembers().size()); assertTrue(topology.getCurrentMembers().toString(), topology.getCurrentMembers().contains(NODE_2)); assertEquals(topology.getPreviousMembers().toString(), 2, topology.getPreviousMembers().size()); assertTrue(topology.getPreviousMembers().toString(), topology.getPreviousMembers().contains(NODE_1)); assertTrue(topology.getPreviousMembers().toString(), topology.getPreviousMembers().contains(NODE_2)); start(NODE_1); Thread.sleep(VIEW_CHANGE_WAIT); topology = bean.getClusterTopology(); assertEquals(topology.getCurrentMembers().toString(), 2, topology.getCurrentMembers().size()); assertTrue(topology.getCurrentMembers().toString(), topology.getCurrentMembers().contains(NODE_1)); assertTrue(topology.getCurrentMembers().toString(), topology.getCurrentMembers().contains(NODE_2)); if (topology.getTargetMember().equals(NODE_2)) { assertEquals(topology.getPreviousMembers().toString(), 1, topology.getPreviousMembers().size()); assertTrue(topology.getPreviousMembers().toString(), topology.getPreviousMembers().contains(NODE_2)); } else { // Since node 1 was just started, its previous membership will be empty assertEquals(topology.getPreviousMembers().toString(), 0, topology.getPreviousMembers().size()); } } } }
7,211
50.884892
138
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/group/bean/Group.java
/* * 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.group.bean; import org.wildfly.clustering.group.Membership; /** * @author Paul Ferraro */ public interface Group extends org.wildfly.clustering.group.Group { Membership getPreviousMembership(); }
1,273
37.606061
70
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/group/bean/ClusterTopologyRetrieverBean.java
package org.jboss.as.test.clustering.cluster.group.bean; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import jakarta.ejb.EJB; import jakarta.ejb.Remote; import jakarta.ejb.Stateless; import org.wildfly.clustering.group.Membership; import org.wildfly.clustering.group.Node; @Stateless @Remote(ClusterTopologyRetriever.class) public class ClusterTopologyRetrieverBean implements ClusterTopologyRetriever { @EJB private Group group; @Override public ClusterTopology getClusterTopology() { return new ClusterTopology(this.group.getLocalMember().getName(), getNames(this.group.getMembership()), getNames(this.group.getPreviousMembership())); } private static List<String> getNames(Membership membership) { return (membership != null) ? membership.getMembers().stream().map(Node::getName).collect(Collectors.toList()) : Collections.emptyList(); } }
937
31.344828
158
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/group/bean/GroupBean.java
package org.jboss.as.test.clustering.cluster.group.bean; import jakarta.annotation.PostConstruct; import jakarta.annotation.PreDestroy; import jakarta.annotation.Resource; import jakarta.ejb.Local; import jakarta.ejb.Singleton; import jakarta.ejb.Startup; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import org.wildfly.clustering.Registration; import org.wildfly.clustering.group.GroupListener; import org.wildfly.clustering.group.Membership; import org.wildfly.clustering.group.Node; @Singleton @Startup @Local(Group.class) public class GroupBean implements Group, GroupListener { @Resource(name = "clustering/group") private org.wildfly.clustering.group.Group group; private Registration registration; private volatile Membership previousMembership; @PostConstruct public void init() { this.registration = this.group.register(this); } @PreDestroy public void destroy() { this.registration.close(); } @Override public void membershipChanged(Membership previousMembership, Membership membership, boolean merged) { try { // Ensure the thread context classloader of the notification is correct Thread.currentThread().getContextClassLoader().loadClass(this.getClass().getName()); // Ensure the correct naming context is set Context context = new InitialContext(); try { context.lookup("java:comp/env/clustering/group"); } finally { context.close(); } } catch (ClassNotFoundException e) { throw new IllegalStateException(e); } catch (NamingException e) { throw new IllegalStateException(e); } this.previousMembership = previousMembership; } @Override public String getName() { return this.group.getName(); } @Override public Node getLocalMember() { return this.group.getLocalMember(); } @Override public Membership getMembership() { return this.group.getMembership(); } @Override public boolean isSingleton() { return this.group.isSingleton(); } @Override public Registration register(GroupListener object) { return this.group.register(object); } @Override public Membership getPreviousMembership() { return this.previousMembership; } }
2,472
27.102273
105
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/group/bean/ClusterTopologyRetriever.java
package org.jboss.as.test.clustering.cluster.group.bean; public interface ClusterTopologyRetriever { ClusterTopology getClusterTopology(); }
147
20.142857
56
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/group/bean/ClusterTopology.java
package org.jboss.as.test.clustering.cluster.group.bean; import java.io.Serializable; import java.util.List; public class ClusterTopology implements Serializable { private static final long serialVersionUID = 413628123168918069L; private final String targetMember; private final List<String> currentMembers; private final List<String> previousMembers; public ClusterTopology(String targetMember, List<String> currentMembers, List<String> previousMembers) { this.targetMember = targetMember; this.currentMembers = currentMembers; this.previousMembers = previousMembers; } public String getTargetMember() { return this.targetMember; } public List<String> getCurrentMembers() { return this.currentMembers; } public List<String> getPreviousMembers() { return this.previousMembers; } }
884
27.548387
108
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/AbstractImmutableWebFailoverTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.web; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.util.Map; import jakarta.servlet.http.HttpServletResponse; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.utils.HttpClientUtils; import org.apache.http.impl.client.CloseableHttpClient; import org.jboss.arquillian.container.test.api.OperateOnDeployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.test.clustering.ClusterHttpClientUtil; import org.jboss.as.test.clustering.cluster.AbstractClusteringTestCase; import org.jboss.as.test.clustering.single.web.SimpleServlet; import org.jboss.as.test.http.util.TestHttpClientUtils; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * Validates behavior of immutable session attributes. * * @author Paul Ferraro */ @RunWith(Arquillian.class) public abstract class AbstractImmutableWebFailoverTestCase extends AbstractClusteringTestCase { private final String deploymentName; protected AbstractImmutableWebFailoverTestCase(String deploymentName) { super(THREE_NODES); this.deploymentName = deploymentName; } @Test public void test( @ArquillianResource(SimpleServlet.class) @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1, @ArquillianResource(SimpleServlet.class) @OperateOnDeployment(DEPLOYMENT_2) URL baseURL2, @ArquillianResource(SimpleServlet.class) @OperateOnDeployment(DEPLOYMENT_3) URL baseURL3) throws Exception { this.testGracefulUndeployFailover(baseURL1, baseURL2, baseURL3); this.testGracefulSimpleFailover(baseURL1, baseURL2, baseURL3); } protected void testGracefulSimpleFailover(URL baseURL1, URL baseURL2, URL baseURL3) throws Exception { this.testFailover(new RestartLifecycle(), baseURL1, baseURL2, baseURL3); } protected void testGracefulUndeployFailover(URL baseURL1, URL baseURL2, URL baseURL3) throws Exception { this.testFailover(new RedeployLifecycle(), baseURL1, baseURL2, baseURL3); } private void testFailover(Lifecycle lifecycle, URL baseURL1, URL baseURL2, URL baseURL3) throws Exception { URI uri1 = SimpleServlet.createURI(baseURL1); URI uri2 = SimpleServlet.createURI(baseURL2); URI uri3 = SimpleServlet.createURI(baseURL3); this.establishTopology(baseURL1, THREE_NODES); try (CloseableHttpClient client = TestHttpClientUtils.promiscuousCookieHttpClient()) { HttpResponse response = client.execute(new HttpGet(uri1)); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(1, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); Map.Entry<String, String> entry = parseSessionRoute(response); Assert.assertNotNull(entry); Assert.assertEquals(NODE_1, entry.getValue()); Assert.assertEquals(entry.getKey(), response.getFirstHeader(SimpleServlet.SESSION_ID_HEADER).getValue()); } finally { HttpClientUtils.closeQuietly(response); } response = client.execute(new HttpGet(uri1)); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(2, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); Map.Entry<String, String> entry = parseSessionRoute(response); // Ensure routing is not changed on 2nd query Assert.assertNull(entry); } finally { HttpClientUtils.closeQuietly(response); } response = client.execute(new HttpGet(uri2)); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); // Because session attribute is defined to be immutable, the previous updates should be lost Assert.assertEquals(2, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); Map.Entry<String, String> entry = parseSessionRoute(response); Assert.assertNotNull(entry); Assert.assertEquals(NODE_2, entry.getValue()); Assert.assertEquals(entry.getKey(), response.getFirstHeader(SimpleServlet.SESSION_ID_HEADER).getValue()); } finally { HttpClientUtils.closeQuietly(response); } response = client.execute(new HttpGet(uri2)); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(3, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); Map.Entry<String, String> entry = parseSessionRoute(response); // Ensure routing is not changed on 2nd query Assert.assertNull(entry); } finally { HttpClientUtils.closeQuietly(response); } response = client.execute(new HttpGet(uri3)); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); // Because session attribute is defined to be immutable, the previous updates should be lost Assert.assertEquals(2, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); Map.Entry<String, String> entry = parseSessionRoute(response); Assert.assertNotNull(entry); Assert.assertEquals(NODE_3, entry.getValue()); Assert.assertEquals(entry.getKey(), response.getFirstHeader(SimpleServlet.SESSION_ID_HEADER).getValue()); } finally { HttpClientUtils.closeQuietly(response); } response = client.execute(new HttpGet(uri3)); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(3, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); Map.Entry<String, String> entry = parseSessionRoute(response); // Ensure routing is not changed on 2nd query Assert.assertNull(entry); } finally { HttpClientUtils.closeQuietly(response); } } } private void establishTopology(URL baseURL, String... nodes) throws URISyntaxException, IOException, InterruptedException { ClusterHttpClientUtil.establishTopology(baseURL, "web", this.deploymentName, nodes); // TODO we should be able to speed this up by observing changes in the routing registry // prevents failing assertions when topology information is expected, e.g.: //java.lang.AssertionError: expected null, but was:<bpAmUlICzeXMtFiOJvTiOCASbXNivRdHTIlQC00c=node-2> Thread.sleep(GRACE_TIME_TOPOLOGY_CHANGE); } }
8,375
48.270588
127
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/CoarseImmutableWebFailoverTestCase.java
/* * 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.web; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.TargetsContainer; import org.jboss.as.test.clustering.ClusterTestUtil; import org.jboss.as.test.clustering.single.web.Mutable; import org.jboss.as.test.clustering.single.web.SimpleServlet; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; /** * Validates behavior of immutable session attributes using SESSION granularity. * @author Paul Ferraro */ public class CoarseImmutableWebFailoverTestCase extends AbstractImmutableWebFailoverTestCase { private static final String MODULE_NAME = CoarseImmutableWebFailoverTestCase.class.getSimpleName(); private static final String DEPLOYMENT_NAME = MODULE_NAME + ".war"; public CoarseImmutableWebFailoverTestCase() { super(DEPLOYMENT_NAME); } @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment1() { return getDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment2() { return getDeployment(); } @Deployment(name = DEPLOYMENT_3, managed = false, testable = false) @TargetsContainer(NODE_3) public static Archive<?> deployment3() { return getDeployment(); } private static Archive<?> getDeployment() { WebArchive war = ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME); war.addClasses(SimpleServlet.class, Mutable.class); ClusterTestUtil.addTopologyListenerDependencies(war); // Take web.xml from the managed test. war.setWebXML(CoarseImmutableWebFailoverTestCase.class.getPackage(), "web.xml"); war.addAsWebInfResource(CoarseImmutableWebFailoverTestCase.class.getPackage(), "distributable-web_immutable_coarse.xml", "distributable-web.xml"); return war; } }
3,106
40.426667
154
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/FineNonTransactionalSessionActivationTestCase.java
/* * 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.web; 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.web.event.SessionActivationServlet; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; /** * @author Paul Ferraro */ @ServerSetup(ConcurrentSessionServerSetup.class) public class FineNonTransactionalSessionActivationTestCase extends AbstractSessionActivationTestCase { private static final String MODULE_NAME = FineNonTransactionalSessionActivationTestCase.class.getSimpleName(); private static final String DEPLOYMENT_NAME = MODULE_NAME + ".war"; @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment1() { return getDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment2() { return getDeployment(); } @Deployment(name = DEPLOYMENT_3, managed = false, testable = false) @TargetsContainer(NODE_3) public static Archive<?> deployment3() { return getDeployment(); } private static Archive<?> getDeployment() { WebArchive war = ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME); war.addClasses(SessionActivationServlet.class); war.setWebXML(DistributableTestCase.class.getPackage(), "web.xml"); war.addAsWebInfResource(DistributableTestCase.class.getPackage(), "jboss-all_concurrent_fine.xml", "jboss-all.xml"); return war; } public FineNonTransactionalSessionActivationTestCase() { super(false); } }
2,895
39.222222
124
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/FineWebFailoverTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2012, 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.web; import org.infinispan.transaction.TransactionMode; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.TargetsContainer; import org.jboss.as.test.clustering.ClusterTestUtil; import org.jboss.as.test.clustering.single.web.Mutable; import org.jboss.as.test.clustering.single.web.SimpleServlet; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; /** * @author Radoslav Husar */ public class FineWebFailoverTestCase extends AbstractWebFailoverTestCase { private static final String MODULE_NAME = FineWebFailoverTestCase.class.getSimpleName(); private static final String DEPLOYMENT_NAME = MODULE_NAME + ".war"; public FineWebFailoverTestCase() { super(DEPLOYMENT_NAME, TransactionMode.TRANSACTIONAL); } @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment1() { return createDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment2() { return createDeployment(); } @Deployment(name = DEPLOYMENT_3, managed = false, testable = false) @TargetsContainer(NODE_3) public static Archive<?> deployment3() { return createDeployment(); } private static Archive<?> createDeployment() { WebArchive war = ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME); war.addClasses(SimpleServlet.class, Mutable.class); ClusterTestUtil.addTopologyListenerDependencies(war); // Take web.xml from the managed test. war.setWebXML(DistributableTestCase.class.getPackage(), "web.xml"); war.addAsWebInfResource(DistributableTestCase.class.getPackage(), "jboss-all_fine.xml", "jboss-all.xml"); return war; } }
3,024
39.878378
113
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/FineTransactionalSessionActivationTestCase.java
/* * 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.web; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.TargetsContainer; import org.jboss.as.test.clustering.cluster.web.event.SessionActivationServlet; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; /** * @author Paul Ferraro */ public class FineTransactionalSessionActivationTestCase extends AbstractSessionActivationTestCase { private static final String MODULE_NAME = FineTransactionalSessionActivationTestCase.class.getSimpleName(); private static final String DEPLOYMENT_NAME = MODULE_NAME + ".war"; @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment1() { return getDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment2() { return getDeployment(); } @Deployment(name = DEPLOYMENT_3, managed = false, testable = false) @TargetsContainer(NODE_3) public static Archive<?> deployment3() { return getDeployment(); } private static Archive<?> getDeployment() { WebArchive war = ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME); war.addClasses(SessionActivationServlet.class); war.setWebXML(DistributableTestCase.class.getPackage(), "web.xml"); war.addAsWebInfResource(DistributableTestCase.class.getPackage(), "jboss-all_fine.xml", "jboss-all.xml"); return war; } public FineTransactionalSessionActivationTestCase() { super(true); } }
2,777
38.685714
113
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/CoarseTransactionalSessionActivationTestCase.java
/* * 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.web; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.TargetsContainer; import org.jboss.as.test.clustering.cluster.web.event.SessionActivationServlet; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; /** * @author Paul Ferraro */ public class CoarseTransactionalSessionActivationTestCase extends AbstractSessionActivationTestCase { private static final String MODULE_NAME = CoarseTransactionalSessionActivationTestCase.class.getSimpleName(); private static final String DEPLOYMENT_NAME = MODULE_NAME + ".war"; @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment1() { return getDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment2() { return getDeployment(); } @Deployment(name = DEPLOYMENT_3, managed = false, testable = false) @TargetsContainer(NODE_3) public static Archive<?> deployment3() { return getDeployment(); } private static Archive<?> getDeployment() { WebArchive war = ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME); war.addClasses(SessionActivationServlet.class); war.setWebXML(DistributableTestCase.class.getPackage(), "web.xml"); return war; } public CoarseTransactionalSessionActivationTestCase() { super(true); } }
2,669
37.695652
113
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/EnableUndertowStatisticsSetupTask.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, 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.web; import org.jboss.as.test.clustering.cluster.AbstractClusteringTestCase; import org.jboss.as.test.shared.CLIServerSetupTask; /** * Task that enable Undertow statistics. * @author Paul Ferraro */ public class EnableUndertowStatisticsSetupTask extends CLIServerSetupTask { public EnableUndertowStatisticsSetupTask() { this.builder.node(AbstractClusteringTestCase.FOUR_NODES) .setup("/subsystem=undertow:write-attribute(name=statistics-enabled, value=true)") .teardown("/subsystem=undertow:undefine-attribute(name=statistics-enabled)") ; } }
1,682
40.04878
98
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/FineImmutableWebFailoverTestCase.java
/* * 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.web; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.TargetsContainer; import org.jboss.as.test.clustering.ClusterTestUtil; import org.jboss.as.test.clustering.single.web.Mutable; import org.jboss.as.test.clustering.single.web.SimpleServlet; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; /** * Validates behavior of immutable session attributes using ATTRIBUTE granularity. * @author Paul Ferraro */ public class FineImmutableWebFailoverTestCase extends AbstractImmutableWebFailoverTestCase { private static final String MODULE_NAME = FineImmutableWebFailoverTestCase.class.getSimpleName(); private static final String DEPLOYMENT_NAME = MODULE_NAME + ".war"; public FineImmutableWebFailoverTestCase() { super(DEPLOYMENT_NAME); } @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment1() { return getDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment2() { return getDeployment(); } @Deployment(name = DEPLOYMENT_3, managed = false, testable = false) @TargetsContainer(NODE_3) public static Archive<?> deployment3() { return getDeployment(); } private static Archive<?> getDeployment() { WebArchive war = ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME); war.addClasses(SimpleServlet.class, Mutable.class); ClusterTestUtil.addTopologyListenerDependencies(war); // Take web.xml from the managed test. war.setWebXML(FineImmutableWebFailoverTestCase.class.getPackage(), "web.xml"); war.addAsWebInfResource(FineImmutableWebFailoverTestCase.class.getPackage(), "distributable-web_immutable_fine.xml", "distributable-web.xml"); return war; } }
3,096
40.293333
150
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/ConcurrentCoarseWebFailoverTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, 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.web; import org.infinispan.transaction.TransactionMode; 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.ClusterTestUtil; import org.jboss.as.test.clustering.single.web.Mutable; import org.jboss.as.test.clustering.single.web.SimpleServlet; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; @ServerSetup(ConcurrentSessionServerSetup.class) public class ConcurrentCoarseWebFailoverTestCase extends AbstractWebFailoverTestCase { private static final String MODULE_NAME = ConcurrentCoarseWebFailoverTestCase.class.getSimpleName(); private static final String DEPLOYMENT_NAME = MODULE_NAME + ".war"; public ConcurrentCoarseWebFailoverTestCase() { super(DEPLOYMENT_NAME, TransactionMode.NON_TRANSACTIONAL); } @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment1() { return getDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment2() { return getDeployment(); } @Deployment(name = DEPLOYMENT_3, managed = false, testable = false) @TargetsContainer(NODE_3) public static Archive<?> deployment3() { return getDeployment(); } private static Archive<?> getDeployment() { WebArchive war = ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME); war.addClasses(SimpleServlet.class, Mutable.class); ClusterTestUtil.addTopologyListenerDependencies(war); // Take web.xml from the managed test. war.setWebXML(DistributableTestCase.class.getPackage(), "web.xml"); war.addAsWebInfResource(DistributableTestCase.class.getPackage(), "jboss-all_concurrent_coarse.xml", "jboss-all.xml"); return war; } }
3,128
41.863014
126
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/NonDistributableTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, 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.web; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.util.Map; import jakarta.servlet.http.HttpServletResponse; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.utils.HttpClientUtils; 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.RunAsClient; 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; import org.jboss.as.test.clustering.single.web.Mutable; import org.jboss.as.test.clustering.single.web.SimpleServlet; import org.jboss.as.test.http.util.TestHttpClientUtils; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * Validate that non-distributable web applications play nicely with a load balancer using sticky sessions. * * @author Paul Ferraro */ @RunWith(Arquillian.class) @RunAsClient public class NonDistributableTestCase extends AbstractClusteringTestCase { private static final String MODULE_NAME = NonDistributableTestCase.class.getSimpleName(); @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment1() { return getDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment2() { return getDeployment(); } private static Archive<?> getDeployment() { WebArchive war = ShrinkWrap.create(WebArchive.class, MODULE_NAME + ".war"); war.addClasses(SimpleServlet.class, Mutable.class); return war; } @Test public void test(@ArquillianResource(SimpleServlet.class) @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1, @ArquillianResource(SimpleServlet.class) @OperateOnDeployment(DEPLOYMENT_2) URL baseURL2) throws IOException, URISyntaxException { URI uri1 = SimpleServlet.createURI(baseURL1); URI uri2 = SimpleServlet.createURI(baseURL2); try (CloseableHttpClient client = TestHttpClientUtils.promiscuousCookieHttpClient()) { HttpResponse response = client.execute(new HttpGet(uri1)); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(1, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); Map.Entry<String, String> entry = parseSessionRoute(response); // Session identifier should contain the route for this node Assert.assertEquals(NODE_1, entry.getValue()); // Session identifier seen by servlet should *not* contain the route Assert.assertEquals(entry.getKey(), response.getFirstHeader(SimpleServlet.SESSION_ID_HEADER).getValue()); } finally { HttpClientUtils.closeQuietly(response); } response = client.execute(new HttpGet(uri1)); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(2, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); Map.Entry<String, String> entry = parseSessionRoute(response); Assert.assertNull(entry); } finally { HttpClientUtils.closeQuietly(response); } response = client.execute(new HttpGet(uri2)); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); // Session should not be replicated Assert.assertEquals(1, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); Map.Entry<String, String> entry = parseSessionRoute(response); // Session identifier should contain the route for this node Assert.assertEquals(NODE_2, entry.getValue()); // Session identifier seen by servlet should *not* contain the route Assert.assertEquals(entry.getKey(), response.getFirstHeader(SimpleServlet.SESSION_ID_HEADER).getValue()); } finally { HttpClientUtils.closeQuietly(response); } response = client.execute(new HttpGet(uri2)); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(2, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); Map.Entry<String, String> entry = parseSessionRoute(response); Assert.assertNull(entry); } finally { HttpClientUtils.closeQuietly(response); } } } }
6,457
45.797101
151
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/ExternalizerTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, 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.web; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import jakarta.servlet.http.HttpServletResponse; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.utils.HttpClientUtils; 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; import org.jboss.as.test.clustering.cluster.web.externalizer.CounterExternalizer; import org.jboss.as.test.clustering.cluster.web.externalizer.CounterServlet; import org.jboss.as.test.http.util.TestHttpClientUtils; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.wildfly.clustering.marshalling.Externalizer; /** * @author Paul Ferraro */ @RunWith(Arquillian.class) public class ExternalizerTestCase extends AbstractClusteringTestCase { private static final String MODULE_NAME = ExternalizerTestCase.class.getSimpleName(); private static final String DEPLOYMENT_NAME = MODULE_NAME + ".war"; @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment0() { return getDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment1() { return getDeployment(); } private static Archive<?> getDeployment() { WebArchive war = ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME); war.addPackage(CounterServlet.class.getPackage()); war.setWebXML(ExternalizerTestCase.class.getPackage(), "web.xml"); war.addAsServiceProvider(Externalizer.class, CounterExternalizer.class); return war; } @Test public void test( @ArquillianResource(CounterServlet.class) @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1, @ArquillianResource(CounterServlet.class) @OperateOnDeployment(DEPLOYMENT_2) URL baseURL2) throws IOException, URISyntaxException { URI uri1 = CounterServlet.createURI(baseURL1); URI uri2 = CounterServlet.createURI(baseURL2); try (CloseableHttpClient client = TestHttpClientUtils.promiscuousCookieHttpClient()) { assertValue(client, uri1, 1); assertValue(client, uri1, 2); assertValue(client, uri2, 3); assertValue(client, uri2, 4); assertValue(client, uri1, 5); assertValue(client, uri1, 6); } } private static void assertValue(HttpClient client, URI uri, int value) throws IOException { HttpResponse response = client.execute(new HttpGet(uri)); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(value, Integer.parseInt(response.getFirstHeader(CounterServlet.COUNT_HEADER).getValue())); } finally { HttpClientUtils.closeQuietly(response); } } }
4,616
39.5
122
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/CoarseWebFailoverTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, 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.web; import org.infinispan.transaction.TransactionMode; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.TargetsContainer; import org.jboss.as.test.clustering.ClusterTestUtil; import org.jboss.as.test.clustering.single.web.Mutable; import org.jboss.as.test.clustering.single.web.SimpleServlet; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; public class CoarseWebFailoverTestCase extends AbstractWebFailoverTestCase { private static final String MODULE_NAME = CoarseWebFailoverTestCase.class.getSimpleName(); private static final String DEPLOYMENT_NAME = MODULE_NAME + ".war"; public CoarseWebFailoverTestCase() { super(DEPLOYMENT_NAME, TransactionMode.TRANSACTIONAL); } @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment1() { return getDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment2() { return getDeployment(); } @Deployment(name = DEPLOYMENT_3, managed = false, testable = false) @TargetsContainer(NODE_3) public static Archive<?> deployment3() { return getDeployment(); } private static Archive<?> getDeployment() { WebArchive war = ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME); war.addClasses(SimpleServlet.class, Mutable.class); ClusterTestUtil.addTopologyListenerDependencies(war); // Take web.xml from the managed test. war.setWebXML(DistributableTestCase.class.getPackage(), "web.xml"); return war; } }
2,870
40.014286
94
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/CoarseNonTransactionalSessionActivationTestCase.java
/* * 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.web; 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.web.event.SessionActivationServlet; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; /** * @author Paul Ferraro */ @ServerSetup(ConcurrentSessionServerSetup.class) public class CoarseNonTransactionalSessionActivationTestCase extends AbstractSessionActivationTestCase { private static final String MODULE_NAME = CoarseNonTransactionalSessionActivationTestCase.class.getSimpleName(); private static final String DEPLOYMENT_NAME = MODULE_NAME + ".war"; @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment1() { return getDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment2() { return getDeployment(); } @Deployment(name = DEPLOYMENT_3, managed = false, testable = false) @TargetsContainer(NODE_3) public static Archive<?> deployment3() { return getDeployment(); } private static Archive<?> getDeployment() { WebArchive war = ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME); war.addClasses(SessionActivationServlet.class); war.setWebXML(DistributableTestCase.class.getPackage(), "web.xml"); war.addAsWebInfResource(DistributableTestCase.class.getPackage(), "jboss-all_concurrent_coarse.xml", "jboss-all.xml"); return war; } public CoarseNonTransactionalSessionActivationTestCase() { super(false); } }
2,903
39.333333
126
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/AbstractWebFailoverTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.web; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.util.Arrays; import java.util.Map; import jakarta.servlet.http.HttpServletResponse; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpDelete; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpHead; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPut; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.impl.client.CloseableHttpClient; import org.infinispan.configuration.cache.CacheMode; import org.infinispan.transaction.TransactionMode; import org.jboss.arquillian.container.test.api.OperateOnDeployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.test.clustering.ClusterHttpClientUtil; import org.jboss.as.test.clustering.cluster.AbstractClusteringTestCase; import org.jboss.as.test.clustering.single.web.SimpleServlet; import org.jboss.as.test.http.util.TestHttpClientUtils; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * Test that HTTP session failover on shutdown and undeploy works. * * @author Radoslav Husar */ @RunWith(Arquillian.class) public abstract class AbstractWebFailoverTestCase extends AbstractClusteringTestCase { private final String deploymentName; private final CacheMode cacheMode; private final Runnable nonTxWait; protected AbstractWebFailoverTestCase(String deploymentName, TransactionMode transactionMode) { this(deploymentName, CacheMode.DIST_SYNC, transactionMode); } protected AbstractWebFailoverTestCase(String deploymentName, CacheMode cacheMode, TransactionMode transactionMode) { super(THREE_NODES); this.deploymentName = deploymentName; this.cacheMode = cacheMode; this.nonTxWait = () -> { // If the cache is non-transactional, we need to wait for that replication to finish, otherwise the read can be stale if (!transactionMode.isTransactional()) { try { Thread.sleep(GRACE_TIME_TO_REPLICATE); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } }; } @Test public void testGracefulSimpleFailover( @ArquillianResource(SimpleServlet.class) @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1, @ArquillianResource(SimpleServlet.class) @OperateOnDeployment(DEPLOYMENT_2) URL baseURL2, @ArquillianResource(SimpleServlet.class) @OperateOnDeployment(DEPLOYMENT_3) URL baseURL3) throws Exception { this.testFailover(new RestartLifecycle(), baseURL1, baseURL2, baseURL3); } @Test public void testGracefulUndeployFailover( @ArquillianResource(SimpleServlet.class) @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1, @ArquillianResource(SimpleServlet.class) @OperateOnDeployment(DEPLOYMENT_2) URL baseURL2, @ArquillianResource(SimpleServlet.class) @OperateOnDeployment(DEPLOYMENT_3) URL baseURL3) throws Exception { this.testFailover(new RedeployLifecycle(), baseURL1, baseURL2, baseURL3); } private void testFailover(Lifecycle lifecycle, URL baseURL1, URL baseURL2, URL baseURL3) throws Exception { URI uri1 = SimpleServlet.createURI(baseURL1); URI uri2 = SimpleServlet.createURI(baseURL2); URI uri3 = SimpleServlet.createURI(baseURL3); this.establishTopology(baseURL1, THREE_NODES); int value = 1; // In case updated route information is received, it must be different from the last route String lastOwner; try (CloseableHttpClient client = TestHttpClientUtils.promiscuousCookieHttpClient()) { try (CloseableHttpResponse response = client.execute(new HttpGet(uri1))) { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(value++, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); Map.Entry<String, String> entry = parseSessionRoute(response); Assert.assertNotNull(entry); Assert.assertEquals(NODE_1, entry.getValue()); lastOwner = entry.getValue(); Assert.assertEquals(entry.getKey(), response.getFirstHeader(SimpleServlet.SESSION_ID_HEADER).getValue()); } this.nonTxWait.run(); try (CloseableHttpResponse response = client.execute(new HttpGet(uri2))) { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(value++, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); Map.Entry<String, String> entry = parseSessionRoute(response); if (!this.cacheMode.needsStateTransfer()) { Assert.assertNotNull(entry); Assert.assertEquals(NODE_2, entry.getValue()); lastOwner = entry.getValue(); } else { Assert.assertNull(entry); } } this.nonTxWait.run(); try (CloseableHttpResponse response = client.execute(new HttpGet(uri3))) { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(value++, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); Map.Entry<String, String> entry = parseSessionRoute(response); if (!this.cacheMode.needsStateTransfer()) { Assert.assertNotNull(entry); Assert.assertEquals(NODE_3, entry.getValue()); lastOwner = entry.getValue(); } else { Assert.assertNull(entry); } } this.nonTxWait.run(); lifecycle.stop(NODE_1); this.establishTopology(baseURL2, NODE_2, NODE_3); // node2 try (CloseableHttpResponse response = client.execute(new HttpGet(uri2))) { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(value++, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); Map.Entry<String, String> entry = parseSessionRoute(response); // After topology change, the session will have to be re-routed to either of the 2 remaining nodes Assert.assertNotNull(entry); Assert.assertNotEquals(lastOwner, entry.getValue()); lastOwner = entry.getValue(); Assert.assertEquals(entry.getKey(), response.getFirstHeader(SimpleServlet.SESSION_ID_HEADER).getValue()); } try (CloseableHttpResponse response = client.execute(new HttpGet(uri2))) { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(value++, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); Map.Entry<String, String> entry = parseSessionRoute(response); if (entry != null) { Assert.assertNotEquals(lastOwner, entry.getValue()); lastOwner = entry.getValue(); Assert.assertEquals(entry.getKey(), response.getFirstHeader(SimpleServlet.SESSION_ID_HEADER).getValue()); } } this.nonTxWait.run(); // node3 try (CloseableHttpResponse response = client.execute(new HttpGet(uri3))) { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(value++, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); Map.Entry<String, String> entry = parseSessionRoute(response); if (!this.cacheMode.needsStateTransfer()) { Assert.assertNotNull(entry); Assert.assertEquals(NODE_3, entry.getValue()); } else { Assert.assertNull(entry); } } try (CloseableHttpResponse response = client.execute(new HttpGet(uri3))) { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(value++, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); Map.Entry<String, String> entry = parseSessionRoute(response); Assert.assertNull(entry); } lifecycle.start(NODE_1); this.establishTopology(baseURL2, THREE_NODES); try (CloseableHttpResponse response = client.execute(new HttpGet(uri2))) { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(value++, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); Map.Entry<String, String> entry = parseSessionRoute(response); if (!this.cacheMode.needsStateTransfer()) { Assert.assertNotNull(entry); Assert.assertEquals(NODE_2, entry.getValue()); } else if (entry != null) { Assert.assertNotEquals(lastOwner, entry.getValue()); lastOwner = entry.getValue(); Assert.assertEquals(entry.getKey(), response.getFirstHeader(SimpleServlet.SESSION_ID_HEADER).getValue()); } } try (CloseableHttpResponse response = client.execute(new HttpGet(uri2))) { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(value++, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); Map.Entry<String, String> entry = parseSessionRoute(response); Assert.assertNull(entry); } this.nonTxWait.run(); try (CloseableHttpResponse response = client.execute(new HttpGet(uri3))) { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(value++, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); Map.Entry<String, String> entry = parseSessionRoute(response); if (!this.cacheMode.needsStateTransfer()) { Assert.assertNotNull(entry); Assert.assertEquals(NODE_3, entry.getValue()); } else { Assert.assertNull(entry); } } this.nonTxWait.run(); lifecycle.stop(NODE_2); this.establishTopology(baseURL1, NODE_1, NODE_3); try (CloseableHttpResponse response = client.execute(new HttpGet(uri1))) { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(value++, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); Map.Entry<String, String> entry = parseSessionRoute(response); if (entry != null) { Assert.assertNotEquals(lastOwner, entry.getValue()); lastOwner = entry.getValue(); Assert.assertEquals(entry.getKey(), response.getFirstHeader(SimpleServlet.SESSION_ID_HEADER).getValue()); } } try (CloseableHttpResponse response = client.execute(new HttpGet(uri1))) { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(value++, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); Map.Entry<String, String> entry = parseSessionRoute(response); if (entry != null) { Assert.assertNotEquals(lastOwner, entry.getValue()); lastOwner = entry.getValue(); Assert.assertEquals(entry.getKey(), response.getFirstHeader(SimpleServlet.SESSION_ID_HEADER).getValue()); } } this.nonTxWait.run(); try (CloseableHttpResponse response = client.execute(new HttpGet(uri3))) { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(value++, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); Map.Entry<String, String> entry = parseSessionRoute(response); if (!this.cacheMode.needsStateTransfer()) { Assert.assertNotNull(entry); Assert.assertEquals(NODE_3, entry.getValue()); } else { if (entry != null) { Assert.assertNotEquals(lastOwner, entry.getValue()); lastOwner = entry.getValue(); Assert.assertEquals(entry.getKey(), response.getFirstHeader(SimpleServlet.SESSION_ID_HEADER).getValue()); } } } try (CloseableHttpResponse response = client.execute(new HttpGet(uri3))) { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(value++, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); Map.Entry<String, String> entry = parseSessionRoute(response); if (entry != null) { Assert.assertNotEquals(lastOwner, entry.getValue()); lastOwner = entry.getValue(); Assert.assertEquals(entry.getKey(), response.getFirstHeader(SimpleServlet.SESSION_ID_HEADER).getValue()); } } lifecycle.start(NODE_2); this.establishTopology(baseURL1, THREE_NODES); this.nonTxWait.run(); try (CloseableHttpResponse response = client.execute(new HttpGet(uri1))) { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(value++, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); Map.Entry<String, String> entry = parseSessionRoute(response); if (!this.cacheMode.needsStateTransfer()) { Assert.assertNotNull(entry); Assert.assertEquals(NODE_1, entry.getValue()); } else if (entry != null) { Assert.assertNotEquals(lastOwner, entry.getValue()); Assert.assertEquals(entry.getKey(), response.getFirstHeader(SimpleServlet.SESSION_ID_HEADER).getValue()); } } try (CloseableHttpResponse response = client.execute(new HttpGet(uri1))) { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(value, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); Map.Entry<String, String> entry = parseSessionRoute(response); if (entry != null) { Assert.assertNotEquals(lastOwner, entry.getValue()); lastOwner = entry.getValue(); Assert.assertEquals(entry.getKey(), response.getFirstHeader(SimpleServlet.SESSION_ID_HEADER).getValue()); } } try (CloseableHttpResponse response = client.execute(new HttpDelete(uri1))) { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); } } } @Test public void testNonPrimaryOwner( @ArquillianResource(SimpleServlet.class) @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1, @ArquillianResource(SimpleServlet.class) @OperateOnDeployment(DEPLOYMENT_2) URL baseURL2, @ArquillianResource(SimpleServlet.class) @OperateOnDeployment(DEPLOYMENT_3) URL baseURL3) throws Exception { URI uri1 = SimpleServlet.createURI(baseURL1); URI uri2 = SimpleServlet.createURI(baseURL2); URI uri3 = SimpleServlet.createURI(baseURL3); try (CloseableHttpClient client = TestHttpClientUtils.promiscuousCookieHttpClient()) { // Create session, establishing primary owner try (CloseableHttpResponse response = client.execute(new HttpHead(uri1))) { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertFalse(response.containsHeader(SimpleServlet.VALUE_HEADER)); } // Test session attribute creation/mutation on non-owners for (URI uri : Arrays.asList(uri2, uri3)) { // Validate correct mutation using different session access patterns for (HttpUriRequest request : Arrays.asList(new HttpGet(uri), new HttpPost(uri))) { this.nonTxWait.run(); int value = 1; try (CloseableHttpResponse response = client.execute(request)) { Assert.assertEquals(request.getMethod(), HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(request.getMethod(), value++, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); } try (CloseableHttpResponse response = client.execute(request)) { Assert.assertEquals(request.getMethod(), HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(request.getMethod(), value++, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); } // Remove attribute so we can try again on another non-owner try (CloseableHttpResponse response = client.execute(new HttpPut(uri))) { Assert.assertEquals(request.getMethod(), HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); } } } this.nonTxWait.run(); // Destroy session try (CloseableHttpResponse response = client.execute(new HttpDelete(uri1))) { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertFalse(response.containsHeader(SimpleServlet.VALUE_HEADER)); } } } private void establishTopology(URL baseURL, String... nodes) throws URISyntaxException, IOException, InterruptedException { if (this.cacheMode.isClustered()) { ClusterHttpClientUtil.establishTopology(baseURL, "web", this.deploymentName, nodes); // TODO we should be able to speed this up by observing changes in the routing registry // prevents failing assertions when topology information is expected, e.g.: //java.lang.AssertionError: expected null, but was:<bpAmUlICzeXMtFiOJvTiOCASbXNivRdHTIlQC00c=node-2> Thread.sleep(GRACE_TIME_TOPOLOGY_CHANGE); } } }
21,062
51.395522
156
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/AbstractSessionActivationTestCase.java
/* * 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.web; import java.io.IOException; import java.net.URI; import java.net.URL; import jakarta.servlet.http.HttpServletResponse; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpDelete; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPut; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.client.utils.HttpClientUtils; import org.apache.http.impl.client.CloseableHttpClient; import org.jboss.arquillian.container.test.api.OperateOnDeployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.test.clustering.cluster.AbstractClusteringTestCase; import org.jboss.as.test.clustering.cluster.web.event.SessionActivationServlet; import org.jboss.as.test.http.util.TestHttpClientUtils; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * @author Paul Ferraro */ @RunWith(Arquillian.class) public abstract class AbstractSessionActivationTestCase extends AbstractClusteringTestCase { private final boolean transactional; protected AbstractSessionActivationTestCase(boolean transactional) { super(THREE_NODES); this.transactional = transactional; } @Test public void test( @ArquillianResource(SessionActivationServlet.class) @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1, @ArquillianResource(SessionActivationServlet.class) @OperateOnDeployment(DEPLOYMENT_2) URL baseURL2, @ArquillianResource(SessionActivationServlet.class) @OperateOnDeployment(DEPLOYMENT_3) URL baseURL3) throws Exception { URI uri1 = SessionActivationServlet.createURI(baseURL1); URI uri2 = SessionActivationServlet.createURI(baseURL2); URI uri3 = SessionActivationServlet.createURI(baseURL3); try (CloseableHttpClient client = TestHttpClientUtils.promiscuousCookieHttpClient()) { // Verify all operations on primary owner this.execute(client, new HttpPut(uri1), false); this.execute(client, new HttpGet(uri1), false); this.execute(client, new HttpDelete(uri1), false); // Verify all operations on both backup owner and non-owner this.execute(client, new HttpPut(uri2), true); this.execute(client, new HttpGet(uri2), false); this.execute(client, new HttpDelete(uri2), true); this.execute(client, new HttpPut(uri3), true); this.execute(client, new HttpGet(uri3), false); this.execute(client, new HttpDelete(uri3), true); } } private void execute(HttpClient client, HttpUriRequest request, boolean failover) throws IOException { if (failover && !this.transactional) { try { Thread.sleep(GRACE_TIME_TO_REPLICATE); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } HttpResponse response = client.execute(request); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); } finally { HttpClientUtils.closeQuietly(response); } } }
4,383
37.79646
131
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/ConcurrentSessionServerSetup.java
/* * JBoss, Home of Professional Open Source. * Copyright 2017, 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.web; import org.jboss.as.test.clustering.cluster.AbstractClusteringTestCase; import org.jboss.as.test.shared.CLIServerSetupTask; /** * @author Paul Ferraro */ public class ConcurrentSessionServerSetup extends CLIServerSetupTask { public ConcurrentSessionServerSetup() { this.builder.node(AbstractClusteringTestCase.THREE_NODES) .setup("/subsystem=infinispan/cache-container=web/distributed-cache=concurrent:add()") .setup("/subsystem=infinispan/cache-container=web/distributed-cache=concurrent/store=file:add(passivation=true, purge=true)") .teardown("/subsystem=infinispan/cache-container=web/distributed-cache=concurrent:remove()") ; } }
1,785
43.65
141
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/DistributableTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.web; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; import jakarta.servlet.http.HttpServletResponse; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.utils.HttpClientUtils; 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; import org.jboss.as.test.clustering.single.web.Mutable; import org.jboss.as.test.clustering.single.web.SimpleServlet; import org.jboss.as.test.http.util.TestHttpClientUtils; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * Validate that <distributable/> works for a two-node cluster. * * @author Paul Ferraro * @author Radoslav Husar */ @RunWith(Arquillian.class) public class DistributableTestCase extends AbstractClusteringTestCase { private static final String MODULE_NAME = DistributableTestCase.class.getSimpleName(); private static final int REQUEST_DURATION = 10000; @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment1() { return getDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment2() { return getDeployment(); } private static Archive<?> getDeployment() { WebArchive war = ShrinkWrap.create(WebArchive.class, MODULE_NAME + ".war"); war.addClasses(SimpleServlet.class, Mutable.class); war.setWebXML(DistributableTestCase.class.getPackage(), "web.xml"); return war; } @Test @OperateOnDeployment(DEPLOYMENT_1) public void testSerialized(@ArquillianResource(SimpleServlet.class) URL baseURL) throws IOException, URISyntaxException { // returns the URL of the deployment (http://127.0.0.1:8180/distributable) URI uri = SimpleServlet.createURI(baseURL); try (CloseableHttpClient client = TestHttpClientUtils.promiscuousCookieHttpClient()) { HttpResponse response = client.execute(new HttpGet(uri)); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(1, Integer.parseInt(response.getFirstHeader("value").getValue())); Assert.assertFalse(Boolean.valueOf(response.getFirstHeader("serialized").getValue())); } finally { HttpClientUtils.closeQuietly(response); } response = client.execute(new HttpGet(uri)); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(2, Integer.parseInt(response.getFirstHeader("value").getValue())); // This won't be true unless we have somewhere to which to replicate Assert.assertTrue(Boolean.valueOf(response.getFirstHeader("serialized").getValue())); } finally { HttpClientUtils.closeQuietly(response); } } } @Test @OperateOnDeployment(DEPLOYMENT_2) // For change, operate on the 2nd deployment first public void testSessionReplication( @ArquillianResource(SimpleServlet.class) @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1, @ArquillianResource(SimpleServlet.class) @OperateOnDeployment(DEPLOYMENT_2) URL baseURL2) throws IOException, URISyntaxException, InterruptedException { URI url1 = SimpleServlet.createURI(baseURL1); URI url2 = SimpleServlet.createURI(baseURL2); try (CloseableHttpClient client = TestHttpClientUtils.promiscuousCookieHttpClient()) { HttpResponse response = client.execute(new HttpGet(url1)); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(1, Integer.parseInt(response.getFirstHeader("value").getValue())); } finally { HttpClientUtils.closeQuietly(response); } // Lets do this twice to have more debug info if failover is slow. response = client.execute(new HttpGet(url1)); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(2, Integer.parseInt(response.getFirstHeader("value").getValue())); } finally { HttpClientUtils.closeQuietly(response); } // Lets wait for the session to replicate Thread.sleep(GRACE_TIME_TO_REPLICATE); // Now check on the 2nd server response = client.execute(new HttpGet(url2)); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(3, Integer.parseInt(response.getFirstHeader("value").getValue())); } finally { HttpClientUtils.closeQuietly(response); } // Lets do one more check. response = client.execute(new HttpGet(url2)); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(4, Integer.parseInt(response.getFirstHeader("value").getValue())); } finally { HttpClientUtils.closeQuietly(response); } } } /** * Test that a session is gracefully served when a clustered application is undeployed. */ @Test public void testGracefulServeOnUndeploy( @ArquillianResource(SimpleServlet.class) @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1) throws Exception { this.testGracefulServe(baseURL1, new RedeployLifecycle()); } /** * Test that a session is gracefully served when clustered AS instanced is shutdown. */ @Test public void testGracefulServeOnShutdown( @ArquillianResource(SimpleServlet.class) @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1) throws Exception { this.testGracefulServe(baseURL1, new RestartLifecycle()); } private void testGracefulServe(URL baseURL, Lifecycle lifecycle) throws URISyntaxException, IOException, InterruptedException { try (CloseableHttpClient client = TestHttpClientUtils.promiscuousCookieHttpClient()) { URI uri = SimpleServlet.createURI(baseURL); // Make sure a normal request will succeed HttpResponse response = client.execute(new HttpGet(uri)); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); } finally { HttpClientUtils.closeQuietly(response); } // Send a long request - in parallel URI longRunningURI = SimpleServlet.createURI(baseURL, REQUEST_DURATION); ExecutorService executor = Executors.newSingleThreadExecutor(); Future<HttpResponse> future = executor.submit(new RequestTask(client, longRunningURI)); // Make sure long request has started Thread.sleep(1000); lifecycle.stop(NODE_1); // Get result of long request // This request should succeed since it initiated before server shutdown try { response = future.get(); try { Assert.assertEquals("Request should succeed since it initiated before undeply or shutdown.", HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); } finally { HttpClientUtils.closeQuietly(response); } } catch (ExecutionException e) { e.printStackTrace(System.err); Assert.fail(e.getCause().getMessage()); } } } /** * Request task to request a long running URL and then undeploy / shutdown the server. */ private class RequestTask implements Callable<HttpResponse> { private final HttpClient client; private final URI uri; RequestTask(HttpClient client, URI uri) { this.client = client; this.uri = uri; } @Override public HttpResponse call() throws Exception { return this.client.execute(new HttpGet(this.uri)); } } }
10,416
41.004032
131
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/ConcurrentFineWebFailoverTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2012, 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.web; import org.infinispan.transaction.TransactionMode; 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.ClusterTestUtil; import org.jboss.as.test.clustering.single.web.Mutable; import org.jboss.as.test.clustering.single.web.SimpleServlet; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; /** * @author Radoslav Husar */ @ServerSetup(ConcurrentSessionServerSetup.class) public class ConcurrentFineWebFailoverTestCase extends AbstractWebFailoverTestCase { private static final String MODULE_NAME = ConcurrentFineWebFailoverTestCase.class.getSimpleName(); private static final String DEPLOYMENT_NAME = MODULE_NAME + ".war"; public ConcurrentFineWebFailoverTestCase() { super(DEPLOYMENT_NAME, TransactionMode.NON_TRANSACTIONAL); } @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment1() { return createDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment2() { return createDeployment(); } @Deployment(name = DEPLOYMENT_3, managed = false, testable = false) @TargetsContainer(NODE_3) public static Archive<?> deployment3() { return createDeployment(); } private static Archive<?> createDeployment() { WebArchive war = ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME); war.addClasses(SimpleServlet.class, Mutable.class); ClusterTestUtil.addTopologyListenerDependencies(war); // Take web.xml from the managed test. war.setWebXML(DistributableTestCase.class.getPackage(), "web.xml"); war.addAsWebInfResource(DistributableTestCase.class.getPackage(), "jboss-all_concurrent_fine.xml", "jboss-all.xml"); return war; } }
3,166
40.671053
124
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/expiration/SessionOperationServlet.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, 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.web.expiration; import java.io.Serializable; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.util.LinkedList; import java.util.List; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpSession; import jakarta.servlet.http.HttpSessionBindingEvent; import jakarta.servlet.http.HttpSessionBindingListener; @WebServlet(urlPatterns = SessionOperationServlet.SERVLET_PATH) public class SessionOperationServlet extends HttpServlet { private static final long serialVersionUID = -1769104491085299700L; private static final String SERVLET_NAME = "listener"; static final String SERVLET_PATH = "/" + SERVLET_NAME; private static final String OPERATION = "operation"; private static final String INVALIDATE = "invalidate"; private static final String GET = "get"; private static final String SET = "set"; private static final String REMOVE = "remove"; private static final String TIMEOUT = "timeout"; private static final String NAME = "name"; private static final String VALUE = "value"; public static final String RESULT = "result"; public static final String SESSION_ID = "jsessionid"; public static final String TARGET_SESSION_ID = "target-session-id"; public static final String CREATED_SESSIONS = "created"; public static final String DESTROYED_SESSIONS = "destroyed"; public static final String ADDED_ATTRIBUTES = "added"; public static final String REPLACED_ATTRIBUTES = "replaced"; public static final String REMOVED_ATTRIBUTES = "removed"; public static final String BOUND_ATTRIBUTES = "bound"; public static final String UNBOUND_ATTRIBUTES = "unbound"; public static URI createGetURI(URL baseURL, String name) throws URISyntaxException { return createGetURI(baseURL, name, null); } /** * @param targetSessionId session for which to query added/replaced/removed attributes though response headers */ public static URI createGetURI(URL baseURL, String name, String targetSessionId) throws URISyntaxException { StringBuilder builder = appendParameter(buildURI(GET), NAME, name); if (targetSessionId != null) { appendParameter(builder, TARGET_SESSION_ID, targetSessionId); } return baseURL.toURI().resolve(builder.toString()); } public static URI createGetAndSetURI(URL baseURL, String name, String value) throws URISyntaxException { StringBuilder builder = appendParameter(buildURI(GET), NAME, name); if (value != null) { appendParameter(builder, VALUE, value); } return baseURL.toURI().resolve(builder.toString()); } public static URI createSetURI(URL baseURL, String name, String... values) throws URISyntaxException { StringBuilder builder = appendParameter(buildURI(SET), NAME, name); for (String value: values) { appendParameter(builder, VALUE, value); } return baseURL.toURI().resolve(builder.toString()); } public static URI createRemoveURI(URL baseURL, String name) throws URISyntaxException { return baseURL.toURI().resolve(appendParameter(buildURI(REMOVE), NAME, name).toString()); } public static URI createInvalidateURI(URL baseURL) throws URISyntaxException { return baseURL.toURI().resolve(buildURI(INVALIDATE).toString()); } public static URI createTimeoutURI(URL baseURL, int timeout) throws URISyntaxException { return baseURL.toURI().resolve(appendParameter(buildURI(TIMEOUT), TIMEOUT, Integer.toString(timeout)).toString()); } private static StringBuilder buildURI(String operation) { return new StringBuilder(SERVLET_NAME).append('?').append(OPERATION).append('=').append(operation); } private static StringBuilder appendParameter(StringBuilder builder, String parameter, String value) { return builder.append('&').append(parameter).append('=').append(value); } @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException { String operation = getRequiredParameter(req, OPERATION); HttpSession session = req.getSession(true); resp.addHeader(SESSION_ID, session.getId()); req.getServletContext().log(String.format("%s?%s;jsessionid=%s", req.getRequestURL(), req.getQueryString(), session.getId())); switch (operation) { case SET: { String name = getRequiredParameter(req, NAME); String[] values = req.getParameterValues(VALUE); if (values != null) { SessionAttributeValue value = new SessionAttributeValue(values[0]); session.setAttribute(name, value); for (int i = 1; i < values.length; ++i) { value.setValue(values[i]); } } else { session.setAttribute(name, null); } break; } case REMOVE: { String name = getRequiredParameter(req, NAME); session.removeAttribute(name); break; } case INVALIDATE: session.invalidate(); break; case GET: { String name = getRequiredParameter(req, NAME); SessionAttributeValue value = (SessionAttributeValue) session.getAttribute(name); if (value != null) { resp.setHeader(RESULT, value.getValue()); String newValue = req.getParameter(VALUE); if (newValue != null) { value.setValue(newValue); } } break; } case TIMEOUT: String timeout = getRequiredParameter(req, TIMEOUT); session.setMaxInactiveInterval(Integer.parseInt(timeout)); break; default: throw new ServletException("Unrecognized operation: " + operation); } String targetSessionId = req.getParameter(TARGET_SESSION_ID); if (targetSessionId == null) { targetSessionId = req.getRequestedSessionId(); } if (targetSessionId == null) { targetSessionId = session.getId(); } setHeader(resp, CREATED_SESSIONS, RecordingWebListener.createdSessions); setHeader(resp, DESTROYED_SESSIONS, RecordingWebListener.destroyedSessions); setHeader(resp, ADDED_ATTRIBUTES, RecordingWebListener.addedAttributes.get(targetSessionId)); setHeader(resp, REPLACED_ATTRIBUTES, RecordingWebListener.replacedAttributes.get(targetSessionId)); setHeader(resp, REMOVED_ATTRIBUTES, RecordingWebListener.removedAttributes.get(targetSessionId)); setHeader(resp, BOUND_ATTRIBUTES, SessionAttributeValue.boundAttributes); setHeader(resp, UNBOUND_ATTRIBUTES, SessionAttributeValue.unboundAttributes); } private static void setHeader(HttpServletResponse response, String header, BlockingQueue<String> queue) { if (queue != null) { List<String> values = new LinkedList<>(); if (queue.drainTo(values) > 0) { for (String value: values) { response.addHeader(header, value); } } } } private static String getRequiredParameter(HttpServletRequest req, String name) throws ServletException { String value = req.getParameter(name); if (value == null) { throw new ServletException("Missing parameter: " + name); } return value; } public static class SessionAttributeValue implements Serializable, HttpSessionBindingListener { private static final long serialVersionUID = -8824497321979784527L; static final BlockingQueue<String> boundAttributes = new LinkedBlockingQueue<>(); static final BlockingQueue<String> unboundAttributes = new LinkedBlockingQueue<>(); private volatile String value; public SessionAttributeValue(String value) { this.value = value; } public String getValue() { return this.value; } public void setValue(String value) { this.value = value; } @Override public void valueBound(HttpSessionBindingEvent event) { boundAttributes.add(((SessionAttributeValue) event.getValue()).getValue()); } @Override public void valueUnbound(HttpSessionBindingEvent event) { unboundAttributes.add(((SessionAttributeValue) event.getValue()).getValue()); } } }
10,140
42.337607
134
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/expiration/FineSessionExpirationTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, 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.web.expiration; import org.infinispan.transaction.TransactionMode; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.TargetsContainer; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.spec.WebArchive; public class FineSessionExpirationTestCase extends SessionExpirationTestCase { private static final String MODULE_NAME = FineSessionExpirationTestCase.class.getSimpleName(); @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment0() { return getDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment1() { return getDeployment(); } static WebArchive getDeployment() { return getBaseDeployment(MODULE_NAME).addAsWebInfResource(SessionExpirationTestCase.class.getPackage(), "jboss-web-fine.xml", "jboss-web.xml"); } public FineSessionExpirationTestCase() { super(TransactionMode.TRANSACTIONAL); } }
2,201
39.777778
151
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/expiration/RecordingWebListener.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, 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.web.expiration; import java.util.concurrent.BlockingQueue; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.LinkedBlockingQueue; import jakarta.servlet.annotation.WebListener; import jakarta.servlet.http.HttpSessionAttributeListener; import jakarta.servlet.http.HttpSessionBindingEvent; import jakarta.servlet.http.HttpSessionEvent; import jakarta.servlet.http.HttpSessionListener; @WebListener public class RecordingWebListener implements HttpSessionListener, HttpSessionAttributeListener { public static final BlockingQueue<String> createdSessions = new LinkedBlockingQueue<>(); public static final BlockingQueue<String> destroyedSessions = new LinkedBlockingQueue<>(); public static final ConcurrentMap<String, BlockingQueue<String>> addedAttributes = new ConcurrentHashMap<>(); public static final ConcurrentMap<String, BlockingQueue<String>> removedAttributes = new ConcurrentHashMap<>(); public static final ConcurrentMap<String, BlockingQueue<String>> replacedAttributes = new ConcurrentHashMap<>(); private static void record(HttpSessionBindingEvent event, ConcurrentMap<String, BlockingQueue<String>> attributes) { BlockingQueue<String> set = new LinkedBlockingQueue<>(); BlockingQueue<String> existing = attributes.putIfAbsent(event.getSession().getId(), set); ((existing != null) ? existing : set).add(event.getName()); } @Override public void attributeAdded(HttpSessionBindingEvent event) { record(event, addedAttributes); } @Override public void attributeRemoved(HttpSessionBindingEvent event) { record(event, removedAttributes); } @Override public void attributeReplaced(HttpSessionBindingEvent event) { record(event, replacedAttributes); } private static void record(HttpSessionEvent event, BlockingQueue<String> sessions) { sessions.add(event.getSession().getId()); } @Override public void sessionCreated(HttpSessionEvent event) { record(event, createdSessions); } @Override public void sessionDestroyed(HttpSessionEvent event) { record(event, destroyedSessions); } }
3,300
40.78481
120
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/expiration/CoarseSessionExpirationTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, 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.web.expiration; import org.infinispan.transaction.TransactionMode; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.TargetsContainer; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.spec.WebArchive; public class CoarseSessionExpirationTestCase extends SessionExpirationTestCase { private static final String MODULE_NAME = CoarseSessionExpirationTestCase.class.getSimpleName(); @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment0() { return getDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment1() { return getDeployment(); } static WebArchive getDeployment() { return getBaseDeployment(MODULE_NAME).addAsWebInfResource(SessionExpirationTestCase.class.getPackage(), "jboss-web-coarse.xml", "jboss-web.xml"); } public CoarseSessionExpirationTestCase() { super(TransactionMode.TRANSACTIONAL); } }
2,209
39.925926
153
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/expiration/SessionExpirationTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, 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.web.expiration; import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; import java.util.Arrays; import java.util.concurrent.TimeUnit; import jakarta.servlet.http.HttpServletResponse; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.utils.HttpClientUtils; import org.apache.http.impl.client.CloseableHttpClient; import org.infinispan.transaction.TransactionMode; import org.jboss.arquillian.container.test.api.OperateOnDeployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.test.clustering.cluster.AbstractClusteringTestCase; import org.jboss.as.test.clustering.cluster.web.DistributableTestCase; import org.jboss.as.test.clustering.cluster.web.EnableUndertowStatisticsSetupTask; import org.jboss.as.test.http.util.TestHttpClientUtils; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * Validates get/set/remove/invalidate session operations, session expiration, and their corresponding events * * @author Paul Ferraro */ @ServerSetup(EnableUndertowStatisticsSetupTask.class) @RunWith(Arquillian.class) public abstract class SessionExpirationTestCase extends AbstractClusteringTestCase { public static WebArchive getBaseDeployment(String moduleName) { WebArchive war = ShrinkWrap.create(WebArchive.class, moduleName + ".war"); war.addClasses(SessionOperationServlet.class, RecordingWebListener.class); // Take web.xml from the managed test. war.setWebXML(DistributableTestCase.class.getPackage(), "web.xml"); return war; } private final boolean transactional; protected SessionExpirationTestCase(TransactionMode mode) { this.transactional = mode.isTransactional(); } @Test public void test(@ArquillianResource(SessionOperationServlet.class) @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1, @ArquillianResource(SessionOperationServlet.class) @OperateOnDeployment(DEPLOYMENT_2) URL baseURL2) throws IOException, URISyntaxException, InterruptedException { HttpResponse response; String sessionId; try (CloseableHttpClient client = TestHttpClientUtils.promiscuousCookieHttpClient()) { // This should trigger session creation event, but not added attribute event response = client.execute(new HttpGet(SessionOperationServlet.createSetURI(baseURL1, "a"))); try { Assert.assertTrue(response.containsHeader(SessionOperationServlet.CREATED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.DESTROYED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.ADDED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REPLACED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REMOVED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.BOUND_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES)); Assert.assertEquals(response.getFirstHeader(SessionOperationServlet.SESSION_ID).getValue(), response.getFirstHeader(SessionOperationServlet.CREATED_SESSIONS).getValue()); } finally { HttpClientUtils.closeQuietly(response); } // This should trigger attribute added event and bound binding event response = client.execute(new HttpGet(SessionOperationServlet.createSetURI(baseURL1, "a", "1"))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertTrue(response.containsHeader(SessionOperationServlet.SESSION_ID)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.CREATED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.DESTROYED_SESSIONS)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.ADDED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REPLACED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REMOVED_ATTRIBUTES)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.BOUND_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES)); Assert.assertEquals("a", response.getFirstHeader(SessionOperationServlet.ADDED_ATTRIBUTES).getValue()); Assert.assertEquals("1", response.getFirstHeader(SessionOperationServlet.BOUND_ATTRIBUTES).getValue()); } finally { HttpClientUtils.closeQuietly(response); } if (!this.transactional) { Thread.sleep(AbstractClusteringTestCase.GRACE_TIME_TO_REPLICATE); } // No events should have been triggered on remote node response = client.execute(new HttpGet(SessionOperationServlet.createGetURI(baseURL2, "a"))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertTrue(response.containsHeader(SessionOperationServlet.RESULT)); Assert.assertEquals("1", response.getFirstHeader(SessionOperationServlet.RESULT).getValue()); Assert.assertFalse(response.containsHeader(SessionOperationServlet.CREATED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.DESTROYED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.ADDED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REPLACED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REMOVED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.BOUND_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES)); } finally { HttpClientUtils.closeQuietly(response); } // Make sure remove attribute event is not fired since attribute does not exist response = client.execute(new HttpGet(SessionOperationServlet.createRemoveURI(baseURL2, "b"))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertFalse(response.containsHeader(SessionOperationServlet.RESULT)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.CREATED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.DESTROYED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.ADDED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REPLACED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REMOVED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.BOUND_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES)); } finally { HttpClientUtils.closeQuietly(response); } if (!this.transactional) { Thread.sleep(AbstractClusteringTestCase.GRACE_TIME_TO_REPLICATE); } // This should trigger attribute replaced event, as well as valueBound/valueUnbound binding events response = client.execute(new HttpGet(SessionOperationServlet.createSetURI(baseURL1, "a", "2"))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertFalse(response.containsHeader(SessionOperationServlet.CREATED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.DESTROYED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.ADDED_ATTRIBUTES)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.REPLACED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REMOVED_ATTRIBUTES)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.BOUND_ATTRIBUTES)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES)); Assert.assertEquals("a", response.getFirstHeader(SessionOperationServlet.REPLACED_ATTRIBUTES).getValue()); Assert.assertEquals("2", response.getFirstHeader(SessionOperationServlet.BOUND_ATTRIBUTES).getValue()); Assert.assertEquals("1", response.getFirstHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES).getValue()); } finally { HttpClientUtils.closeQuietly(response); } if (!this.transactional) { Thread.sleep(AbstractClusteringTestCase.GRACE_TIME_TO_REPLICATE); } // No events should have been triggered on remote node response = client.execute(new HttpGet(SessionOperationServlet.createGetURI(baseURL2, "a"))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertTrue(response.containsHeader(SessionOperationServlet.RESULT)); Assert.assertEquals("2", response.getFirstHeader(SessionOperationServlet.RESULT).getValue()); Assert.assertFalse(response.containsHeader(SessionOperationServlet.CREATED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.DESTROYED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.ADDED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REPLACED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REMOVED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.BOUND_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES)); } finally { HttpClientUtils.closeQuietly(response); } if (!this.transactional) { Thread.sleep(AbstractClusteringTestCase.GRACE_TIME_TO_REPLICATE); } // This should trigger attribute removed event and valueUnbound binding event response = client.execute(new HttpGet(SessionOperationServlet.createSetURI(baseURL1, "a"))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertFalse(response.containsHeader(SessionOperationServlet.CREATED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.DESTROYED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.ADDED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REPLACED_ATTRIBUTES)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.REMOVED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.BOUND_ATTRIBUTES)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES)); Assert.assertEquals("a", response.getFirstHeader(SessionOperationServlet.REMOVED_ATTRIBUTES).getValue()); Assert.assertEquals("2", response.getFirstHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES).getValue()); } finally { HttpClientUtils.closeQuietly(response); } if (!this.transactional) { Thread.sleep(AbstractClusteringTestCase.GRACE_TIME_TO_REPLICATE); } // No events should have been triggered on remote node response = client.execute(new HttpGet(SessionOperationServlet.createGetURI(baseURL2, "a"))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertFalse(response.containsHeader(SessionOperationServlet.RESULT)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.CREATED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.DESTROYED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.ADDED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REPLACED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REMOVED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.BOUND_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES)); } finally { HttpClientUtils.closeQuietly(response); } if (!this.transactional) { Thread.sleep(AbstractClusteringTestCase.GRACE_TIME_TO_REPLICATE); } // This should trigger attribute added event and valueBound binding event response = client.execute(new HttpGet(SessionOperationServlet.createSetURI(baseURL1, "a", "3", "4"))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertFalse(response.containsHeader(SessionOperationServlet.CREATED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.DESTROYED_SESSIONS)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.ADDED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REPLACED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REMOVED_ATTRIBUTES)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.BOUND_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES)); Assert.assertEquals("a", response.getFirstHeader(SessionOperationServlet.ADDED_ATTRIBUTES).getValue()); Assert.assertEquals("3", response.getFirstHeader(SessionOperationServlet.BOUND_ATTRIBUTES).getValue()); } finally { HttpClientUtils.closeQuietly(response); } if (!this.transactional) { Thread.sleep(AbstractClusteringTestCase.GRACE_TIME_TO_REPLICATE); } // No events should have been triggered on remote node response = client.execute(new HttpGet(SessionOperationServlet.createGetURI(baseURL2, "a"))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertTrue(response.containsHeader(SessionOperationServlet.RESULT)); Assert.assertEquals("4", response.getFirstHeader(SessionOperationServlet.RESULT).getValue()); Assert.assertFalse(response.containsHeader(SessionOperationServlet.CREATED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.DESTROYED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.ADDED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REPLACED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REMOVED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.BOUND_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES)); } finally { HttpClientUtils.closeQuietly(response); } if (!this.transactional) { Thread.sleep(AbstractClusteringTestCase.GRACE_TIME_TO_REPLICATE); } // This should trigger attribute removed event and valueUnbound binding event response = client.execute(new HttpGet(SessionOperationServlet.createRemoveURI(baseURL1, "a"))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertFalse(response.containsHeader(SessionOperationServlet.CREATED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.DESTROYED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.ADDED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REPLACED_ATTRIBUTES)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.REMOVED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.BOUND_ATTRIBUTES)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES)); Assert.assertEquals("a", response.getFirstHeader(SessionOperationServlet.REMOVED_ATTRIBUTES).getValue()); Assert.assertEquals("4", response.getFirstHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES).getValue()); } finally { HttpClientUtils.closeQuietly(response); } if (!this.transactional) { Thread.sleep(AbstractClusteringTestCase.GRACE_TIME_TO_REPLICATE); } // No events should have been triggered on remote node response = client.execute(new HttpGet(SessionOperationServlet.createGetURI(baseURL2, "a"))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertFalse(response.containsHeader(SessionOperationServlet.RESULT)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.CREATED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.DESTROYED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.ADDED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REPLACED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REMOVED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.BOUND_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES)); } finally { HttpClientUtils.closeQuietly(response); } // This should trigger attribute added event and valueBound binding event response = client.execute(new HttpGet(SessionOperationServlet.createSetURI(baseURL2, "a", "5"))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertTrue(response.containsHeader(SessionOperationServlet.SESSION_ID)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.CREATED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.DESTROYED_SESSIONS)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.ADDED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REPLACED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REMOVED_ATTRIBUTES)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.BOUND_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES)); Assert.assertEquals("a", response.getFirstHeader(SessionOperationServlet.ADDED_ATTRIBUTES).getValue()); Assert.assertEquals("5", response.getFirstHeader(SessionOperationServlet.BOUND_ATTRIBUTES).getValue()); } finally { HttpClientUtils.closeQuietly(response); } if (!this.transactional) { Thread.sleep(AbstractClusteringTestCase.GRACE_TIME_TO_REPLICATE); } // This should trigger session destroyed event, attribute removed event, and valueUnbound binding event response = client.execute(new HttpGet(SessionOperationServlet.createInvalidateURI(baseURL1))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertTrue(response.containsHeader(SessionOperationServlet.SESSION_ID)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.CREATED_SESSIONS)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.DESTROYED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.ADDED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REPLACED_ATTRIBUTES)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.REMOVED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.BOUND_ATTRIBUTES)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES)); Assert.assertEquals(response.getFirstHeader(SessionOperationServlet.SESSION_ID).getValue(), response.getFirstHeader(SessionOperationServlet.DESTROYED_SESSIONS).getValue()); Assert.assertEquals("a", response.getFirstHeader(SessionOperationServlet.REMOVED_ATTRIBUTES).getValue()); Assert.assertEquals("5", response.getFirstHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES).getValue()); } finally { HttpClientUtils.closeQuietly(response); } if (!this.transactional) { Thread.sleep(AbstractClusteringTestCase.GRACE_TIME_TO_REPLICATE); } // This should trigger attribute added event and valueBound binding event response = client.execute(new HttpGet(SessionOperationServlet.createSetURI(baseURL2, "a", "6"))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertTrue(response.containsHeader(SessionOperationServlet.SESSION_ID)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.CREATED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.DESTROYED_SESSIONS)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.ADDED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REPLACED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REMOVED_ATTRIBUTES)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.BOUND_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES)); Assert.assertEquals(response.getFirstHeader(SessionOperationServlet.SESSION_ID).getValue(), response.getFirstHeader(SessionOperationServlet.CREATED_SESSIONS).getValue()); Assert.assertEquals("a", response.getFirstHeader(SessionOperationServlet.ADDED_ATTRIBUTES).getValue()); Assert.assertEquals("6", response.getFirstHeader(SessionOperationServlet.BOUND_ATTRIBUTES).getValue()); } finally { HttpClientUtils.closeQuietly(response); } // This should not trigger any events response = client.execute(new HttpGet(SessionOperationServlet.createGetAndSetURI(baseURL2, "a", "7"))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertTrue(response.containsHeader(SessionOperationServlet.RESULT)); Assert.assertEquals("6", response.getFirstHeader(SessionOperationServlet.RESULT).getValue()); Assert.assertTrue(response.containsHeader(SessionOperationServlet.SESSION_ID)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.CREATED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.DESTROYED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.ADDED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REPLACED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REMOVED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.BOUND_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES)); } finally { HttpClientUtils.closeQuietly(response); } // This should not trigger any events response = client.execute(new HttpGet(SessionOperationServlet.createGetURI(baseURL2, "a"))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertTrue(response.containsHeader(SessionOperationServlet.RESULT)); Assert.assertEquals("7", response.getFirstHeader(SessionOperationServlet.RESULT).getValue()); Assert.assertTrue(response.containsHeader(SessionOperationServlet.SESSION_ID)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.CREATED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.DESTROYED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.ADDED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REPLACED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REMOVED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.BOUND_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES)); } finally { HttpClientUtils.closeQuietly(response); } if (!this.transactional) { Thread.sleep(AbstractClusteringTestCase.GRACE_TIME_TO_REPLICATE); } // Trigger session timeout in 1 second response = client.execute(new HttpGet(SessionOperationServlet.createTimeoutURI(baseURL1, 1))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertFalse(response.containsHeader(SessionOperationServlet.RESULT)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.SESSION_ID)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.CREATED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.DESTROYED_SESSIONS)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.ADDED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REPLACED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REMOVED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.BOUND_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES)); sessionId = response.getFirstHeader(SessionOperationServlet.SESSION_ID).getValue(); } finally { HttpClientUtils.closeQuietly(response); } } // Trigger timeout of sessionId - accounts for session timeout (1s) and infinispan reaper thread interval (1s) // so that test conditions are typically met within the first attempt Thread.sleep(TimeUnit.SECONDS.toMillis(2)); // Use a new session for awaiting expiration notification of the previous session scheduled to expire try (CloseableHttpClient client = TestHttpClientUtils.promiscuousCookieHttpClient()) { boolean destroyed = false; String newSessionId = null; int maxAttempts = 30; // Retry a couple of times since expiration in the remote case expiration depends on timing of the reaper thread for (int attempt = 1; attempt <= maxAttempts && !destroyed; attempt++) { // Timeout should trigger session destroyed event, attribute removed event, and valueUnbound binding event for (URL baseURL : Arrays.asList(baseURL1, baseURL2)) { if (!destroyed) { response = client.execute(new HttpGet(SessionOperationServlet.createGetURI(baseURL, "a", sessionId))); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertFalse(response.containsHeader(SessionOperationServlet.RESULT)); Assert.assertTrue(response.containsHeader(SessionOperationServlet.SESSION_ID)); Assert.assertEquals(newSessionId == null, response.containsHeader(SessionOperationServlet.CREATED_SESSIONS)); if (newSessionId == null) { newSessionId = response.getFirstHeader(SessionOperationServlet.SESSION_ID).getValue(); } else { Assert.assertEquals(newSessionId, response.getFirstHeader(SessionOperationServlet.SESSION_ID).getValue()); } destroyed = response.containsHeader(SessionOperationServlet.DESTROYED_SESSIONS); Assert.assertFalse(response.containsHeader(SessionOperationServlet.ADDED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.REPLACED_ATTRIBUTES)); Assert.assertEquals(destroyed, response.containsHeader(SessionOperationServlet.REMOVED_ATTRIBUTES)); Assert.assertFalse(response.containsHeader(SessionOperationServlet.BOUND_ATTRIBUTES)); Assert.assertEquals(destroyed, response.containsHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES)); if (destroyed) { Assert.assertEquals(sessionId, response.getFirstHeader(SessionOperationServlet.DESTROYED_SESSIONS).getValue()); Assert.assertEquals("a", response.getFirstHeader(SessionOperationServlet.REMOVED_ATTRIBUTES).getValue()); Assert.assertEquals("7", response.getFirstHeader(SessionOperationServlet.UNBOUND_ATTRIBUTES).getValue()); log.infof("Session destroyed within %d attempts.", attempt); } } finally { HttpClientUtils.closeQuietly(response); } } } Thread.sleep(TimeUnit.SECONDS.toMillis(1)); } Assert.assertTrue("Session has not been destroyed following expiration within " + maxAttempts + " attempts.", destroyed); } } }
34,011
67.711111
188
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/async/AsyncServletTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, 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.web.async; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import jakarta.servlet.http.HttpServletResponse; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.utils.HttpClientUtils; 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.arquillian.api.ServerSetup; import org.jboss.as.test.clustering.cluster.AbstractClusteringTestCase; import org.jboss.as.test.clustering.cluster.web.async.servlet.AsyncServlet; import org.jboss.as.test.clustering.single.web.SimpleServlet; import org.jboss.as.test.http.util.TestHttpClientUtils; import org.jboss.as.test.shared.CLIServerSetupTask; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * Test case for WFLY-3715 * @author Paul Ferraro */ @RunWith(Arquillian.class) @ServerSetup(AsyncServletTestCase.ServerSetupTask.class) public class AsyncServletTestCase extends AbstractClusteringTestCase { private static final String MODULE_NAME = AsyncServletTestCase.class.getSimpleName(); private static final String DEPLOYMENT_NAME = MODULE_NAME + ".war"; @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment0() { return getDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment1() { return getDeployment(); } private static Archive<?> getDeployment() { WebArchive war = ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME); war.addPackage(AsyncServlet.class.getPackage()); // Take web.xml from the managed test. war.setWebXML(SimpleServlet.class.getPackage(), "web.xml"); war.addAsWebInfResource(AsyncServletTestCase.class.getPackage(), "jboss-all.xml", "jboss-all.xml"); return war; } @Test public void test( @ArquillianResource(AsyncServlet.class) @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1, @ArquillianResource(AsyncServlet.class) @OperateOnDeployment(DEPLOYMENT_2) URL baseURL2) throws IOException, URISyntaxException { URI uri1 = AsyncServlet.createURI(baseURL1); URI uri2 = AsyncServlet.createURI(baseURL2); HttpClient client = TestHttpClientUtils.promiscuousCookieHttpClient(); try { assertValue(client, uri1, 1); assertValue(client, uri1, 2); assertValue(client, uri2, 3); assertValue(client, uri2, 4); assertValue(client, uri1, 5); assertValue(client, uri1, 6); } finally { HttpClientUtils.closeQuietly(client); } } private static void assertValue(HttpClient client, URI uri, int value) throws IOException { HttpResponse response = client.execute(new HttpGet(uri)); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(value, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); } finally { HttpClientUtils.closeQuietly(response); } } public static class ServerSetupTask extends CLIServerSetupTask { public ServerSetupTask() { this.builder.node(AbstractClusteringTestCase.THREE_NODES) .setup("/subsystem=distributable-web/infinispan-session-management=attribute:add(cache-container=web, granularity=ATTRIBUTE)") .teardown("/subsystem=distributable-web/infinispan-session-management=attribute:remove()") ; } } }
5,260
39.782946
146
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/async/servlet/AsyncServlet.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, 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.web.async.servlet; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import jakarta.servlet.AsyncContext; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpSession; /** * @author Paul Ferraro */ @WebServlet(urlPatterns = { AsyncServlet.SERVLET_PATH }, asyncSupported = true) public class AsyncServlet extends HttpServlet { private static final long serialVersionUID = -5308818413653125145L; private static final String SERVLET_NAME = "async"; static final String SERVLET_PATH = "/" + SERVLET_NAME; public static final String VALUE_HEADER = "value"; public static final String SESSION_ID_HEADER = "sessionId"; static final String ATTRIBUTE = "count"; public static URI createURI(URL baseURL) throws URISyntaxException { return baseURL.toURI().resolve(SERVLET_NAME); } @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(true); AtomicInteger value = (AtomicInteger) session.getAttribute(ATTRIBUTE); if (value == null) { value = new AtomicInteger(0); session.setAttribute(ATTRIBUTE, value); } AsyncContext context = request.startAsync(request, response); context.start(new AsyncTask(context)); } private static class AsyncTask implements Runnable { private final AsyncContext context; AsyncTask(AsyncContext context) { this.context = context; } @Override public void run() { try { TimeUnit.SECONDS.sleep(1); HttpServletRequest request = (HttpServletRequest) this.context.getRequest(); HttpServletResponse response = (HttpServletResponse) this.context.getResponse(); AtomicInteger value = (AtomicInteger) request.getSession().getAttribute(ATTRIBUTE); response.setIntHeader(VALUE_HEADER, value.incrementAndGet()); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } finally { this.context.complete(); } } } }
3,627
38.434783
123
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/externalizer/Counter.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, 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.web.externalizer; import java.util.concurrent.atomic.AtomicInteger; /** * Non-serializable counter, to be externalized via {@link CounterExternalizer}. * @author Paul Ferraro */ public class Counter { private final AtomicInteger count; public Counter(int count) { this.count = new AtomicInteger(count); } int getValue() { return this.count.get(); } public int increment() { return this.count.incrementAndGet(); } }
1,544
32.586957
80
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/externalizer/CounterServlet.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, 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.web.externalizer; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpSession; /** * @author Paul Ferraro */ @WebServlet(urlPatterns = { CounterServlet.SERVLET_PATH }) public class CounterServlet extends HttpServlet { private static final long serialVersionUID = -2155119413031863741L; private static final String SERVLET_NAME = "counter"; static final String SERVLET_PATH = "/" + SERVLET_NAME; public static final String COUNT_HEADER = "count"; private static final String ATTRIBUTE = "counter"; public static URI createURI(URL baseURL) throws URISyntaxException { return baseURL.toURI().resolve(SERVLET_NAME); } @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { HttpSession session = req.getSession(true); Counter counter = (Counter) session.getAttribute(ATTRIBUTE); int count = 0; if (counter == null) { counter = new Counter(count); session.setAttribute(ATTRIBUTE, counter); } resp.setIntHeader(COUNT_HEADER, counter.increment()); } }
2,459
36.846154
95
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/externalizer/CounterExternalizer.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, 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.web.externalizer; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; import org.wildfly.clustering.marshalling.Externalizer; /** * {@link Externalizer} for {@link Counter}. * @author Paul Ferraro */ public class CounterExternalizer implements Externalizer<Counter> { @Override public void writeObject(ObjectOutput output, Counter object) throws IOException { output.writeInt(object.getValue()); } @Override public Counter readObject(ObjectInput input) throws IOException, ClassNotFoundException { return new Counter(input.readInt()); } @Override public Class<Counter> getTargetClass() { return Counter.class; } }
1,785
33.346154
93
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/shared/SharedSessionTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, 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.web.shared; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.TargetsContainer; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.junit.runner.RunWith; /** * Validates that web applications within an ear can share sessions if configured appropriately. * * @author Paul Ferraro */ @RunWith(Arquillian.class) public class SharedSessionTestCase extends AbstractSharedSessionTestCase { private static final String MODULE = SharedSessionTestCase.class.getSimpleName(); @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment1() { return getDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment2() { return getDeployment(); } private static Archive<?> getDeployment() { return getDeployment(MODULE, "jboss-all_shared-session-config-2.0.xml"); } }
2,157
37.535714
96
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/shared/AbstractSharedSessionTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, 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.web.shared; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import jakarta.servlet.http.HttpServletResponse; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.jboss.arquillian.container.test.api.OperateOnDeployment; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.test.clustering.cluster.AbstractClusteringTestCase; import org.jboss.as.test.clustering.cluster.web.AbstractWebFailoverTestCase; import org.jboss.as.test.clustering.single.web.Mutable; import org.jboss.as.test.clustering.single.web.SimpleServlet; import org.jboss.as.test.http.util.TestHttpClientUtils; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Assert; import org.junit.Test; /** * Base class for distributed shared session tests. * @author Paul Ferraro */ public abstract class AbstractSharedSessionTestCase extends AbstractClusteringTestCase { private static final String MODULE_1 = "web1"; private static final String MODULE_2 = "web2"; static Archive<?> getDeployment(String module, String fileName) { JavaArchive jar = ShrinkWrap.create(JavaArchive.class, module + ".jar"); jar.addClass(Mutable.class); WebArchive war1 = ShrinkWrap.create(WebArchive.class, MODULE_1 + ".war"); war1.addClass(SimpleServlet.class); war1.setWebXML(AbstractWebFailoverTestCase.class.getPackage(), "web.xml"); WebArchive war2 = ShrinkWrap.create(WebArchive.class, MODULE_2 + ".war"); war2.addClass(SimpleServlet.class); war2.setWebXML(AbstractWebFailoverTestCase.class.getPackage(), "web.xml"); EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, module + ".ear"); ear.addAsLibraries(jar); ear.addAsModule(war1); ear.addAsModule(war2); ear.addAsManifestResource(AbstractSharedSessionTestCase.class.getPackage(), fileName, "jboss-all.xml"); return ear; } @Test public void test( @ArquillianResource @OperateOnDeployment(DEPLOYMENT_1) URL baseURLDep1, @ArquillianResource @OperateOnDeployment(DEPLOYMENT_2) URL baseURLDep2) throws URISyntaxException, IOException { URI baseURI1 = new URI(baseURLDep1.toExternalForm() + "/"); URI baseURI2 = new URI(baseURLDep2.toExternalForm() + "/"); URI uri11 = SimpleServlet.createURI(baseURI1.resolve(MODULE_1 + "/")); URI uri12 = SimpleServlet.createURI(baseURI1.resolve(MODULE_2 + "/")); URI uri21 = SimpleServlet.createURI(baseURI2.resolve(MODULE_1 + "/")); URI uri22 = SimpleServlet.createURI(baseURI2.resolve(MODULE_2 + "/")); try (CloseableHttpClient client = TestHttpClientUtils.promiscuousCookieHttpClient()) { int expected = 1; try (CloseableHttpResponse response = client.execute(new HttpGet(uri11))) { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(expected++, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); } try (CloseableHttpResponse response = client.execute(new HttpGet(uri12))) { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(expected++, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); } try (CloseableHttpResponse response = client.execute(new HttpGet(uri21))) { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(expected++, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); } try (CloseableHttpResponse response = client.execute(new HttpGet(uri22))) { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(expected++, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); } } } }
5,557
49.072072
130
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/shared/LegacySharedSessionTestCase.java
/* * * Copyright 2019 Red Hat, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package org.jboss.as.test.clustering.cluster.web.shared; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.TargetsContainer; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.junit.runner.RunWith; /** * Validates that web applications within an ear can share sessions if configured appropriately. * This test uses shared-session-config:1.0 where sessions are shared by default when WildFly is started with HA config. * @author Martin Simka */ @RunWith(Arquillian.class) public class LegacySharedSessionTestCase extends AbstractSharedSessionTestCase { private static final String MODULE = LegacySharedSessionTestCase.class.getSimpleName(); @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment1() { return getDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment2() { return getDeployment(); } private static Archive<?> getDeployment() { return getDeployment(MODULE, "jboss-all_shared-session-config-1.0.xml"); } }
1,864
35.568627
120
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/remote/FineHotRodSessionExpirationTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2020, 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.web.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.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.spec.WebArchive; /** * @author Paul Ferraro */ @ServerSetup({ InfinispanServerSetupTask.class, LocalRoutingServerSetup.class }) public class FineHotRodSessionExpirationTestCase extends AbstractHotRodSessionExpirationTestCase { private static final String MODULE_NAME = FineHotRodSessionExpirationTestCase.class.getSimpleName(); @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment0() { return getDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment1() { return getDeployment(); } static WebArchive getDeployment() { return getBaseDeployment(MODULE_NAME).addAsWebInfResource(FineHotRodSessionExpirationTestCase.class.getPackage(), "jboss-all_fine_transactional.xml", "jboss-all.xml"); } }
2,260
40.109091
175
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/remote/CoarseHotRodSessionActivationTestCase.java
/* * 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.web.remote; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.TargetsContainer; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.test.clustering.cluster.web.DistributableTestCase; import org.jboss.as.test.clustering.cluster.web.event.SessionActivationServlet; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.runner.RunWith; /** * @author Paul Ferraro */ @RunWith(Arquillian.class) @ServerSetup({ InfinispanServerSetupTask.class, LocalRoutingServerSetup.class }) public class CoarseHotRodSessionActivationTestCase extends AbstractHotRodSessionActivationTestCase { private static final String MODULE_NAME = CoarseHotRodSessionActivationTestCase.class.getSimpleName(); private static final String DEPLOYMENT_NAME = MODULE_NAME + ".war"; @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment1() { return getDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment2() { return getDeployment(); } @Deployment(name = DEPLOYMENT_3, managed = false, testable = false) @TargetsContainer(NODE_3) public static Archive<?> deployment3() { return getDeployment(); } private static Archive<?> getDeployment() { WebArchive war = ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME); war.addClasses(SessionActivationServlet.class); war.setWebXML(DistributableTestCase.class.getPackage(), "web.xml"); war.addAsWebInfResource(AbstractHotRodSessionActivationTestCase.class.getPackage(), "jboss-all_coarse.xml", "jboss-all.xml"); return war; } public CoarseHotRodSessionActivationTestCase() { super(false); } }
3,102
39.828947
133
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/remote/AbstractHotRodSessionActivationTestCase.java
/* * 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.web.remote; import org.jboss.as.test.clustering.InfinispanServerUtil; import org.jboss.as.test.clustering.cluster.web.AbstractSessionActivationTestCase; import org.junit.ClassRule; import org.junit.rules.TestRule; /** * @author Paul Ferraro * @author Radoslav Husar */ public abstract class AbstractHotRodSessionActivationTestCase extends AbstractSessionActivationTestCase { @ClassRule public static final TestRule INFINISPAN_SERVER_RULE = InfinispanServerUtil.infinispanServerTestRule(); protected AbstractHotRodSessionActivationTestCase(boolean transactional) { super(transactional); } }
1,691
37.454545
106
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/remote/CoarseHotRodSessionExpirationTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2020, 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.web.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.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.spec.WebArchive; /** * @author Paul Ferraro */ @ServerSetup({ InfinispanServerSetupTask.class, LocalRoutingServerSetup.class }) public class CoarseHotRodSessionExpirationTestCase extends AbstractHotRodSessionExpirationTestCase { private static final String MODULE_NAME = CoarseHotRodSessionExpirationTestCase.class.getSimpleName(); @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment0() { return getDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment1() { return getDeployment(); } static WebArchive getDeployment() { return getBaseDeployment(MODULE_NAME).addAsWebInfResource(CoarseHotRodSessionExpirationTestCase.class.getPackage(), "jboss-all_coarse_transactional.xml", "jboss-all.xml"); } }
2,268
40.254545
179
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/remote/AbstractHotRodSessionExpirationTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2020, 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.web.remote; import org.infinispan.transaction.TransactionMode; import org.jboss.as.test.clustering.InfinispanServerUtil; import org.jboss.as.test.clustering.cluster.web.expiration.SessionExpirationTestCase; import org.junit.ClassRule; import org.junit.rules.TestRule; /** * @author Paul Ferraro */ public abstract class AbstractHotRodSessionExpirationTestCase extends SessionExpirationTestCase { @ClassRule public static final TestRule INFINISPAN_SERVER_RULE = InfinispanServerUtil.infinispanServerTestRule(); public AbstractHotRodSessionExpirationTestCase() { super(TransactionMode.NON_TRANSACTIONAL); } }
1,706
38.697674
106
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/remote/FineHotRodPersistenceWebFailoverTestCase.java
/* * 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.web.remote; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.TargetsContainer; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.shrinkwrap.api.Archive; import org.junit.runner.RunWith; /** * @author Paul Ferraro */ @RunWith(Arquillian.class) @ServerSetup({ InfinispanServerSetupTask.class, AbstractHotRodPersistenceWebFailoverTestCase.ServerSetupTask.class }) public class FineHotRodPersistenceWebFailoverTestCase extends AbstractHotRodPersistenceWebFailoverTestCase { private static final String DEPLOYMENT_NAME = FineHotRodPersistenceWebFailoverTestCase.class.getSimpleName() + ".war"; @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment1() { return getDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment2() { return getDeployment(); } @Deployment(name = DEPLOYMENT_3, managed = false, testable = false) @TargetsContainer(NODE_3) public static Archive<?> deployment3() { return getDeployment(); } private static Archive<?> getDeployment() { return getDeployment(DEPLOYMENT_NAME, "distributable-web-fine.xml"); } public FineHotRodPersistenceWebFailoverTestCase() { super(DEPLOYMENT_NAME); } }
2,572
37.402985
122
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/remote/InfinispanServerSetupTask.java
/* * 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.web.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=web:add(default-remote-cluster=infinispan-server-cluster, tcp-keep-alive=true, marshaller=PROTOSTREAM, modules=[org.wildfly.clustering.web.hotrod], 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=web/remote-cluster=infinispan-server-cluster:add(socket-bindings=[infinispan-server])") .teardown("/subsystem=infinispan/remote-cache-container=web:remove") .teardown("/socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=infinispan-server:remove") ; } }
2,936
60.1875
404
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/remote/CoarseHotRodPersistenceWebFailoverTestCase.java
/* * 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.web.remote; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.TargetsContainer; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.shrinkwrap.api.Archive; import org.junit.runner.RunWith; /** * @author Paul Ferraro */ @RunWith(Arquillian.class) @ServerSetup({ InfinispanServerSetupTask.class, AbstractHotRodPersistenceWebFailoverTestCase.ServerSetupTask.class }) public class CoarseHotRodPersistenceWebFailoverTestCase extends AbstractHotRodPersistenceWebFailoverTestCase { private static final String DEPLOYMENT_NAME = CoarseHotRodPersistenceWebFailoverTestCase.class.getSimpleName() + ".war"; @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment1() { return getDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment2() { return getDeployment(); } @Deployment(name = DEPLOYMENT_3, managed = false, testable = false) @TargetsContainer(NODE_3) public static Archive<?> deployment3() { return getDeployment(); } private static Archive<?> getDeployment() { return getDeployment(DEPLOYMENT_NAME, "distributable-web-coarse.xml"); } public CoarseHotRodPersistenceWebFailoverTestCase() { super(DEPLOYMENT_NAME); } }
2,580
37.522388
124
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/remote/FineHotRodWebFailoverTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2018, 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.web.remote; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.TargetsContainer; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.test.clustering.cluster.web.AbstractWebFailoverTestCase; import org.jboss.as.test.clustering.single.web.Mutable; import org.jboss.as.test.clustering.single.web.SimpleServlet; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.runner.RunWith; /** * @author Paul Ferraro */ @RunWith(Arquillian.class) @ServerSetup({ InfinispanServerSetupTask.class, LocalRoutingServerSetup.class }) public class FineHotRodWebFailoverTestCase extends AbstractHotRodWebFailoverTestCase { private static final String DEPLOYMENT_NAME = FineHotRodWebFailoverTestCase.class.getSimpleName() + ".war"; public FineHotRodWebFailoverTestCase() { super(DEPLOYMENT_NAME); } @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment1() { return getDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment2() { return getDeployment(); } @Deployment(name = DEPLOYMENT_3, managed = false, testable = false) @TargetsContainer(NODE_3) public static Archive<?> deployment3() { return getDeployment(); } private static Archive<?> getDeployment() { WebArchive war = ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME); war.addClasses(SimpleServlet.class, Mutable.class); war.setWebXML(AbstractWebFailoverTestCase.class.getPackage(), "web.xml"); war.addAsWebInfResource(FineHotRodWebFailoverTestCase.class.getPackage(), "jboss-all_fine.xml", "jboss-all.xml"); war.addAsWebInfResource(FineHotRodWebFailoverTestCase.class.getPackage(), "jboss-web.xml", "jboss-web.xml"); return war; } }
3,182
40.337662
121
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/remote/CoarseTransactionalHotRodWebFailoverTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2020, 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.web.remote; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.TargetsContainer; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.test.clustering.cluster.web.AbstractWebFailoverTestCase; import org.jboss.as.test.clustering.single.web.Mutable; import org.jboss.as.test.clustering.single.web.SimpleServlet; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.runner.RunWith; /** * @author Paul Ferraro */ @RunWith(Arquillian.class) @ServerSetup({ InfinispanServerSetupTask.class, LocalRoutingServerSetup.class }) public class CoarseTransactionalHotRodWebFailoverTestCase extends AbstractHotRodWebFailoverTestCase { private static final String DEPLOYMENT_NAME = CoarseTransactionalHotRodWebFailoverTestCase.class.getSimpleName() + ".war"; public CoarseTransactionalHotRodWebFailoverTestCase() { super(DEPLOYMENT_NAME); } @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment1() { return getDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment2() { return getDeployment(); } @Deployment(name = DEPLOYMENT_3, managed = false, testable = false) @TargetsContainer(NODE_3) public static Archive<?> deployment3() { return getDeployment(); } private static Archive<?> getDeployment() { WebArchive war = ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME); war.addClasses(SimpleServlet.class, Mutable.class); war.setWebXML(AbstractWebFailoverTestCase.class.getPackage(), "web.xml"); war.addAsWebInfResource(CoarseTransactionalHotRodWebFailoverTestCase.class.getPackage(), "jboss-all_coarse_transactional.xml", "jboss-all.xml"); war.addAsWebInfResource(CoarseTransactionalHotRodWebFailoverTestCase.class.getPackage(), "jboss-web.xml", "jboss-web.xml"); return war; } }
3,273
41.519481
152
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/remote/CoarseHotRodWebFailoverTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2018, 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.web.remote; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.TargetsContainer; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.test.clustering.cluster.web.AbstractWebFailoverTestCase; import org.jboss.as.test.clustering.single.web.Mutable; import org.jboss.as.test.clustering.single.web.SimpleServlet; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.runner.RunWith; /** * @author Paul Ferraro */ @RunWith(Arquillian.class) @ServerSetup({ InfinispanServerSetupTask.class, LocalRoutingServerSetup.class }) public class CoarseHotRodWebFailoverTestCase extends AbstractHotRodWebFailoverTestCase { private static final String DEPLOYMENT_NAME = CoarseHotRodWebFailoverTestCase.class.getSimpleName() + ".war"; public CoarseHotRodWebFailoverTestCase() { super(DEPLOYMENT_NAME); } @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment1() { return getDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment2() { return getDeployment(); } @Deployment(name = DEPLOYMENT_3, managed = false, testable = false) @TargetsContainer(NODE_3) public static Archive<?> deployment3() { return getDeployment(); } private static Archive<?> getDeployment() { WebArchive war = ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME); war.addClasses(SimpleServlet.class, Mutable.class); war.setWebXML(AbstractWebFailoverTestCase.class.getPackage(), "web.xml"); war.addAsWebInfResource(CoarseHotRodWebFailoverTestCase.class.getPackage(), "jboss-all_coarse.xml", "jboss-all.xml"); war.addAsWebInfResource(CoarseHotRodWebFailoverTestCase.class.getPackage(), "jboss-web.xml", "jboss-web.xml"); return war; } }
3,194
40.493506
125
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/remote/FineHotRodSessionActivationTestCase.java
/* * 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.web.remote; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.TargetsContainer; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.test.clustering.cluster.web.DistributableTestCase; import org.jboss.as.test.clustering.cluster.web.event.SessionActivationServlet; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.runner.RunWith; /** * @author Paul Ferraro */ @RunWith(Arquillian.class) @ServerSetup({ InfinispanServerSetupTask.class, LocalRoutingServerSetup.class }) public class FineHotRodSessionActivationTestCase extends AbstractHotRodSessionActivationTestCase { private static final String MODULE_NAME = FineHotRodSessionActivationTestCase.class.getSimpleName(); private static final String DEPLOYMENT_NAME = MODULE_NAME + ".war"; @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment1() { return getDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment2() { return getDeployment(); } @Deployment(name = DEPLOYMENT_3, managed = false, testable = false) @TargetsContainer(NODE_3) public static Archive<?> deployment3() { return getDeployment(); } private static Archive<?> getDeployment() { WebArchive war = ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME); war.addClasses(SessionActivationServlet.class); war.setWebXML(DistributableTestCase.class.getPackage(), "web.xml"); war.addAsWebInfResource(AbstractHotRodSessionActivationTestCase.class.getPackage(), "jboss-all_coarse.xml", "jboss-all.xml"); return war; } public FineHotRodSessionActivationTestCase() { super(false); } }
3,096
39.75
133
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/remote/FineTransactionalHotRodWebFailoverTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2020, 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.web.remote; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.TargetsContainer; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.test.clustering.cluster.web.AbstractWebFailoverTestCase; import org.jboss.as.test.clustering.single.web.Mutable; import org.jboss.as.test.clustering.single.web.SimpleServlet; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.runner.RunWith; /** * @author Paul Ferraro */ @RunWith(Arquillian.class) @ServerSetup({ InfinispanServerSetupTask.class, LocalRoutingServerSetup.class }) public class FineTransactionalHotRodWebFailoverTestCase extends AbstractHotRodWebFailoverTestCase { private static final String DEPLOYMENT_NAME = FineTransactionalHotRodWebFailoverTestCase.class.getSimpleName() + ".war"; public FineTransactionalHotRodWebFailoverTestCase() { super(DEPLOYMENT_NAME); } @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment1() { return getDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment2() { return getDeployment(); } @Deployment(name = DEPLOYMENT_3, managed = false, testable = false) @TargetsContainer(NODE_3) public static Archive<?> deployment3() { return getDeployment(); } private static Archive<?> getDeployment() { WebArchive war = ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME); war.addClasses(SimpleServlet.class, Mutable.class); war.setWebXML(AbstractWebFailoverTestCase.class.getPackage(), "web.xml"); war.addAsWebInfResource(FineTransactionalHotRodWebFailoverTestCase.class.getPackage(), "jboss-all_fine_transactional.xml", "jboss-all.xml"); war.addAsWebInfResource(FineTransactionalHotRodWebFailoverTestCase.class.getPackage(), "jboss-web.xml", "jboss-web.xml"); return war; } }
3,261
41.363636
148
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/remote/AbstractHotRodPersistenceWebFailoverTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2018, 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.web.remote; import org.infinispan.configuration.cache.CacheMode; import org.infinispan.transaction.TransactionMode; import org.jboss.as.test.clustering.ClusterTestUtil; import org.jboss.as.test.clustering.InfinispanServerUtil; import org.jboss.as.test.clustering.cluster.web.AbstractWebFailoverTestCase; import org.jboss.as.test.clustering.single.web.Mutable; import org.jboss.as.test.clustering.single.web.SimpleServlet; import org.jboss.as.test.shared.CLIServerSetupTask; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.ClassRule; import org.junit.rules.TestRule; /** * Variation of {@link AbstractWebFailoverTestCase} using invalidation cache with HotRod-based store implementation referencing * {@literal remote-cache-container} configuration. Test runs against running genuine Infinispan Server instance. * * @author Radoslav Husar */ public abstract class AbstractHotRodPersistenceWebFailoverTestCase extends AbstractWebFailoverTestCase { @ClassRule public static final TestRule INFINISPAN_SERVER_RULE = InfinispanServerUtil.infinispanServerTestRule(); static Archive<?> getDeployment(String deploymentName, String deploymentDescriptor) { WebArchive war = ShrinkWrap.create(WebArchive.class, deploymentName); war.addClasses(SimpleServlet.class, Mutable.class); ClusterTestUtil.addTopologyListenerDependencies(war); war.setWebXML(AbstractWebFailoverTestCase.class.getPackage(), "web.xml"); war.addAsWebInfResource(AbstractHotRodPersistenceWebFailoverTestCase.class.getPackage(), deploymentDescriptor, "distributable-web.xml"); return war; } public AbstractHotRodPersistenceWebFailoverTestCase(String deploymentName) { super(deploymentName, CacheMode.INVALIDATION_SYNC, TransactionMode.NON_TRANSACTIONAL); } public static class ServerSetupTask extends CLIServerSetupTask { public ServerSetupTask() { this.builder.node(THREE_NODES) .setup("/subsystem=infinispan/cache-container=web/invalidation-cache=hotrod-persistence:add") .setup("/subsystem=infinispan/cache-container=web/invalidation-cache=hotrod-persistence/store=hotrod:add(remote-cache-container=web, cache-configuration=default, shared=true)") .teardown("/subsystem=infinispan/cache-container=web/invalidation-cache=hotrod-persistence:remove") ; } } }
3,593
48.232877
196
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/remote/AbstractHotRodWebFailoverTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2018, 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.web.remote; import static org.jboss.as.test.clustering.ClusterTestUtil.execute; import java.net.URL; import org.infinispan.configuration.cache.CacheMode; import org.infinispan.transaction.TransactionMode; import org.jboss.arquillian.container.test.api.OperateOnDeployment; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.test.clustering.InfinispanServerUtil; import org.jboss.as.test.clustering.cluster.web.AbstractWebFailoverTestCase; import org.jboss.dmr.ModelNode; import org.junit.Assert; import org.junit.ClassRule; import org.junit.rules.TestRule; /** * Variation of {@link AbstractWebFailoverTestCase} using hotrod-based session manager. * Test runs against running genuine Infinispan Server instance. * * @author Radoslav Husar * @author Paul Ferraro */ public abstract class AbstractHotRodWebFailoverTestCase extends AbstractWebFailoverTestCase { @ClassRule public static final TestRule INFINISPAN_SERVER_RULE = InfinispanServerUtil.infinispanServerTestRule(); @ArquillianResource @OperateOnDeployment(DEPLOYMENT_1) private ManagementClient client1; @ArquillianResource @OperateOnDeployment(DEPLOYMENT_2) private ManagementClient client2; @ArquillianResource @OperateOnDeployment(DEPLOYMENT_3) private ManagementClient client3; private final String deploymentName; public AbstractHotRodWebFailoverTestCase(String deploymentName) { super(deploymentName, CacheMode.LOCAL, TransactionMode.NON_TRANSACTIONAL); this.deploymentName = deploymentName; } @Override public void testGracefulSimpleFailover(URL baseURL1, URL baseURL2, URL baseURL3) throws Exception { super.testGracefulSimpleFailover(baseURL1, baseURL2, baseURL3); String readResource = String.format("/subsystem=infinispan/remote-cache-container=web/remote-cache=%s:read-resource(include-runtime=true, recursive=true)", this.deploymentName); String resetStatistics = String.format("/subsystem=infinispan/remote-cache-container=web/remote-cache=%s:reset-statistics", this.deploymentName); ModelNode result = execute(this.client1, readResource); Assert.assertNotEquals(0L, result.get("hits").asLong()); Assert.assertNotEquals(0L, result.get("writes").asLong()); result = execute(this.client2, readResource); Assert.assertEquals(0L, result.get("hits").asLong()); Assert.assertEquals(0L, result.get("writes").asLong()); result = execute(this.client3, readResource); Assert.assertNotEquals(0L, result.get("hits").asLong()); Assert.assertNotEquals(0L, result.get("writes").asLong()); execute(this.client1, resetStatistics); execute(this.client2, resetStatistics); execute(this.client3, resetStatistics); // These metrics should have reset result = execute(this.client1, readResource); Assert.assertEquals(0L, result.get("hits").asLong()); Assert.assertEquals(0L, result.get("writes").asLong()); result = execute(this.client2, readResource); Assert.assertEquals(0L, result.get("hits").asLong()); Assert.assertEquals(0L, result.get("writes").asLong()); result = execute(this.client3, readResource); Assert.assertEquals(0L, result.get("hits").asLong()); Assert.assertEquals(0L, result.get("writes").asLong()); } }
4,522
42.490385
185
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/remote/LocalRoutingServerSetup.java
/* * 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.web.remote; import org.jboss.as.test.clustering.cluster.AbstractClusteringTestCase; import org.jboss.as.test.shared.CLIServerSetupTask; /** * @author Paul Ferraro */ public class LocalRoutingServerSetup extends CLIServerSetupTask { public LocalRoutingServerSetup() { this.builder.node(AbstractClusteringTestCase.THREE_NODES) .setup("/subsystem=distributable-web/routing=infinispan:remove") .setup("/subsystem=distributable-web/routing=local:add") .teardown("/subsystem=distributable-web/routing=local:remove") .teardown("/subsystem=distributable-web/routing=infinispan:add(cache-container=web, cache=routing)") ; } }
1,780
40.418605
116
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/context/ConversationServlet.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, 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.web.context; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import jakarta.inject.Inject; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; /** * @author Paul Ferraro */ @WebServlet(urlPatterns = { ConversationServlet.SERVLET_PATH }) public class ConversationServlet extends HttpServlet { private static final long serialVersionUID = -1574442587573954813L; private static final String SERVLET_NAME = "conversation"; static final String SERVLET_PATH = "/" + SERVLET_NAME; public static final String COUNT_HEADER = "count"; public static final String CONVERSATION_ID = "cid"; public static URI createURI(URL baseURL) throws URISyntaxException { return baseURL.toURI().resolve(SERVLET_NAME); } public static URI createURI(URL baseURL, String conversation) throws URISyntaxException { return baseURL.toURI().resolve(SERVLET_NAME + '?' + CONVERSATION_ID + '=' + conversation); } @Inject private ConversationBean bean; @Override protected void service(HttpServletRequest request, HttpServletResponse response) { response.setHeader(COUNT_HEADER, String.valueOf(this.bean.increment())); response.setHeader(CONVERSATION_ID, this.bean.getConversationId()); } }
2,482
38.412698
98
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/context/LogoutServlet.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, 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.web.context; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import jakarta.inject.Inject; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpSession; /** * @author Paul Ferraro */ @WebServlet(urlPatterns = { LogoutServlet.SERVLET_PATH }) public class LogoutServlet extends HttpServlet { private static final long serialVersionUID = -1574442587573954813L; private static final String SERVLET_NAME = "logout"; static final String SERVLET_PATH = "/" + SERVLET_NAME; public static URI createURI(URL baseURL, String conversation) throws URISyntaxException { return baseURL.toURI().resolve(new StringBuilder(SERVLET_NAME).append('?').append(ConversationServlet.CONVERSATION_ID).append('=').append(conversation).toString()); } @Inject private ConversationBean bean; @Override protected void service(HttpServletRequest request, HttpServletResponse response) { response.setHeader(ConversationServlet.COUNT_HEADER, String.valueOf(this.bean.increment())); response.setHeader(ConversationServlet.CONVERSATION_ID, this.bean.getConversationId()); HttpSession session = request.getSession(false); if (session != null) { session.invalidate(); } } }
2,506
39.435484
172
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/context/InvalidateConversationTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, 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.web.context; import static org.junit.Assert.*; import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; import jakarta.servlet.http.HttpServletResponse; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.utils.HttpClientUtils; 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.ClusterHttpClientUtil; import org.jboss.as.test.clustering.ClusterTestUtil; import org.jboss.as.test.clustering.cluster.AbstractClusteringTestCase; import org.jboss.as.test.clustering.cluster.web.DistributableTestCase; import org.jboss.as.test.http.util.TestHttpClientUtils; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; /** * Test case for WFLY-4067 * @author Paul Ferraro */ @RunWith(Arquillian.class) public class InvalidateConversationTestCase extends AbstractClusteringTestCase { private static final String MODULE_NAME = InvalidateConversationTestCase.class.getSimpleName(); private static final String DEPLOYMENT_NAME = MODULE_NAME + ".war"; @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment1() { return getDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment2() { return getDeployment(); } private static Archive<?> getDeployment() { WebArchive war = ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME); ClusterTestUtil.addTopologyListenerDependencies(war); war.addClasses(ConversationServlet.class, ConversationBean.class, LogoutServlet.class); war.setWebXML(DistributableTestCase.class.getPackage(), "web.xml"); return war; } @Test public void testInvalidate( @ArquillianResource(ConversationServlet.class) @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1, @ArquillianResource(ConversationServlet.class) @OperateOnDeployment(DEPLOYMENT_2) URL baseURL2) throws IOException, URISyntaxException { String conversation = null; establishTopology(baseURL1, TWO_NODES); try (CloseableHttpClient client = TestHttpClientUtils.promiscuousCookieHttpClient()) { HttpResponse response = client.execute(new HttpGet(ConversationServlet.createURI(baseURL1))); try { assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); assertTrue(response.containsHeader(ConversationServlet.COUNT_HEADER)); assertEquals(1, Integer.parseInt(response.getFirstHeader(ConversationServlet.COUNT_HEADER).getValue())); conversation = response.getFirstHeader(ConversationServlet.CONVERSATION_ID).getValue(); } finally { HttpClientUtils.closeQuietly(response); } response = client.execute(new HttpGet(ConversationServlet.createURI(baseURL2, conversation))); try { assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); assertTrue(response.containsHeader(ConversationServlet.COUNT_HEADER)); assertEquals(2, Integer.parseInt(response.getFirstHeader(ConversationServlet.COUNT_HEADER).getValue())); assertEquals(conversation, response.getFirstHeader(ConversationServlet.CONVERSATION_ID).getValue()); } finally { HttpClientUtils.closeQuietly(response); } response = client.execute(new HttpGet(LogoutServlet.createURI(baseURL1, conversation))); try { assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); assertTrue(response.containsHeader(ConversationServlet.COUNT_HEADER)); assertEquals(3, Integer.parseInt(response.getFirstHeader(ConversationServlet.COUNT_HEADER).getValue())); assertEquals(conversation, response.getFirstHeader(ConversationServlet.CONVERSATION_ID).getValue()); } finally { HttpClientUtils.closeQuietly(response); } } } private static void establishTopology(URL baseURL, String... nodes) throws URISyntaxException, IOException { ClusterHttpClientUtil.establishTopology(baseURL, "web", DEPLOYMENT_NAME, nodes); } }
5,976
44.976923
120
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/context/ConversationBean.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, 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.web.context; import java.io.Serializable; import java.util.concurrent.atomic.AtomicInteger; import jakarta.enterprise.context.Conversation; import jakarta.enterprise.context.ConversationScoped; import jakarta.inject.Inject; /** * @author Paul Ferraro */ @ConversationScoped public class ConversationBean implements Serializable { private static final long serialVersionUID = 3657454752821514883L; @Inject private Conversation conversation; private final AtomicInteger value = new AtomicInteger(0); public int increment() { if (this.conversation.isTransient()) { this.conversation.begin(); } return this.value.incrementAndGet(); } public String getConversationId() { return this.conversation.getId(); } public void end() { this.conversation.end(); } }
1,921
32.137931
70
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/passivation/CoarseSessionPassivationTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, 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.web.passivation; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.TargetsContainer; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.runner.RunWith; @RunWith(Arquillian.class) public class CoarseSessionPassivationTestCase extends SessionPassivationTestCase { private static final String MODULE_NAME = CoarseSessionPassivationTestCase.class.getSimpleName(); @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment0() { return getDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment1() { return getDeployment(); } static WebArchive getDeployment() { return getBaseDeployment(MODULE_NAME).addAsWebInfResource(SessionPassivationTestCase.class.getPackage(), "jboss-web-coarse.xml", "jboss-web.xml"); } }
2,169
40.730769
154
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/passivation/FineSessionPassivationTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, 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.web.passivation; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.TargetsContainer; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.runner.RunWith; @RunWith(Arquillian.class) public class FineSessionPassivationTestCase extends SessionPassivationTestCase { private static final String MODULE_NAME = FineSessionPassivationTestCase.class.getSimpleName(); @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment0() { return getDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment1() { return getDeployment(); } static WebArchive getDeployment() { return getBaseDeployment(MODULE_NAME).addAsWebInfResource(SessionPassivationTestCase.class.getPackage(), "jboss-web-fine.xml", "jboss-web.xml"); } }
2,163
40.615385
152
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/passivation/SessionPassivationTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, 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.web.passivation; import static org.junit.Assert.*; import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; import java.util.Formatter; import java.util.HashMap; import java.util.LinkedList; import java.util.Map; import java.util.Queue; import java.util.stream.Stream; import jakarta.servlet.http.HttpServletResponse; import org.apache.http.Header; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.utils.HttpClientUtils; import org.apache.http.impl.client.CloseableHttpClient; import org.jboss.arquillian.container.test.api.OperateOnDeployment; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.test.clustering.cluster.AbstractClusteringTestCase; import org.jboss.as.test.clustering.cluster.web.DistributableTestCase; import org.jboss.as.test.clustering.cluster.web.EnableUndertowStatisticsSetupTask; import org.jboss.as.test.clustering.single.web.passivation.SessionOperationServlet; import org.jboss.as.test.http.util.TestHttpClientUtils; import org.jboss.as.test.shared.TimeoutUtil; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; @ServerSetup(EnableUndertowStatisticsSetupTask.class) public abstract class SessionPassivationTestCase extends AbstractClusteringTestCase { private static final int MAX_PASSIVATION_WAIT = TimeoutUtil.adjust(10000); static WebArchive getBaseDeployment(String moduleName) { WebArchive war = ShrinkWrap.create(WebArchive.class, moduleName + ".war"); war.addClasses(SessionOperationServlet.class); // Take web.xml from the managed test. war.setWebXML(DistributableTestCase.class.getPackage(), "web.xml"); return war; } @Test public void test(@ArquillianResource(SessionOperationServlet.class) @OperateOnDeployment(DEPLOYMENT_1) URL baseURL) throws IOException, URISyntaxException { String session1; String session2; try (CloseableHttpClient client1 = TestHttpClientUtils.promiscuousCookieHttpClient(); CloseableHttpClient client2 = TestHttpClientUtils.promiscuousCookieHttpClient()) { // This should not trigger any passivation/activation events HttpResponse response = client1.execute(new HttpGet(SessionOperationServlet.createSetURI(baseURL, "a", "1"))); try { assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); session1 = getRequiredHeaderValue(response, SessionOperationServlet.SESSION_ID); } finally { HttpClientUtils.closeQuietly(response); } long now = System.currentTimeMillis(); long start = now; Map<String, Queue<SessionOperationServlet.EventType>> events = new HashMap<>(); Map<String, SessionOperationServlet.EventType> expectedEvents = new HashMap<>(); events.put(session1, new LinkedList<>()); expectedEvents.put(session1, SessionOperationServlet.EventType.PASSIVATION); // This will trigger passivation of session1 response = client2.execute(new HttpGet(SessionOperationServlet.createSetURI(baseURL, "a", "2"))); try { assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); session2 = getRequiredHeaderValue(response, SessionOperationServlet.SESSION_ID); events.put(session2, new LinkedList<>()); expectedEvents.put(session2, SessionOperationServlet.EventType.PASSIVATION); collectEvents(response, events); } finally { HttpClientUtils.closeQuietly(response); } // Ensure session1 was passivated while (events.get(session1).isEmpty() && ((now - start) < MAX_PASSIVATION_WAIT)) { response = client2.execute(new HttpGet(SessionOperationServlet.createGetURI(baseURL, "a"))); try { assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); assertEquals(session2, getRequiredHeaderValue(response, SessionOperationServlet.SESSION_ID)); assertEquals("2", getRequiredHeaderValue(response, SessionOperationServlet.RESULT)); collectEvents(response, events); } finally { HttpClientUtils.closeQuietly(response); } Thread.yield(); now = System.currentTimeMillis(); } assertFalse(events.get(session1).isEmpty()); validateEvents(session1, events, expectedEvents); now = System.currentTimeMillis(); start = now; // This should trigger activation of session1 and passivation of session2 response = client1.execute(new HttpGet(SessionOperationServlet.createGetURI(baseURL, "a"))); try { assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); assertEquals(session1, getRequiredHeaderValue(response, SessionOperationServlet.SESSION_ID)); assertEquals("1", getRequiredHeaderValue(response, SessionOperationServlet.RESULT)); collectEvents(response, events); assertFalse(events.get(session1).isEmpty()); assertTrue(events.get(session1).contains(SessionOperationServlet.EventType.ACTIVATION)); } finally { HttpClientUtils.closeQuietly(response); } // Verify session2 was passivated while (events.get(session2).isEmpty() && ((now - start) < MAX_PASSIVATION_WAIT)) { response = client1.execute(new HttpGet(SessionOperationServlet.createGetURI(baseURL, "a"))); try { assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); assertEquals(session1, getRequiredHeaderValue(response, SessionOperationServlet.SESSION_ID)); assertEquals("1", getRequiredHeaderValue(response, SessionOperationServlet.RESULT)); collectEvents(response, events); } finally { HttpClientUtils.closeQuietly(response); } Thread.yield(); now = System.currentTimeMillis(); } assertFalse(events.get(session2).isEmpty()); validateEvents(session2, events, expectedEvents); now = System.currentTimeMillis(); start = now; // This should trigger activation of session2 and passivation of session1 response = client2.execute(new HttpGet(SessionOperationServlet.createGetURI(baseURL, "a"))); try { assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); assertEquals(session2, getRequiredHeaderValue(response, SessionOperationServlet.SESSION_ID)); assertEquals("2", getRequiredHeaderValue(response, SessionOperationServlet.RESULT)); collectEvents(response, events); assertFalse(events.get(session2).isEmpty()); assertTrue(events.get(session2).contains(SessionOperationServlet.EventType.ACTIVATION)); } finally { HttpClientUtils.closeQuietly(response); } // Verify session1 was passivated while (!events.get(session1).isEmpty() && ((now - start) < MAX_PASSIVATION_WAIT)) { response = client2.execute(new HttpGet(SessionOperationServlet.createGetURI(baseURL, "a"))); try { assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); assertEquals(session2, getRequiredHeaderValue(response, SessionOperationServlet.SESSION_ID)); assertEquals("2", getRequiredHeaderValue(response, SessionOperationServlet.RESULT)); collectEvents(response, events); } finally { HttpClientUtils.closeQuietly(response); } Thread.yield(); now = System.currentTimeMillis(); } assertFalse(events.get(session1).isEmpty()); validateEvents(session1, events, expectedEvents); validateEvents(session2, events, expectedEvents); } } private static void collectEvents(HttpResponse response, Map<String, Queue<SessionOperationServlet.EventType>> events) { events.entrySet().forEach((Map.Entry<String, Queue<SessionOperationServlet.EventType>> entry) -> { String sessionId = entry.getKey(); if (response.containsHeader(sessionId)) { Stream.of(response.getHeaders(sessionId)).forEach((Header header) -> { entry.getValue().add(SessionOperationServlet.EventType.valueOf(header.getValue())); }); } }); } private static void validateEvents(String sessionId, Map<String, Queue<SessionOperationServlet.EventType>> events, Map<String, SessionOperationServlet.EventType> expectedEvents) { Queue<SessionOperationServlet.EventType> types = events.get(sessionId); SessionOperationServlet.EventType type = types.poll(); SessionOperationServlet.EventType expected = expectedEvents.get(sessionId); while (type != null) { assertSame(expected, type); type = types.poll(); // ACTIVATE event must follow PASSIVATE event and vice versa expected = SessionOperationServlet.EventType.values()[(expected.ordinal() + 1) % 2]; } expectedEvents.put(sessionId, expected); } private static String getRequiredHeaderValue(HttpResponse response, String name) { assertTrue(String.format("response doesn't contain header '%s', all response headers = %s", name, showHeaders(response.getAllHeaders())), response.containsHeader(name)); return response.getFirstHeader(name).getValue(); } private static String showHeaders(Header[] headers) { StringBuilder stringBuilder = new StringBuilder(); try (Formatter result = new Formatter(stringBuilder)) { Stream.of(headers).forEach((Header header) -> result.format("{name=%s, value=%s}, ", header.getName(), header.getValue())); return result.toString(); } } }
11,752
49.226496
183
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/event/SessionActivationServlet.java
/* * 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.web.event; import java.io.IOException; import java.io.Serializable; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpSession; import jakarta.servlet.http.HttpSessionActivationListener; import jakarta.servlet.http.HttpSessionBindingEvent; import jakarta.servlet.http.HttpSessionBindingListener; import jakarta.servlet.http.HttpSessionEvent; import net.jcip.annotations.Immutable; /** * @author Paul Ferraro */ @WebServlet(urlPatterns = { SessionActivationServlet.SERVLET_PATH }) public class SessionActivationServlet extends HttpServlet { private static final long serialVersionUID = 1000811377717375782L; private static final String SERVLET_NAME = "activation"; static final String SERVLET_PATH = "/" + SERVLET_NAME; private static final String IMMUTABLE_ATTRIBUTE_NAME = "immutable"; private static final String MUTABLE_ATTRIBUTE_NAME = "mutable"; public static URI createURI(URL baseURL) throws URISyntaxException { return createURI(baseURL.toURI()); } public static URI createURI(URI baseURI) { return baseURI.resolve(SERVLET_NAME); } @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.getServletContext().log(String.format("[%s] %s", request.getMethod(), request.getRequestURI())); super.service(request, response); } @Override protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); SessionActivationListener listener = new ImmutableSessionActivationListener(true); session.setAttribute(IMMUTABLE_ATTRIBUTE_NAME, listener); listener.assertActive(); listener = new MutableSessionActivationListener(true); session.setAttribute(MUTABLE_ATTRIBUTE_NAME, listener); listener.assertActive(); } @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); ((SessionActivationListener) session.getAttribute(IMMUTABLE_ATTRIBUTE_NAME)).assertActive(); ((SessionActivationListener) session.getAttribute(MUTABLE_ATTRIBUTE_NAME)).assertActive(); } @Override protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); session.removeAttribute(IMMUTABLE_ATTRIBUTE_NAME); session.removeAttribute(MUTABLE_ATTRIBUTE_NAME); } private static class MutableSessionActivationListener extends SessionActivationListener { private static final long serialVersionUID = 7944013938798510317L; MutableSessionActivationListener(boolean active) { super(active); } } @Immutable private static class ImmutableSessionActivationListener extends SessionActivationListener { private static final long serialVersionUID = -6294242158180373273L; ImmutableSessionActivationListener(boolean active) { super(active); } } private abstract static class SessionActivationListener implements HttpSessionActivationListener, HttpSessionBindingListener, Serializable { private static final long serialVersionUID = 8262547876438811845L; private transient boolean active = false; SessionActivationListener(boolean active) { this.active = active; } public void assertActive() { if (!this.active) { throw new AssertionError(String.format("%s.sessionDidActivate(...) not invoked", this.getClass().getSimpleName())); } } @Override public void sessionWillPassivate(HttpSessionEvent event) { if (!this.active) { throw new AssertionError(String.format("%s.sessionWillPassivate(...) already invoked", this.getClass().getSimpleName())); } this.active = false; } @Override public void sessionDidActivate(HttpSessionEvent event) { if (this.active) { throw new AssertionError(String.format("%s.sessionDidActivate(...) already invoked", this.getClass().getSimpleName())); } this.active = true; } @Override public void valueBound(HttpSessionBindingEvent event) { this.assertActive(); } @Override public void valueUnbound(HttpSessionBindingEvent event) { this.assertActive(); } private void writeObject(java.io.ObjectOutputStream out) throws IOException { if (this.active) { throw new AssertionError(String.format("%s.sessionWillPassivate(...) not invoked", this.getClass().getSimpleName())); } out.defaultWriteObject(); } } }
6,365
38.540373
144
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/persistence/FineDatabasePersistenceWebFailoverTestCase.java
/* * 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.web.persistence; 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.shared.CLIServerSetupTask; import org.jboss.shrinkwrap.api.Archive; /** * @author Paul Ferraro */ @ServerSetup({ AbstractDatabasePersistenceWebFailoverTestCase.ServerSetupTask.class, FineDatabasePersistenceWebFailoverTestCase.ServerSetupTask.class }) public class FineDatabasePersistenceWebFailoverTestCase extends AbstractDatabasePersistenceWebFailoverTestCase { private static final String DEPLOYMENT_NAME = FineDatabasePersistenceWebFailoverTestCase.class.getSimpleName() + ".war"; @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment1() { return getDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment2() { return getDeployment(); } @Deployment(name = DEPLOYMENT_3, managed = false, testable = false) @TargetsContainer(NODE_3) public static Archive<?> deployment3() { return getDeployment(); } private static Archive<?> getDeployment() { return getDeployment(DEPLOYMENT_NAME); } public FineDatabasePersistenceWebFailoverTestCase() { super(DEPLOYMENT_NAME); } public static class ServerSetupTask extends CLIServerSetupTask { public ServerSetupTask() { this.builder.node(THREE_NODES) .setup("/subsystem=distributable-web/infinispan-session-management=database:add(cache-container=web, cache=database-persistence, granularity=ATTRIBUTE)") .setup("/subsystem=distributable-web/infinispan-session-management=database/affinity=local:add()") .teardown("/subsystem=distributable-web/infinispan-session-management=database:remove") ; } } }
3,123
40.653333
173
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/persistence/CoarseDatabasePersistenceWebFailoverTestCase.java
/* * 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.web.persistence; 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.shared.CLIServerSetupTask; import org.jboss.shrinkwrap.api.Archive; /** * @author Paul Ferraro */ @ServerSetup({ AbstractDatabasePersistenceWebFailoverTestCase.ServerSetupTask.class, CoarseDatabasePersistenceWebFailoverTestCase.ServerSetupTask.class }) public class CoarseDatabasePersistenceWebFailoverTestCase extends AbstractDatabasePersistenceWebFailoverTestCase { private static final String DEPLOYMENT_NAME = CoarseDatabasePersistenceWebFailoverTestCase.class.getSimpleName() + ".war"; @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment1() { return getDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment2() { return getDeployment(); } @Deployment(name = DEPLOYMENT_3, managed = false, testable = false) @TargetsContainer(NODE_3) public static Archive<?> deployment3() { return getDeployment(); } private static Archive<?> getDeployment() { return getDeployment(DEPLOYMENT_NAME); } public CoarseDatabasePersistenceWebFailoverTestCase() { super(DEPLOYMENT_NAME); } public static class ServerSetupTask extends CLIServerSetupTask { public ServerSetupTask() { this.builder.node(THREE_NODES) .setup("/subsystem=distributable-web/infinispan-session-management=database:add(cache-container=web, cache=database-persistence, granularity=SESSION)") .setup("/subsystem=distributable-web/infinispan-session-management=database/affinity=local:add()") .teardown("/subsystem=distributable-web/infinispan-session-management=database:remove") ; } } }
3,129
40.733333
171
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/persistence/AbstractDatabasePersistenceWebFailoverTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2017, 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.web.persistence; import org.infinispan.configuration.cache.CacheMode; import org.infinispan.transaction.TransactionMode; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.test.clustering.ClusterTestUtil; import org.jboss.as.test.clustering.ClusterDatabaseTestUtil; import org.jboss.as.test.clustering.cluster.web.AbstractWebFailoverTestCase; import org.jboss.as.test.clustering.single.web.Mutable; import org.jboss.as.test.clustering.single.web.SimpleServlet; import org.jboss.as.test.shared.CLIServerSetupTask; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.runner.RunWith; /** * Tests session failover where sessions are stored in a shared H2 database using invalidation cache mode. * * @author Tomas Remes * @author Radoslav Husar */ @RunWith(Arquillian.class) public abstract class AbstractDatabasePersistenceWebFailoverTestCase extends AbstractWebFailoverTestCase { public AbstractDatabasePersistenceWebFailoverTestCase(String deploymentName) { super(deploymentName, CacheMode.INVALIDATION_SYNC, TransactionMode.NON_TRANSACTIONAL); } static Archive<?> getDeployment(String deploymentName) { WebArchive war = ShrinkWrap.create(WebArchive.class, deploymentName); war.addClasses(SimpleServlet.class, Mutable.class); ClusterTestUtil.addTopologyListenerDependencies(war); war.setWebXML(AbstractWebFailoverTestCase.class.getPackage(), "web.xml"); war.addAsWebInfResource(AbstractDatabasePersistenceWebFailoverTestCase.class.getPackage(), "distributable-web.xml", "distributable-web.xml"); return war; } @BeforeClass public static void beforeClass() throws Exception { ClusterDatabaseTestUtil.startH2(); } @AfterClass public static void afterClass() throws Exception { ClusterDatabaseTestUtil.stopH2(); } public static class ServerSetupTask extends CLIServerSetupTask { public ServerSetupTask() { this.builder.node(THREE_NODES) .setup("/subsystem=datasources/data-source=web-sessions-ds:add(jndi-name=\"java:jboss/datasources/web-sessions-ds\", enabled=true, use-java-context=true, connection-url=\"jdbc:h2:tcp://localhost:%s/./web-sessions;VARIABLE_BINARY=TRUE\", driver-name=h2", DB_PORT) .setup("/subsystem=infinispan/cache-container=web/invalidation-cache=database-persistence:add") .setup("/subsystem=infinispan/cache-container=web/invalidation-cache=database-persistence/store=jdbc:add(data-source=web-sessions-ds, shared=true)") .teardown("/subsystem=infinispan/cache-container=web/invalidation-cache=database-persistence:remove") .teardown("/subsystem=datasources/data-source=web-sessions-ds:remove"); } } }
4,022
46.892857
282
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/authentication/BasicAuthenticationWebFailoverTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, 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.web.authentication; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import jakarta.servlet.http.HttpServletResponse; import org.apache.http.HttpResponse; import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.client.CredentialsProvider; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.utils.HttpClientUtils; import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.impl.client.HttpClients; 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.arquillian.api.ServerSetup; import org.jboss.as.test.clustering.cluster.AbstractClusteringTestCase; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.wildfly.test.security.common.elytron.ServletElytronDomainSetup; /** * Validates that a user remains authenticated following failover when using BASIC authentication. * @author Paul Ferraro */ @RunWith(Arquillian.class) @ServerSetup({BasicAuthenticationWebFailoverTestCase.ElytronDomainSetupOverride.class, BasicAuthenticationWebFailoverTestCase.ServletElytronDomainSetupOverride.class}) public class BasicAuthenticationWebFailoverTestCase extends AbstractClusteringTestCase { private static final String MODULE_NAME = BasicAuthenticationWebFailoverTestCase.class.getSimpleName(); private static final String SECURITY_DOMAIN_NAME = "authentication"; @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment0() { return getDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment1() { return getDeployment(); } private static Archive<?> getDeployment() { WebArchive war = ShrinkWrap.create(WebArchive.class, MODULE_NAME + ".war"); war.addClass(SecureServlet.class); war.setWebXML(SecureServlet.class.getPackage(), "web-basic.xml"); war.addAsWebInfResource(SecureServlet.class.getPackage(), "jboss-web.xml", "jboss-web.xml"); return war; } @Test public void test( @ArquillianResource(SecureServlet.class) @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1, @ArquillianResource(SecureServlet.class) @OperateOnDeployment(DEPLOYMENT_2) URL baseURL2) throws IOException, URISyntaxException { CredentialsProvider provider = new BasicCredentialsProvider(); HttpClient client = HttpClients.custom().setDefaultCredentialsProvider(provider).build(); URI uri1 = SecureServlet.createURI(baseURL1); URI uri2 = SecureServlet.createURI(baseURL2); try { // Valid login, invalid role setCredentials(provider, "forbidden", "password", baseURL1, baseURL2); HttpResponse response = client.execute(new HttpGet(uri1)); try { Assert.assertEquals(HttpServletResponse.SC_FORBIDDEN, response.getStatusLine().getStatusCode()); } finally { HttpClientUtils.closeQuietly(response); } // Invalid login, valid role setCredentials(provider, "allowed", "bad", baseURL1, baseURL2); response = client.execute(new HttpGet(uri1)); try { Assert.assertEquals(HttpServletResponse.SC_UNAUTHORIZED, response.getStatusLine().getStatusCode()); } finally { HttpClientUtils.closeQuietly(response); } // Valid login, valid role setCredentials(provider, "allowed", "password", baseURL1, baseURL2); String sessionId = null; response = client.execute(new HttpGet(uri1)); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertNotNull(response.getFirstHeader(SecureServlet.SESSION_ID_HEADER)); sessionId = response.getFirstHeader(SecureServlet.SESSION_ID_HEADER).getValue(); } finally { HttpClientUtils.closeQuietly(response); } undeploy(DEPLOYMENT_1); response = client.execute(new HttpGet(uri2)); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(sessionId, response.getFirstHeader(SecureServlet.SESSION_ID_HEADER).getValue()); } finally { HttpClientUtils.closeQuietly(response); } deploy(DEPLOYMENT_1); response = client.execute(new HttpGet(uri1)); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(sessionId, response.getFirstHeader(SecureServlet.SESSION_ID_HEADER).getValue()); } finally { HttpClientUtils.closeQuietly(response); } } finally { HttpClientUtils.closeQuietly(client); } } private static void setCredentials(CredentialsProvider provider, String user, String password, URL... urls) { for (URL url: urls) { provider.setCredentials(new AuthScope(url.getHost(), url.getPort()), new UsernamePasswordCredentials(user, password)); } } static class ElytronDomainSetupOverride extends ElytronDomainServerSetupTask { public ElytronDomainSetupOverride() { super(SECURITY_DOMAIN_NAME); } } static class ServletElytronDomainSetupOverride extends ServletElytronDomainSetup { protected ServletElytronDomainSetupOverride() { super(SECURITY_DOMAIN_NAME, false); } } }
7,405
41.809249
167
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/authentication/ElytronDomainServerSetupTask.java
/* * 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.web.authentication; import java.io.File; import org.wildfly.test.security.common.elytron.ElytronDomainSetup; public class ElytronDomainServerSetupTask extends ElytronDomainSetup { public ElytronDomainServerSetupTask(String securityDomain) { super(new File(FormAuthenticationWebFailoverTestCase.class.getResource("users.properties").getFile()).getAbsolutePath(), new File(FormAuthenticationWebFailoverTestCase.class.getResource("roles.properties").getFile()).getAbsolutePath(), securityDomain); } }
1,618
43.972222
130
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/authentication/FormAuthenticationWebFailoverTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, 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.web.authentication; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import jakarta.servlet.http.HttpServletResponse; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.utils.HttpClientUtils; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.message.BasicNameValuePair; 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.arquillian.api.ServerSetup; import org.jboss.as.test.clustering.cluster.AbstractClusteringTestCase; import org.jboss.as.test.http.util.TestHttpClientUtils; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.wildfly.test.security.common.elytron.ServletElytronDomainSetup; /** * Validates that a user remains authenticated following failover when using FORM authentication. * @author Paul Ferraro */ @RunWith(Arquillian.class) @ServerSetup({FormAuthenticationWebFailoverTestCase.ElytronDomainSetupOverride.class, FormAuthenticationWebFailoverTestCase.ServletElytronDomainSetupOverride.class}) public class FormAuthenticationWebFailoverTestCase extends AbstractClusteringTestCase { private static final String MODULE_NAME = BasicAuthenticationWebFailoverTestCase.class.getSimpleName(); private static final String SECURITY_DOMAIN_NAME = "authentication"; @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment0() { return getDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment1() { return getDeployment(); } private static Archive<?> getDeployment() { WebArchive war = ShrinkWrap.create(WebArchive.class, MODULE_NAME + ".war"); war.addClass(SecureServlet.class); war.setWebXML(SecureServlet.class.getPackage(), "web-form.xml"); war.addAsWebInfResource(SecureServlet.class.getPackage(), "jboss-web.xml", "jboss-web.xml"); war.addAsWebResource(SecureServlet.class.getPackage(), "login.html", "login.html"); war.addAsWebResource(SecureServlet.class.getPackage(), "error.html", "error.html"); return war; } @Test public void test( @ArquillianResource(SecureServlet.class) @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1, @ArquillianResource(SecureServlet.class) @OperateOnDeployment(DEPLOYMENT_2) URL baseURL2) throws IOException, URISyntaxException { URI uri1 = SecureServlet.createURI(baseURL1); URI uri2 = SecureServlet.createURI(baseURL2); try (CloseableHttpClient client = TestHttpClientUtils.promiscuousCookieHttpClient()) { HttpResponse response = client.execute(new HttpGet(uri1)); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertNull(response.getFirstHeader(SecureServlet.SESSION_ID_HEADER)); } finally { HttpClientUtils.closeQuietly(response); } HttpPost login = new HttpPost(baseURL1.toURI().resolve("j_security_check")); List<NameValuePair> pairs = new ArrayList<>(2); pairs.add(new BasicNameValuePair("j_username", "allowed")); pairs.add(new BasicNameValuePair("j_password", "password")); login.setEntity(new UrlEncodedFormEntity(pairs, StandardCharsets.UTF_8)); response = client.execute(login); try { Assert.assertEquals(HttpServletResponse.SC_FOUND, response.getStatusLine().getStatusCode()); } finally { HttpClientUtils.closeQuietly(response); } String sessionId = null; response = client.execute(new HttpGet(uri1)); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertNotNull(response.getFirstHeader(SecureServlet.SESSION_ID_HEADER)); sessionId = response.getFirstHeader(SecureServlet.SESSION_ID_HEADER).getValue(); } finally { HttpClientUtils.closeQuietly(response); } undeploy(DEPLOYMENT_1); response = client.execute(new HttpGet(uri2)); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(sessionId, response.getFirstHeader(SecureServlet.SESSION_ID_HEADER).getValue()); } finally { HttpClientUtils.closeQuietly(response); } deploy(DEPLOYMENT_1); response = client.execute(new HttpGet(uri1)); try { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(sessionId, response.getFirstHeader(SecureServlet.SESSION_ID_HEADER).getValue()); } finally { HttpClientUtils.closeQuietly(response); } } } static class ElytronDomainSetupOverride extends ElytronDomainServerSetupTask { public ElytronDomainSetupOverride() { super(SECURITY_DOMAIN_NAME); } } static class ServletElytronDomainSetupOverride extends ServletElytronDomainSetup { protected ServletElytronDomainSetupOverride() { super(SECURITY_DOMAIN_NAME, false); } } }
7,324
42.343195
165
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/authentication/SecureServlet.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, 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.web.authentication; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import jakarta.servlet.annotation.HttpConstraint; import jakarta.servlet.annotation.ServletSecurity; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpSession; @WebServlet(urlPatterns = { SecureServlet.SERVLET_PATH }) @ServletSecurity(@HttpConstraint(rolesAllowed = { "allowed" })) public class SecureServlet extends HttpServlet { private static final long serialVersionUID = -6366000117528193641L; private static final String SERVLET_NAME = "secure"; static final String SERVLET_PATH = "/" + SERVLET_NAME; public static final String SESSION_ID_HEADER = "session-id"; public static URI createURI(URL baseURL) throws URISyntaxException { return baseURL.toURI().resolve(SERVLET_NAME); } @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) { String sessionId = ""; HttpSession session = request.getSession(false); if (session != null) { sessionId = (String) session.getAttribute(SESSION_ID_HEADER); if (sessionId == null) { sessionId = session.getId(); session.setAttribute(SESSION_ID_HEADER, sessionId); } } response.setHeader(SESSION_ID_HEADER, sessionId); } }
2,587
40.079365
84
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/authentication/CustomAuthenticationWebFailoverTestCase.java
/* * 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.web.authentication; import static org.jboss.as.test.shared.PermissionUtils.createPermissionsXmlAsset; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import jakarta.servlet.http.HttpServletResponse; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpUriRequest; 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.arquillian.api.ServerSetup; import org.jboss.as.test.clustering.cluster.AbstractClusteringTestCase; import org.jboss.as.test.clustering.cluster.web.authentication.custom.CustomAuthenticationMechanism; import org.jboss.as.test.clustering.cluster.web.authentication.custom.LogoutServlet; import org.jboss.as.test.clustering.cluster.web.authentication.custom.SecuredServlet; import org.jboss.as.test.clustering.single.web.SimpleServlet; import org.jboss.as.test.http.util.TestHttpClientUtils; import org.jboss.as.test.shared.ManagementServerSetupTask; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.wildfly.security.permission.ElytronPermission; import org.wildfly.test.security.common.elytron.ServletElytronDomainSetup; /** * Validates that a user remains authenticated following failover when using FORM authentication. * @author Paul Ferraro */ @RunWith(Arquillian.class) @ServerSetup({ CustomAuthenticationWebFailoverTestCase.ElytronDomainSetupOverride.class, CustomAuthenticationWebFailoverTestCase.ServletElytronDomainSetupOverride.class, CustomAuthenticationWebFailoverTestCase.ServerSetup.class }) public class CustomAuthenticationWebFailoverTestCase extends AbstractClusteringTestCase { private static final String MODULE_NAME = CustomAuthenticationWebFailoverTestCase.class.getSimpleName(); private static final String SECURITY_DOMAIN_NAME = "authentication"; @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment0() { return getDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment1() { return getDeployment(); } private static Archive<?> getDeployment() { WebArchive war = ShrinkWrap.create(WebArchive.class, MODULE_NAME + ".war"); war.addPackage(SecuredServlet.class.getPackage()); war.setWebXML(SimpleServlet.class.getPackage(), "web.xml"); war.addAsWebInfResource("beans.xml", "beans.xml"); war.addAsWebInfResource(CustomAuthenticationWebFailoverTestCase.class.getPackage(), "jboss-web.xml", "jboss-web.xml"); war.addAsWebInfResource(CustomAuthenticationWebFailoverTestCase.class.getPackage(), "distributable-web.xml", "distributable-web.xml"); war.addAsManifestResource(createPermissionsXmlAsset(new ElytronPermission("getSecurityDomain"), new ElytronPermission("authenticate")), "permissions.xml"); return war; } @Test public void test( @ArquillianResource(SecuredServlet.class) @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1, @ArquillianResource(SecuredServlet.class) @OperateOnDeployment(DEPLOYMENT_2) URL baseURL2) throws IOException, URISyntaxException { URI uri1 = SecuredServlet.createURI(baseURL1); URI uri2 = SecuredServlet.createURI(baseURL2); try (CloseableHttpClient client = TestHttpClientUtils.promiscuousCookieHttpClient()) { try (CloseableHttpResponse response = client.execute(new HttpGet(uri1))) { Assert.assertEquals(HttpServletResponse.SC_UNAUTHORIZED, response.getStatusLine().getStatusCode()); Assert.assertEquals(CustomAuthenticationMechanism.CREDENTIAL_REQUIRED_MESSAGE, response.getFirstHeader(CustomAuthenticationMechanism.MESSAGE_HEADER).getValue()); } try (CloseableHttpResponse response = client.execute(new HttpGet(uri2))) { Assert.assertEquals(HttpServletResponse.SC_UNAUTHORIZED, response.getStatusLine().getStatusCode()); Assert.assertEquals(CustomAuthenticationMechanism.CREDENTIAL_REQUIRED_MESSAGE, response.getFirstHeader(CustomAuthenticationMechanism.MESSAGE_HEADER).getValue()); } HttpUriRequest request = new HttpGet(uri1); // Validate login with incorrect credentials request.setHeader(CustomAuthenticationMechanism.USERNAME_HEADER, "allowed"); request.setHeader(CustomAuthenticationMechanism.PASSWORD_HEADER, "wrong"); try (CloseableHttpResponse response = client.execute(request)) { Assert.assertEquals(HttpServletResponse.SC_UNAUTHORIZED, response.getStatusLine().getStatusCode()); Assert.assertEquals(CustomAuthenticationMechanism.INVALID_CREDENTIAL_MESSAGE, response.getFirstHeader(CustomAuthenticationMechanism.MESSAGE_HEADER).getValue()); } // Login as unauthorized user request.setHeader(CustomAuthenticationMechanism.USERNAME_HEADER, "forbidden"); request.setHeader(CustomAuthenticationMechanism.PASSWORD_HEADER, "password"); try (CloseableHttpResponse response = client.execute(request)) { Assert.assertEquals(HttpServletResponse.SC_FORBIDDEN, response.getStatusLine().getStatusCode()); } // Logout so we can login again as an authorized user try (CloseableHttpResponse response = client.execute(new HttpGet(LogoutServlet.createURI(baseURL1)))) { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); } // Validate login with correct credentials request.setHeader(CustomAuthenticationMechanism.USERNAME_HEADER, "allowed"); request.setHeader(CustomAuthenticationMechanism.PASSWORD_HEADER, "password"); try (CloseableHttpResponse response = client.execute(request)) { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertNotNull(response.getFirstHeader(SecuredServlet.PRINCIPAL_HEADER)); Assert.assertEquals("allowed", response.getFirstHeader(SecuredServlet.PRINCIPAL_HEADER).getValue()); } // Validate that subsequent request is already authenticated try (CloseableHttpResponse response = client.execute(new HttpGet(uri1))) { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertNotNull(response.getFirstHeader(SecuredServlet.PRINCIPAL_HEADER)); Assert.assertEquals("allowed", response.getFirstHeader(SecuredServlet.PRINCIPAL_HEADER).getValue()); } undeploy(DEPLOYMENT_1); // Validate that failover request is auto-authenticated try (CloseableHttpResponse response = client.execute(new HttpGet(uri2))) { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertNotNull(response.getFirstHeader(SecuredServlet.PRINCIPAL_HEADER)); Assert.assertEquals("allowed", response.getFirstHeader(SecuredServlet.PRINCIPAL_HEADER).getValue()); } deploy(DEPLOYMENT_1); // Validate that failback request is auto-authenticated try (CloseableHttpResponse response = client.execute(new HttpGet(uri1))) { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertNotNull(response.getFirstHeader(SecuredServlet.PRINCIPAL_HEADER)); Assert.assertEquals("allowed", response.getFirstHeader(SecuredServlet.PRINCIPAL_HEADER).getValue()); } // Logout try (CloseableHttpResponse response = client.execute(new HttpGet(LogoutServlet.createURI(baseURL1)))) { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); } // Verify that we are no longer authenticated on either server try (CloseableHttpResponse response = client.execute(new HttpGet(uri1))) { Assert.assertEquals(HttpServletResponse.SC_UNAUTHORIZED, response.getStatusLine().getStatusCode()); Assert.assertEquals(CustomAuthenticationMechanism.CREDENTIAL_REQUIRED_MESSAGE, response.getFirstHeader(CustomAuthenticationMechanism.MESSAGE_HEADER).getValue()); } try (CloseableHttpResponse response = client.execute(new HttpGet(uri2))) { Assert.assertEquals(HttpServletResponse.SC_UNAUTHORIZED, response.getStatusLine().getStatusCode()); Assert.assertEquals(CustomAuthenticationMechanism.CREDENTIAL_REQUIRED_MESSAGE, response.getFirstHeader(CustomAuthenticationMechanism.MESSAGE_HEADER).getValue()); } } } static class ElytronDomainSetupOverride extends ElytronDomainServerSetupTask { public ElytronDomainSetupOverride() { super(SECURITY_DOMAIN_NAME); } } static class ServletElytronDomainSetupOverride extends ServletElytronDomainSetup { protected ServletElytronDomainSetupOverride() { super(SECURITY_DOMAIN_NAME, false); } } static class ServerSetup extends ManagementServerSetupTask { ServerSetup() { super(NODE_1_2, createContainerConfigurationBuilder() .setupScript(createScriptBuilder() .startBatch() .add("/subsystem=undertow/application-security-domain=%s:write-attribute(name=integrated-jaspi, value=false)", SECURITY_DOMAIN_NAME) .endBatch() .build()) .build()); } } }
11,540
52.430556
230
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/authentication/custom/SecuredServlet.java
/* * 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.web.authentication.custom; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import jakarta.servlet.annotation.HttpConstraint; import jakarta.servlet.annotation.ServletSecurity; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; /** * @author Paul Ferraro */ @WebServlet(urlPatterns = { SecuredServlet.SERVLET_PATH }) @ServletSecurity(@HttpConstraint(rolesAllowed = { "allowed" })) public class SecuredServlet extends HttpServlet { private static final long serialVersionUID = -7525845342219183894L; private static final String SERVLET_NAME = "secured"; static final String SERVLET_PATH = "/" + SERVLET_NAME; public static final String PRINCIPAL_HEADER = "principal"; public static URI createURI(URL baseURL) throws URISyntaxException { return baseURL.toURI().resolve(SERVLET_NAME); } @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) { response.setHeader(PRINCIPAL_HEADER, request.getUserPrincipal().getName()); } }
2,246
38.421053
84
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/authentication/custom/LogoutServlet.java
/* * 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.web.authentication.custom; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; /** * @author Paul Ferraro */ @WebServlet(urlPatterns = { LogoutServlet.SERVLET_PATH }) public class LogoutServlet extends HttpServlet { private static final long serialVersionUID = -7525845342219183894L; private static final String SERVLET_NAME = "logout"; static final String SERVLET_PATH = "/" + SERVLET_NAME; public static URI createURI(URL baseURL) throws URISyntaxException { return baseURL.toURI().resolve(SERVLET_NAME); } @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException { request.logout(); } }
2,022
36.462963
108
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/authentication/custom/CustomAuthenticationMechanism.java
/* * 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.web.authentication.custom; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import jakarta.security.enterprise.AuthenticationException; import jakarta.security.enterprise.AuthenticationStatus; import jakarta.security.enterprise.authentication.mechanism.http.AutoApplySession; import jakarta.security.enterprise.authentication.mechanism.http.HttpAuthenticationMechanism; import jakarta.security.enterprise.authentication.mechanism.http.HttpMessageContext; import jakarta.security.enterprise.credential.Credential; import jakarta.security.enterprise.credential.UsernamePasswordCredential; import jakarta.security.enterprise.identitystore.CredentialValidationResult; import jakarta.security.enterprise.identitystore.CredentialValidationResult.Status; import jakarta.security.enterprise.identitystore.IdentityStoreHandler; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; /** * @author Paul Ferraro */ @AutoApplySession @ApplicationScoped public class CustomAuthenticationMechanism implements HttpAuthenticationMechanism { public static final String USERNAME_HEADER = "X-USERNAME"; public static final String PASSWORD_HEADER = "X-PASSWORD"; public static final String MESSAGE_HEADER = "X-MESSAGE"; public static final String INVALID_CREDENTIAL_MESSAGE = "Credential was not valid."; public static final String CREDENTIAL_REQUIRED_MESSAGE = "Credential is required."; @Inject private IdentityStoreHandler handler; @Override public AuthenticationStatus validateRequest(HttpServletRequest request, HttpServletResponse response, HttpMessageContext context) throws AuthenticationException { String username = request.getHeader(USERNAME_HEADER); String password = request.getHeader(PASSWORD_HEADER); if ((username != null) && (password != null)) { Credential credential = new UsernamePasswordCredential(username, password); CredentialValidationResult result = this.handler.validate(credential); if (result.getStatus() == Status.VALID) { return context.notifyContainerAboutLogin(result); } response.addHeader(MESSAGE_HEADER, INVALID_CREDENTIAL_MESSAGE); } else { response.addHeader(MESSAGE_HEADER, CREDENTIAL_REQUIRED_MESSAGE); } return context.responseUnauthorized(); } }
3,500
44.467532
166
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/web/authentication/custom/ElytronIdentityStore.java
/* * 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.web.authentication.custom; import java.util.Set; import java.util.TreeSet; import jakarta.enterprise.context.ApplicationScoped; import jakarta.security.enterprise.credential.Credential; import jakarta.security.enterprise.credential.UsernamePasswordCredential; import jakarta.security.enterprise.identitystore.CredentialValidationResult; import jakarta.security.enterprise.identitystore.IdentityStore; import org.wildfly.security.auth.server.RealmUnavailableException; import org.wildfly.security.auth.server.SecurityDomain; import org.wildfly.security.auth.server.SecurityIdentity; import org.wildfly.security.evidence.PasswordGuessEvidence; /** * @author Paul Ferraro */ @ApplicationScoped public class ElytronIdentityStore implements IdentityStore { @Override public CredentialValidationResult validate(Credential credential) { if (!(credential instanceof UsernamePasswordCredential)) { return CredentialValidationResult.INVALID_RESULT; } UsernamePasswordCredential usernamePassword = (UsernamePasswordCredential) credential; try { SecurityIdentity identity = SecurityDomain.getCurrent().authenticate(usernamePassword.getCaller(), new PasswordGuessEvidence(usernamePassword.getPassword().getValue())); Set<String> groups = new TreeSet<>(); identity.getRoles().forEach(groups::add); return new CredentialValidationResult(identity.getPrincipal().getName(), groups); } catch (RealmUnavailableException e) { return CredentialValidationResult.NOT_VALIDATED_RESULT; } catch (SecurityException e) { return CredentialValidationResult.INVALID_RESULT; } } }
2,781
41.151515
181
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/ejb/stateful/StatefulTimeoutTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.stateful; import static org.junit.Assert.assertEquals; import java.io.IOException; import java.net.URI; import java.net.URL; import jakarta.servlet.http.HttpServletResponse; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.utils.HttpClientUtils; 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; import org.jboss.as.test.clustering.cluster.ejb.stateful.bean.Incrementor; import org.jboss.as.test.clustering.cluster.ejb.stateful.bean.TimeoutIncrementorBean; import org.jboss.as.test.clustering.cluster.ejb.stateful.servlet.AbstractStatefulServlet; import org.jboss.as.test.clustering.cluster.ejb.stateful.servlet.StatefulServlet; import org.jboss.as.test.clustering.ejb.EJBDirectory; import org.jboss.as.test.http.util.TestHttpClientUtils; import org.jboss.as.test.shared.TimeoutUtil; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; /** * Validates failover of a SFSB in different contexts * @author Paul Ferraro */ @RunWith(Arquillian.class) public class StatefulTimeoutTestCase extends AbstractClusteringTestCase { private static final String MODULE_NAME = StatefulTimeoutTestCase.class.getSimpleName(); private static final long WAIT_FOR_TIMEOUT = TimeoutUtil.adjust(5000); @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment0() { return createDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment1() { return createDeployment(); } private static WebArchive createDeployment() { WebArchive war = ShrinkWrap.create(WebArchive.class, MODULE_NAME + ".war"); war.addClasses(TimeoutIncrementorBean.class, Incrementor.class); war.addClasses(StatefulServlet.class, AbstractStatefulServlet.class); war.addPackage(EJBDirectory.class.getPackage()); war.setWebXML(StatefulServlet.class.getPackage(), "web.xml"); return war; } /** * Validates that a @Stateful(passivationCapable=false) bean does not replicate */ @Test public void timeout( @ArquillianResource() @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1, @ArquillianResource() @OperateOnDeployment(DEPLOYMENT_2) URL baseURL2) throws Exception { URI uri1 = StatefulServlet.createURI(baseURL1, MODULE_NAME, TimeoutIncrementorBean.class.getSimpleName()); URI uri2 = StatefulServlet.createURI(baseURL2, MODULE_NAME, TimeoutIncrementorBean.class.getSimpleName()); try (CloseableHttpClient client = TestHttpClientUtils.promiscuousCookieHttpClient()) { assertEquals(1, queryCount(client, uri1)); assertEquals(2, queryCount(client, uri1)); // Make sure state replicated correctly assertEquals(3, queryCount(client, uri2)); assertEquals(4, queryCount(client, uri2)); Thread.sleep(WAIT_FOR_TIMEOUT); // SFSB should have timed out assertEquals(0, queryCount(client, uri1)); // Subsequent request will create it again assertEquals(1, queryCount(client, uri1)); Thread.sleep(WAIT_FOR_TIMEOUT); // Make sure SFSB times out on other node too assertEquals(0, queryCount(client, uri2)); } } private static int queryCount(HttpClient client, URI uri) throws IOException { HttpResponse response = client.execute(new HttpGet(uri)); try { assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); return Integer.parseInt(response.getFirstHeader("count").getValue()); } finally { HttpClientUtils.closeQuietly(response); } } }
5,486
40.885496
114
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/ejb/stateful/AbstractStatefulFailoverTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.stateful; import static org.junit.Assert.assertEquals; import java.io.IOException; import java.net.URI; import java.net.URL; import jakarta.servlet.http.HttpServletResponse; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.utils.HttpClientUtils; import org.apache.http.impl.client.CloseableHttpClient; import org.jboss.arquillian.container.test.api.OperateOnDeployment; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.test.clustering.cluster.AbstractClusteringTestCase; import org.jboss.as.test.clustering.cluster.ejb.stateful.bean.JDBCResourceManagerConnectionFactoryIncrementorBean; import org.jboss.as.test.clustering.cluster.ejb.stateful.bean.JMSResourceManagerConnectionFactoryIncrementorBean; import org.jboss.as.test.clustering.cluster.ejb.stateful.bean.NestedIncrementorBean; import org.jboss.as.test.clustering.cluster.ejb.stateful.bean.PassivationIncapableIncrementorBean; import org.jboss.as.test.clustering.cluster.ejb.stateful.bean.PersistenceIncrementorBean; import org.jboss.as.test.clustering.cluster.ejb.stateful.bean.SimpleIncrementorBean; import org.jboss.as.test.clustering.cluster.ejb.stateful.servlet.SessionScopedStatefulServlet; import org.jboss.as.test.clustering.cluster.ejb.stateful.servlet.StatefulServlet; import org.jboss.as.test.http.util.TestHttpClientUtils; import org.junit.Test; /** * Validates failover of a SFSB in different contexts * @author Paul Ferraro */ public abstract class AbstractStatefulFailoverTestCase extends AbstractClusteringTestCase { private final String moduleName; AbstractStatefulFailoverTestCase(String moduleName) { this.moduleName = moduleName; } /** * Validates that a @Stateful(passivationCapable=false) bean does not replicate */ @Test public void noFailover( @ArquillianResource() @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1, @ArquillianResource() @OperateOnDeployment(DEPLOYMENT_2) URL baseURL2) throws Exception { URI uri1 = StatefulServlet.createURI(baseURL1, this.moduleName, PassivationIncapableIncrementorBean.class.getSimpleName()); URI uri2 = StatefulServlet.createURI(baseURL2, this.moduleName, PassivationIncapableIncrementorBean.class.getSimpleName()); try (CloseableHttpClient client = TestHttpClientUtils.promiscuousCookieHttpClient()) { assertEquals(1, queryCount(client, uri1)); assertEquals(2, queryCount(client, uri1)); assertEquals(0, queryCount(client, uri2)); undeploy(DEPLOYMENT_2); assertEquals(1, queryCount(client, uri1)); assertEquals(2, queryCount(client, uri1)); deploy(DEPLOYMENT_2); assertEquals(3, queryCount(client, uri1)); assertEquals(4, queryCount(client, uri1)); assertEquals(0, queryCount(client, uri2)); undeploy(DEPLOYMENT_1); assertEquals(1, queryCount(client, uri2)); assertEquals(2, queryCount(client, uri2)); deploy(DEPLOYMENT_1); assertEquals(0, queryCount(client, uri1)); } } /** * Validates failover on redeploy of a simple @Stateful bean */ @Test public void simpleFailover( @ArquillianResource() @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1, @ArquillianResource() @OperateOnDeployment(DEPLOYMENT_2) URL baseURL2) throws Exception { this.failover(SimpleIncrementorBean.class, baseURL1, baseURL2); } /** * Validates failover on redeploy of a @Stateful bean containing injected JDBC resource manager connection factories * test for WFLY-30 @Resource injection of Datasource on clustered SFSB fails with serialization error */ @Test public void connectionFactoryFailover( @ArquillianResource() @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1, @ArquillianResource() @OperateOnDeployment(DEPLOYMENT_2) URL baseURL2) throws Exception { this.failover(JDBCResourceManagerConnectionFactoryIncrementorBean.class, baseURL1, baseURL2); } /** * Validates failover on redeploy of a @Stateful bean containing injected JMS resource manager connection factories */ @Test public void jmsConnectionFactoryFailover( @ArquillianResource() @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1, @ArquillianResource() @OperateOnDeployment(DEPLOYMENT_2) URL baseURL2) throws Exception { this.failover(JMSResourceManagerConnectionFactoryIncrementorBean.class, baseURL1, baseURL2); } /** * Validates failover on redeploy of a simple @Stateful bean */ @Test public void persistenceFailover( @ArquillianResource() @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1, @ArquillianResource() @OperateOnDeployment(DEPLOYMENT_2) URL baseURL2) throws Exception { this.failover(PersistenceIncrementorBean.class, baseURL1, baseURL2); } private void failover(Class<?> beanClass, URL baseURL1, URL baseURL2) throws Exception { URI uri1 = StatefulServlet.createURI(baseURL1, this.moduleName, beanClass.getSimpleName()); URI uri2 = StatefulServlet.createURI(baseURL2, this.moduleName, beanClass.getSimpleName()); this.failover(uri1, uri2); } @Test public void sessionScopedFailover( @ArquillianResource() @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1, @ArquillianResource() @OperateOnDeployment(DEPLOYMENT_2) URL baseURL2) throws Exception { URI uri1 = SessionScopedStatefulServlet.createURI(baseURL1); URI uri2 = SessionScopedStatefulServlet.createURI(baseURL2); this.failover(uri1, uri2); } private void failover(URI uri1, URI uri2) throws Exception { try (CloseableHttpClient client = TestHttpClientUtils.promiscuousCookieHttpClient()) { assertEquals(1, queryCount(client, uri1)); assertEquals(2, queryCount(client, uri1)); assertEquals(3, queryCount(client, uri2)); assertEquals(4, queryCount(client, uri2)); undeploy(DEPLOYMENT_2); assertEquals(5, queryCount(client, uri1)); assertEquals(6, queryCount(client, uri1)); deploy(DEPLOYMENT_2); assertEquals(7, queryCount(client, uri1)); assertEquals(8, queryCount(client, uri1)); assertEquals(9, queryCount(client, uri2)); assertEquals(10, queryCount(client, uri2)); undeploy(DEPLOYMENT_1); assertEquals(11, queryCount(client, uri2)); assertEquals(12, queryCount(client, uri2)); deploy(DEPLOYMENT_1); assertEquals(13, queryCount(client, uri1)); assertEquals(14, queryCount(client, uri1)); assertEquals(15, queryCount(client, uri2)); assertEquals(16, queryCount(client, uri2)); } } /** * Validates failover on server restart of a simple @Stateful bean */ @Test public void failoverOnStop( @ArquillianResource() @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1, @ArquillianResource() @OperateOnDeployment(DEPLOYMENT_2) URL baseURL2) throws Exception { URI uri1 = StatefulServlet.createURI(baseURL1, this.moduleName, SimpleIncrementorBean.class.getSimpleName()); URI uri2 = StatefulServlet.createURI(baseURL2, this.moduleName, SimpleIncrementorBean.class.getSimpleName()); try (CloseableHttpClient client = TestHttpClientUtils.promiscuousCookieHttpClient()) { assertEquals(1, queryCount(client, uri1)); assertEquals(2, queryCount(client, uri1)); assertEquals(3, queryCount(client, uri2)); assertEquals(4, queryCount(client, uri2)); stop(NODE_2); assertEquals(5, queryCount(client, uri1)); assertEquals(6, queryCount(client, uri1)); start(NODE_2); assertEquals(7, queryCount(client, uri1)); assertEquals(8, queryCount(client, uri1)); assertEquals(9, queryCount(client, uri2)); assertEquals(10, queryCount(client, uri2)); stop(NODE_1); assertEquals(11, queryCount(client, uri2)); assertEquals(12, queryCount(client, uri2)); start(NODE_1); assertEquals(13, queryCount(client, uri1)); assertEquals(14, queryCount(client, uri1)); assertEquals(15, queryCount(client, uri2)); assertEquals(16, queryCount(client, uri2)); } } /** * Validates failover of a @Stateful bean containing a nested @Stateful bean * containing an injected CDI bean that uses an interceptor and decorator. */ @Test public void nestedBeanFailover( @ArquillianResource() @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1, @ArquillianResource() @OperateOnDeployment(DEPLOYMENT_2) URL baseURL2) throws Exception { URI uri1 = StatefulServlet.createURI(baseURL1, this.moduleName, NestedIncrementorBean.class.getSimpleName()); URI uri2 = StatefulServlet.createURI(baseURL2, this.moduleName, NestedIncrementorBean.class.getSimpleName()); try (CloseableHttpClient client = TestHttpClientUtils.promiscuousCookieHttpClient()) { assertEquals(20010101, queryCount(client, uri1)); assertEquals(20020202, queryCount(client, uri1)); assertEquals(20030303, queryCount(client, uri2)); assertEquals(20040404, queryCount(client, uri2)); undeploy(DEPLOYMENT_2); assertEquals(20050505, queryCount(client, uri1)); assertEquals(20060606, queryCount(client, uri1)); deploy(DEPLOYMENT_2); assertEquals(20070707, queryCount(client, uri1)); assertEquals(20080808, queryCount(client, uri1)); assertEquals(20090909, queryCount(client, uri2)); assertEquals(20101010, queryCount(client, uri2)); undeploy(DEPLOYMENT_1); assertEquals(20111111, queryCount(client, uri2)); assertEquals(20121212, queryCount(client, uri2)); deploy(DEPLOYMENT_1); assertEquals(20131313, queryCount(client, uri1)); assertEquals(20141414, queryCount(client, uri1)); assertEquals(20151515, queryCount(client, uri2)); assertEquals(20161616, queryCount(client, uri2)); } } private static int queryCount(HttpClient client, URI uri) throws IOException { HttpResponse response = client.execute(new HttpGet(uri)); try { assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); return Integer.parseInt(response.getFirstHeader("count").getValue()); } finally { HttpClientUtils.closeQuietly(response); } } }
12,127
39.426667
131
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/ejb/stateful/ProtoStreamStatefulFailoverTestCase.java
/* * 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.stateful; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.TargetsContainer; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.test.clustering.cluster.ejb.stateful.bean.CounterDecorator; import org.jboss.as.test.clustering.cluster.ejb.stateful.bean.Incrementor; import org.jboss.as.test.clustering.cluster.ejb.stateful.bean.IncrementorDDInterceptor; import org.jboss.as.test.clustering.cluster.ejb.stateful.bean.PersistenceIncrementorBean; import org.jboss.as.test.clustering.cluster.ejb.stateful.servlet.StatefulServlet; import org.jboss.as.test.clustering.ejb.EJBDirectory; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.runner.RunWith; /** * @author Paul Ferraro */ @RunWith(Arquillian.class) public class ProtoStreamStatefulFailoverTestCase extends AbstractStatefulFailoverTestCase { private static final String MODULE_NAME = ProtoStreamStatefulFailoverTestCase.class.getSimpleName(); @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment0() { return createDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment1() { return createDeployment(); } private static WebArchive createDeployment() { WebArchive war = ShrinkWrap.create(WebArchive.class, MODULE_NAME + ".war"); war.addPackage(Incrementor.class.getPackage()); war.addPackage(StatefulServlet.class.getPackage()); war.addPackage(EJBDirectory.class.getPackage()); war.setWebXML(StatefulServlet.class.getPackage(), "web.xml"); war.addAsWebInfResource(new StringAsset("<beans bean-discovery-mode=\"all\">" + "<interceptors><class>" + IncrementorDDInterceptor.class.getName() + "</class></interceptors>" + "<decorators><class>" + CounterDecorator.class.getName() + "</class></decorators>" + "</beans>"), "beans.xml"); war.addAsResource(PersistenceIncrementorBean.class.getPackage(), "persistence.xml", "/META-INF/persistence.xml"); war.addAsWebInfResource(StatefulServlet.class.getPackage(), "distributable-web.xml", "distributable-web.xml"); return war; } public ProtoStreamStatefulFailoverTestCase() { super(MODULE_NAME); } }
3,655
45.871795
121
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/ejb/stateful/StatefulFailoverTestCase.java
/* * 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.stateful; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.TargetsContainer; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.test.clustering.cluster.ejb.stateful.bean.CounterDecorator; import org.jboss.as.test.clustering.cluster.ejb.stateful.bean.Incrementor; import org.jboss.as.test.clustering.cluster.ejb.stateful.bean.IncrementorDDInterceptor; import org.jboss.as.test.clustering.cluster.ejb.stateful.bean.PersistenceIncrementorBean; import org.jboss.as.test.clustering.cluster.ejb.stateful.servlet.StatefulServlet; import org.jboss.as.test.clustering.ejb.EJBDirectory; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.runner.RunWith; /** * @author Paul Ferraro */ @RunWith(Arquillian.class) public class StatefulFailoverTestCase extends AbstractStatefulFailoverTestCase { private static final String MODULE_NAME = StatefulFailoverTestCase.class.getSimpleName(); @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(NODE_1) public static Archive<?> deployment0() { return createDeployment(); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(NODE_2) public static Archive<?> deployment1() { return createDeployment(); } private static WebArchive createDeployment() { WebArchive war = ShrinkWrap.create(WebArchive.class, MODULE_NAME + ".war"); war.addPackage(Incrementor.class.getPackage()); war.addPackage(StatefulServlet.class.getPackage()); war.addPackage(EJBDirectory.class.getPackage()); war.setWebXML(StatefulServlet.class.getPackage(), "web.xml"); war.addAsWebInfResource(new StringAsset("<beans bean-discovery-mode=\"all\">" + "<interceptors><class>" + IncrementorDDInterceptor.class.getName() + "</class></interceptors>" + "<decorators><class>" + CounterDecorator.class.getName() + "</class></decorators>" + "</beans>"), "beans.xml"); war.addAsResource(PersistenceIncrementorBean.class.getPackage(), "persistence.xml", "/META-INF/persistence.xml"); return war; } public StatefulFailoverTestCase() { super(MODULE_NAME); } }
3,503
44.506494
121
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/ejb/stateful/servlet/StatefulServlet.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.stateful.servlet; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import javax.naming.NamingException; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpSession; import org.jboss.as.test.clustering.cluster.ejb.stateful.bean.Incrementor; import org.jboss.as.test.clustering.ejb.LocalEJBDirectory; /** * Test servlet that stores a SFSB reference within the HttpSession. * @author Paul Ferraro */ @WebServlet(urlPatterns = { StatefulServlet.SERVLET_PATH }) public class StatefulServlet extends AbstractStatefulServlet { private static final long serialVersionUID = -592774116315946908L; private static final String SERVLET_NAME = "count"; static final String SERVLET_PATH = "/" + SERVLET_NAME; private static final String MODULE = "module"; public static final String COUNT = "count"; public static final String BEAN = "bean"; public static URI createURI(URL baseURL, String module, String bean) throws URISyntaxException { StringBuilder builder = new StringBuilder(SERVLET_NAME) .append('?').append(MODULE).append('=').append(module) .append('&').append(BEAN).append('=').append(bean) ; return baseURL.toURI().resolve(builder.toString()); } @Override public Incrementor apply(HttpServletRequest request) throws ServletException { Incrementor incrementor = (Incrementor) request.getSession().getAttribute(BEAN); if (incrementor == null) { String module = getRequiredParameter(request, MODULE); String bean = getRequiredParameter(request, BEAN); try (LocalEJBDirectory directory = new LocalEJBDirectory(module)) { incrementor = directory.lookupStateful(bean, Incrementor.class); } catch (NamingException e) { throw new ServletException(e); } } return incrementor; } @Override public void accept(HttpSession session, Incrementor incrementor) { session.setAttribute(BEAN, incrementor); } private static String getRequiredParameter(HttpServletRequest req, String name) throws ServletException { String value = req.getParameter(name); if (value == null) { throw new ServletException("Missing parameter: " + name); } return value; } }
3,553
39.850575
109
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/ejb/stateful/servlet/AbstractStatefulServlet.java
/* * 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.stateful.servlet; import java.io.IOException; import java.util.function.BiConsumer; import jakarta.ejb.NoSuchEJBException; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpSession; import org.jboss.as.test.clustering.cluster.ejb.stateful.bean.Incrementor; import org.wildfly.common.function.ExceptionFunction; /** * @author Paul Ferraro */ public abstract class AbstractStatefulServlet extends HttpServlet implements ExceptionFunction<HttpServletRequest, Incrementor, ServletException>, BiConsumer<HttpSession, Incrementor> { private static final long serialVersionUID = 6443963367894900618L; public static final String MODULE = "module"; public static final String COUNT = "count"; public static final String BEAN = "bean"; @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(true); Incrementor incrementor = this.apply(request); try { response.setHeader(COUNT, String.valueOf(incrementor.increment())); this.accept(session, incrementor); } catch (NoSuchEJBException e) { response.setHeader(COUNT, String.valueOf(0)); this.accept(session, null); } response.getWriter().write("Success"); } }
2,576
40.564516
185
java
null
wildfly-main/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/ejb/stateful/servlet/SessionScopedStatefulServlet.java
/* * 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.stateful.servlet; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import jakarta.inject.Inject; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpSession; import org.jboss.as.test.clustering.cluster.ejb.stateful.bean.Incrementor; import org.jboss.as.test.clustering.cluster.ejb.stateful.bean.ScopedIncrementor; /** * Test servlet that uses a injected @SessionScoped SFSB. * @author Paul Ferraro */ @WebServlet(urlPatterns = { SessionScopedStatefulServlet.SERVLET_PATH }) public class SessionScopedStatefulServlet extends AbstractStatefulServlet { private static final long serialVersionUID = 6261258621320385992L; private static final String SERVLET_NAME = "scoped-count"; static final String SERVLET_PATH = "/" + SERVLET_NAME; public static URI createURI(URL baseURL) throws URISyntaxException { return baseURL.toURI().resolve(SERVLET_NAME); } @Inject private ScopedIncrementor bean; @Override public Incrementor apply(HttpServletRequest request) { return this.bean; } @Override public void accept(HttpSession session, Incrementor incrementor) { // SFSB is already scoped to the HttpSession. } }
2,363
35.9375
80
java