changeset 258:5b803a3098d6

Fix memory space name regression Reviewed-by: neugens, rkennke Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-April/001016.html
author Omair Majid <omajid@redhat.com>
date Mon, 23 Apr 2012 10:12:55 -0400
parents 9c2e7e00665c
children 04338ff62c91
files common/src/main/java/com/redhat/thermostat/common/dao/VmMemoryStatConverter.java common/src/main/java/com/redhat/thermostat/common/dao/VmMemoryStatDAO.java common/src/test/java/com/redhat/thermostat/common/dao/VmMemoryStatConverterTest.java
diffstat 3 files changed, 88 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/common/src/main/java/com/redhat/thermostat/common/dao/VmMemoryStatConverter.java	Mon Apr 23 12:22:09 2012 +0200
+++ b/common/src/main/java/com/redhat/thermostat/common/dao/VmMemoryStatConverter.java	Mon Apr 23 10:12:55 2012 -0400
@@ -115,7 +115,7 @@
         newGen.collector = chunk.get(VmMemoryStatDAO.edenCollectorKey);
 
         space = new Space();
-        space.name = chunk.get(VmMemoryStatDAO.edenGenKey);
+        space.name = VmMemoryStatDAO.edenKey.getName();
         space.capacity = chunk.get(VmMemoryStatDAO.edenCapacityKey);
         space.maxCapacity = chunk.get(VmMemoryStatDAO.edenMaxCapacityKey);
         space.used = chunk.get(VmMemoryStatDAO.edenUsedKey);
@@ -124,7 +124,7 @@
         newGen.maxCapacity += space.maxCapacity;
 
         space = new Space();
-        space.name = chunk.get(VmMemoryStatDAO.s0GenKey);
+        space.name = VmMemoryStatDAO.s0Key.getName();
         space.capacity = chunk.get(VmMemoryStatDAO.s0CapacityKey);
         space.maxCapacity = chunk.get(VmMemoryStatDAO.s0MaxCapacityKey);
         space.used = chunk.get(VmMemoryStatDAO.s0UsedKey);
@@ -133,7 +133,7 @@
         newGen.maxCapacity += space.maxCapacity;
 
         space = new Space();
-        space.name = chunk.get(VmMemoryStatDAO.s1GenKey);
+        space.name = VmMemoryStatDAO.s1Key.getName();
         space.capacity = chunk.get(VmMemoryStatDAO.s1CapacityKey);
         space.maxCapacity = chunk.get(VmMemoryStatDAO.s1MaxCapacityKey);
         space.used = chunk.get(VmMemoryStatDAO.s1UsedKey);
@@ -150,7 +150,7 @@
         oldGen.collector = chunk.get(VmMemoryStatDAO.oldCollectorKey);
 
         space = new Space();
-        space.name = chunk.get(VmMemoryStatDAO.oldGenKey);
+        space.name = VmMemoryStatDAO.oldKey.getName();
         space.capacity = chunk.get(VmMemoryStatDAO.oldCapacityKey);
         space.maxCapacity = chunk.get(VmMemoryStatDAO.oldMaxCapacityKey);
         space.used = chunk.get(VmMemoryStatDAO.oldUsedKey);
@@ -167,7 +167,7 @@
         permGen.collector = chunk.get(VmMemoryStatDAO.permCollectorKey);
 
         space = new Space();
-        space.name = chunk.get(VmMemoryStatDAO.permGenKey);
+        space.name = VmMemoryStatDAO.permKey.getName();
         space.capacity = chunk.get(VmMemoryStatDAO.permCapacityKey);
         space.maxCapacity = chunk.get(VmMemoryStatDAO.permMaxCapacityKey);
         space.used = chunk.get(VmMemoryStatDAO.permUsedKey);
