You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by Paul Smith <ps...@aconex.com> on 2008/08/16 02:15:27 UTC

maven test phase oddity

I went and finally revisited a patch I proposed about a million years  
ago to enable testing of the JMSAppender class using ActiveMQ (Bug  
38153).

See my patch below [1].  However when I run the tests locally I'm  
getting a compile error:

...
prepare:
[available] DEPRECATED - <available> used to override an existing  
property.
[available]   Build file should not reuse the same property name for  
different values.

build:
     [javac] Compiling 2 source files to /workspace/log4j/tests/classes
/workspace/log4j/tests/src/java/org/apache/log4j/jms/ 
JMSAppenderTest.java:19: package javax.jms does not exist
import javax.jms.Connection;

We appear to run the tests via an antrun call within Maven, is that  
right?  Just curious of the rationale there, why we couldn't just make  
it a standard maven test phase.  Maybe there's a complication I'm not  
aware of, it's just not something I've had to deal with before, so I'm  
a bit confused on how to proceed.  Normally for testing under Maven  
I've just added dependencies under the test scope and been on my way.

help appreciated.

cheers,

Paul

[1] current patch


Property changes on: .
___________________________________________________________________
Modified: svn:ignore
    - goEnv*
dist
build.properties
target
surefire*
cobertura.ser
.classpath
.project
.settings
log4j.i*



    + goEnv*
dist
build.properties
target
surefire*
cobertura.ser
.classpath
.project
.settings
log4j.i*
activemq-data




