You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by nc...@apache.org on 2014/04/29 20:24:45 UTC

git commit: AMBARI-5623. GET request on cluster resource gives psql exception (ncole)

Repository: ambari
Updated Branches:
  refs/heads/trunk 35f618e36 -> f3637b565


AMBARI-5623.  GET request on cluster resource gives psql exception (ncole)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/f3637b56
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/f3637b56
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/f3637b56

Branch: refs/heads/trunk
Commit: f3637b5653d86e3f38db4f3bf1f07bda045abeb6
Parents: 35f618e
Author: Nate Cole <nc...@hortonworks.com>
Authored: Tue Apr 29 13:34:06 2014 -0400
Committer: Nate Cole <nc...@hortonworks.com>
Committed: Tue Apr 29 13:37:18 2014 -0400

----------------------------------------------------------------------
 .../ambari/server/orm/dao/RequestDAO.java       |  6 ++
 .../ambari/server/orm/dao/RequestDAOTest.java   | 71 ++++++++++++++++++++
 2 files changed, 77 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/f3637b56/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RequestDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RequestDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RequestDAO.java
index 241c1fd..9d538f7 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RequestDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RequestDAO.java
@@ -22,6 +22,7 @@ import com.google.inject.Inject;
 import com.google.inject.Provider;
 import com.google.inject.Singleton;
 import com.google.inject.persist.Transactional;
+
 import org.apache.ambari.server.actionmanager.HostRoleStatus;
 import org.apache.ambari.server.orm.RequiresSession;
 import org.apache.ambari.server.orm.entities.RequestEntity;
@@ -29,7 +30,9 @@ import org.apache.ambari.server.orm.entities.RequestResourceFilterEntity;
 
 import javax.persistence.EntityManager;
 import javax.persistence.TypedQuery;
+
 import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 
 @Singleton
@@ -46,6 +49,9 @@ public class RequestDAO {
 
   @RequiresSession
   public List<RequestEntity> findByPks(Collection<Long> requestIds) {
+    if (null == requestIds || 0 == requestIds.size())
+      return Collections.emptyList();
+    
     TypedQuery<RequestEntity> query = entityManagerProvider.get().createQuery("SELECT request FROM RequestEntity request " +
         "WHERE request.requestId IN ?1", RequestEntity.class);
     return daoUtils.selectList(query, requestIds);

http://git-wip-us.apache.org/repos/asf/ambari/blob/f3637b56/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/RequestDAOTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/RequestDAOTest.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/RequestDAOTest.java
new file mode 100644
index 0000000..ffdcd6e
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/RequestDAOTest.java
@@ -0,0 +1,71 @@
+/**
+ * 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.ambari.server.orm.dao;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.orm.GuiceJpaInitializer;
+import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
+import org.apache.ambari.server.orm.entities.RequestEntity;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.persist.PersistService;
+
+/**
+ * RequestDAO unit tests
+ */
+public class RequestDAOTest {
+  private Injector injector;
+  private ClusterDAO clusterDAO;
+  
+  
+  @Before
+  public void setup() throws Exception {
+    injector = Guice.createInjector(new InMemoryDefaultTestModule());
+    injector.getInstance(GuiceJpaInitializer.class);
+
+    clusterDAO = injector.getInstance(ClusterDAO.class);
+  }
+
+  @After
+  public void teardown() throws AmbariException {
+    injector.getInstance(PersistService.class).stop();
+  }
+
+  
+  @Test
+  public void testFindAll() throws Exception {
+    RequestDAO dao = injector.getInstance(RequestDAO.class);
+    
+    Set<Long> set = Collections.emptySet();
+    
+    List<RequestEntity> list = dao.findByPks(set);
+    
+    Assert.assertEquals(0, list.size());
+    
+  }
+  
+}