You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by st...@apache.org on 2018/02/19 10:48:07 UTC
[22/50] tomee git commit: updating test on
examples/polling-parent/polling-mdb
updating test on examples/polling-parent/polling-mdb
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/99f35dba
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/99f35dba
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/99f35dba
Branch: refs/heads/fb_tomee8
Commit: 99f35dba833e44f732a942f48f5a019beb249c17
Parents: bba479d
Author: Thiago Veronezi <th...@veronezi.org>
Authored: Fri Jan 5 13:55:56 2018 -0500
Committer: Thiago Veronezi <th...@veronezi.org>
Committed: Fri Jan 5 13:55:56 2018 -0500
----------------------------------------------------------------------
.../openejb/assembler/classic/Assembler.java | 4 +
.../openejb/core/mdb/MdbInstanceManager.java | 11 ++-
.../openejb/core/mdb/MdbPoolContainer.java | 4 +
.../src/main/java/org/superbiz/mdb/ApiLog.java | 8 +-
.../main/java/org/superbiz/mdb/CounterBean.java | 44 +++++++++++
.../src/main/java/org/superbiz/mdb/LogMdb.java | 17 ++--
.../main/java/org/superbiz/mdb/LogsBean.java | 40 ----------
.../test/java/org/superbiz/SimpleMdbTest.java | 83 +++++++++++++++-----
8 files changed, 129 insertions(+), 82 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/99f35dba/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
index 0ac819d..e3414bb 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
@@ -2582,6 +2582,10 @@ public class Assembler extends AssemblerTool implements org.apache.openejb.spi.A
ClassLoaderUtil.destroyClassLoader(appInfo.appId, appInfo.path);
if (undeployException.getCauses().size() > 0) {
+ // logging causes here otherwise it will be eaten in later logs.
+ for (Throwable cause : undeployException.getCauses()) {
+ logger.error("undeployException original cause", cause);
+ }
throw undeployException;
}
http://git-wip-us.apache.org/repos/asf/tomee/blob/99f35dba/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbInstanceManager.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbInstanceManager.java b/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbInstanceManager.java
index 833d626..d1fcd6c 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbInstanceManager.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbInstanceManager.java
@@ -38,6 +38,7 @@ import javax.management.Attribute;
import javax.management.AttributeList;
import javax.management.AttributeNotFoundException;
import javax.management.DynamicMBean;
+import javax.management.InstanceNotFoundException;
import javax.management.InvalidAttributeValueException;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanConstructorInfo;
@@ -209,7 +210,11 @@ public class MdbInstanceManager extends InstanceManager {
}
public void undeploy(final BeanContext beanContext){
- final EndpointFactory endpointFactory = (EndpointFactory) beanContext.getContainerData();
+ final MdbPoolContainer.MdbActivationContext actContext = activationContexts.get(beanContext);
+ if (actContext == null) {
+ return;
+ }
+ final EndpointFactory endpointFactory = actContext.getEndpointFactory();
if (endpointFactory != null) {
final ObjectName jmxBeanToRemove = mbeanNames.remove(beanContext);
@@ -227,8 +232,10 @@ public class MdbInstanceManager extends InstanceManager {
for (final ObjectName objectName : jmxNames) {
try {
server.unregisterMBean(objectName);
+ } catch (final InstanceNotFoundException e) {
+ // ignore it as the object name is gone already
} catch (final Exception e) {
- logger.error("Unable to unregister MBean " + objectName);
+ logger.error("Unable to unregister MBean " + objectName, e);
}
}
}
http://git-wip-us.apache.org/repos/asf/tomee/blob/99f35dba/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbPoolContainer.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbPoolContainer.java b/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbPoolContainer.java
index df51dcf..4b3ac2d 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbPoolContainer.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbPoolContainer.java
@@ -496,6 +496,10 @@ public class MdbPoolContainer implements RpcContainer, BaseMdbContainer {
this.activationSpec = activationSpec;
}
+ public EndpointFactory getEndpointFactory() {
+ return endpointFactory;
+ }
+
public ResourceAdapter getResourceAdapter() {
return resourceAdapter;
}
http://git-wip-us.apache.org/repos/asf/tomee/blob/99f35dba/examples/polling-parent/polling-mdb/src/main/java/org/superbiz/mdb/ApiLog.java
----------------------------------------------------------------------
diff --git a/examples/polling-parent/polling-mdb/src/main/java/org/superbiz/mdb/ApiLog.java b/examples/polling-parent/polling-mdb/src/main/java/org/superbiz/mdb/ApiLog.java
index e9ab76f..28474d3 100644
--- a/examples/polling-parent/polling-mdb/src/main/java/org/superbiz/mdb/ApiLog.java
+++ b/examples/polling-parent/polling-mdb/src/main/java/org/superbiz/mdb/ApiLog.java
@@ -43,7 +43,7 @@ public class ApiLog {
private Queue vector;
@EJB
- private LogsBean logs;
+ private CounterBean logs;
@GET
@Path("/{txt}")
@@ -61,10 +61,4 @@ public class ApiLog {
return Response.ok().build();
}
- @GET
- @Path("/")
- @Produces("application/json")
- public List<String> get() {
- return logs.getMessages();
- }
}
http://git-wip-us.apache.org/repos/asf/tomee/blob/99f35dba/examples/polling-parent/polling-mdb/src/main/java/org/superbiz/mdb/CounterBean.java
----------------------------------------------------------------------
diff --git a/examples/polling-parent/polling-mdb/src/main/java/org/superbiz/mdb/CounterBean.java b/examples/polling-parent/polling-mdb/src/main/java/org/superbiz/mdb/CounterBean.java
new file mode 100644
index 0000000..0b5328b
--- /dev/null
+++ b/examples/polling-parent/polling-mdb/src/main/java/org/superbiz/mdb/CounterBean.java
@@ -0,0 +1,44 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.superbiz.mdb;
+
+import javax.ejb.Singleton;
+import javax.ejb.Startup;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.concurrent.atomic.AtomicInteger;
+
+@Singleton
+@Startup
+public class CounterBean {
+ private Map<Integer, AtomicInteger> logs = new TreeMap<>();
+
+ public void add(Integer beanId) {
+ if(!this.logs.containsKey(beanId)) {
+ this.logs.put(beanId, new AtomicInteger(0));
+ }
+ this.logs.get(beanId).incrementAndGet();
+ }
+
+ public Map<Integer, AtomicInteger> getUsage() {
+ Map<Integer, AtomicInteger> copy = new TreeMap<>();
+ copy.putAll(this.logs);
+ return copy;
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/tomee/blob/99f35dba/examples/polling-parent/polling-mdb/src/main/java/org/superbiz/mdb/LogMdb.java
----------------------------------------------------------------------
diff --git a/examples/polling-parent/polling-mdb/src/main/java/org/superbiz/mdb/LogMdb.java b/examples/polling-parent/polling-mdb/src/main/java/org/superbiz/mdb/LogMdb.java
index 0c86df5..5695e1d 100644
--- a/examples/polling-parent/polling-mdb/src/main/java/org/superbiz/mdb/LogMdb.java
+++ b/examples/polling-parent/polling-mdb/src/main/java/org/superbiz/mdb/LogMdb.java
@@ -19,30 +19,23 @@ package org.superbiz.mdb;
import javax.ejb.EJB;
import javax.ejb.MessageDriven;
-import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
-import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.atomic.AtomicInteger;
@MessageDriven(activationConfig = {
@javax.ejb.ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@javax.ejb.ActivationConfigProperty(propertyName = "destination", propertyValue = "LogMDB")
})
public class LogMdb implements MessageListener {
- private static final AtomicLong ID_MANAGER = new AtomicLong(0);
- private long id = ID_MANAGER.incrementAndGet();
- private int usageCount = 0;
+ private static final AtomicInteger ID_MANAGER = new AtomicInteger(0);
+ private int id = ID_MANAGER.incrementAndGet();
@EJB
- private LogsBean logs;
+ private CounterBean logs;
public void onMessage(Message message) {
- usageCount++;
- try {
- logs.add("BEAN_" + this.id + " [" + usageCount + "] -> " + message.getStringProperty("txt"));
- } catch (JMSException e) {
- throw new IllegalStateException(e);
- }
+ logs.add(this.id);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
http://git-wip-us.apache.org/repos/asf/tomee/blob/99f35dba/examples/polling-parent/polling-mdb/src/main/java/org/superbiz/mdb/LogsBean.java
----------------------------------------------------------------------
diff --git a/examples/polling-parent/polling-mdb/src/main/java/org/superbiz/mdb/LogsBean.java b/examples/polling-parent/polling-mdb/src/main/java/org/superbiz/mdb/LogsBean.java
deleted file mode 100644
index f9a26dc..0000000
--- a/examples/polling-parent/polling-mdb/src/main/java/org/superbiz/mdb/LogsBean.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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.superbiz.mdb;
-
-import javax.ejb.Singleton;
-import javax.ejb.Startup;
-import java.util.ArrayList;
-import java.util.List;
-
-@Singleton
-@Startup
-public class LogsBean {
- private List<String> logs = new ArrayList<>();
-
- public void add(String txt) {
- this.logs.add(txt);
- }
-
- public List<String> getMessages() {
- List<String> copy = new ArrayList<>();
- copy.addAll(this.logs);
- return copy;
- }
-}
-
http://git-wip-us.apache.org/repos/asf/tomee/blob/99f35dba/examples/polling-parent/polling-mdb/src/test/java/org/superbiz/SimpleMdbTest.java
----------------------------------------------------------------------
diff --git a/examples/polling-parent/polling-mdb/src/test/java/org/superbiz/SimpleMdbTest.java b/examples/polling-parent/polling-mdb/src/test/java/org/superbiz/SimpleMdbTest.java
index 654e3d0..d70b8d8 100644
--- a/examples/polling-parent/polling-mdb/src/test/java/org/superbiz/SimpleMdbTest.java
+++ b/examples/polling-parent/polling-mdb/src/test/java/org/superbiz/SimpleMdbTest.java
@@ -27,16 +27,22 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.superbiz.mdb.Api;
import org.superbiz.mdb.ApiLog;
+import org.superbiz.mdb.CounterBean;
import org.superbiz.mdb.LogMdb;
-import org.superbiz.mdb.LogsBean;
import javax.ejb.EJB;
-import javax.ws.rs.client.Client;
-import javax.ws.rs.client.ClientBuilder;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URISyntaxException;
import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
@RunWith(Arquillian.class)
public class SimpleMdbTest {
@@ -44,32 +50,67 @@ public class SimpleMdbTest {
@Deployment
public static WebArchive createDeployment() {
return ShrinkWrap.create(WebArchive.class)
- .addClasses(Api.class, ApiLog.class, LogMdb.class, LogsBean.class)
+ .addClasses(Api.class, ApiLog.class, LogMdb.class, CounterBean.class)
.addAsResource(new ClassLoaderAsset("META-INF/beans.xml"), "META-INF/beans.xml")
.addAsResource(new ClassLoaderAsset("META-INF/ejb-jar.xml"), "META-INF/ejb-jar.xml");
}
@ArquillianResource
- private URL baseURL;
+ private URL deploymentUrl;
@EJB
- private LogsBean logs;
+ private CounterBean logs;
@Test
public void testDataSourceOne() throws Exception {
- final Client client = ClientBuilder.newClient();
- for (int i = 0; i < 2; i++) {
- client.target(baseURL.toExternalForm())
- .request("log/lala_" + i)
- .get();
+ ExecutorService executor = Executors.newFixedThreadPool(4);
+ for (int i = 0; i < 200; i++) {
+ executor.submit(new CallGet(this.deploymentUrl, i));
}
- Thread.sleep(2000);
- List<String> expected = new ArrayList<>();
- expected.add("BEAN_1 [7] -> lala_61");
- List<String> actual = this.logs.getMessages();
- Collections.sort(expected);
- Collections.sort(actual);
- Assert.assertEquals(expected, actual);
+ executor.shutdown();
+ Assert.assertTrue("Unable to execute all the GET calls", executor.awaitTermination(10, TimeUnit.SECONDS));
+ Map<Integer, AtomicInteger> expected = new TreeMap<>();
+ expected.put(1, new AtomicInteger(20));
+ expected.put(2, new AtomicInteger(20));
+ expected.put(3, new AtomicInteger(20));
+ expected.put(4, new AtomicInteger(20));
+ expected.put(5, new AtomicInteger(20));
+ expected.put(6, new AtomicInteger(20));
+ expected.put(7, new AtomicInteger(20));
+ expected.put(8, new AtomicInteger(20));
+ expected.put(9, new AtomicInteger(20));
+ expected.put(10, new AtomicInteger(20));
+ for(int i = 0; i < 10; i++) {
+ if (expected.toString().equals(logs.getUsage().toString())) {
+ break;
+ }
+ Thread.sleep(1000);
+ }
+ Assert.assertEquals(expected.toString(), logs.getUsage().toString());
}
+ private class CallGet implements Runnable {
+ private final URL url;
+ private final int index;
+
+ private CallGet(URL url, int index) {
+ this.url = url;
+ this.index = index;
+ }
+
+ @Override
+ public void run() {
+ try {
+ HttpURLConnection conn = (HttpURLConnection) url.toURI().resolve("log/lala_" + index).toURL().openConnection();
+ conn.setRequestMethod("GET");
+ try (BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
+ while (rd.readLine() != null) {
+ // ignore
+ }
+ }
+ } catch (IOException | URISyntaxException e) {
+ // ignore
+ }
+ }
+ }
}