Tests: Java agent: update after Java agent refactoring
authorMichael Jeanson <mjeanson@efficios.com>
Tue, 4 Aug 2015 22:21:40 +0000 (18:21 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 4 Aug 2015 23:44:37 +0000 (19:44 -0400)
This patch fixes the Java agent tests which were impossible to run since
the Jar files have been renamed. It also overhauls the java part of the
configure script to match what's in UST and replace some hardcoded path
with configurable values.

The tests are now enabled when corresponding classes are found in the
CLASSPATH during configure.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
.gitignore
config/ax_check_class.m4
configure.ac
tests/regression/ust/java-jul/JTestLTTng.java
tests/regression/ust/java-jul/Makefile.am
tests/regression/ust/java-jul/test_java_jul
tests/regression/ust/java-log4j/JTestLTTng.java
tests/regression/ust/java-log4j/Makefile.am
tests/regression/ust/java-log4j/test_java_log4j

index ff19c8d0db09993f70cfee307393bcabb369c32d..5d24bec18733cc2759cec29d5beaabe7dc33d350 100644 (file)
@@ -93,3 +93,5 @@ health_check
 /benchmark/
 
 /include/version.h
+
+classnoinst.stamp
index 098aa77290b1f618f7234366cb3f6784c136284d..42b51d72c1e4f061ca09ae837218888fd93462bf 100644 (file)
@@ -118,7 +118,7 @@ EOF
                         ac_cv_prog_uudecode_base64=no
                 fi
         rm -f Test.uue
-        if AC_TRY_COMMAND($JAVA $JAVAFLAGS Test $1) >/dev/null 2>&1; then
+        if AC_TRY_COMMAND($JAVA -classpath ".:$CLASSPATH" $JAVAFLAGS Test $1) >/dev/null 2>&1; then
                 eval "ac_cv_class_$ac_var_name=yes"
         else
                 eval "ac_cv_class_$ac_var_name=no"
index 2fc6e536ca06f40fa8471bf87f2c1e78cbeb9973..bfef1785cac364cafe2c5400264ae145e45643d0 100644 (file)
@@ -355,65 +355,43 @@ AX_CONFIG_FEATURE(
 )
 AM_CONDITIONAL([COMPAT_EPOLL], [ test "$enable_epoll" = "yes" ])
 
-# Set compile flags to java include files if given. This is only used to
-# compile java agent tests.
-AC_ARG_WITH([java-jdk],
-       [AS_HELP_STRING([--with-java-jdk=DIR],[use the Java JDK in DIR. Ex : $JAVA_HOME.])],
-       [JAVA_JDK=$withval],
-       [JAVA_JDK=""]
-)
-AM_CONDITIONAL([HAVE_JAVA_JDK], [test $JAVA_JDK], [Java JDK path])
-AC_SUBST([JAVA_JDK])
+AX_JAVA_OPTIONS
+AX_PROG_JAVAC
+AX_PROG_JAVA
+AX_PROG_JAR
 
-AS_IF([test $JAVA_JDK],[
-       AS_IF([test -d $JAVA_JDK],
-               [
-                       AC_MSG_RESULT([using Java includes in $JAVA_SDK])
-                       SUBDIRS=`find $JAVA_JDK/include -type d`
-                       CPPFLAGS+=" "
-                       CPPFLAGS+=`for x in $SUBDIRS; do echo -n "-I$x "; done`
-                       CPPFLAGS+=" "
-        ],[AC_MSG_ERROR(Unable to find Java include files in $JAVA_JDK)]
-       )
-])
+AX_CHECK_CLASSPATH
 
-# Check for the UST agent jar file in the system. Hardcoded path is added here
-# since we have *no* idea where this could be installed. Note that this is only
-# used for agent testing.
-AC_MSG_CHECKING(Java UST agent jar file)
-java_agent_jar_path="${prefix}/share/java/liblttng-ust-agent.jar"
-if test -f $java_agent_jar_path; then
-       build_java_agent=yes
-       AC_MSG_RESULT(found)
+# Check for Java UST agent common class first
+AX_CHECK_CLASS(org.lttng.ust.agent.AbstractLttngAgent)
+if test "x$ac_cv_class_org_lttng_ust_agent_AbstractLttngAgent" = "xyes"; then
+       java_agent_common=yes
 else
-       build_java_agent=no
-       AC_MSG_RESULT(not found)
+       java_agent_common=no
 fi
-AM_CONDITIONAL([BUILD_JAVA_AGENT], [test "x$build_java_agent" = "xyes"])
-AC_SUBST([java_agent_jar_path])
-
-# Check for log4j support on the system to know if we can build or not the
-# log4j tests.
-if test "x$build_java_agent" = "xyes"; then
-       AC_MSG_CHECKING(Java agent support for log4j)
-       AX_JAVA_OPTIONS
-       AX_PROG_JAR
-       AX_PROG_JAVA
-       AX_PROG_JAVAC
-
-       # By default, use a commonly used classpath on the system to ease things up
-       # for the Java testing in this directory.
-       LOG4J_CLASSPATH="$java_agent_jar_path:$CLASSPATH:.:/usr/share/java/*"
-       JAVAFLAGS="-cp $LOG4J_CLASSPATH"
-       JAVACFLAGS="$JAVAFLAGS"
+
+# If the common class is available, test for each agent
+if test "x$java_agent_common" = "xyes"; then
+       # Check for JUL
+       AX_CHECK_CLASS(org.lttng.ust.agent.jul.LttngLogHandler)
+       AX_CHECK_CLASS(org.lttng.ust.agent.log4j.LttngLogAppender)
        AX_CHECK_CLASS(org.apache.log4j.Logger)
 
-       if test "x$ac_cv_class_org_apache_log4j_Logger" = "xno"; then
-               build_java_log4j_agent=no
-       else
-               build_java_log4j_agent=yes
+       build_java_jul_agent=no
+       if test "x$ac_cv_class_org_lttng_ust_agent_jul_LttngLogHandler" = "xyes"; then
+               build_java_jul_agent=yes
        fi
+
+       build_java_log4j_agent=no
+       if test "x$ac_cv_class_org_lttng_ust_agent_log4j_LttngLogAppender" = "xyes"; then
+               if test "x$ac_cv_class_org_apache_log4j_Logger" = "xyes"; then
+                       build_java_log4j_agent=yes
+               fi
+       fi
+
 fi
+
+AM_CONDITIONAL([BUILD_JAVA_JUL_AGENT], [test "x$build_java_jul_agent" = "xyes"])
 AM_CONDITIONAL([BUILD_JAVA_LOG4J_AGENT], [test "x$build_java_log4j_agent" = "xyes"])
 
 AC_SYS_LARGEFILE
index 9431551cdb4a580c2e06ff92b96f694f90cdcd01..741d820321425148719d59a5d48437c8a18fd13b 100644 (file)
@@ -1,4 +1,5 @@
 /*
+ * Copyright (C) 2015 - Michael Jeanson <mjeanson@efficios.com>
  * Copyright (C) 2013 - David Goulet <dgoulet@efficios.com>
  *
  * This program is free software; you can redistribute it and/or modify it
  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
+import java.io.IOException;
 import java.lang.Integer;
+import java.util.logging.Handler;
 import java.util.logging.Logger;
 import java.util.logging.Level;
 
-import org.lttng.ust.agent.LTTngAgent;
+import org.lttng.ust.agent.jul.LttngLogHandler;
 
-public class JTestLTTng
-{
-       private static LTTngAgent lttngAgent;
+public class JTestLTTng {
+
+       /**
+        * Application start
+        *
+        * @param args
+        *            Command-line arguments
+        * @throws IOException
+        * @throws InterruptedException
+        */
+       public static void main(String args[]) throws IOException, InterruptedException {
 
-       public static void main(String args[]) throws Exception
-       {
                Logger lttng = Logger.getLogger("JTestLTTng");
                Logger lttng2 = Logger.getLogger("JTestLTTng2");
+
                int nrIter = Integer.parseInt(args[0]);
                int waitTime = Integer.parseInt(args[1]);
                int fire_finest_tp = 0;
@@ -41,7 +51,11 @@ public class JTestLTTng
                        fire_second_tp = Integer.parseInt(args[3]);
                }
 
-               lttngAgent = LTTngAgent.getLTTngAgent();
+               /* Instantiate a LTTngLogHandler object, and attach it to our loggers */
+               Handler lttngHandler = new LttngLogHandler();
+               lttng.addHandler(lttngHandler);
+               lttng2.addHandler(lttngHandler);
+
                lttng.setLevel(Level.FINEST);
 
                for (int iter = 0; iter < nrIter; iter++) {
@@ -57,6 +71,10 @@ public class JTestLTTng
                        lttng2.info("JUL second logger fired");
                }
 
-               lttngAgent.dispose();
+               /*
+                * Do not forget to close() all handlers so that the agent can shutdown
+                * and the session daemon socket gets cleaned up explicitly.
+                */
+               lttngHandler.close();
        }
 }