--- a/common/src/main/java/com/redhat/thermostat/common/dao/VmMemoryStatDAO.java	Mon Apr 23 12:22:09 2012 +0200
+++ b/common/src/main/java/com/redhat/thermostat/common/dao/VmMemoryStatDAO.java	Mon Apr 23 10:12:55 2012 -0400
@@ -42,30 +42,35 @@
 
 public interface VmMemoryStatDAO {
 
+    static final Key<String> edenKey = new Key<>("eden", false);
     static final Key<String> edenGenKey = new Key<>("eden.gen", false);
     static final Key<String> edenCollectorKey = new Key<>("eden.collector", false);
     static final Key<Long> edenCapacityKey = new Key<>("eden.capacity", false);
     static final Key<Long> edenMaxCapacityKey = new Key<>("eden.max-capacity", false);
     static final Key<Long> edenUsedKey = new Key<>("eden.used", false);
 
+    static final Key<String> s0Key = new Key<>("s0", false);
     static final Key<String> s0GenKey = new Key<>("s0.gen", false);
     static final Key<String> s0CollectorKey = new Key<>("s0.collector", false);
     static final Key<Long> s0CapacityKey = new Key<>("s0.capacity", false);
     static final Key<Long> s0MaxCapacityKey = new Key<>("s0.max-capacity", false);
     static final Key<Long> s0UsedKey = new Key<>("s0.used", false);
 
+    static final Key<String> s1Key = new Key<>("s1", false);
     static final Key<String> s1GenKey = new Key<>("s1.gen", false);
     static final Key<String> s1CollectorKey = new Key<>("s1.collector", false);
     static final Key<Long> s1CapacityKey = new Key<>("s1.capacity", false);
     static final Key<Long> s1MaxCapacityKey = new Key<>("s1.max-capacity", false);
     static final Key<Long> s1UsedKey = new Key<>("s1.used", false);
 
+    static final Key<String> oldKey = new Key<>("old", false);
     static final Key<String> oldGenKey = new Key<>("old.gen", false);
     static final Key<String> oldCollectorKey = new Key<>("old.collector", false);
     static final Key<Long> oldCapacityKey = new Key<>("old.capacity", false);
     static final Key<Long> oldMaxCapacityKey = new Key<>("old.max-capacity", false);
     static final Key<Long> oldUsedKey = new Key<>("old.used", false);
 
+    static final Key<String> permKey = new Key<>("perm", false);
     static final Key<String> permGenKey = new Key<>("perm.gen", false);
     static final Key<String> permCollectorKey = new Key<>("perm.collector", false);
     static final Key<Long> permCapacityKey = new Key<>("perm.capacity", false);
--- a/common/src/test/java/com/redhat/thermostat/common/dao/VmMemoryStatConverterTest.java	Mon Apr 23 12:22:09 2012 +0200
+++ b/common/src/test/java/com/redhat/thermostat/common/dao/VmMemoryStatConverterTest.java	Mon Apr 23 10:12:55 2012 -0400
@@ -122,6 +122,26 @@
         final long TIMESTAMP = 1234l;
         final int VM_ID = 4567;
 
+        final long EDEN_USED = 1;
+        final long EDEN_CAPACITY = 2;
+        final long EDEN_MAX_CAPACITY = 3;
+        
+        final long S0_USED = 4;
+        final long S0_CAPACITY = 5;
+        final long S0_MAX_CAPACITY = 6;
+        
+        final long S1_USED = 7;
+        final long S1_CAPACITY = 8;
+        final long S1_MAX_CAPACITY = 9;
+        
+        final long OLD_USED = 10;
+        final long OLD_CAPACITY = 11;
+        final long OLD_MAX_CAPACITY = 12;
+        
+        final long PERM_USED = 13;
+        final long PERM_CAPACITY = 14;
+        final long PERM_MAX_CAPACITY = 15;
+        
         Chunk chunk = new Chunk(VmMemoryStatDAO.vmMemoryStatsCategory, false);
 
         chunk.put(Key.TIMESTAMP, TIMESTAMP);
@@ -129,33 +149,33 @@
 
         chunk.put(VmMemoryStatDAO.edenGenKey, "new");
         chunk.put(VmMemoryStatDAO.edenCollectorKey, "new-collector");
-        chunk.put(VmMemoryStatDAO.edenUsedKey, 1l);
-        chunk.put(VmMemoryStatDAO.edenCapacityKey, 2l);
-        chunk.put(VmMemoryStatDAO.edenMaxCapacityKey, 3l);
+        chunk.put(VmMemoryStatDAO.edenUsedKey, EDEN_USED);
+        chunk.put(VmMemoryStatDAO.edenCapacityKey, EDEN_CAPACITY);
+        chunk.put(VmMemoryStatDAO.edenMaxCapacityKey, EDEN_MAX_CAPACITY);
 
         chunk.put(VmMemoryStatDAO.s0GenKey, "new");
         chunk.put(VmMemoryStatDAO.s0CollectorKey, "new-collector");
-        chunk.put(VmMemoryStatDAO.s0UsedKey, 4l);
-        chunk.put(VmMemoryStatDAO.s0CapacityKey, 5l);
-        chunk.put(VmMemoryStatDAO.s0MaxCapacityKey, 6l);
+        chunk.put(VmMemoryStatDAO.s0UsedKey, S0_USED);
+        chunk.put(VmMemoryStatDAO.s0CapacityKey, S0_CAPACITY);
+        chunk.put(VmMemoryStatDAO.s0MaxCapacityKey, S0_MAX_CAPACITY);
 
         chunk.put(VmMemoryStatDAO.s1GenKey, "new");
         chunk.put(VmMemoryStatDAO.s1CollectorKey, "new-collector");
-        chunk.put(VmMemoryStatDAO.s1UsedKey, 7l);
-        chunk.put(VmMemoryStatDAO.s1CapacityKey, 8l);
-        chunk.put(VmMemoryStatDAO.s1MaxCapacityKey, 9l);
+        chunk.put(VmMemoryStatDAO.s1UsedKey, S1_USED);
+        chunk.put(VmMemoryStatDAO.s1CapacityKey, S1_CAPACITY);
+        chunk.put(VmMemoryStatDAO.s1MaxCapacityKey, S1_MAX_CAPACITY);
 
         chunk.put(VmMemoryStatDAO.oldGenKey, "old");
         chunk.put(VmMemoryStatDAO.oldCollectorKey, "old-collector");
-        chunk.put(VmMemoryStatDAO.oldUsedKey, 10l);
-        chunk.put(VmMemoryStatDAO.oldCapacityKey, 11l);
-        chunk.put(VmMemoryStatDAO.oldMaxCapacityKey, 12l);
+        chunk.put(VmMemoryStatDAO.oldUsedKey, OLD_USED);
+        chunk.put(VmMemoryStatDAO.oldCapacityKey, OLD_CAPACITY);
+        chunk.put(VmMemoryStatDAO.oldMaxCapacityKey, OLD_MAX_CAPACITY);
 
         chunk.put(VmMemoryStatDAO.permGenKey, "perm");
         chunk.put(VmMemoryStatDAO.permCollectorKey, "perm-collector");
-        chunk.put(VmMemoryStatDAO.permUsedKey, 13l);
-        chunk.put(VmMemoryStatDAO.permCapacityKey, 14l);
-        chunk.put(VmMemoryStatDAO.permMaxCapacityKey, 15l);
+        chunk.put(VmMemoryStatDAO.permUsedKey, PERM_USED);
+        chunk.put(VmMemoryStatDAO.permCapacityKey, PERM_CAPACITY);
+        chunk.put(VmMemoryStatDAO.permMaxCapacityKey, PERM_MAX_CAPACITY);
 
         VmMemoryStat stat = new VmMemoryStatConverter().fromChunk(chunk);
 
@@ -165,13 +185,49 @@
 
         assertEquals(3, stat.getGenerations().size());
 
-        assertEquals(3, stat.getGeneration("new").spaces.size());
-        assertEquals("new-collector", stat.getGeneration("new").collector);
+        Generation newGen = stat.getGeneration("new");
+        assertNotNull(newGen);
+        assertEquals(3, newGen.spaces.size());
+        assertEquals("new-collector", newGen.collector);
+        
+        Space eden = newGen.getSpace("eden");
+        assertNotNull(eden);
+        assertEquals(EDEN_USED, eden.used);
+        assertEquals(EDEN_CAPACITY, eden.capacity);
+        assertEquals(EDEN_MAX_CAPACITY, eden.maxCapacity);
+        
+        Space s0 = newGen.getSpace("s0");
+        assertNotNull(s0);
+        assertEquals(S0_USED, s0.used);
+        assertEquals(S0_CAPACITY, s0.capacity);
+        assertEquals(S0_MAX_CAPACITY, s0.maxCapacity);
+        
+        Space s1 = newGen.getSpace("s1");
+        assertNotNull(s1);
+        assertEquals(S1_USED, s1.used);
+        assertEquals(S1_CAPACITY, s1.capacity);
+        assertEquals(S1_MAX_CAPACITY, s1.maxCapacity);
+        
+        Generation oldGen = stat.getGeneration("old");
+        assertNotNull(oldGen);
+        assertEquals(1, oldGen.spaces.size());
+        assertEquals("old-collector", oldGen.collector);
 
-        assertEquals(1, stat.getGeneration("old").spaces.size());
-        assertEquals("old-collector", stat.getGeneration("old").collector);
-
-        assertEquals(1, stat.getGeneration("perm").spaces.size());
-        assertEquals("perm-collector", stat.getGeneration("perm").collector);
+        Space old = oldGen.getSpace("old");
+        assertNotNull(old);
+        assertEquals(OLD_USED, old.used);
+        assertEquals(OLD_CAPACITY, old.capacity);
+        assertEquals(OLD_MAX_CAPACITY, old.maxCapacity);
+        
+        Generation permGen = stat.getGeneration("perm");
+        assertNotNull(permGen);
+        assertEquals(1, permGen.spaces.size());
+        assertEquals("perm-collector", permGen.collector);
+        
+        Space permSpace = permGen.getSpace("perm");
+        assertNotNull(permSpace);
+        assertEquals(PERM_USED, permSpace.used);
+        assertEquals(PERM_CAPACITY, permSpace.capacity);
+        assertEquals(PERM_MAX_CAPACITY, permSpace.maxCapacity);
     }
 }