changeset 603:55792b78bcc4

Replace remaining find(Query) with findPojo(Query). Reviewed-by: neugens Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-September/003152.html
author Roman Kennke <rkennke@redhat.com>
date Tue, 11 Sep 2012 22:55:50 +0200
parents 6bb30e80f53a
children 5cd4aaf85d02
files common/core/src/main/java/com/redhat/thermostat/common/dao/AgentInfoDAOImpl.java common/core/src/main/java/com/redhat/thermostat/common/dao/HeapDAOImpl.java common/core/src/main/java/com/redhat/thermostat/common/dao/VmInfoConverter.java common/core/src/main/java/com/redhat/thermostat/common/dao/VmInfoDAOImpl.java common/core/src/main/java/com/redhat/thermostat/common/storage/MongoStorage.java common/core/src/main/java/com/redhat/thermostat/common/storage/Storage.java common/core/src/test/java/com/redhat/thermostat/common/dao/AgentInfoDAOTest.java common/core/src/test/java/com/redhat/thermostat/common/dao/HeapDAOTest.java common/core/src/test/java/com/redhat/thermostat/common/dao/VmInfoConverterTest.java common/core/src/test/java/com/redhat/thermostat/common/dao/VmInfoDAOTest.java thread/collector/src/main/java/com/redhat/thermostat/thread/dao/impl/ThreadDaoImpl.java thread/collector/src/test/java/com/redhat/thermostat/thread/dao/impl/ThreadDaoImplTest.java
diffstat 12 files changed, 53 insertions(+), 327 deletions(-) [+]
line wrap: on
line diff
--- a/common/core/src/main/java/com/redhat/thermostat/common/dao/AgentInfoDAOImpl.java	Tue Sep 11 17:56:15 2012 +0200
+++ b/common/core/src/main/java/com/redhat/thermostat/common/dao/AgentInfoDAOImpl.java	Tue Sep 11 22:55:50 2012 +0200
@@ -98,8 +98,7 @@
                 .from(CATEGORY)
                 .where(Key.AGENT_ID, Criteria.EQUALS, agentRef.getAgentId());
 
-        Chunk agentInfo = storage.find(query);
-        return agentInfo == null ? null : converter.fromChunk(agentInfo);
+        return storage.findPojo(query, AgentInformation.class);
     }
 
     @Override
--- a/common/core/src/main/java/com/redhat/thermostat/common/dao/HeapDAOImpl.java	Tue Sep 11 17:56:15 2012 +0200
+++ b/common/core/src/main/java/com/redhat/thermostat/common/dao/HeapDAOImpl.java	Tue Sep 11 22:55:50 2012 +0200
@@ -149,9 +149,9 @@
         Query query = storage.createQuery()
                 .from(heapInfoCategory)
                 .where(heapIdKey, Criteria.EQUALS, heapId);
