commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1509129 - in /commons/sandbox/monitoring/trunk/spring: ./ src/main/java/org/apache/commons/monitoring/spring/ src/main/java/org/apache/commons/monitoring/spring/aop/ src/main/java/org/apache/commons/monitoring/spring/config/ src/test/java/...
Date Thu, 01 Aug 2013 09:02:57 GMT
Author: rmannibucau
Date: Thu Aug  1 09:02:57 2013
New Revision: 1509129

URL: http://svn.apache.org/r1509129
Log:
adding a basic test for spring module

Added:
    commons/sandbox/monitoring/trunk/spring/src/main/java/org/apache/commons/monitoring/spring/AopaliancePerformanceInterceptor.java
      - copied, changed from r1509112, commons/sandbox/monitoring/trunk/spring/src/main/java/org/apache/commons/monitoring/spring/aop/AopaliancePerformanceInterceptor.java
    commons/sandbox/monitoring/trunk/spring/src/test/java/org/
    commons/sandbox/monitoring/trunk/spring/src/test/java/org/apache/
    commons/sandbox/monitoring/trunk/spring/src/test/java/org/apache/commons/
    commons/sandbox/monitoring/trunk/spring/src/test/java/org/apache/commons/monitoring/
    commons/sandbox/monitoring/trunk/spring/src/test/java/org/apache/commons/monitoring/spring/
    commons/sandbox/monitoring/trunk/spring/src/test/java/org/apache/commons/monitoring/spring/SpringMonitoringTest.java
    commons/sandbox/monitoring/trunk/spring/src/test/java/org/apache/commons/monitoring/spring/service/
    commons/sandbox/monitoring/trunk/spring/src/test/java/org/apache/commons/monitoring/spring/service/MyService.java
    commons/sandbox/monitoring/trunk/spring/src/test/resources/monitoring.xml
Removed:
    commons/sandbox/monitoring/trunk/spring/src/main/java/org/apache/commons/monitoring/spring/AspectJMonitoringAutoProxyCreator.java
    commons/sandbox/monitoring/trunk/spring/src/main/java/org/apache/commons/monitoring/spring/MonitoringAdviceFactory.java
    commons/sandbox/monitoring/trunk/spring/src/main/java/org/apache/commons/monitoring/spring/aop/
    commons/sandbox/monitoring/trunk/spring/src/main/java/org/apache/commons/monitoring/spring/config/
Modified:
    commons/sandbox/monitoring/trunk/spring/pom.xml
    commons/sandbox/monitoring/trunk/spring/src/main/java/org/apache/commons/monitoring/spring/BeanNameMonitoringAutoProxyCreator.java
    commons/sandbox/monitoring/trunk/spring/src/main/java/org/apache/commons/monitoring/spring/PointcutMonitoringAutoProxyCreator.java

Modified: commons/sandbox/monitoring/trunk/spring/pom.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/spring/pom.xml?rev=1509129&r1=1509128&r2=1509129&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/spring/pom.xml (original)
+++ commons/sandbox/monitoring/trunk/spring/pom.xml Thu Aug  1 09:02:57 2013
@@ -23,7 +23,6 @@
     <version>1.0-SNAPSHOT</version>
   </parent>
   <modelVersion>4.0.0</modelVersion>
-  <groupId>org.apache.commons.monitoring</groupId>
   <artifactId>commons-monitoring-spring</artifactId>
   <name>Commons Monitoring (Sandbox) :: Spring Integration</name>
 
@@ -34,12 +33,7 @@
   <dependencies>
     <dependency>
       <groupId>org.springframework</groupId>
-      <artifactId>spring-context</artifactId>
-      <version>${spring.version}</version>
-    </dependency>
-    <dependency>
-      <groupId>org.springframework</groupId>
-      <artifactId>spring-beans</artifactId>
+      <artifactId>spring-aop</artifactId>
       <version>${spring.version}</version>
     </dependency>
     <dependency>
@@ -48,18 +42,7 @@
     </dependency>
     <dependency>
       <groupId>org.apache.commons.monitoring</groupId>
-      <artifactId>commons-monitoring-instrumentation</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.springframework</groupId>
-      <artifactId>spring-aop</artifactId>
-      <version>${spring.version}</version>
-    </dependency>
-    <dependency>
-      <groupId>org.springframework</groupId>
-      <artifactId>spring-web</artifactId>
-      <version>${spring.version}</version>
-      <optional>true</optional>
+      <artifactId>commons-monitoring-aop</artifactId>
     </dependency>
     <dependency>
       <groupId>aopalliance</groupId>
