zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ph...@apache.org
Subject svn commit: r1420022 - in /zookeeper/branches/branch-3.4: ./ src/java/test/org/apache/zookeeper/test/
Date Tue, 11 Dec 2012 07:45:11 GMT
Author: phunt
Date: Tue Dec 11 07:45:09 2012
New Revision: 1420022

URL: http://svn.apache.org/viewvc?rev=1420022&view=rev
Log:
ZOOKEEPER-1564. Allow JUnit test build with IBM Java (Paulo Ricardo Paz Vital via phunt)

Modified:
    zookeeper/branches/branch-3.4/CHANGES.txt
    zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/ClientBase.java
    zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/ClientTest.java
    zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/QuorumBase.java
    zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/QuorumUtil.java

Modified: zookeeper/branches/branch-3.4/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/CHANGES.txt?rev=1420022&r1=1420021&r2=1420022&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/CHANGES.txt (original)
+++ zookeeper/branches/branch-3.4/CHANGES.txt Tue Dec 11 07:45:09 2012
@@ -7,6 +7,11 @@ BUGFIXES:
   ZOOKEEPER-1474. Cannot build Zookeeper with IBM Java: use of Sun
   MXBean classes (Adalberto Medeiros via phunt)
 
+IMPROVEMENTS:
+
+  ZOOKEEPER-1564. Allow JUnit test build with IBM Java
+    (Paulo Ricardo Paz Vital via phunt)
+
 
 Release 3.4.5 - 2012-09-30
 

Modified: zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/ClientBase.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/ClientBase.java?rev=1420022&r1=1420021&r2=1420022&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/ClientBase.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/ClientBase.java
Tue Dec 11 07:45:09 2012
@@ -25,8 +25,6 @@ import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
-import java.lang.management.ManagementFactory;
-import java.lang.management.OperatingSystemMXBean;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.LinkedList;
@@ -54,14 +52,13 @@ import org.apache.zookeeper.server.ZKDat
 import org.apache.zookeeper.server.ZooKeeperServer;
 import org.apache.zookeeper.server.persistence.FileTxnLog;
 import org.apache.zookeeper.server.quorum.QuorumPeer;