-        Chunk found = null;
+        HeapInfo found = null;
         try {
-            found = storage.find(query);
+            found = storage.findPojo(query, HeapInfo.class);
         } catch (IllegalArgumentException iae) {
             /*
              * if the heap id is not found, we get a nice
@@ -162,11 +162,7 @@
                 throw iae;
             }
         }
-        if (found == null) {
-            return null;
-        } else {
-            return convertChunkToHeapInfo(null, found);
-        }
+        return found;
     }
 
     @Override
--- a/common/core/src/main/java/com/redhat/thermostat/common/dao/VmInfoConverter.java	Tue Sep 11 17:56:15 2012 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,89 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc.
- *
- * This file is part of Thermostat.
- *
- * Thermostat is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2, or (at your
- * option) any later version.
- *
- * Thermostat is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Thermostat; see the file COPYING.  If not see
- * <http://www.gnu.org/licenses/>.
- *
- * Linking this code with other modules is making a combined work
- * based on this code.  Thus, the terms and conditions of the GNU
- * General Public License cover the whole combination.
- *
- * As a special exception, the copyright holders of this code give
- * you permission to link this code with independent modules to
- * produce an executable, regardless of the license terms of these
- * independent modules, and to copy and distribute the resulting
- * executable under terms of your choice, provided that you also
- * meet, for each linked independent module, the terms and conditions
- * of the license of that module.  An independent module is a module
- * which is not derived from or based on this code.  If you modify
- * this code, you may extend this exception to your version of the
- * library, but you are not obligated to do so.  If you do not wish
- * to do so, delete this exception statement from your version.
- */
-
-package com.redhat.thermostat.common.dao;
-
-import java.util.List;
-import java.util.Map;
-
-import com.redhat.thermostat.common.model.VmInfo;
-import com.redhat.thermostat.common.storage.Chunk;
-import com.redhat.thermostat.common.storage.Key;
-
-public class VmInfoConverter implements Converter<VmInfo> {
-
-    @Override
-    public Chunk toChunk(VmInfo info) {
-        Chunk chunk = new Chunk(VmInfoDAO.vmInfoCategory, true);
-
-        chunk.put(Key.VM_ID, info.getVmId());
-        chunk.put(VmInfoDAO.vmPidKey, info.getVmPid());
-        chunk.put(VmInfoDAO.startTimeKey, info.getStartTimeStamp());
-        chunk.put(VmInfoDAO.stopTimeKey, info.getStopTimeStamp());
-        chunk.put(VmInfoDAO.runtimeVersionKey, info.getJavaVersion());
-        chunk.put(VmInfoDAO.javaHomeKey, info.getJavaHome());
-        chunk.put(VmInfoDAO.mainClassKey, info.getMainClass());
-        chunk.put(VmInfoDAO.commandLineKey, info.getJavaCommandLine());
-        chunk.put(VmInfoDAO.vmNameKey, info.getVmName());
-        chunk.put(VmInfoDAO.vmInfoKey, info.getVmInfo());
-        chunk.put(VmInfoDAO.vmVersionKey, info.getVmVersion());
-        chunk.put(VmInfoDAO.vmArgumentsKey, info.getVmArguments());
-        chunk.put(VmInfoDAO.propertiesKey, info.getProperties());
-        chunk.put(VmInfoDAO.environmentKey, info.getEnvironment());
-        chunk.put(VmInfoDAO.librariesKey, info.getLoadedNativeLibraries());
-        return chunk;
-    }
-
-    @Override
-    public VmInfo fromChunk(Chunk chunk) {
-        int vmId = chunk.get(Key.VM_ID);
-        long startTime = chunk.get(VmInfoDAO.startTimeKey);
-        long stopTime = chunk.get(VmInfoDAO.stopTimeKey);
-        String jVersion = chunk.get(VmInfoDAO.runtimeVersionKey);
-        String jHome = chunk.get(VmInfoDAO.javaHomeKey);
-        String mainClass = chunk.get(VmInfoDAO.mainClassKey);
-        String commandLine = chunk.get(VmInfoDAO.commandLineKey);
-        String vmName = chunk.get(VmInfoDAO.vmNameKey);
-        String vmInfo = chunk.get(VmInfoDAO.vmInfoKey);
-        String vmVersion = chunk.get(VmInfoDAO.vmVersionKey);
-        String vmArgs = chunk.get(VmInfoDAO.vmArgumentsKey);
-        Map<String, String> props = chunk.get(VmInfoDAO.propertiesKey);
-        Map<String, String> env = chunk.get(VmInfoDAO.propertiesKey);
-        List<String> libs = chunk.get(VmInfoDAO.librariesKey);
-        return new VmInfo(vmId, startTime, stopTime, jVersion, jHome, mainClass, commandLine, vmName,
-                vmInfo, vmVersion, vmArgs, props, env, libs);
-    }
-}
--- a/common/core/src/main/java/com/redhat/thermostat/common/dao/VmInfoDAOImpl.java	Tue Sep 11 17:56:15 2012 +0200
+++ b/common/core/src/main/java/com/redhat/thermostat/common/dao/VmInfoDAOImpl.java	Tue Sep 11 22:55:50 2012 +0200
@@ -45,17 +45,15 @@
 import com.redhat.thermostat.common.storage.Cursor;
 import com.redhat.thermostat.common.storage.Key;
 import com.redhat.thermostat.common.storage.Query;
+import com.redhat.thermostat.common.storage.Query.Criteria;
 import com.redhat.thermostat.common.storage.Storage;
-import com.redhat.thermostat.common.storage.Query.Criteria;
 
 class VmInfoDAOImpl implements VmInfoDAO {
 
     private Storage storage;
-    private VmInfoConverter converter;
 
     VmInfoDAOImpl(Storage storage) {
         this.storage = storage;
-        this.converter = new VmInfoConverter();
     }
 
     @Override
@@ -64,11 +62,11 @@
                 .from(vmInfoCategory)
                 .where(Key.AGENT_ID, Criteria.EQUALS, ref.getAgent().getAgentId())
                 .where(Key.VM_ID, Criteria.EQUALS, ref.getId());
-        Chunk result = storage.find(findMatchingVm);
+        VmInfo result = storage.findPojo(findMatchingVm, VmInfo.class);
         if (result == null) {
             throw new DAOException("Unknown VM: host:" + ref.getAgent().getAgentId() + ";vm:" + ref.getId());
         }
-        return converter.fromChunk(result);
+        return result;
     }
 
     @Override
--- a/common/core/src/main/java/com/redhat/thermostat/common/storage/MongoStorage.java	Tue Sep 11 17:56:15 2012 +0200
+++ b/common/core/src/main/java/com/redhat/thermostat/common/storage/MongoStorage.java	Tue Sep 11 22:55:50 2012 +0200
@@ -39,6 +39,7 @@
 import java.io.InputStream;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Set;
 import java.util.Map.Entry;
 import java.util.UUID;
 
@@ -95,7 +96,7 @@
 
     private void setupConverters() {
         converters = new HashMap<>();
-        addConverter(VmMemoryStat.class, new VmMemoryStatConverter());
+        converters.put(VmMemoryStat.class, new VmMemoryStatConverter());
     }
 
     @Override
@@ -323,7 +324,30 @@
     }
 
     @Override
