You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by nd...@apache.org on 2009/04/24 04:53:31 UTC

svn commit: r768133 - in /harmony/enhanced/classlib/trunk/modules/lang-management/src: main/java/java/lang/management/ test/api/java/org/apache/harmony/lang/management/tests/java/lang/management/

Author: ndbeyer
Date: Fri Apr 24 02:53:31 2009
New Revision: 768133

URL: http://svn.apache.org/viewvc?rev=768133&view=rev
Log:
Apply modified patch for HARMONY-6148 - [classlib][lang-management] java.lang.management.MemoryNotificationInfo.from(CompositeData cd) should return null if the argument is null

Added:
    harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/org/apache/harmony/lang/management/tests/java/lang/management/MemoryNotificationInfoTest.java
Modified:
    harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/java/lang/management/MemoryNotificationInfo.java
    harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/java/lang/management/MemoryUsage.java
    harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/org/apache/harmony/lang/management/tests/java/lang/management/MemoryUsageTest.java

Modified: harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/java/lang/management/MemoryNotificationInfo.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/java/lang/management/MemoryNotificationInfo.java?rev=768133&r1=768132&r2=768133&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/java/lang/management/MemoryNotificationInfo.java (original)
+++ harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/java/lang/management/MemoryNotificationInfo.java Fri Apr 24 02:53:31 2009
@@ -37,11 +37,14 @@
      * </p>
      * 
      * @param cd The CompositeDate object to retrieve data from.
-     * @return A MemoryNotificationInfo instance.
+     * @return A MemoryNotificationInfo instance or {@code null} if {@code cd} is {@code null}
      * @throws IllegalArgumentException if <code>cd</code> does not contain
      *         MemoryUsage data.
      */
     public static MemoryNotificationInfo from(CompositeData cd) {
+        if (cd == null) {
+            return null;
+        }
         String poolName = (String) cd.get("poolName");
         MemoryUsage usage = MemoryUsage.from((CompositeData) cd.get("usage"));
         long count = ((Long) cd.get("count")).longValue();
@@ -62,9 +65,19 @@
      * @param poolName The memory pool name.
      * @param usage The memory usage snapshot.
      * @param count The threshold crossing count.
+     * 
+     * @throws NullPointerException if {@code poolName} or {@code usage} is {@code null}
      */
     public MemoryNotificationInfo(String poolName, MemoryUsage usage, long count) {
         super();
+        if (poolName == null) {
+            throw new NullPointerException("pooName is null"); //$NON-NLS-1$
+        }
+        
+        if (usage == null) {
+            throw new NullPointerException("usage is null"); //$NON-NLS-1$
+        }
+        
         this.poolName = poolName;
         this.usage = usage;
         this.count = count;

Modified: harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/java/lang/management/MemoryUsage.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/java/lang/management/MemoryUsage.java?rev=768133&r1=768132&r2=768133&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/java/lang/management/MemoryUsage.java (original)
+++ harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/java/lang/management/MemoryUsage.java Fri Apr 24 02:53:31 2009
@@ -39,6 +39,9 @@
      *         MemoryUsage data.
      */
     public static MemoryUsage from(CompositeData cd) {
+        if (cd == null) {
+            return null;
+        }
         try {
             long init = ((Long) cd.get("init")).longValue();
             long used = ((Long) cd.get("used")).longValue();

Added: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/org/apache/harmony/lang/management/tests/java/lang/management/MemoryNotificationInfoTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/org/apache/harmony/lang/management/tests/java/lang/management/MemoryNotificationInfoTest.java?rev=768133&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/org/apache/harmony/lang/management/tests/java/lang/management/MemoryNotificationInfoTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/org/apache/harmony/lang/management/tests/java/lang/management/MemoryNotificationInfoTest.java Fri Apr 24 02:53:31 2009
@@ -0,0 +1,90 @@
+/* 
+ * 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.harmony.lang.management.tests.java.lang.management;
+
+import java.lang.management.MemoryNotificationInfo;
+import java.lang.management.MemoryUsage;
+
+import javax.management.openmbean.CompositeData;
+
+import junit.framework.TestCase;
+
+import org.apache.harmony.lang.management.ManagementUtils;
+
+public class MemoryNotificationInfoTest extends TestCase {
+
+    public void test_Constructor_NullPoolName_NullUsage() {
+        try {
+            new MemoryNotificationInfo((String) null, (MemoryUsage) null,
+                    -4294901761L);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // Expected
+        }
+    }
+
+    public void test_Constructor_NullUsage() {
+        try {
+            new MemoryNotificationInfo("poolName", (MemoryUsage) null,
+                    -4294901761L);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // Expected
+        }
+    }
+
+    public void test_from_NullCompositeData() {
+        assertNull(MemoryNotificationInfo.from(null));
+    }
+
+    public void test_from() {
+        final MemoryUsage memoryUsage = new MemoryUsage(1, 2, 3, 4);
+        final MemoryNotificationInfo memoryNotifyInfo = new MemoryNotificationInfo("Lloyd", memoryUsage, 42);
+        
+        CompositeData compositeData = ManagementUtils
+                .toMemoryNotificationInfoCompositeData(memoryNotifyInfo);
+        MemoryNotificationInfo fromInfo = MemoryNotificationInfo
+                .from(compositeData);
+        assertEquals(memoryNotifyInfo.getPoolName(), fromInfo.getPoolName());
+        assertEquals(memoryNotifyInfo.getCount(), fromInfo.getCount());
+
+        MemoryUsage fromUsage = fromInfo.getUsage();
+        assertEquals(memoryUsage.getInit(), fromUsage.getInit());
+        assertEquals(memoryUsage.getMax(), fromUsage.getMax());
+        assertEquals(memoryUsage.getUsed(), fromUsage.getUsed());
+        assertEquals(memoryUsage.getCommitted(), fromUsage.getCommitted());
+    }
+
+    public void test_getPoolName() {
+        final MemoryUsage memoryUsage = new MemoryUsage(1, 2, 3, 4);
+        final MemoryNotificationInfo memoryNotifyInfo = new MemoryNotificationInfo("Lloyd", memoryUsage, 42);
+        assertEquals("Lloyd", memoryNotifyInfo.getPoolName());
+    }
+
+    public void test_getUsage() {
+        final MemoryUsage memoryUsage = new MemoryUsage(1, 2, 3, 4);
+        final MemoryNotificationInfo memoryNotifyInfo = new MemoryNotificationInfo("Lloyd", memoryUsage, 42);
+        assertEquals(memoryUsage, memoryNotifyInfo.getUsage());
+    }
+
+    public void test_get() {
+        final MemoryUsage memoryUsage = new MemoryUsage(1, 2, 3, 4);
+        final MemoryNotificationInfo memoryNotifyInfo = new MemoryNotificationInfo("Lloyd", memoryUsage, 42);
+        assertEquals(42, memoryNotifyInfo.getCount());
+    }
+}

Modified: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/org/apache/harmony/lang/management/tests/java/lang/management/MemoryUsageTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/org/apache/harmony/lang/management/tests/java/lang/management/MemoryUsageTest.java?rev=768133&r1=768132&r2=768133&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/org/apache/harmony/lang/management/tests/java/lang/management/MemoryUsageTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/org/apache/harmony/lang/management/tests/java/lang/management/MemoryUsageTest.java Fri Apr 24 02:53:31 2009
@@ -90,6 +90,10 @@
         }
     }
 
+    public void test_from_NullCompositeData() {
+        assertNull(MemoryUsage.from(null));
+    }
+
     public void testConstructor() {
         try {
             new MemoryUsage(-2, 2048, 4096, 8128);