@@ -67,12 +50,22 @@
       <version>1.0</version>
       <optional>true</optional>
     </dependency>
+
     <dependency>
-      <groupId>javax.servlet</groupId>
-      <artifactId>servlet-api</artifactId>
-      <version>2.3</version>
-      <scope>provided</scope>
-      <optional>true</optional>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-context</artifactId>
+      <version>${spring.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-test</artifactId>
+      <version>${spring.version}</version>
+      <scope>test</scope>
     </dependency>
   </dependencies>
 </project>
\ No newline at end of file

Copied: commons/sandbox/monitoring/trunk/spring/src/main/java/org/apache/commons/monitoring/spring/AopaliancePerformanceInterceptor.java
(from r1509112, commons/sandbox/monitoring/trunk/spring/src/main/java/org/apache/commons/monitoring/spring/aop/AopaliancePerformanceInterceptor.java)
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/spring/src/main/java/org/apache/commons/monitoring/spring/AopaliancePerformanceInterceptor.java?p2=commons/sandbox/monitoring/trunk/spring/src/main/java/org/apache/commons/monitoring/spring/AopaliancePerformanceInterceptor.java&p1=commons/sandbox/monitoring/trunk/spring/src/main/java/org/apache/commons/monitoring/spring/aop/AopaliancePerformanceInterceptor.java&r1=1509112&r2=1509129&rev=1509129&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/spring/src/main/java/org/apache/commons/monitoring/spring/aop/AopaliancePerformanceInterceptor.java
(original)
+++ commons/sandbox/monitoring/trunk/spring/src/main/java/org/apache/commons/monitoring/spring/AopaliancePerformanceInterceptor.java
Thu Aug  1 09:02:57 2013
@@ -15,39 +15,30 @@
  * limitations under the License.
  */
 
-package org.apache.commons.monitoring.spring.aop;
+package org.apache.commons.monitoring.spring;
 
 import org.aopalliance.intercept.MethodInterceptor;
 import org.aopalliance.intercept.MethodInvocation;
-import org.apache.commons.monitoring.instrumentation.aop.AbstractPerformanceInterceptor;
+import org.apache.commons.monitoring.aop.AbstractPerformanceInterceptor;
 
 /**
  * Spring-aop implementation of PerformanceInterceptor.
  *
  * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
  */
-public class AopaliancePerformanceInterceptor
-    extends AbstractPerformanceInterceptor<MethodInvocation>
-    implements MethodInterceptor {
-
-    /**
-     * {@inheritDoc}
-     *
-     * @see org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation)
-     */
-    public Object invoke(MethodInvocation invocation)
-        throws Throwable {
+public class AopaliancePerformanceInterceptor extends AbstractPerformanceInterceptor<MethodInvocation>
implements MethodInterceptor {
+    @Override
+    public Object invoke(final MethodInvocation invocation) throws Throwable {
         return doInvoke(invocation);
     }
 
     @Override
-    protected String getMonitorName(MethodInvocation invocation) {
-        return getMonitorName(invocation.getMethod());
+    protected String getMonitorName(final MethodInvocation invocation) {
+        return getMonitorName(invocation.getThis(), invocation.getMethod());
     }
 
     @Override
-    protected Object proceed(MethodInvocation invocation)
-        throws Throwable {
+    protected Object proceed(final MethodInvocation invocation) throws Throwable {
         return invocation.proceed();
     }
 

Modified: commons/sandbox/monitoring/trunk/spring/src/main/java/org/apache/commons/monitoring/spring/BeanNameMonitoringAutoProxyCreator.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/spring/src/main/java/org/apache/commons/monitoring/spring/BeanNameMonitoringAutoProxyCreator.java?rev=1509129&r1=1509128&r2=1509129&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/spring/src/main/java/org/apache/commons/monitoring/spring/BeanNameMonitoringAutoProxyCreator.java
(original)
+++ commons/sandbox/monitoring/trunk/spring/src/main/java/org/apache/commons/monitoring/spring/BeanNameMonitoringAutoProxyCreator.java
Thu Aug  1 09:02:57 2013
@@ -17,9 +17,8 @@
 
 package org.apache.commons.monitoring.spring;
 
-import org.aopalliance.aop.Advice;
-import org.apache.commons.monitoring.instrumentation.aop.MonitorNameExtractor;
-import org.apache.commons.monitoring.spring.MonitoringAdviceFactory.MonitoringConfigSource;
+import org.apache.commons.monitoring.aop.DefaultMonitorNameExtractor;
+import org.apache.commons.monitoring.aop.MonitorNameExtractor;
 import org.springframework.aop.TargetSource;
 import org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator;
 
@@ -28,23 +27,17 @@ import org.springframework.aop.framework
  *
  * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
  */
-public class BeanNameMonitoringAutoProxyCreator
-    extends BeanNameAutoProxyCreator implements MonitoringConfigSource {
-    private String category;
+public class BeanNameMonitoringAutoProxyCreator extends BeanNameAutoProxyCreator {
+    private String category = "spring";
+    private MonitorNameExtractor monitorNameExtractor = DefaultMonitorNameExtractor.INSTANCE;
 
-    private MonitorNameExtractor monitorNameExtractor;
-
-    /**
-     * {@inheritDoc}
-     *
-     * @see org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator#getAdvicesAndAdvisorsForBean(java.lang.Class,
-     * java.lang.String, org.springframework.aop.TargetSource)
-     */
     @Override
-    protected Object[] getAdvicesAndAdvisorsForBean(Class beanClass, String beanName, TargetSource
targetSource) {
+    protected Object[] getAdvicesAndAdvisorsForBean(final Class beanClass, final String beanName,
final TargetSource targetSource) {
         if (super.getAdvicesAndAdvisorsForBean(beanClass, beanName, targetSource) != DO_NOT_PROXY)
{
-            Advice advice = MonitoringAdviceFactory.getAdvice(this);
-            return new Object[]{advice};
+            final AopaliancePerformanceInterceptor interceptor = new AopaliancePerformanceInterceptor();
+            interceptor.setCategory(category);
+            interceptor.setMonitorNameExtractor(monitorNameExtractor);
+            return new Object[] { interceptor };
         }
         return DO_NOT_PROXY;
     }
@@ -52,14 +45,14 @@ public class BeanNameMonitoringAutoProxy
     /**
      * @param category the category to set
      */
-    public void setCategory(String category) {
+    public void setCategory(final String category) {
         this.category = category;
     }
 
     /**
      * @param monitorNameExtractor the monitorNameExtractor to set
      */
-    public void setMonitorNameExtractor(MonitorNameExtractor monitorNameExtractor) {
+    public void setMonitorNameExtractor(final MonitorNameExtractor monitorNameExtractor)
{
         this.monitorNameExtractor = monitorNameExtractor;
     }
 

Modified: commons/sandbox/monitoring/trunk/spring/src/main/java/org/apache/commons/monitoring/spring/PointcutMonitoringAutoProxyCreator.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/spring/src/main/java/org/apache/commons/monitoring/spring/PointcutMonitoringAutoProxyCreator.java?rev=1509129&r1=1509128&r2=1509129&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/spring/src/main/java/org/apache/commons/monitoring/spring/PointcutMonitoringAutoProxyCreator.java
(original)
+++ commons/sandbox/monitoring/trunk/spring/src/main/java/org/apache/commons/monitoring/spring/PointcutMonitoringAutoProxyCreator.java
Thu Aug  1 09:02:57 2013
@@ -18,8 +18,8 @@
 package org.apache.commons.monitoring.spring;
 
 import org.aopalliance.aop.Advice;
-import org.apache.commons.monitoring.instrumentation.aop.MonitorNameExtractor;
-import org.apache.commons.monitoring.spring.MonitoringAdviceFactory.MonitoringConfigSource;
+import org.apache.commons.monitoring.aop.DefaultMonitorNameExtractor;
+import org.apache.commons.monitoring.aop.MonitorNameExtractor;
 import org.springframework.aop.Advisor;
 import org.springframework.aop.Pointcut;
 import org.springframework.aop.PointcutAdvisor;
@@ -34,26 +34,20 @@ import java.util.List;
  *
  * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
  */
-public class PointcutMonitoringAutoProxyCreator
-    extends AbstractAdvisorAutoProxyCreator
-    implements MonitoringConfigSource {
-    private String category;
-
-    private MonitorNameExtractor monitorNameExtractor;
-
+public class PointcutMonitoringAutoProxyCreator extends AbstractAdvisorAutoProxyCreator {
+    private String category = "spring";
+    private MonitorNameExtractor monitorNameExtractor = DefaultMonitorNameExtractor.INSTANCE;
     private Pointcut pointcut;
 
-    /**
-     * {@inheritDoc}
-     *
-     * @see org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator#findCandidateAdvisors()
-     */
     @Override
     protected List<Advisor> findCandidateAdvisors() {
-        List<Advisor> adivisors = new ArrayList<Advisor>(1);
+        final AopaliancePerformanceInterceptor interceptor = new AopaliancePerformanceInterceptor();
+        interceptor.setCategory(category);
+        interceptor.setMonitorNameExtractor(monitorNameExtractor);
 
-        PointcutAdvisor adivsor = createPointcutAdvisor(MonitoringAdviceFactory.getAdvice(this));
+        final PointcutAdvisor adivsor = createPointcutAdvisor(interceptor);
 
+        final List<Advisor> adivisors = new ArrayList<Advisor>(1);
         adivisors.add(adivsor);
         return adivisors;
     }
@@ -62,37 +56,22 @@ public class PointcutMonitoringAutoProxy
         return new DefaultPointcutAdvisor(pointcut, advice);
     }
 
-    /**
-     * @param category the category to set
-     */
-    public void setCategory(String category) {
+    public void setCategory(final String category) {
         this.category = category;
     }
 
-    /**
-     * @param monitorNameExtractor the monitorNameExtractor to set
-     */
-    public void setMonitorNameExtractor(MonitorNameExtractor monitorNameExtractor) {
+    public void setMonitorNameExtractor(final MonitorNameExtractor monitorNameExtractor)
{
         this.monitorNameExtractor = monitorNameExtractor;
     }
 
-    /**
-     * @param pointcut the pointcut to set
-     */
-    public void setPointcut(Pointcut pointcut) {
+    public void setPointcut(final Pointcut pointcut) {
         this.pointcut = pointcut;
     }
 
-    /**
-     * @return the category
-     */
     public String getCategory() {
         return category;
     }
 
-    /**
-     * @return the monitorNameExtractor
-     */
     public MonitorNameExtractor getMonitorNameExtractor() {
         return monitorNameExtractor;
     }

Added: commons/sandbox/monitoring/trunk/spring/src/test/java/org/apache/commons/monitoring/spring/SpringMonitoringTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/spring/src/test/java/org/apache/commons/monitoring/spring/SpringMonitoringTest.java?rev=1509129&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/spring/src/test/java/org/apache/commons/monitoring/spring/SpringMonitoringTest.java
(added)
+++ commons/sandbox/monitoring/trunk/spring/src/test/java/org/apache/commons/monitoring/spring/SpringMonitoringTest.java
Thu Aug  1 09:02:57 2013
@@ -0,0 +1,42 @@
+/*
+ * 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.commons.monitoring.spring;
+
+import org.apache.commons.monitoring.Role;
+import org.apache.commons.monitoring.monitors.Monitor;
+import org.apache.commons.monitoring.repositories.Repository;
+import org.apache.commons.monitoring.spring.service.MyService;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import static org.junit.Assert.assertEquals;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration("/monitoring.xml")
+public class SpringMonitoringTest {
+    @Autowired
+    private MyService service;
+
+    @Test
+    public void checkMonitoringIsActivated() {
+        service.doIt();
+        assertEquals(1, Repository.INSTANCE.getMonitor(new Monitor.Key(MyService.class.getName()
+ ".doIt", "spring")).getCounter(Role.PERFORMANCES).getHits());
+    }
+}

Added: commons/sandbox/monitoring/trunk/spring/src/test/java/org/apache/commons/monitoring/spring/service/MyService.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/spring/src/test/java/org/apache/commons/monitoring/spring/service/MyService.java?rev=1509129&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/spring/src/test/java/org/apache/commons/monitoring/spring/service/MyService.java
(added)
+++ commons/sandbox/monitoring/trunk/spring/src/test/java/org/apache/commons/monitoring/spring/service/MyService.java
Thu Aug  1 09:02:57 2013
@@ -0,0 +1,23 @@
+/*
+ * 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.commons.monitoring.spring.service;
+
+public class MyService {
+    public String doIt() {
+        return "ok";
+    }
+}

Added: commons/sandbox/monitoring/trunk/spring/src/test/resources/monitoring.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/spring/src/test/resources/monitoring.xml?rev=1509129&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/spring/src/test/resources/monitoring.xml (added)
+++ commons/sandbox/monitoring/trunk/spring/src/test/resources/monitoring.xml Thu Aug  1 09:02:57
2013
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans
+                           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
+
+  <bean id="service" class="org.apache.commons.monitoring.spring.service.MyService" />
+
+  <bean id="monitoringAdvisor" class="org.apache.commons.monitoring.spring.AopaliancePerformanceInterceptor"
/>
+
+  <bean class="org.apache.commons.monitoring.spring.BeanNameMonitoringAutoProxyCreator">
+    <property name="beanNames">
+      <list>
+        <value>service</value>
+      </list>
+    </property>
+    <property name="interceptorNames">
+      <list>
+        <value>monitoringAdvisor</value>
+      </list>
+    </property>
+  </bean>
+</beans>
\ No newline at end of file



Mime
View raw message