-    public Chunk find(Query query) {
+    public <T> T findPojo(Query query, Class<T> resultClass) {
+        Chunk resultChunk = find(query);
+        if (resultChunk == null) {
+            return null;
+        }
+        try {
+            Object pojo = resultClass.newInstance();
+            ChunkAdapter chunk = new ChunkAdapter(pojo);
+            Set<Key<?>> keys = resultChunk.getKeys();
+            for (Key key : keys) {
+                if (key == null) {
+                    System.err.println("WARNING: null key in result: " + resultChunk);
+                    continue;
+                 }
+                 chunk.put(key, resultChunk.get(key));
+            }
+            return (T) chunk.getAdaptee();
+        } catch (InstantiationException | IllegalAccessException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    // TODO: Make this private, and change the testcase to test putPojo() instead.
+    Chunk find(Query query) {
         MongoQuery mongoQuery = checkAndCastQuery(query);
         DBCollection coll = getCachedCollection(mongoQuery.getCollectionName());
         DBObject dbResult = coll.findOne(mongoQuery.getGeneratedQuery());
@@ -374,6 +398,7 @@
         }
     }
 
+    @Override
     public void putPojo(Category category, boolean replace, Pojo pojo) {
         Converter customConverter = converters.get(pojo.getClass());
         Chunk chunk;
@@ -385,8 +410,4 @@
         putChunk(chunk);
     }
 
-
-    void addConverter(Class<?> type, Converter<?> converter) {
-        converters.put(type, converter);
-    }
 }
--- a/common/core/src/main/java/com/redhat/thermostat/common/storage/Storage.java	Tue Sep 11 17:56:15 2012 +0200
+++ b/common/core/src/main/java/com/redhat/thermostat/common/storage/Storage.java	Tue Sep 11 22:55:50 2012 +0200
@@ -37,7 +37,6 @@
 package com.redhat.thermostat.common.storage;
 
 import java.io.InputStream;
-import java.util.Set;
 import java.util.UUID;
 
 import com.redhat.thermostat.common.model.Pojo;
@@ -73,27 +72,7 @@
     
     public abstract Cursor findAll(Query query);
 
-    public abstract Chunk find(Query query);
-
-    // TODO: Move implementation to MongoStorage and remve find(Query) and make this abstract.
-    public <T> T findPojo(Query query, Class<T> resultClass) {
-        Chunk resultChunk = find(query);
-        try {
-            Object pojo = resultClass.newInstance();
-            ChunkAdapter chunk = new ChunkAdapter(pojo);
-            Set<Key<?>> keys = resultChunk.getKeys();
-            for (Key key : keys) {
-                if (key == null) {
-                    System.err.println("WARNING: null key in result: " + resultChunk);
-                    continue;
-                 }
-                 chunk.put(key, resultChunk.get(key));
-            }
-            return (T) chunk.getAdaptee();
-        } catch (InstantiationException | IllegalAccessException e) {
-            throw new RuntimeException(e);
-        }
-    }
+    public abstract <T> T findPojo(Query query, Class<T> resultClass);
 
     public abstract Cursor findAllFromCategory(Category category);
     
--- a/common/core/src/test/java/com/redhat/thermostat/common/dao/AgentInfoDAOTest.java	Tue Sep 11 17:56:15 2012 +0200
+++ b/common/core/src/test/java/com/redhat/thermostat/common/dao/AgentInfoDAOTest.java	Tue Sep 11 22:55:50 2012 +0200
@@ -37,6 +37,7 @@
 package com.redhat.thermostat.common.dao;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
@@ -168,7 +169,7 @@
         Storage storage = mock(Storage.class);
         MockQuery query = new MockQuery();
         when(storage.createQuery()).thenReturn(query);
-        when(storage.find(query)).thenReturn(agentChunk1);
+        when(storage.findPojo(query, AgentInformation.class)).thenReturn(agentInfo1);
         AgentInfoDAO dao = new AgentInfoDAOImpl(storage);
 
         AgentInformation computed = dao.getAgentInformation(agentRef);
@@ -177,7 +178,7 @@
         assertTrue(query.hasWhereClause(Key.AGENT_ID, Criteria.EQUALS, agentInfo1.getAgentId()));
 
         AgentInformation expected = agentInfo1;
-        assertEquals(expected, computed);
+        assertSame(expected, computed);
     }
 
     @Test
