From a14c8d73d0e3da5dcb6f5ad8b4a03d9472516cab Mon Sep 17 00:00:00 2001 From: Daniel Cihak Date: Tue, 11 Jul 2023 09:27:03 +0200 Subject: [PATCH 01/42] [WFLY-18040] Tests if deployments can share client context if static interceptors are used --- .../ejb/sharedcontext/EjbClientServlet.java | 67 +++++++++ .../ejb/sharedcontext/FrontendServlet.java | 63 ++++++++ .../SharedClientContextTestCase.java | 140 ++++++++++++++++++ .../ejb/sharedcontext/TestEjb.java | 33 +++++ .../ejb/sharedcontext/TestEjbRemote.java | 26 ++++ 5 files changed, 329 insertions(+) create mode 100644 testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/sharedcontext/EjbClientServlet.java create mode 100644 testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/sharedcontext/FrontendServlet.java create mode 100644 testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/sharedcontext/SharedClientContextTestCase.java create mode 100644 testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/sharedcontext/TestEjb.java create mode 100644 testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/sharedcontext/TestEjbRemote.java diff --git a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/sharedcontext/EjbClientServlet.java b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/sharedcontext/EjbClientServlet.java new file mode 100644 index 000000000000..3b5fa5e175e5 --- /dev/null +++ b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/sharedcontext/EjbClientServlet.java @@ -0,0 +1,67 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2023, Red Hat Middleware LLC, and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.as.test.integration.ejb.sharedcontext; + +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +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 java.io.IOException; +import java.io.PrintWriter; +import java.util.Properties; + +@WebServlet(urlPatterns = "/*") +public class EjbClientServlet extends HttpServlet { + private static final String INITIAL_CONTEXT_FACTORY = "org.wildfly.naming.client.WildFlyInitialContextFactory"; + private static final String MODULE_NAME = "shared-client-context-ejb"; + private static final String PROVIDER_URL = "remote+http://localhost:8080"; + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + final PrintWriter out = resp.getWriter(); + InitialContext ctx = null; + try { + Properties props = new Properties(); + props.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY); + props.put(Context.PROVIDER_URL, PROVIDER_URL); + ctx = new InitialContext(props); + + TestEjbRemote myEjb = (TestEjbRemote) ctx.lookup("ejb:/" + MODULE_NAME + "/" + "TestEjb!" + TestEjbRemote.class.getName()); + myEjb.test(); + } catch (NamingException e) { + e.printStackTrace(out); + } finally { + if (ctx != null) { + try { + ctx.close(); + } catch (NamingException e) { + throw new RuntimeException(e); + } + } + } + } +} diff --git a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/sharedcontext/FrontendServlet.java b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/sharedcontext/FrontendServlet.java new file mode 100644 index 000000000000..d47f73bc75eb --- /dev/null +++ b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/sharedcontext/FrontendServlet.java @@ -0,0 +1,63 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2023, Red Hat Middleware LLC, and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.as.test.integration.ejb.sharedcontext; + +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletContext; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; + +/** + * Servlet shares the context for the client servlets + */ +@WebServlet(urlPatterns = "/*") +public class FrontendServlet extends HttpServlet { + + private static final int MAX_CLIENTS = 50; + public static final String FRONTEND_SERVLET_OK = "OK"; + private static final String FRONTEND_SERVLET_FAILED = "FAILED"; + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { + final PrintWriter out = resp.getWriter(); + + try { + for (int i = 0; i < MAX_CLIENTS; i++) { + String contextPath = String.format("/shared-client-context-client-%02d", i); + ServletContext context = req.getServletContext().getContext(contextPath); + if (context == null || !context.getContextPath().equals(contextPath)) { + break; + } + RequestDispatcher disp = context.getRequestDispatcher("/"); + disp.include(req, resp); + } + out.print(FrontendServlet.FRONTEND_SERVLET_OK); + } catch (Exception e) { + e.printStackTrace(); + out.print(FrontendServlet.FRONTEND_SERVLET_FAILED); + } + } +} diff --git a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/sharedcontext/SharedClientContextTestCase.java b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/sharedcontext/SharedClientContextTestCase.java new file mode 100644 index 000000000000..672bfe5d0b50 --- /dev/null +++ b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/sharedcontext/SharedClientContextTestCase.java @@ -0,0 +1,140 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2023, Red Hat Middleware LLC, and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.as.test.integration.ejb.sharedcontext; + +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; +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.junit.Arquillian; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.as.test.integration.management.base.AbstractCliTestBase; +import org.jboss.as.test.shared.TestSuiteEnvironment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.impl.base.exporter.zip.ZipExporterImpl; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +/** + * @author Daniel Cihak + * + * https://issues.redhat.com/browse/WFLY-18040 + * + * Tests if deployments can share client context if static interceptors are used. + */ +@RunWith(Arquillian.class) +@RunAsClient +public class SharedClientContextTestCase extends AbstractCliTestBase { + + private static final String EJB = "shared-client-context-ejb"; + private static final String FRONTEND = "shared-client-context-frontend"; + private static final int CLIENTS_NUMBER = 50; + private static List clientWarFiles = new ArrayList<>(); + + @ArquillianResource + @OperateOnDeployment(FRONTEND) + private URL frontendUrl; + + @Deployment(name = EJB) + public static WebArchive deployment1() { + final WebArchive archive = ShrinkWrap.create(WebArchive.class, EJB + ".war"); + archive.addClasses(TestEjbRemote.class, TestEjb.class); + return archive; + } + + @Deployment(name = FRONTEND) + public static WebArchive deployment3() { + final WebArchive archive = ShrinkWrap.create(WebArchive.class, FRONTEND + ".war"); + archive.addClasses(FrontendServlet.class); + return archive; + } + + /** + * Creates list of 50 clients trying to lookup remote bean from the other deployment + * + */ + @BeforeClass + public static void beforeClass() throws Exception { + File clientWarFile = null; + for (int i = 0; i < CLIENTS_NUMBER; i++){ + String clientWarFileName = String.format("shared-client-context-client-%02d", i); + clientWarFile = exportClientWar(clientWarFileName + ".war"); + clientWarFiles.add(clientWarFile); + } + + AbstractCliTestBase.initCLI(); + } + + private static File exportClientWar(String name) { + final WebArchive war = ShrinkWrap.create(WebArchive.class, name + ".war"); + + war.addClasses(EjbClientServlet.class, TestEjbRemote.class, TestSuiteEnvironment.class); + String tempDir = TestSuiteEnvironment.getTmpDir(); + File warFile = new File(tempDir + File.separator + name); + new ZipExporterImpl(war).exportTo(warFile, true); + return warFile; + } + + @Before + public void before() throws MalformedURLException { + for (int i = 0; i < clientWarFiles.size(); i++) { + String clientWarFileName = String.format("shared-client-context-client-%02d", i); + cli.sendLine("deploy --url=" + clientWarFiles.get(i).toURI().toURL().toExternalForm() + " --name=" + clientWarFileName + ".war --runtime-name=" + clientWarFileName + ".war"); + } + } + + @AfterClass + public static void closeCli() throws Exception { + for (int i = 0; i < clientWarFiles.size(); i++) { + clientWarFiles.get(i).delete(); + } + + AbstractCliTestBase.closeCLI(); + } + + @Test + public void testSharedClientContext() throws IOException { + try (CloseableHttpClient httpClient = HttpClients.createDefault()) { + String url = frontendUrl.toExternalForm() + "frontend"; + HttpGet httpget = new HttpGet(url); + HttpResponse response = httpClient.execute(httpget); + assertEquals("FrontEndServlet could not process the shared client context or EJB lookup failed.", FrontendServlet.FRONTEND_SERVLET_OK, EntityUtils.toString(response.getEntity())); + } + } +} diff --git a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/sharedcontext/TestEjb.java b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/sharedcontext/TestEjb.java new file mode 100644 index 000000000000..e8af3cad7d58 --- /dev/null +++ b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/sharedcontext/TestEjb.java @@ -0,0 +1,33 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2023, Red Hat Middleware LLC, and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.as.test.integration.ejb.sharedcontext; + +import jakarta.ejb.Remote; +import jakarta.ejb.Stateless; + +@Remote(TestEjbRemote.class) +@Stateless +public class TestEjb implements TestEjbRemote { + + @Override + public void test() {} +} diff --git a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/sharedcontext/TestEjbRemote.java b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/sharedcontext/TestEjbRemote.java new file mode 100644 index 000000000000..63f08fecd57e --- /dev/null +++ b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/sharedcontext/TestEjbRemote.java @@ -0,0 +1,26 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2023, Red Hat Middleware LLC, and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.as.test.integration.ejb.sharedcontext; + +public interface TestEjbRemote { + void test(); +} From 8102111f6a6a7631d7e027e828d015bdf835bc83 Mon Sep 17 00:00:00 2001 From: Yeray Borges Date: Tue, 8 Aug 2023 15:40:00 +0100 Subject: [PATCH 02/42] [WFLY-18326] Verify that jboss.server.name can be resolved as a JVM option in a managed server Jira issue: https://issues.redhat.com/browse/WFLY-18326 --- .../as/test/integration/domain/JVMServerPropertiesTestCase.java | 1 + .../src/test/resources/domain-configs/domain-jvm-properties.xml | 1 + .../test/resources/host-configs/host-primary-jvm-properties.xml | 2 ++ 3 files changed, 4 insertions(+) diff --git a/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/JVMServerPropertiesTestCase.java b/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/JVMServerPropertiesTestCase.java index b2dd09e5515f..f90242b06b1d 100644 --- a/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/JVMServerPropertiesTestCase.java +++ b/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/JVMServerPropertiesTestCase.java @@ -179,6 +179,7 @@ private void validateProperties(String server, int port, String directoryGroupin Assert.assertEquals(serverLogDir.toAbsolutePath().toString(), p.getProperty("test.jboss.server.log.dir")); Assert.assertEquals(serverDataDir.toAbsolutePath().toString(), p.getProperty("test.jboss.server.data.dir")); Assert.assertEquals(serverTmpDir.toAbsolutePath().toString(), p.getProperty("test.jboss.server.temp.dir")); + Assert.assertEquals(server, p.getProperty("test.jboss.server.name")); } private static String performHttpCall(String host, int port, String context) throws IOException { diff --git a/testsuite/domain/src/test/resources/domain-configs/domain-jvm-properties.xml b/testsuite/domain/src/test/resources/domain-configs/domain-jvm-properties.xml index dd45500504cd..36a47d8d72b0 100644 --- a/testsuite/domain/src/test/resources/domain-configs/domain-jvm-properties.xml +++ b/testsuite/domain/src/test/resources/domain-configs/domain-jvm-properties.xml @@ -478,6 +478,7 @@