PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/jboss-as-7.1.1.Final/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/SessionObjectReferenceTestCase.java

#
Java | 123 lines | 82 code | 11 blank | 30 comment | 0 complexity | ff4341e69224c47277cf2f2bd02e3875 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. /*
  2. * JBoss, Home of Professional Open Source.
  3. * Copyright (c) 2011, Red Hat, Inc., and individual contributors
  4. * as indicated by the @author tags. See the copyright.txt file in the
  5. * distribution for a full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.jboss.as.test.integration.weld.ejb;
  23. import java.beans.XMLDecoder;
  24. import java.io.ByteArrayInputStream;
  25. import java.io.IOException;
  26. import java.net.MalformedURLException;
  27. import java.net.URL;
  28. import java.util.List;
  29. import java.util.concurrent.ExecutionException;
  30. import java.util.concurrent.TimeoutException;
  31. import javax.ejb.ConcurrentAccessException;
  32. import org.jboss.arquillian.container.test.api.Deployment;
  33. import org.jboss.arquillian.container.test.api.RunAsClient;
  34. import org.jboss.arquillian.junit.Arquillian;
  35. import org.jboss.arquillian.test.api.ArquillianResource;
  36. import org.jboss.as.test.integration.common.HttpRequest;
  37. import org.jboss.shrinkwrap.api.ShrinkWrap;
  38. import org.jboss.shrinkwrap.api.asset.EmptyAsset;
  39. import org.jboss.shrinkwrap.api.asset.StringAsset;
  40. import org.jboss.shrinkwrap.api.spec.WebArchive;
  41. import org.jboss.stdio.WriterOutputStream;
  42. import org.junit.Test;
  43. import org.junit.runner.RunWith;
  44. import static java.util.concurrent.TimeUnit.SECONDS;
  45. import static org.junit.Assert.assertEquals;
  46. import static org.junit.Assert.assertTrue;
  47. /**
  48. * Test two things:
  49. * 1. EJBTHREE-697: First concurrent call doesn't throw exception
  50. * 2. make sure the SFSB is instantiated in the same thread as the Servlet, so propagation works
  51. * <p/>
  52. * Make sure a concurrent call to a SFSB proxy over Weld gets a ConcurrentAccessException.
  53. *
  54. * @author <a href="mailto:cdewolf@redhat.com">Carlo de Wolf</a>
  55. */
  56. @RunWith(Arquillian.class)
  57. @RunAsClient
  58. public class SessionObjectReferenceTestCase {
  59. @ArquillianResource
  60. private URL url;
  61. @Deployment
  62. public static WebArchive deployment() {
  63. WebArchive war = ShrinkWrap.create(WebArchive.class, "war-example.war")
  64. .addClasses(HttpRequest.class, SimpleServlet.class, SimpleStatefulSessionBean.class, WriterOutputStream.class)
  65. .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
  66. .addAsWebInfResource(new StringAsset(WEB_XML), "web.xml");
  67. return war;
  68. }
  69. private String performCall(String urlPattern, String param) {
  70. String spec = url.toExternalForm() + urlPattern + "?input=" + param;
  71. try {
  72. return HttpRequest.get(spec, 30, SECONDS);
  73. } catch (ExecutionException e) {
  74. throw new RuntimeException(e.getCause());
  75. } catch (MalformedURLException e) {
  76. throw new RuntimeException(e);
  77. } catch (TimeoutException e) {
  78. throw new RuntimeException(e);
  79. } catch (IOException e) {
  80. throw new RuntimeException(e);
  81. }
  82. }
  83. @Test
  84. public void testEcho() throws Exception {
  85. String result = performCall("simple", "Hello+world");
  86. XMLDecoder decoder = new XMLDecoder(new ByteArrayInputStream(result.getBytes()));
  87. List<String> results = (List<String>) decoder.readObject();
  88. List<Exception> exceptions = (List<Exception>) decoder.readObject();
  89. String sharedContext = (String) decoder.readObject();
  90. decoder.close();
  91. assertEquals(1, results.size());
  92. assertEquals("Echo Hello world", results.get(0));
  93. assertEquals(1, exceptions.size());
  94. assertTrue(exceptions.get(0) instanceof ConcurrentAccessException);
  95. assertEquals("Shared context", sharedContext);
  96. }
  97. private static final String WEB_XML = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" +
  98. "<!--org.jboss.as.weld.deployment.processors.WebIntegrationProcessor checks for the existence of WebMetaData -->\n" +
  99. "<web-app version=\"3.0\" xmlns=\"http://java.sun.com/xml/ns/j2ee\"\n" +
  100. " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
  101. " xsi:schemaLocation=\"http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_3_0.xsd\">\n" +
  102. " <!-- if I have a web.xml, annotations won't work anymore -->\n" +
  103. " <servlet>\n" +
  104. " <servlet-name>SimpleServlet</servlet-name>\n" +
  105. " <servlet-class>org.jboss.as.test.integration.weld.ejb.SimpleServlet</servlet-class>\n" +
  106. " </servlet>\n" +
  107. " <servlet-mapping>\n" +
  108. " <servlet-name>SimpleServlet</servlet-name>\n" +
  109. " <url-pattern>/simple</url-pattern>\n" +
  110. " </servlet-mapping>\n" +
  111. "</web-app>";
  112. }