--- a/common/core/src/test/java/com/redhat/thermostat/common/dao/HeapDAOTest.java	Tue Sep 11 17:56:15 2012 +0200
+++ b/common/core/src/test/java/com/redhat/thermostat/common/dao/HeapDAOTest.java	Tue Sep 11 22:55:50 2012 +0200
@@ -279,7 +279,7 @@
     public void testInvalidHeapId() throws IOException {
         storage = mock(Storage.class);
         when(storage.createQuery()).thenReturn(new MockQuery());
-        when(storage.find(isA(Query.class))).thenThrow(new IllegalArgumentException("invalid ObjectId"));
+        when(storage.findPojo(any(Query.class), any(Class.class))).thenThrow(new IllegalArgumentException("invalid ObjectId"));
         dao = new HeapDAOImpl(storage);
         heapInfo = dao.getHeapInfo("some-random-heap-id");
         assertTrue(heapInfo == null);
--- a/common/core/src/test/java/com/redhat/thermostat/common/dao/VmInfoConverterTest.java	Tue Sep 11 17:56:15 2012 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,151 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc.
- *
- * This file is part of Thermostat.
- *
- * Thermostat is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2, or (at your
- * option) any later version.
- *
- * Thermostat is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Thermostat; see the file COPYING.  If not see
- * <http://www.gnu.org/licenses/>.
- *
- * Linking this code with other modules is making a combined work
- * based on this code.  Thus, the terms and conditions of the GNU
- * General Public License cover the whole combination.
- *
- * As a special exception, the copyright holders of this code give
- * you permission to link this code with independent modules to
- * produce an executable, regardless of the license terms of these
- * independent modules, and to copy and distribute the resulting
- * executable under terms of your choice, provided that you also
- * meet, for each linked independent module, the terms and conditions
- * of the license of that module.  An independent module is a module
- * which is not derived from or based on this code.  If you modify
- * this code, you may extend this exception to your version of the
- * library, but you are not obligated to do so.  If you do not wish
- * to do so, delete this exception statement from your version.
- */
-
-package com.redhat.thermostat.common.dao;
-
-import static org.junit.Assert.*;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import com.redhat.thermostat.common.model.VmInfo;
-import com.redhat.thermostat.common.storage.Chunk;
-import com.redhat.thermostat.common.storage.Key;
-
-public class VmInfoConverterTest {
-
-    private int vmId;
-    private long startTime;
-    private long stopTime;
-    private String jVersion;
-    private String jHome;
-    private String mainClass;
-    private String commandLine;
-    private String vmName;
-    private String vmInfo;
-    private String vmVersion;
-    private String vmArgs;
-    private Map<String, String> props;
-    private Map<String, String> env;
-    private List<String> libs;
-
-    @Before
-    public void setUp() {
-        vmId = 1;
-        startTime = 2;
-        stopTime = 3;
-        jVersion = "java 1.0";
-        jHome = "/path/to/jdk/home";
-        mainClass = "Hello.class";
-        commandLine = "World";
-        vmArgs = "-XX=+FastestJITPossible";
-        vmName = "Hotspot";
-        vmInfo = "Some info";
-        vmVersion = "1.0";
-        props = new HashMap<>();
-        env = new HashMap<>();
-        libs = new ArrayList<>();
-    }
-
-    @Test
-    public void testVmInfoToChunk() {
-        VmInfo info = new VmInfo(vmId, startTime, stopTime,
-                jVersion, jHome, mainClass, commandLine,
-                vmName, vmInfo, vmVersion, vmArgs,
-                props, env, libs);
-
-        Chunk chunk = new VmInfoConverter().toChunk(info);
-
-        assertNotNull(chunk);
-        assertEquals((Integer) vmId, chunk.get(Key.VM_ID));
-        assertEquals((Long) startTime, chunk.get(VmInfoDAO.startTimeKey));
-        assertEquals((Long) stopTime, chunk.get(VmInfoDAO.stopTimeKey));
-        assertEquals(jVersion, chunk.get(VmInfoDAO.runtimeVersionKey));
-        assertEquals(jHome, chunk.get(VmInfoDAO.javaHomeKey));
-        assertEquals(mainClass, chunk.get(VmInfoDAO.mainClassKey));
-        assertEquals(commandLine, chunk.get(VmInfoDAO.commandLineKey));
-        assertEquals(vmName, chunk.get(VmInfoDAO.vmNameKey));
-        assertEquals(vmInfo, chunk.get(VmInfoDAO.vmInfoKey));
-        assertEquals(vmVersion, chunk.get(VmInfoDAO.vmVersionKey));
-        assertEquals(vmArgs, chunk.get(VmInfoDAO.vmArgumentsKey));
-
-        // FIXME test environment, properties and loaded native libraries later
-    }
-
-    @Test
-    public void testChunkToVmInfo() {
-        Chunk chunk = new Chunk(VmInfoDAO.vmInfoCategory, true);
-
-        chunk.put(Key.VM_ID, vmId);
-        chunk.put(VmInfoDAO.vmPidKey, vmId);
-        chunk.put(VmInfoDAO.startTimeKey, startTime);
-        chunk.put(VmInfoDAO.stopTimeKey, stopTime);
-        chunk.put(VmInfoDAO.runtimeVersionKey, jVersion);
-        chunk.put(VmInfoDAO.javaHomeKey, jHome);
-        chunk.put(VmInfoDAO.mainClassKey, mainClass);
-        chunk.put(VmInfoDAO.commandLineKey, commandLine);
-        chunk.put(VmInfoDAO.vmNameKey, vmName);
-        chunk.put(VmInfoDAO.vmInfoKey, vmInfo);
-        chunk.put(VmInfoDAO.vmVersionKey, vmVersion);
-        chunk.put(VmInfoDAO.vmArgumentsKey, vmArgs);
-        chunk.put(VmInfoDAO.propertiesKey, props);
-        chunk.put(VmInfoDAO.environmentKey, env);
-        chunk.put(VmInfoDAO.librariesKey, libs);
-
-        VmInfo info = new VmInfoConverter().fromChunk(chunk);
-
-        assertNotNull(info);
-        assertEquals((Integer) vmId, (Integer) info.getVmId());
-        assertEquals((Integer) vmId, (Integer) info.getVmPid());
-        assertEquals((Long) startTime, (Long) info.getStartTimeStamp());
-        assertEquals((Long) stopTime, (Long) info.getStopTimeStamp());
-        assertEquals(jVersion, info.getJavaVersion());
-        assertEquals(jHome, info.getJavaHome());
-        assertEquals(mainClass, info.getMainClass());
-        assertEquals(commandLine, info.getJavaCommandLine());
-        assertEquals(vmName, info.getVmName());
-        assertEquals(vmInfo, info.getVmInfo());
-        assertEquals(vmVersion, info.getVmVersion());
-        assertEquals(vmArgs, info.getVmArguments());
-
-        // FIXME test environment, properties and loaded native libraries later
-    }
-}
--- a/common/core/src/test/java/com/redhat/thermostat/common/dao/VmInfoDAOTest.java	Tue Sep 11 17:56:15 2012 +0200
+++ b/common/core/src/test/java/com/redhat/thermostat/common/dao/VmInfoDAOTest.java	Tue Sep 11 22:55:50 2012 +0200
@@ -142,7 +142,8 @@
         Storage storage = mock(Storage.class);
         Query query = new MockQuery();
         when(storage.createQuery()).thenReturn(query);
-        when(storage.find(query)).thenReturn(chunk);
+        VmInfo expected = new VmInfo(vmId, startTime, stopTime, jVersion, jHome, mainClass, commandLine, vmName, vmInfo, vmVersion, vmArgs, props, env, libs);
+        when(storage.findPojo(query, VmInfo.class)).thenReturn(expected);
 
         HostRef hostRef = mock(HostRef.class);
         when(hostRef.getAgentId()).thenReturn("system");
@@ -153,22 +154,7 @@
 
         VmInfoDAO dao = new VmInfoDAOImpl(storage);
         VmInfo info = dao.getVmInfo(vmRef);
-
-        assertNotNull(info);
-        assertEquals((Integer) vmId, (Integer) info.getVmId());
-        assertEquals((Integer) vmId, (Integer) info.getVmPid());
-        assertEquals((Long) startTime, (Long) info.getStartTimeStamp());
-        assertEquals((Long) stopTime, (Long) info.getStopTimeStamp());
-        assertEquals(jVersion, info.getJavaVersion());
-        assertEquals(jHome, info.getJavaHome());
-        assertEquals(mainClass, info.getMainClass());
-        assertEquals(commandLine, info.getJavaCommandLine());
-        assertEquals(vmName, info.getVmName());
-        assertEquals(vmInfo, info.getVmInfo());
-        assertEquals(vmVersion, info.getVmVersion());
-        assertEquals(vmArgs, info.getVmArguments());
-
-        // FIXME test environment, properties and loaded native libraries later
+        assertEquals(expected, info);
     }
 
     @Test