+import org.apache.zookeeper.server.util.OSMXBean;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.sun.management.UnixOperatingSystemMXBean;
-
 public abstract class ClientBase extends ZKTestCase {
     protected static final Logger LOG = LoggerFactory.getLogger(ClientBase.class);
 
@@ -393,12 +390,9 @@ public abstract class ClientBase extends
          * correctly. Unfortunately this only works on unix systems (the
          * only place sun has implemented as part of the mgmt bean api.
          */
-        OperatingSystemMXBean osMbean =
-            ManagementFactory.getOperatingSystemMXBean();
-        if (osMbean != null && osMbean instanceof UnixOperatingSystemMXBean) {
-            UnixOperatingSystemMXBean unixos =
-                (UnixOperatingSystemMXBean)osMbean;
-            initialFdCount = unixos.getOpenFileDescriptorCount();
+        OSMXBean osMbean = new OSMXBean();
+        if (osMbean.getUnix() == true) {
+            initialFdCount = osMbean.getOpenFileDescriptorCount();  	
             LOG.info("Initial fdcount is: "
                     + initialFdCount);
         }
@@ -474,12 +468,9 @@ public abstract class ClientBase extends
          * correctly. Unfortunately this only works on unix systems (the
          * only place sun has implemented as part of the mgmt bean api.
          */
-        OperatingSystemMXBean osMbean =
-            ManagementFactory.getOperatingSystemMXBean();
-        if (osMbean != null && osMbean instanceof UnixOperatingSystemMXBean) {
-            UnixOperatingSystemMXBean unixos =
-                (UnixOperatingSystemMXBean)osMbean;
-            long fdCount = unixos.getOpenFileDescriptorCount();
+        OSMXBean osMbean = new OSMXBean();
+        if (osMbean.getUnix() == true) {
+            long fdCount = osMbean.getOpenFileDescriptorCount();     
             String message = "fdcount after test is: "
                     + fdCount + " at start it was " + initialFdCount;
             LOG.info(message);

Modified: zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/ClientTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/ClientTest.java?rev=1420022&r1=1420021&r2=1420022&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/ClientTest.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/ClientTest.java
Tue Dec 11 07:45:09 2012
@@ -19,8 +19,6 @@
 package org.apache.zookeeper.test;
 
 import java.io.IOException;
-import java.lang.management.ManagementFactory;
-import java.lang.management.OperatingSystemMXBean;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -45,11 +43,10 @@ import org.apache.zookeeper.data.ACL;
 import org.apache.zookeeper.data.Id;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.server.PrepRequestProcessor;
+import org.apache.zookeeper.server.util.OSMXBean;
 import org.junit.Assert;
 import org.junit.Test;
 
-import com.sun.management.UnixOperatingSystemMXBean;
-
 public class ClientTest extends ClientBase {
     protected static final Logger LOG = LoggerFactory.getLogger(ClientTest.class);
 
@@ -709,11 +706,8 @@ public class ClientTest extends ClientBa
      */
     @Test
     public void testClientCleanup() throws Throwable {
-        OperatingSystemMXBean osMbean =
-            ManagementFactory.getOperatingSystemMXBean();
-        if (osMbean == null 
-                || !(osMbean instanceof UnixOperatingSystemMXBean))
-        {
+        OSMXBean osMbean = new OSMXBean();
+        if (osMbean.getUnix() == false) {
             LOG.warn("skipping testClientCleanup, only available on Unix");
             return;
         }
@@ -726,9 +720,7 @@ public class ClientTest extends ClientBa
          * on unix systems (the only place sun has implemented as part of the
          * mgmt bean api).
          */
-        UnixOperatingSystemMXBean unixos =
-            (UnixOperatingSystemMXBean) osMbean;
-        long initialFdCount = unixos.getOpenFileDescriptorCount();
+        long initialFdCount = osMbean.getOpenFileDescriptorCount();
 
         VerifyClientCleanup threads[] = new VerifyClientCleanup[threadCount];
 
@@ -744,7 +736,7 @@ public class ClientTest extends ClientBa
 
         // if this Assert.fails it means we are not cleaning up after the closed
         // sessions.
-        long currentCount = unixos.getOpenFileDescriptorCount();
+        long currentCount = osMbean.getOpenFileDescriptorCount();
         final String logmsg = "open fds after test ({}) are not significantly higher than
before ({})";
         
         if (currentCount > initialFdCount + 10) {

Modified: zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/QuorumBase.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/QuorumBase.java?rev=1420022&r1=1420021&r2=1420022&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/QuorumBase.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/QuorumBase.java
Tue Dec 11 07:45:09 2012
@@ -20,8 +20,6 @@ package org.apache.zookeeper.test;
 
 import java.io.File;
 import java.io.IOException;
-import java.lang.management.ManagementFactory;
-import java.lang.management.OperatingSystemMXBean;
 import java.net.InetSocketAddress;
 import java.util.HashMap;
 import java.util.LinkedHashSet;
@@ -35,10 +33,10 @@ import org.apache.zookeeper.server.quoru
 import org.apache.zookeeper.server.quorum.QuorumPeer;
 import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType;
 import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer;
+import org.apache.zookeeper.server.util.OSMXBean;
 import org.junit.Assert;
 import org.junit.Test;
 
-import com.sun.management.UnixOperatingSystemMXBean;
 
 public class QuorumBase extends ClientBase {
     private static final Logger LOG = LoggerFactory.getLogger(QuorumBase.class);
@@ -102,13 +100,10 @@ public class QuorumBase extends ClientBa
 
         startServers(withObservers);
 
-        OperatingSystemMXBean osMbean =
-            ManagementFactory.getOperatingSystemMXBean();
-        if (osMbean != null && osMbean instanceof UnixOperatingSystemMXBean) {
-            UnixOperatingSystemMXBean unixos =
-                (UnixOperatingSystemMXBean)osMbean;
+        OSMXBean osMbean = new OSMXBean();
+        if (osMbean.getUnix() == true) {
             LOG.info("Initial fdcount is: "
-                    + unixos.getOpenFileDescriptorCount());
+                    + osMbean.getOpenFileDescriptorCount());
         }
 
         LOG.info("Setup finished");
@@ -291,13 +286,10 @@ public class QuorumBase extends ClientBa
     public void tearDown() throws Exception {
         LOG.info("TearDown started");
         
-        OperatingSystemMXBean osMbean =
-            ManagementFactory.getOperatingSystemMXBean();
-        if (osMbean != null && osMbean instanceof UnixOperatingSystemMXBean) {
-            UnixOperatingSystemMXBean unixos =
-                (UnixOperatingSystemMXBean)osMbean;
+        OSMXBean osMbean = new OSMXBean();
+        if (osMbean.getUnix() == true) {
             LOG.info("fdcount after test is: "
-                    + unixos.getOpenFileDescriptorCount());
+                    + osMbean.getOpenFileDescriptorCount());
         }
 
         shutdownServers();

Modified: zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/QuorumUtil.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/QuorumUtil.java?rev=1420022&r1=1420021&r2=1420022&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/QuorumUtil.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/QuorumUtil.java
Tue Dec 11 07:45:09 2012
@@ -20,8 +20,6 @@ package org.apache.zookeeper.test;
 
 import java.io.File;
 import java.io.IOException;
-import java.lang.management.ManagementFactory;
-import java.lang.management.OperatingSystemMXBean;
 import java.net.InetSocketAddress;
 import java.util.HashMap;
 import java.util.LinkedHashSet;
@@ -35,10 +33,9 @@ import org.apache.zookeeper.server.quoru
 import org.apache.zookeeper.server.quorum.QuorumPeer;
 import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType;
 import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer;
+import org.apache.zookeeper.server.util.OSMXBean;
 import org.junit.Assert;
 
-import com.sun.management.UnixOperatingSystemMXBean;
-
 /**
  * Utility for quorum testing. Setups 2n+1 peers and allows to start/stop all
  * peers, particular peer, n peers etc.
@@ -246,10 +243,9 @@ public class QuorumUtil {
     public void tearDown() throws Exception {
         LOG.info("TearDown started");
 
-        OperatingSystemMXBean osMbean = ManagementFactory.getOperatingSystemMXBean();
-        if (osMbean != null && osMbean instanceof UnixOperatingSystemMXBean) {
-            UnixOperatingSystemMXBean unixos = (UnixOperatingSystemMXBean) osMbean;
-            LOG.info("fdcount after test is: " + unixos.getOpenFileDescriptorCount());
+        OSMXBean osMbean = new OSMXBean();
+        if (osMbean.getUnix() == true) {    
+            LOG.info("fdcount after test is: " + osMbean.getOpenFileDescriptorCount());
         }
 
         shutdownAll();



Mime
View raw message