Index: tests/src/java/org/apache/log4j/jms/JMSAppenderTest.java
===================================================================
--- tests/src/java/org/apache/log4j/jms/JMSAppenderTest.java	(revision  
0)
+++ tests/src/java/org/apache/log4j/jms/JMSAppenderTest.java	(revision  
0)
@@ -0,0 +1,100 @@
+/*
+ * 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.log4j.jms;
+
+import javax.jms.Connection;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.Session;
+import javax.jms.Topic;
+
+import junit.framework.TestCase;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.jndi.ActiveMQInitialContextFactory;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.net.JMSAppender;
+
+public class JMSAppenderTest extends TestCase {
+
+    public void testJMSAppender() {
+        ActiveMQConnectionFactory factory = new  
ActiveMQConnectionFactory("vm://localhost");
+        Connection conn = null;
+        try {
+            conn = factory.createConnection();
+            conn.start();
+
+             
Logger.getLogger("org.apache.activemq").setLevel(Level.OFF);
+            JMSAppender appender = new JMSAppender();
+             
appender 
.setInitialContextFactoryName 
(ActiveMQInitialContextFactory.class.getName());
+            appender.setProviderURL("vm://localhost");
+             
appender.setTopicConnectionFactoryBindingName("TopicConnectionFactory");
+            appender.setTopicBindingName("dynamicTopics/ 
jmsappendertest");
+            appender.activateOptions();
+
+            Logger.getRootLogger().addAppender(appender);
+
+            Session session = conn.createSession(false,  
Session.AUTO_ACKNOWLEDGE);
+            Topic topic = session.createTopic("jmsappendertest");
+            MessageConsumer consumer = session.createConsumer(topic);
+            TopicConsumer topicConsumer = new TopicConsumer(consumer);
+            Thread thread = new Thread(topicConsumer);
+
+
+            thread.start();
+
+            Logger.getRootLogger().info("Hello World");
+
+            thread.join();
+            assertTrue("Should have received a message",  
topicConsumer.receivedMessage);
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("Error during test");
+        } finally {
+            if (conn != null) {
+                try {
+                    conn.stop();
+                    conn.close();
+                } catch (Exception e) {
+                    e.printStackTrace();
+                    fail("Error on close/stop");
+                }
+            }
+        }
+
+    }
+
+    private static class TopicConsumer implements Runnable {
+        private boolean receivedMessage = false;
+
+        private MessageConsumer consumer;
+
+        private TopicConsumer(MessageConsumer consumer) {
+            this.consumer = consumer;
+        }
+
+        public void run() {
+            try {
+                Message message = consumer.receive(5000);
+                receivedMessage = (message != null);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+    }
+}
\ No newline at end of file
Index: tests/resources/jndi.properties
===================================================================
--- tests/resources/jndi.properties	(revision 0)
+++ tests/resources/jndi.properties	(revision 0)
@@ -0,0 +1,13 @@
+# Used by JMSAppenderTest
+#
+java.naming.factory.initial =  
org.apache.activemq.jndi.ActiveMQInitialContextFactory
+
+# use the following property to configure the default connector
+java.naming.provider.url = vm://localhost
+
+connectionFactoryNames = ConnectionFactory, QueueConnectionFactory,  
TopicConnectionFactory
+
+
+# register some topics in JNDI using the form
+# topic.[jndiName] = [physicalName]
+topic.jmsappendertest = jmsappendertest
\ No newline at end of file
Index: src/changes/changes.xml
===================================================================
--- src/changes/changes.xml	(revision 686420)
+++ src/changes/changes.xml	(working copy)
@@ -59,6 +59,7 @@
         <action action="fix" issue="40246">HierarchyDynamicMBean  
missing unregister MBean</action>
         <action action="fix" issue="45635">Support -Dm2_repo option  
on Maven build for non-default Maven repository location.</action>
         <action action="fix" issue="45636">2 tests for DateLayout are  
failing because of ill initialized DateFormat.</action>
+       <action action="add" issue="38513">Added test case for  
JMSAppender using ActiveMQ</action>
      </release>


Index: pom.xml
===================================================================
--- pom.xml	(revision 686420)
+++ pom.xml	(working copy)
@@ -443,6 +443,18 @@
        <version>1.0</version>
        <optional>true</optional>
      </dependency>
+    <dependency>
+    	<groupId>org.apache.activemq</groupId>
+    	<artifactId>activemq-core</artifactId>
+    	<version>4.1.2</version>
+    	<scope>test</scope>
+    </dependency>
+    <dependency>
+    	<groupId>org.apache.derby</groupId>
+    	<artifactId>derby</artifactId>
+    	<version>10.4.1.3</version>
+    	<scope>test</scope>
+    </dependency>
   </dependencies>
    <reporting>
      <excludeDefaults>true</excludeDefaults>


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Re: maven test phase oddity

Posted by Curt Arnold <ca...@apache.org>.
On Aug 15, 2008, at 7:15 PM, Paul Smith wrote:

> I went and finally revisited a patch I proposed about a million  
> years ago to enable testing of the JMSAppender class using ActiveMQ  
> (Bug 38153).
>
> See my patch below [1].  However when I run the tests locally I'm  
> getting a compile error:
>
> ...
> prepare:
> [available] DEPRECATED - <available> used to override an existing  
> property.
> [available]   Build file should not reuse the same property name for  
> different values.
>
> build:
>    [javac] Compiling 2 source files to /workspace/log4j/tests/classes
> /workspace/log4j/tests/src/java/org/apache/log4j/jms/ 
> JMSAppenderTest.java:19: package javax.jms does not exist
> import javax.jms.Connection;
>
> We appear to run the tests via an antrun call within Maven, is that  
> right?  Just curious of the rationale there, why we couldn't just  
> make it a standard maven test phase.  Maybe there's a complication  
> I'm not aware of, it's just not something I've had to deal with  
> before, so I'm a bit confused on how to proceed.  Normally for  
> testing under Maven I've just added dependencies under the test  
> scope and been on my way.

I fought and fought to try to get the unit tests to run under maven- 
surefire-plugin when doing the initial Maven build, but think I ran  
into a wall.  There are some artifacts of my previous attempts in the  
pom.xml file.  My earlier posts didn't jump out in the mailing list  
archives and I don't have time at the moment to cross-reference the  
changes I made to pom.xml and against my posts to try to find them to  
see exactly what I ran into.

tests/build.xml does not appear to have any JMS support in it.  I'm  
guessing this is the first test that requires JMS and that the test  
would also fail if you did:

cd tests
ant runAll

tests/build.xml needs to be kept working since it is the only  
mechanism to test on JDK 1.3 and on Gump.

You'd also need to update the Gump descriptor to make log4j-test  
depend on ActiveMQ.

jndi.properties would still need an ASF source file header license  
notice.


The following changes were enough for me to get JMSAppenderTest to  
compile for me.  There would still need to be modifications to add an  
explicit target to run the JMS test and then add the JMS test into the  
regression target.

Index: build.xml
===================================================================
--- build.xml	(revision 686147)
+++ build.xml	(working copy)
@@ -36,8 +36,11 @@
    <property name="checkstyle.jar" location="${m2_repo}/checkstyle/ 
checkstyle/${checkstyle.version}/checkstyle-${checkstyle.version}.jar"/>
    <property name="javamail.jar" location="${m2_repo}/javax/mail/mail/ 
1.4/mail-1.4.jar"/>
    <property name="activation.jar" location="${m2_repo}/javax/ 
activation/activation/1.1/activation-1.1.jar"/>
+  <property name="activemq-core.version" value="4.1.2"/>
+  <property name="activemq-core.jar" location="${m2_repo}/org/apache/ 
activemq/activemq-core/${activemq-core.version}/activemq-core-$ 
{activemq-core.version}.jar"/>
+  <property name="geronimo-jms.jar"
+           value="${m2_repo}/org/apache/geronimo/specs/geronimo- 
jms_1.1_spec/1.0/geronimo-jms_1.1_spec-1.0.jar"/>

-
    <!-- Read the system environment variables and stores them in  
properties, -->
    <!-- prefixed with "env". -->
    <property environment="env"/>
@@ -69,6 +72,8 @@
      <pathelement location="${junit.jar}"/>
      <pathelement location="${javamail.jar}"/>
      <pathelement location="${activation.jar}"/>
+    <pathelement location="${activemq-core.jar}"/>
+    <pathelement location="${geronimo-jms.jar}"/>
      <pathelement path="${java.class.path}"/>
    </path>

I'll go ahead and preemptively add the JMS dependency to Gump.  The  
derby dependency seems unrelated but there would be similar issues  
when you add whatever tests depend on it.

I'm going to be busy this weekend.  Might be able to check some  
emails, but no heavy lifting.

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org