--- a/thread/collector/src/main/java/com/redhat/thermostat/thread/dao/impl/ThreadDaoImpl.java	Tue Sep 11 17:56:15 2012 +0200
+++ b/thread/collector/src/main/java/com/redhat/thermostat/thread/dao/impl/ThreadDaoImpl.java	Tue Sep 11 22:55:50 2012 +0200
@@ -64,21 +64,19 @@
 
     @Override
     public VMThreadCapabilities loadCapabilities(VmRef vm) {
-        
-        VMThreadCapabilities caps = null;
-        
+        try {
         Query query = storage.createQuery()
                 .from(THREAD_CAPABILITIES)
                 .where(Key.VM_ID, Query.Criteria.EQUALS, vm.getId())
                 .where(Key.AGENT_ID, Query.Criteria.EQUALS, vm.getAgent().getAgentId());
         
-        Chunk found = storage.find(query);
-        if (found != null) {
-            caps = new VMThreadCapabilities();
-            caps.setSupportedFeaturesList(found.get(SUPPORTED_FEATURES_LIST_KEY));
+        VMThreadCapabilities caps = storage.findPojo(query, VMThreadCapabilities.class);
+        return caps;
+        } catch (Throwable t) {
+            t.printStackTrace();
+            System.exit(0);
+            return null;
         }
-        
-        return caps;
     }
     
     @Override
@@ -164,17 +162,6 @@
         return result;
     }
     
