You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by st...@apache.org on 2018/02/09 21:25:08 UTC
[5/5] deltaspike git commit: DELTASPIKE-1316 add unit test and enable
interceptor
DELTASPIKE-1316 add unit test and enable interceptor
Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/3734100f
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/3734100f
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/3734100f
Branch: refs/heads/master
Commit: 3734100febf7895923028a5ef836027eed2015c0
Parents: 0a914ba
Author: Mark Struberg <st...@apache.org>
Authored: Fri Feb 9 22:22:30 2018 +0100
Committer: Mark Struberg <st...@apache.org>
Committed: Fri Feb 9 22:23:05 2018 +0100
----------------------------------------------------------------------
.../impl/src/main/resources/META-INF/beans.xml | 1 +
.../test/core/impl/interdyn/InterDynTest.java | 61 +++++++++++++++++++
.../core/impl/interdyn/SomeTestService.java | 63 ++++++++++++++++++++
.../META-INF/apache-deltaspike.properties | 5 ++
4 files changed, 130 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/3734100f/deltaspike/core/impl/src/main/resources/META-INF/beans.xml
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/resources/META-INF/beans.xml b/deltaspike/core/impl/src/main/resources/META-INF/beans.xml
index 5d96bf1..e3319aa 100644
--- a/deltaspike/core/impl/src/main/resources/META-INF/beans.xml
+++ b/deltaspike/core/impl/src/main/resources/META-INF/beans.xml
@@ -24,5 +24,6 @@
<class>org.apache.deltaspike.core.impl.throttling.ThrottledInterceptor</class>
<class>org.apache.deltaspike.core.impl.lock.LockedInterceptor</class>
<class>org.apache.deltaspike.core.impl.future.FutureableInterceptor</class>
+ <class>org.apache.deltaspike.core.impl.monitoring.InvocationMonitorInterceptor</class>
</interceptors>
</beans>
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/3734100f/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/interdyn/InterDynTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/interdyn/InterDynTest.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/interdyn/InterDynTest.java
new file mode 100644
index 0000000..8264a9e
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/interdyn/InterDynTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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
+ *
+ * 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.apache.deltaspike.test.core.impl.interdyn;
+
+import org.apache.deltaspike.test.util.ArchiveUtils;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.inject.Inject;
+
+@RunWith(Arquillian.class)
+public class InterDynTest {
+
+ @Deployment
+ public static WebArchive deploy()
+ {
+ JavaArchive testJar = ShrinkWrap.create(JavaArchive.class, "InterDynTest.jar")
+ .addPackage(SomeTestService.class.getPackage().getName())
+ .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
+
+ return ShrinkWrap.create(WebArchive.class, "InterDynTest.war")
+ .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreArchive())
+ .addAsLibraries(testJar)
+ .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
+ }
+
+ @Inject
+ private SomeTestService service;
+
+ @Test
+ public void invokeServiceMethods()
+ {
+ service.enableChecking();
+
+ service.pingA();
+ service.pingB();
+ service.pingA();
+ }
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/3734100f/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/interdyn/SomeTestService.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/interdyn/SomeTestService.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/interdyn/SomeTestService.java
new file mode 100644
index 0000000..fa1adfb
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/interdyn/SomeTestService.java
@@ -0,0 +1,63 @@
+/*
+ * 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
+ *
+ * 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.apache.deltaspike.test.core.impl.interdyn;
+
+import org.apache.deltaspike.core.api.monitoring.MonitorResultEvent;
+import org.junit.Assert;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Observes;
+
+@ApplicationScoped
+public class SomeTestService
+{
+
+ private boolean check = false;
+
+ public String pingA()
+ {
+ return "a";
+ }
+
+ public String pingB()
+ {
+ try
+ {
+ Thread.sleep(30L);
+ }
+ catch (InterruptedException e) {
+ // all fine
+ }
+ return "b";
+ }
+
+ public void enableChecking()
+ {
+ this.check = true;
+ }
+
+ public void observer(@Observes MonitorResultEvent mre)
+ {
+ if (check)
+ {
+ Assert.assertTrue(mre.getClassInvocations().keySet().contains(SomeTestService.class.getName()));
+ check = false;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/3734100f/deltaspike/core/impl/src/test/resources/META-INF/apache-deltaspike.properties
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/resources/META-INF/apache-deltaspike.properties b/deltaspike/core/impl/src/test/resources/META-INF/apache-deltaspike.properties
index 2bb3fc0..d979b4c 100644
--- a/deltaspike/core/impl/src/test/resources/META-INF/apache-deltaspike.properties
+++ b/deltaspike/core/impl/src/test/resources/META-INF/apache-deltaspike.properties
@@ -55,3 +55,8 @@ deactivate.org.apache.deltaspike.test.core.impl.activation.DeactivatedClass=true
urlListFromProperties = http://127.0.0.2
prefix.suffix = done
+
+# InterDynTest
+deltaspike.interdyn.enabled=true
+deltaspike.interdyn.rule.1.match=org\\.apache\\.deltaspike\\.test\\.core\\.impl\\.interdyn\\.Some.*Service
+deltaspike.interdyn.rule.1.annotation=org.apache.deltaspike.core.api.monitoring.InvocationMonitored