index 286e3df2293611f2888cbd8603529de6c5eea937..877237fffd02d47d37c65630f18b226e34a51836 100644 (file)
@@ -1,25 +1,13 @@
+JAVAROOT = .
 
 noinst_SCRIPTS = test_java_jul JTestLTTng.java
 EXTRA_DIST = test_java_jul JTestLTTng.java
 
-if HAVE_JAVA_JDK
-JCC=$(JAVA_JDK)/bin/javac
-else
-JCC=javac
-endif
+if BUILD_JAVA_JUL_AGENT
+dist_noinst_JAVA = JTestLTTng.java
+endif # BUILD_JAVA_JUL_AGENT
 
-AGENT_JAR_FILE=$(java_agent_jar_path)
-
-
-# Still need to copy test files in case of out of tree build
-if BUILD_JAVA_AGENT
-all-local: static_file JTestLTTng.class
-%.class: %.java
-       $(JCC) -d "$(builddir)" -cp "$(AGENT_JAR_FILE):." $<
-else
 all-local: static_file
-endif # BUILD_JAVA_AGENT
-
 
 static_file:
        @if [ x"$(srcdir)" != x"$(builddir)" ]; then \
@@ -28,7 +16,6 @@ static_file:
                done; \
        fi
 
-
 clean-local:
        rm -f *.class
        @if [ x"$(srcdir)" != x"$(builddir)" ]; then \