-    private Chunk prepareChunk(Category category, boolean replace, String vmId, String agentId) {
-        Chunk chunk = new Chunk(category, replace);
-        chunk.put(Key.AGENT_ID, agentId);
-        chunk.put(Key.VM_ID, Integer.valueOf(vmId));
-        return chunk;
-    }
-    
-    private Chunk prepareChunk(Category category, boolean replace, VmRef vm) {
-        return prepareChunk(category, replace, vm.getIdString(), vm.getAgent().getAgentId());
-    }
-
     private Query prepareQuery(Category category, VmRef vm) {
         return prepareQuery(category, vm.getIdString(), vm.getAgent().getAgentId());
     }
--- a/thread/collector/src/test/java/com/redhat/thermostat/thread/dao/impl/ThreadDaoImplTest.java	Tue Sep 11 17:56:15 2012 +0200
+++ b/thread/collector/src/test/java/com/redhat/thermostat/thread/dao/impl/ThreadDaoImplTest.java	Tue Sep 11 22:55:50 2012 +0200
@@ -36,7 +36,6 @@
 
 package com.redhat.thermostat.thread.dao.impl;
 
-import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.mock;
@@ -46,15 +45,13 @@
 import java.util.Arrays;
 
 import org.junit.Test;
-import org.mockito.ArgumentCaptor;
 
 import com.redhat.thermostat.common.dao.HostRef;
 import com.redhat.thermostat.common.dao.VmRef;
 import com.redhat.thermostat.common.storage.Chunk;
 import com.redhat.thermostat.common.storage.Key;