index 48c8b7401c7e5721d26223a6d10bed72ebf2d4d1..f9f244b61611523be8d030eddc55d6fd22e6b85c 100755 (executable)
@@ -27,7 +27,7 @@ TESTAPP_PATH="$CURDIR/$TESTAPP_NAME"
 SESSION_NAME="jul"
 EVENT_NAME="JTestLTTng"
 EVENT_NAME2="JTestLTTng2"
-JAVA_CP="$CURDIR:/usr/local/share/java/liblttng-ust-agent.jar:/usr/share/java/liblttng-ust-agent.jar"
+JAVA_CP="$CURDIR:$CLASSPATH"
 
 NUM_TESTS=155
 
@@ -39,7 +39,7 @@ function run_app
        local fire_second_tp=$2
 
        #FIXME: app should have synchro.
-       java -cp $JAVA_CP -Djava.library.path="/usr/local/lib:/usr/lib" $TESTAPP_NAME $NR_ITER $NR_MSEC_WAIT $finest_tp $fire_second_tp >/dev/null 2>&1
+       java -cp $JAVA_CP -Djava.library.path="$LD_LIBRARY_PATH:/usr/local/lib:/usr/lib" $TESTAPP_NAME $NR_ITER $NR_MSEC_WAIT $finest_tp $fire_second_tp >/dev/null 2>&1
 }
 
 function run_app_background
index 0019cb825b7d4fff1a4163d5a1fb3e102540df2d..64a471bf85607ffe6238f5ced8b6d436cc73a875 100644 (file)
@@ -1,4 +1,5 @@
 /*
+ * Copyright (C) 2015 - Michael Jeanson <dgoulet@efficios.com>
  * Copyright (C) 2014 - David Goulet <dgoulet@efficios.com>
  *                      Christian Babeux <christian.babeux@efficios.com>
  *
 import java.io.IOException;
 import java.lang.Integer;
 
-import org.apache.log4j.Logger;
+import org.apache.log4j.Appender;
 import org.apache.log4j.BasicConfigurator;
+import org.apache.log4j.Logger;
+import org.lttng.ust.agent.log4j.LttngLogAppender;
 
-import org.lttng.ust.agent.LTTngAgent;
+public class JTestLTTng {
 
-public class JTestLTTng
-{
-       private static LTTngAgent lttngAgent;
+       /**
+        * Application start
+        *
+        * @param args
+        *            Command-line arguments
+        * @throws IOException
+        * @throws InterruptedException
+        */
+       public static void main(String args[]) throws IOException, InterruptedException {
 
-       public static void main(String args[]) throws Exception
-       {
                Logger lttng = Logger.getLogger("log4j-event");
                Logger lttng2 = Logger.getLogger("log4j-event-2");
+
                int nrIter = Integer.parseInt(args[0]);
                int waitTime = Integer.parseInt(args[1]);
                int fire_debug_tp = 0;
@@ -44,8 +52,16 @@ public class JTestLTTng
                        fire_second_tp = Integer.parseInt(args[3]);
                }
 
+               /* Start with the default Log4j configuration, which logs to console */
                BasicConfigurator.configure();
-               lttngAgent = LTTngAgent.getLTTngAgent();
+
+               /*
+                * Add a LTTng log appender to both loggers, which will also send the
+                * logged events to UST.
+                */
+               Appender lttngAppender = new LttngLogAppender();
+               lttng.addAppender(lttngAppender);
+               lttng2.addAppender(lttngAppender);
 
                for (int iter = 0; iter < nrIter; iter++) {
                        lttng.info("LOG4J tp fired!");
@@ -59,5 +75,11 @@ public class JTestLTTng
                if (fire_second_tp == 1) {
                        lttng2.info("LOG4J second logger fired");
                }
+
+               /*
+                * Do not forget to close() all handlers so that the agent can shutdown
+                * and the session daemon socket gets cleaned up explicitly.
+                */
+               lttngAppender.close();
        }
 }
index 7d6c0481a0997629587a9183299560b5b32972e7..42daab81b85d9d51c908a8c97de759e5950ab6d1 100644 (file)
@@ -1,24 +1,13 @@
+JAVAROOT = .
 
 noinst_SCRIPTS = test_java_log4j JTestLTTng.java
 EXTRA_DIST = test_java_log4j JTestLTTng.java
 
-if HAVE_JAVA_JDK
-JCC=$(JAVA_JDK)/bin/javac
-else
-JCC=javac
-endif
-
-# We still need to copy static files for out of tree and dist build
 if BUILD_JAVA_LOG4J_AGENT
-all-local: static_file JTestLTTng.class
-
-%.class: %.java
-       $(JCC) -d "$(builddir)" $(JAVACFLAGS) $<
-else
-all-local: static_file
+dist_noinst_JAVA = JTestLTTng.java
 endif # BUILD_JAVA_LOG4J_AGENT
 
-JTestLTTng.class: JTestLTTng.java
+all-local: static_file
 
 static_file:
        @if [ x"$(srcdir)" != x"$(builddir)" ]; then \
index cdc0c4c34470c6751da5b9ebdfbc9af62c975825..d5c66218476986529f3acb29f5d2a327d697c24e 100755 (executable)
@@ -27,7 +27,7 @@ TESTAPP_PATH="$CURDIR/$TESTAPP_NAME"
 SESSION_NAME="log4j"
 EVENT_NAME="log4j-event"
 EVENT_NAME2="log4j-event-2"
-JAVA_CP="$CURDIR:/usr/local/share/java/liblttng-ust-agent.jar:/usr/share/java/*"
+JAVA_CP="$CURDIR:$CLASSPATH"
 OUTPUT_DEST="/dev/null"
 
 NUM_TESTS=155
@@ -40,7 +40,7 @@ function run_app
        local fire_second_tp=$2
 
        # FIXME: test app should have synchro.
-       java -cp $JAVA_CP -Djava.library.path="/usr/local/lib:/usr/lib" $TESTAPP_NAME $NR_ITER $NR_MSEC_WAIT $debug_tp $fire_second_tp >/dev/null 2>&1
+       java -cp $JAVA_CP -Djava.library.path="$LD_LIBRARY_PATH:/usr/local/lib:/usr/lib" $TESTAPP_NAME $NR_ITER $NR_MSEC_WAIT $debug_tp $fire_second_tp >/dev/null 2>&1
 }
 
 function run_app_background
This page took 0.032365 seconds and 4 git commands to generate.