-import com.redhat.thermostat.common.storage.Query;
+import com.redhat.thermostat.common.storage.Query.Criteria;
 import com.redhat.thermostat.common.storage.Storage;
-import com.redhat.thermostat.common.storage.Query.Criteria;
 import com.redhat.thermostat.test.MockQuery;
 import com.redhat.thermostat.thread.dao.ThreadDao;
 import com.redhat.thermostat.thread.model.VMThreadCapabilities;
@@ -89,7 +86,9 @@
         Chunk answer = mock(Chunk.class);
         when(answer.get(ThreadDao.SUPPORTED_FEATURES_LIST_KEY)).thenReturn(Arrays.asList(ThreadDao.CPU_TIME, ThreadDao.THREAD_ALLOCATED_MEMORY));
         
-        when(storage.find(query)).thenReturn(answer);
+        VMThreadCapabilities expected = new VMThreadCapabilities();
+        expected.setSupportedFeaturesList(Arrays.asList(ThreadDao.CPU_TIME, ThreadDao.THREAD_ALLOCATED_MEMORY));
+        when(storage.findPojo(query, VMThreadCapabilities.class)).thenReturn(expected);
         
         ThreadDaoImpl dao = new ThreadDaoImpl(storage);
         VMThreadCapabilities caps = dao.loadCapabilities(ref);