incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject svn commit: r1396481 - in /incubator/ambari/branches/AMBARI-666: ./ ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/ ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ ambari-server/src/main/java/org/apach...
Date Wed, 10 Oct 2012 06:34:23 GMT
Author: mahadev
Date: Wed Oct 10 06:34:22 2012
New Revision: 1396481

URL: http://svn.apache.org/viewvc?rev=1396481&view=rev
Log:
AMBARI-844. Mock JMX provider for manual tests. (Tom Beerbower via mahadev)

Added:
    incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/TestProviderModule.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/jdbc/JDBCPropertyProviderTest.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/jdbc/TestJDBCResourceProvider.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/TestHostMappingProvider.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/TestStreamProvider.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/test/resources/data.db   (with props)
Removed:
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXHelper.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/jdbc/JDBCManagementControllerTest.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/JMXHelperTest.java
Modified:
    incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProvider.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterControllerImpl.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/jdbc/JDBCProviderModule.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXPropertyProvider.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/GreaterEqualsPredicate.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/GreaterPredicate.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/LessEqualsPredicate.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/LessPredicate.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/PropertyHelper.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/JMXPropertyProviderTest.java

Modified: incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt?rev=1396481&r1=1396480&r2=1396481&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt (original)
+++ incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt Wed Oct 10 06:34:22 2012
@@ -12,6 +12,8 @@ AMBARI-666 branch (unreleased changes)
 
   NEW FEATURES
 
+  AMBARI-844. Mock JMX provider for manual tests. (Tom Beerbower via mahadev)
+
   AMBARI-841. Fix comparison predicates in case where resource does not have
   property value. (Tom Beerbower via mahadev)
 

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProvider.java?rev=1396481&r1=1396480&r2=1396481&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProvider.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProvider.java Wed Oct 10 06:34:22 2012
@@ -25,6 +25,7 @@ import org.apache.ambari.server.controll
 import org.apache.ambari.server.controller.spi.Request;
 import org.apache.ambari.server.controller.spi.Resource;
 import org.apache.ambari.server.controller.utilities.PredicateHelper;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
 
 import java.util.HashMap;
 import java.util.HashSet;
@@ -119,7 +120,7 @@ public class GangliaPropertyProvider imp
     String component = resource.getPropertyValue(new PropertyIdImpl("component_name", "HostRoles", false));
 
     // ---- TODO : HACK to fix host name that's been made all lower case... Ganglia doesn't like!!
-    host = hackHostName(host);
+    host = PropertyHelper.fixHostName(host);
     // -----
 
     String cluster = COMPONENT_MAP.get(component);
@@ -160,17 +161,5 @@ public class GangliaPropertyProvider imp
     stringBuilder.append("]");
     return stringBuilder.toString();
   }
-
-  private String hackHostName(String host) {
-    int first_dash = host.indexOf('-');
-    int first_dot = host.indexOf('.');
-    String segment1 = host.substring(0, first_dash);
-    if (segment1.equals("domu")) {
-      segment1 = "domU";
-    }
-    String segment2 = host.substring(first_dash, first_dot).toUpperCase();
-    host = segment1 + segment2 + host.substring(first_dot);
-    return host;
-  }
 }
 

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterControllerImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterControllerImpl.java?rev=1396481&r1=1396480&r2=1396481&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterControllerImpl.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterControllerImpl.java Wed Oct 10 06:34:22 2012
@@ -18,6 +18,7 @@
 
 package org.apache.ambari.server.controller.internal;
 
+import org.apache.ambari.server.controller.spi.PropertyId;
 import org.apache.ambari.server.controller.spi.ProviderModule;
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.controller.spi.ClusterController;
@@ -27,9 +28,11 @@ import org.apache.ambari.server.controll
 import org.apache.ambari.server.controller.spi.Resource;
 import org.apache.ambari.server.controller.spi.ResourceProvider;
 import org.apache.ambari.server.controller.spi.Schema;
+import org.apache.ambari.server.controller.utilities.PredicateHelper;
 
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.NoSuchElementException;
@@ -115,12 +118,34 @@ public class ClusterControllerImpl imple
     Set<Resource> keepers = resources;
 
     for (PropertyProvider propertyProvider : resourceProviders.get(type).getPropertyProviders()) {
-      //TODO : only call the provider if it provides properties that we need ...
-      keepers = propertyProvider.populateResources(keepers, request, predicate);
+      if (providesRequestProperties(propertyProvider, request, predicate)) {
+        keepers = propertyProvider.populateResources(keepers, request, predicate);
+      }
     }
     return keepers;
   }
 
+  /**
+   * Indicates whether or not the given property provider can service the given request.
+   *
+   * @param provider   the property provider
+   * @param request    the request
+   * @param predicate  the predicate
+   *
+   * @return true if the given provider can service the request
+   */
+  private boolean providesRequestProperties(PropertyProvider provider, Request request, Predicate predicate) {
+    Set<PropertyId> requestPropertyIds = new HashSet<PropertyId>(request.getPropertyIds());
+
+    if (requestPropertyIds.size() == 0) {
+      return true;
+    }
+    requestPropertyIds.addAll(PredicateHelper.getPropertyIds(predicate));
+    requestPropertyIds.retainAll(provider.getPropertyIds());
+
+    return !requestPropertyIds.isEmpty();
+  }
+
   private Map<Resource.Type, ResourceProvider> getResourceSchemas() {
     Map<Resource.Type, ResourceProvider> resourceProviders = new HashMap<Resource.Type, ResourceProvider>();
 

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/jdbc/JDBCProviderModule.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/jdbc/JDBCProviderModule.java?rev=1396481&r1=1396480&r2=1396481&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/jdbc/JDBCProviderModule.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/jdbc/JDBCProviderModule.java Wed Oct 10 06:34:22 2012
@@ -29,7 +29,7 @@ import java.util.LinkedList;
 import java.util.List;
 
 /**
- *
+ * Module to plug in the JDBC resource provider.
  */
 public class JDBCProviderModule implements ProviderModule {
 

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXPropertyProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXPropertyProvider.java?rev=1396481&r1=1396480&r2=1396481&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXPropertyProvider.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXPropertyProvider.java Wed Oct 10 06:34:22 2012
@@ -126,11 +126,11 @@ public class JMXPropertyProvider impleme
       return true;
     }
 
-    Set<PropertyId> ids = PropertyHelper.getRequestPropertyIds(this, request, predicate);
+    Set<PropertyId> ids = PropertyHelper.getRequestPropertyIds(getPropertyIds(), request, predicate);
 
     Map<String, String> hosts = mappingProvider.getHostMap();
 
-    String hostName = hosts.get(resource.getPropertyValue(HOST_COMPONENT_HOST_NAME_PROPERTY_ID));
+    String hostName = hosts.get(PropertyHelper.fixHostName(resource.getPropertyValue(HOST_COMPONENT_HOST_NAME_PROPERTY_ID)));
     String port = JMX_PORTS.get(resource.getPropertyValue(HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID));
 
     if (hostName == null || port == null) {

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/GreaterEqualsPredicate.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/GreaterEqualsPredicate.java?rev=1396481&r1=1396480&r2=1396481&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/GreaterEqualsPredicate.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/GreaterEqualsPredicate.java Wed Oct 10 06:34:22 2012
@@ -33,7 +33,7 @@ public class GreaterEqualsPredicate exte
   @Override
   public boolean evaluate(Resource resource) {
     String propertyValue = resource.getPropertyValue(getPropertyId());
-    return propertyValue == null ? false : getValue().compareTo(resource.getPropertyValue(getPropertyId())) <= 0;
+    return propertyValue == null ? false : getValue().compareTo(propertyValue) <= 0;
   }
 
   @Override

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/GreaterPredicate.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/GreaterPredicate.java?rev=1396481&r1=1396480&r2=1396481&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/GreaterPredicate.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/GreaterPredicate.java Wed Oct 10 06:34:22 2012
@@ -32,7 +32,7 @@ public class GreaterPredicate extends Co
   @Override
   public boolean evaluate(Resource resource) {
     String propertyValue = resource.getPropertyValue(getPropertyId());
-    return propertyValue == null ? false : getValue().compareTo(resource.getPropertyValue(getPropertyId())) < 0;
+    return propertyValue == null ? false : getValue().compareTo(propertyValue) < 0;
   }
 
   @Override

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/LessEqualsPredicate.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/LessEqualsPredicate.java?rev=1396481&r1=1396480&r2=1396481&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/LessEqualsPredicate.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/LessEqualsPredicate.java Wed Oct 10 06:34:22 2012
@@ -33,7 +33,7 @@ public class LessEqualsPredicate extends
   @Override
   public boolean evaluate(Resource resource) {
     String propertyValue = resource.getPropertyValue(getPropertyId());
-    return propertyValue == null ? false : getValue().compareTo(resource.getPropertyValue(getPropertyId())) >= 0;
+    return propertyValue == null ? false : getValue().compareTo(propertyValue) >= 0;
   }
 
   @Override

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/LessPredicate.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/LessPredicate.java?rev=1396481&r1=1396480&r2=1396481&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/LessPredicate.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/LessPredicate.java Wed Oct 10 06:34:22 2012
@@ -32,7 +32,7 @@ public class LessPredicate extends Compa
   @Override
   public boolean evaluate(Resource resource) {
     String propertyValue = resource.getPropertyValue(getPropertyId());
-    return propertyValue == null ? false : getValue().compareTo(resource.getPropertyValue(getPropertyId())) > 0;
+    return propertyValue == null ? false : getValue().compareTo(propertyValue) > 0;
   }
 
   @Override

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/PropertyHelper.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/PropertyHelper.java?rev=1396481&r1=1396480&r2=1396481&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/PropertyHelper.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/PropertyHelper.java Wed Oct 10 06:34:22 2012
@@ -24,6 +24,7 @@ import org.apache.ambari.server.controll
 import org.apache.ambari.server.controller.spi.PropertyProvider;
 import org.apache.ambari.server.controller.spi.Request;
 import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.spi.ResourceProvider;
 import org.codehaus.jackson.map.ObjectMapper;
 import org.codehaus.jackson.type.TypeReference;
 
@@ -81,20 +82,20 @@ public class PropertyHelper {
   }
 
   /**
-   * Get the set of property id required to satisfy the given request for the given property
-   * provider and predicate.
+   * Get the set of property ids required to satisfy the given request.
    *
-   * @param provider   the property provider
-   * @param request    the request
-   * @param predicate  the predicate
+   * @param providerPropertyIds  the provider property ids
+   * @param request              the request
+   * @param predicate            the predicate
    *
    * @return the set of property ids needed to satisfy the request
    */
-  public static Set<PropertyId> getRequestPropertyIds(PropertyProvider provider,
+  public static Set<PropertyId> getRequestPropertyIds(Set<PropertyId> providerPropertyIds,
                                                       Request request,
                                                       Predicate predicate) {
     Set<PropertyId> requestPropertyIds  = new HashSet<PropertyId>(request.getPropertyIds());
-    Set<PropertyId> providerPropertyIds = new HashSet<PropertyId>(provider.getPropertyIds());
+
+    providerPropertyIds = new HashSet<PropertyId>(providerPropertyIds);
 
     if (requestPropertyIds == null || requestPropertyIds.isEmpty()) {
       return providerPropertyIds;
@@ -108,6 +109,26 @@ public class PropertyHelper {
   }
 
   /**
+   * For some reason the host names are stored all lower case.  Attempt to undo that with
+   * this hack.
+   *
+   * @param host  the host name to be fixed
+   *
+   * @return the fixed host name
+   */
+  public static String fixHostName(String host) {
+    int first_dash = host.indexOf('-');
+    int first_dot = host.indexOf('.');
+    String segment1 = host.substring(0, first_dash);
+    if (segment1.equals("domu")) {
+      segment1 = "domU";
+    }
+    String segment2 = host.substring(first_dash, first_dot).toUpperCase();
+    host = segment1 + segment2 + host.substring(first_dot);
+    return host;
+  }
+
+  /**
    * Factory method to create a create request from the given set of property maps.
    * Each map contains the properties to be used to create a resource.  Multiple maps in the
    * set should result in multiple creates.

Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/TestProviderModule.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/TestProviderModule.java?rev=1396481&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/TestProviderModule.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/TestProviderModule.java Wed Oct 10 06:34:22 2012
@@ -0,0 +1,72 @@
+/**
+ * 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.controller.internal;
+
+import org.apache.ambari.server.controller.jdbc.TestJDBCResourceProvider;
+import org.apache.ambari.server.controller.jmx.JMXPropertyProvider;
+import org.apache.ambari.server.controller.jmx.TestHostMappingProvider;
+import org.apache.ambari.server.controller.jmx.TestStreamProvider;
+import org.apache.ambari.server.controller.spi.PropertyId;
+import org.apache.ambari.server.controller.spi.PropertyProvider;
+import org.apache.ambari.server.controller.spi.ProviderModule;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.spi.ResourceProvider;
+import org.apache.ambari.server.controller.utilities.DBHelper;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Module to plug in the JDBC resource provider.
+ */
+public class TestProviderModule implements ProviderModule {
+
+  private static final Map<Resource.Type, List<PropertyProvider>> propertyProviders = new HashMap<Resource.Type, List<PropertyProvider>>();
+
+  static {
+
+    Set< PropertyId > propertyIds           = PropertyHelper.getPropertyIds(Resource.Type.HostComponent, "JMX");
+    TestStreamProvider streamProvider       = new TestStreamProvider();
+    TestHostMappingProvider mappingProvider = new TestHostMappingProvider();
+
+    PropertyProvider propertyProvider = new JMXPropertyProvider(propertyIds,
+        streamProvider,
+        mappingProvider);
+
+    propertyProviders.put(Resource.Type.HostComponent, Collections.singletonList(propertyProvider));
+  }
+
+  @Override
+  public ResourceProvider getResourceProvider(Resource.Type type) {
+
+    List<PropertyProvider> providers = propertyProviders.get(type);
+
+
+    return new TestJDBCResourceProvider(
+        DBHelper.CONNECTION_FACTORY,
+        type,
+        providers == null ? Collections.<PropertyProvider>emptyList() : providers,
+        PropertyHelper.getPropertyIds(type, "DB"),
+        PropertyHelper.getKeyPropertyIds(type));
+  }
+}

Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/jdbc/JDBCPropertyProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/jdbc/JDBCPropertyProviderTest.java?rev=1396481&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/jdbc/JDBCPropertyProviderTest.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/jdbc/JDBCPropertyProviderTest.java Wed Oct 10 06:34:22 2012
@@ -0,0 +1,841 @@
+/**
+ * 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.controller.jdbc;
+
+import static org.easymock.EasyMock.createNiceMock;
+
+/**
+*
+*/
+public class JDBCPropertyProviderTest {
+
+//  @Test
+//  public void testCreateClusters() throws Exception {
+//    ConnectionFactory connectionFactory = createNiceMock(ConnectionFactory.class);
+//    Connection connection = createNiceMock(Connection.class);
+//    Statement statement = createNiceMock(Statement.class);
+//
+//    expect(connectionFactory.getConnection()).andReturn(connection).once();
+//    expect(connection.createStatement()).andReturn(statement).once();
+//    expect(statement.execute("insert into Clusters (cluster_name, version, state) values ('MyCluster', '1.0', 'initial')")).andReturn(true).once();
+//
+//    replay(connectionFactory, connection, statement);
+//
+//    JDBCManagementController controller =  new JDBCManagementController(connectionFactory, ClusterControllerHelper.RESOURCE_TABLES);
+//
+//    Map<PropertyId, Object> properties = new LinkedHashMap<PropertyId, Object>();
+//
+//    PropertyId id = PropertyHelper.getPropertyId("cluster_name", "Clusters");
+//    properties.put(id, "MyCluster");
+//
+//    id = PropertyHelper.getPropertyId("version", "Clusters");
+//    properties.put(id, "1.0");
+//
+//    id = PropertyHelper.getPropertyId("state", "Clusters");
+//    properties.put(id, "initial");
+//
+//    Set<Map<PropertyId, Object>> propertySet = new LinkedHashSet<Map<PropertyId, Object>>();
+//    propertySet.add(properties);
+//
+//    Request request = new RequestImpl(null, propertySet);
+//
+//    controller.createClusters(request);
+//
+//    verify(connectionFactory, connection, statement);
+//  }
+//
+//  @Test
+//  public void testCreateServices() throws Exception{
+//
+//    ConnectionFactory connectionFactory = createNiceMock(ConnectionFactory.class);
+//    Connection connection = createNiceMock(Connection.class);
+//    Statement statement = createNiceMock(Statement.class);
+//
+//    expect(connectionFactory.getConnection()).andReturn(connection).once();
+//    expect(connection.createStatement()).andReturn(statement).once();
+//    expect(statement.execute("insert into ServiceInfo (cluster_name, service_name, state) values ('MyCluster', 'MyService', 'initial')")).andReturn(true).once();
+//
+//    replay(connectionFactory, connection, statement);
+//
+//    JDBCManagementController controller =  new JDBCManagementController(connectionFactory, ClusterControllerHelper.RESOURCE_TABLES);
+//
+//    Map<PropertyId, Object> properties = new LinkedHashMap<PropertyId, Object>();
+//
+//    PropertyId id = PropertyHelper.getPropertyId("cluster_name", "ServiceInfo");
+//    properties.put(id, "MyCluster");
+//
+//    id = PropertyHelper.getPropertyId("service_name", "ServiceInfo");
+//    properties.put(id, "MyService");
+//
+//    id = PropertyHelper.getPropertyId("state", "ServiceInfo");
+//    properties.put(id, "initial");
+//
+//    Set<Map<PropertyId, Object>> propertySet = new LinkedHashSet<Map<PropertyId, Object>>();
+//    propertySet.add(properties);
+//
+//    Request request = new RequestImpl(null, propertySet);
+//
+//    controller.createServices(request);
+//
+//    verify(connectionFactory, connection, statement);
+//  }
+//
+//  @Test
+//  public void testCreateHosts() throws Exception{
+//
+//    ConnectionFactory connectionFactory = createNiceMock(ConnectionFactory.class);
+//    Connection connection = createNiceMock(Connection.class);
+//    Statement statement = createNiceMock(Statement.class);
+//
+//    expect(connectionFactory.getConnection()).andReturn(connection).once();
+//    expect(connection.createStatement()).andReturn(statement).once();
+//    expect(statement.execute("insert into Hosts (cluster_name, host_name, ip) values ('MyCluster', 'MyHost1', '10.68.18.171')")).andReturn(true).once();
+//    expect(connection.createStatement()).andReturn(statement).once();
+//    expect(statement.execute("insert into Hosts (cluster_name, host_name, ip) values ('MyCluster', 'MyHost2', '10.111.35.113')")).andReturn(true).once();
+//
+//    replay(connectionFactory, connection, statement);
+//
+//    JDBCManagementController controller =  new JDBCManagementController(connectionFactory, ClusterControllerHelper.RESOURCE_TABLES);
+//
+//    Set<Map<PropertyId, Object>> propertySet = new LinkedHashSet<Map<PropertyId, Object>>();
+//
+//    // first host
+//    Map<PropertyId, Object> properties = new LinkedHashMap<PropertyId, Object>();
+//
+//    PropertyId id = PropertyHelper.getPropertyId("cluster_name", "Hosts");
+//    properties.put(id, "MyCluster");
+//
+//    id = PropertyHelper.getPropertyId("host_name", "Hosts");
+//    properties.put(id, "MyHost1");
+//
+//    id = PropertyHelper.getPropertyId("ip", "Hosts");
+//    properties.put(id, "10.68.18.171");
+//
+//    propertySet.add(properties);
+//
+//    // second host
+//    properties = new LinkedHashMap<PropertyId, Object>();
+//
+//    id = PropertyHelper.getPropertyId("cluster_name", "Hosts");
+//    properties.put(id, "MyCluster");
+//
+//    id = PropertyHelper.getPropertyId("host_name", "Hosts");
+//    properties.put(id, "MyHost2");
+//
+//    id = PropertyHelper.getPropertyId("ip", "Hosts");
+//    properties.put(id, "10.111.35.113");
+//
+//    propertySet.add(properties);
+//
+//    Request request = new RequestImpl(null, propertySet);
+//
+//    controller.createHosts(request);
+//
+//    verify(connectionFactory, connection, statement);
+//  }
+//
+//  @Test
+//  public void testCreateComponents() throws Exception{
+//
+//    ConnectionFactory connectionFactory = createNiceMock(ConnectionFactory.class);
+//    Connection connection = createNiceMock(Connection.class);
+//    Statement statement = createNiceMock(Statement.class);
+//
+//    expect(connectionFactory.getConnection()).andReturn(connection).once();
+//    expect(connection.createStatement()).andReturn(statement).once();
+//    expect(statement.execute("insert into ServiceComponentInfo (cluster_name, service_name, component_name, description) values ('MyCluster', 'MyService', 'MyComponent', 'This is my component')")).andReturn(true).once();
+//
+//    replay(connectionFactory, connection, statement);
+//
+//    JDBCManagementController controller =  new JDBCManagementController(connectionFactory, ClusterControllerHelper.RESOURCE_TABLES);
+//
+//    Map<PropertyId, Object> properties = new LinkedHashMap<PropertyId, Object>();
+//
+//    PropertyId id = PropertyHelper.getPropertyId("cluster_name", "ServiceComponentInfo");
+//    properties.put(id, "MyCluster");
+//
+//    id = PropertyHelper.getPropertyId("service_name", "ServiceComponentInfo");
+//    properties.put(id, "MyService");
+//
+//    id = PropertyHelper.getPropertyId("component_name", "ServiceComponentInfo");
+//    properties.put(id, "MyComponent");
+//
+//    id = PropertyHelper.getPropertyId("description", "ServiceComponentInfo");
+//    properties.put(id, "This is my component");
+//
+//    Set<Map<PropertyId, Object>> propertySet = new LinkedHashSet<Map<PropertyId, Object>>();
+//    propertySet.add(properties);
+//
+//    Request request = new RequestImpl(null, propertySet);
+//
+//    controller.createComponents(request);
+//
+//    verify(connectionFactory, connection, statement);
+//  }
+//
+//  @Test
+//  public void testCreateHostComponents() throws Exception{
+//
+//    ConnectionFactory connectionFactory = createNiceMock(ConnectionFactory.class);
+//    Connection connection = createNiceMock(Connection.class);
+//    Statement statement = createNiceMock(Statement.class);
+//
+//    expect(connectionFactory.getConnection()).andReturn(connection).once();
+//    expect(connection.createStatement()).andReturn(statement).once();
+//    expect(statement.execute("insert into HostRoles (cluster_name, host_name, component_name, role_id) values ('MyCluster', 'MyHost', 'MyComponent', 1)")).andReturn(true).once();
+//
+//    replay(connectionFactory, connection, statement);
+//
+//    JDBCManagementController controller =  new JDBCManagementController(connectionFactory, ClusterControllerHelper.RESOURCE_TABLES);
+//
+//    Map<PropertyId, Object> properties = new LinkedHashMap<PropertyId, Object>();
+//
+//    PropertyId id = PropertyHelper.getPropertyId("cluster_name", "HostRoles");
+//    properties.put(id, "MyCluster");
+//
+//    id = PropertyHelper.getPropertyId("host_name", "HostRoles");
+//    properties.put(id, "MyHost");
+//
+//    id = PropertyHelper.getPropertyId("component_name", "HostRoles");
+//    properties.put(id, "MyComponent");
+//
+//    id = PropertyHelper.getPropertyId("role_id", "HostRoles");
+//    properties.put(id, 1);
+//
+//    Set<Map<PropertyId, Object>> propertySet = new LinkedHashSet<Map<PropertyId, Object>>();
+//    propertySet.add(properties);
+//
+//    Request request = new RequestImpl(null, propertySet);
+//
+//    controller.createHostComponents(request);
+//
+//    verify(connectionFactory, connection, statement);
+//  }
+//
+//  @Test
+//  public void testDeleteClusters() throws Exception{
+//
+//    ConnectionFactory connectionFactory = createNiceMock(ConnectionFactory.class);
+//    Connection connection = createNiceMock(Connection.class);
+//    Statement statement = createNiceMock(Statement.class);
+//
+//    expect(connectionFactory.getConnection()).andReturn(connection).once();
+//    expect(connection.createStatement()).andReturn(statement).once();
+//    expect(statement.execute("delete from Clusters where Clusters.cluster_name = \"MyCluster\"")).andReturn(true).once();
+//
+//    replay(connectionFactory, connection, statement);
+//
+//    JDBCManagementController controller =  new JDBCManagementController(connectionFactory, ClusterControllerHelper.RESOURCE_TABLES);
+//
+//    Predicate predicate = new PredicateBuilder().property("cluster_name", "Clusters").equals("MyCluster").toPredicate();
+//
+//    controller.deleteClusters(predicate);
+//
+//    verify(connectionFactory, connection, statement);
+//  }
+//
+//  @Test
+//  public void testDeleteServices() throws Exception{
+//
+//    ConnectionFactory connectionFactory = createNiceMock(ConnectionFactory.class);
+//    Connection connection = createNiceMock(Connection.class);
+//    DatabaseMetaData databaseMetaData = createNiceMock(DatabaseMetaData.class);
+//    ResultSet metaDataResultSet = createNiceMock(ResultSet.class);
+//    Statement statement = createNiceMock(Statement.class);
+//    ResultSet resultSet = createNiceMock(ResultSet.class);
+//    ResultSetMetaData resultSetMetaData = createNiceMock(ResultSetMetaData.class);
+//
+//    expect(connectionFactory.getConnection()).andReturn(connection).once();
+//    expect(connection.getMetaData()).andReturn(databaseMetaData).atLeastOnce();
+//    expect(databaseMetaData.getImportedKeys((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(metaDataResultSet).atLeastOnce();
+//    expect(metaDataResultSet.next()).andReturn(true).once();
+//    expect(metaDataResultSet.getString("PKCOLUMN_NAME")).andReturn("service_name").once();
+//    expect(metaDataResultSet.getString("PKTABLE_NAME")).andReturn("ServiceInfo").once();
+//    expect(metaDataResultSet.getString("FKCOLUMN_NAME")).andReturn("service_name").once();
+//    expect(metaDataResultSet.getString("FKTABLE_NAME")).andReturn("Services").once();
+//    expect(metaDataResultSet.next()).andReturn(false).once();
+//    expect(databaseMetaData.getPrimaryKeys((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(metaDataResultSet).atLeastOnce();
+//    expect(metaDataResultSet.next()).andReturn(true).once();
+//    expect(metaDataResultSet.getString("COLUMN_NAME")).andReturn("service_name").once();
+//    expect(metaDataResultSet.getString("TABLE_NAME")).andReturn("ServiceInfo").once();
+//    expect(metaDataResultSet.next()).andReturn(true).once();
+//    expect(metaDataResultSet.getString("COLUMN_NAME")).andReturn("cluster_name").once();
+//    expect(metaDataResultSet.getString("TABLE_NAME")).andReturn("ServiceInfo").once();
+//    expect(metaDataResultSet.next()).andReturn(false).once();
+//    expect(connection.createStatement()).andReturn(statement).atLeastOnce();
+//    expect(statement.executeQuery("select ServiceInfo.service_name, ServiceInfo.cluster_name from Services, ServiceInfo where Services.display_name = \"my service\" AND ServiceInfo.service_name = Services.service_name")).andReturn(resultSet).once();
+//    expect(resultSet.getMetaData()).andReturn(resultSetMetaData).once();
+//    expect(resultSetMetaData.getColumnCount()).andReturn(2).once();
+//    expect(resultSet.next()).andReturn(true).once();
+//    expect(resultSetMetaData.getColumnName(1)).andReturn("service_name").once();
+//    expect(resultSetMetaData.getTableName(1)).andReturn("ServiceInfo").once();
+//    expect(resultSet.getString(1)).andReturn("MyService").once();
+//    expect(resultSetMetaData.getColumnName(2)).andReturn("cluster_name").once();
+//    expect(resultSetMetaData.getTableName(2)).andReturn("ServiceInfo").once();
+//    expect(resultSet.getString(2)).andReturn("MyCluster").once();
+//    expect(resultSet.next()).andReturn(false).once();
+//    expect(statement.execute("delete from ServiceInfo where (ServiceInfo.cluster_name = \"MyCluster\" AND ServiceInfo.service_name = \"MyService\")")).andReturn(true).once();
+//
+//    replay(connectionFactory, connection, databaseMetaData, metaDataResultSet, statement, resultSet, resultSetMetaData);
+//
+//    JDBCManagementController controller =  new JDBCManagementController(connectionFactory, ClusterControllerHelper.RESOURCE_TABLES);
+//
+//    Predicate predicate = new PredicateBuilder().property("display_name", "Services").equals("my service").toPredicate();
+//
+//    controller.deleteServices(predicate);
+//
+//    verify(connectionFactory, connection, databaseMetaData, metaDataResultSet, statement, resultSet, resultSetMetaData);
+//  }
+//
+//  @Test
+//  public void testDeleteHosts() throws Exception{
+//
+//    ConnectionFactory connectionFactory = createNiceMock(ConnectionFactory.class);
+//    Connection connection = createNiceMock(Connection.class);
+//    Statement statement = createNiceMock(Statement.class);
+//
+//    expect(connectionFactory.getConnection()).andReturn(connection).once();
+//    expect(connection.createStatement()).andReturn(statement).once();
+//    expect(statement.execute("delete from Hosts where (Hosts.host_name = \"MyHost1\" OR Hosts.host_name = \"MyHost2\")")).andReturn(true).once();
+//
+//    replay(connectionFactory, connection, statement);
+//
+//    JDBCManagementController controller =  new JDBCManagementController(connectionFactory, ClusterControllerHelper.RESOURCE_TABLES);
+//
+//    Predicate predicate = new PredicateBuilder().property("host_name", "Hosts").equals("MyHost1").or().
+//                                                 property("host_name", "Hosts").equals("MyHost2").toPredicate();
+//
+//    controller.deleteHosts(predicate);
+//
+//    verify(connectionFactory, connection, statement);
+//  }
+//
+//  @Test
+//  public void testDeleteComponents() throws Exception{
+//
+//    ConnectionFactory connectionFactory = createNiceMock(ConnectionFactory.class);
+//    Connection connection = createNiceMock(Connection.class);
+//    Statement statement = createNiceMock(Statement.class);
+//
+//    expect(connectionFactory.getConnection()).andReturn(connection).once();
+//    expect(connection.createStatement()).andReturn(statement).once();
+//    expect(statement.execute("delete from ServiceComponentInfo where ServiceComponentInfo.service_name = \"MyService\"")).andReturn(true).once();
+//
+//    replay(connectionFactory, connection, statement);
+//
+//    JDBCManagementController controller =  new JDBCManagementController(connectionFactory, ClusterControllerHelper.RESOURCE_TABLES);
+//
+//    Predicate predicate = new PredicateBuilder().property("service_name", "ServiceComponentInfo").equals("MyService").toPredicate();
+//
+//    controller.deleteComponents(predicate);
+//
+//    verify(connectionFactory, connection, statement);
+//  }
+//
+//  @Test
+//  public void testDeleteHostComponents() throws Exception{
+//
+//    ConnectionFactory connectionFactory = createNiceMock(ConnectionFactory.class);
+//    Connection connection = createNiceMock(Connection.class);
+//    Statement statement = createNiceMock(Statement.class);
+//
+//    expect(connectionFactory.getConnection()).andReturn(connection).once();
+//    expect(connection.createStatement()).andReturn(statement).once();
+//    expect(statement.execute("delete from HostRoles where HostRoles.component_name = \"MyComponent\"")).andReturn(true).once();
+//
+//    replay(connectionFactory, connection, statement);
+//
+//    JDBCManagementController controller =  new JDBCManagementController(connectionFactory, ClusterControllerHelper.RESOURCE_TABLES);
+//
+//    Predicate predicate = new PredicateBuilder().property("component_name", "HostRoles").equals("MyComponent").toPredicate();
+//
+//    controller.deleteHostComponents(predicate);
+//
+//    verify(connectionFactory, connection, statement);
+//  }
+//
+//  @Test
+//  public void testUpdateClusters() throws Exception{
+//
+//    ConnectionFactory connectionFactory = createNiceMock(ConnectionFactory.class);
+//    Connection connection = createNiceMock(Connection.class);
+//    Statement statement = createNiceMock(Statement.class);
+//
+//    expect(connectionFactory.getConnection()).andReturn(connection).once();
+//    expect(connection.createStatement()).andReturn(statement).once();
+//    expect(statement.execute("update Clusters set state = 'running' where Clusters.cluster_name = \"MyCluster\"")).andReturn(true).once();
+//
+//    replay(connectionFactory, connection, statement);
+//
+//    JDBCManagementController controller =  new JDBCManagementController(connectionFactory, ClusterControllerHelper.RESOURCE_TABLES);
+//
+//    Map<PropertyId, Object> properties = new LinkedHashMap<PropertyId, Object>();
+//
+//    PropertyId id = PropertyHelper.getPropertyId("state", "Clusters");
+//    properties.put(id, "running");
+//
+//    Predicate predicate = new PredicateBuilder().property("cluster_name", "Clusters").equals("MyCluster").toPredicate();
+//
+//    Set<Map<PropertyId, Object>> propertySet = new LinkedHashSet<Map<PropertyId, Object>>();
+//    propertySet.add(properties);
+//
+//    Request request = new RequestImpl(null, propertySet);
+//
+//    controller.updateClusters(request, predicate);
+//
+//    verify(connectionFactory, connection, statement);
+//  }
+//
+//  @Test
+//  public void testUpdateServices() throws Exception{
+//
+//    ConnectionFactory connectionFactory = createNiceMock(ConnectionFactory.class);
+//    Connection connection = createNiceMock(Connection.class);
+//    DatabaseMetaData databaseMetaData = createNiceMock(DatabaseMetaData.class);
+//    ResultSet metaDataResultSet = createNiceMock(ResultSet.class);
+//    Statement statement = createNiceMock(Statement.class);
+//    ResultSet resultSet = createNiceMock(ResultSet.class);
+//    ResultSetMetaData resultSetMetaData = createNiceMock(ResultSetMetaData.class);
+//
+//    expect(connectionFactory.getConnection()).andReturn(connection).once();
+//    expect(connection.getMetaData()).andReturn(databaseMetaData).atLeastOnce();
+//    expect(databaseMetaData.getImportedKeys((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(metaDataResultSet).atLeastOnce();
+//    expect(metaDataResultSet.next()).andReturn(true).once();
+//    expect(metaDataResultSet.getString("PKCOLUMN_NAME")).andReturn("service_name").once();
+//    expect(metaDataResultSet.getString("PKTABLE_NAME")).andReturn("ServiceInfo").once();
+//    expect(metaDataResultSet.getString("FKCOLUMN_NAME")).andReturn("service_name").once();
+//    expect(metaDataResultSet.getString("FKTABLE_NAME")).andReturn("Services").once();
+//    expect(metaDataResultSet.next()).andReturn(false).once();
+//    expect(metaDataResultSet.next()).andReturn(false).once();
+//    expect(databaseMetaData.getPrimaryKeys((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(metaDataResultSet).atLeastOnce();
+//    expect(metaDataResultSet.next()).andReturn(true).once();
+//    expect(metaDataResultSet.getString("COLUMN_NAME")).andReturn("service_name").once();
+//    expect(metaDataResultSet.getString("TABLE_NAME")).andReturn("ServiceInfo").once();
+//    expect(metaDataResultSet.next()).andReturn(true).once();
+//    expect(metaDataResultSet.getString("COLUMN_NAME")).andReturn("cluster_name").once();
+//    expect(metaDataResultSet.getString("TABLE_NAME")).andReturn("ServiceInfo").once();
+//    expect(metaDataResultSet.next()).andReturn(false).once();
+//    expect(connection.createStatement()).andReturn(statement).atLeastOnce();
+//    expect(statement.executeQuery("select ServiceInfo.service_name, ServiceInfo.cluster_name from Services, ServiceInfo where (ServiceInfo.service_name = \"MyService\" AND Services.display_name = \"my service\") AND ServiceInfo.service_name = Services.service_name")).andReturn(resultSet).once();
+//    expect(resultSet.getMetaData()).andReturn(resultSetMetaData).once();
+//    expect(resultSetMetaData.getColumnCount()).andReturn(2).once();
+//    expect(resultSet.next()).andReturn(true).once();
+//    expect(resultSetMetaData.getColumnName(1)).andReturn("service_name").once();
+//    expect(resultSetMetaData.getTableName(1)).andReturn("ServiceInfo").once();
+//    expect(resultSet.getString(1)).andReturn("MyService").once();
+//    expect(resultSetMetaData.getColumnName(2)).andReturn("cluster_name").once();
+//    expect(resultSetMetaData.getTableName(2)).andReturn("ServiceInfo").once();
+//    expect(resultSet.getString(2)).andReturn("MyCluster").once();
+//    expect(resultSet.next()).andReturn(false).once();
+//    expect(statement.execute("update ServiceInfo set state = 'running' where (ServiceInfo.cluster_name = \"MyCluster\" AND ServiceInfo.service_name = \"MyService\")")).andReturn(true).once();
+//
+//    replay(connectionFactory, connection, databaseMetaData, metaDataResultSet, statement, resultSet, resultSetMetaData);
+//
+//    JDBCManagementController controller =  new JDBCManagementController(connectionFactory, ClusterControllerHelper.RESOURCE_TABLES);
+//
+//    Map<PropertyId, Object> properties = new LinkedHashMap<PropertyId, Object>();
+//
+//    PropertyId id = PropertyHelper.getPropertyId("state", "ServiceInfo");
+//    properties.put(id, "running");
+//
+//    Predicate predicate = new PredicateBuilder().property("service_name", "ServiceInfo").equals("MyService").and().
+//                                                 property("display_name", "Services").equals("my service").toPredicate();
+//
+//    Set<Map<PropertyId, Object>> propertySet = new LinkedHashSet<Map<PropertyId, Object>>();
+//    propertySet.add(properties);
+//
+//    Request request = new RequestImpl(null, propertySet);
+//
+//    controller.updateServices(request, predicate);
+//
+//    verify(connectionFactory, connection, databaseMetaData, metaDataResultSet, statement, resultSet, resultSetMetaData);
+//  }
+//
+//  @Test
+//  public void testUpdateHosts() throws Exception{
+//
+//    ConnectionFactory connectionFactory = createNiceMock(ConnectionFactory.class);
+//    Connection connection = createNiceMock(Connection.class);
+//    Statement statement = createNiceMock(Statement.class);
+//
+//    expect(connectionFactory.getConnection()).andReturn(connection).once();
+//    expect(connection.createStatement()).andReturn(statement).once();
+//    expect(statement.execute("update Hosts set cpu_count = 4 where (Hosts.host_name = \"MyHost1\" OR Hosts.host_name = \"MyHost2\")")).andReturn(true).once();
+//
+//    replay(connectionFactory, connection, statement);
+//
+//    JDBCManagementController controller =  new JDBCManagementController(connectionFactory, ClusterControllerHelper.RESOURCE_TABLES);
+//
+//    Map<PropertyId, Object> properties = new LinkedHashMap<PropertyId, Object>();
+//
+//    PropertyId id = PropertyHelper.getPropertyId("cpu_count", "Hosts");
+//    properties.put(id, 4);
+//
+//    Set<Map<PropertyId, Object>> propertySet = new LinkedHashSet<Map<PropertyId, Object>>();
+//    propertySet.add(properties);
+//
+//    Predicate predicate = new PredicateBuilder().property("host_name", "Hosts").equals("MyHost1").or().
+//                                                 property("host_name", "Hosts").equals("MyHost2").toPredicate();
+//
+//    Request request = new RequestImpl(null, propertySet);
+//
+//    controller.updateHosts(request, predicate);
+//
+//    verify(connectionFactory, connection, statement);
+//  }
+//
+//  @Test
+//  public void testUpdateComponents() throws Exception{
+//
+//    ConnectionFactory connectionFactory = createNiceMock(ConnectionFactory.class);
+//    Connection connection = createNiceMock(Connection.class);
+//    Statement statement = createNiceMock(Statement.class);
+//
+//    expect(connectionFactory.getConnection()).andReturn(connection).once();
+//    expect(connection.createStatement()).andReturn(statement).once();
+//    expect(statement.execute("update ServiceComponentInfo set description = 'new description' where ServiceComponentInfo.service_name = \"MyService\"")).andReturn(true).once();
+//
+//    replay(connectionFactory, connection, statement);
+//
+//    JDBCManagementController controller =  new JDBCManagementController(connectionFactory, ClusterControllerHelper.RESOURCE_TABLES);
+//
+//    Map<PropertyId, Object> properties = new LinkedHashMap<PropertyId, Object>();
+//
+//    PropertyId id = PropertyHelper.getPropertyId("description", "ServiceComponentInfo");
+//    properties.put(id, "new description");
+//
+//    Predicate predicate = new PredicateBuilder().property("service_name", "ServiceComponentInfo").equals("MyService").toPredicate();
+//
+//    Set<Map<PropertyId, Object>> propertySet = new LinkedHashSet<Map<PropertyId, Object>>();
+//    propertySet.add(properties);
+//
+//    Request request = new RequestImpl(null, propertySet);
+//
+//    controller.updateComponents(request, predicate);
+//
+//    verify(connectionFactory, connection, statement);
+//  }
+//
+//  @Test
+//  public void testUpdateHostComponents() throws Exception{
+//
+//    ConnectionFactory connectionFactory = createNiceMock(ConnectionFactory.class);
+//    Connection connection = createNiceMock(Connection.class);
+//    Statement statement = createNiceMock(Statement.class);
+//
+//    expect(connectionFactory.getConnection()).andReturn(connection).once();
+//    expect(connection.createStatement()).andReturn(statement).once();
+//    expect(statement.execute("update HostRoles set state = 'running' where HostRoles.component_name = \"MyComponent\"")).andReturn(true).once();
+//
+//    replay(connectionFactory, connection, statement);
+//
+//    JDBCManagementController controller =  new JDBCManagementController(connectionFactory, ClusterControllerHelper.RESOURCE_TABLES);
+//
+//    Map<PropertyId, Object> properties = new LinkedHashMap<PropertyId, Object>();
+//
+//    PropertyId id = PropertyHelper.getPropertyId("state", "HostRoles");
+//    properties.put(id, "running");
+//
+//    Predicate predicate = new PredicateBuilder().property("component_name", "HostRoles").equals("MyComponent").toPredicate();
+//
+//    Set<Map<PropertyId, Object>> propertySet = new LinkedHashSet<Map<PropertyId, Object>>();
+//    propertySet.add(properties);
+//
+//    Request request = new RequestImpl(null, propertySet);
+//
+//    controller.updateHostComponents(request, predicate);
+//
+//    verify(connectionFactory, connection, statement);
+//  }
+//
+//  @Test
+//  public void testGetClusters() throws Exception{
+//
+//    ConnectionFactory connectionFactory = createNiceMock(ConnectionFactory.class);
+//    Connection connection = createNiceMock(Connection.class);
+//    DatabaseMetaData databaseMetaData = createNiceMock(DatabaseMetaData.class);
+//    ResultSet metaDataResultSet = createNiceMock(ResultSet.class);
+//    Statement statement = createNiceMock(Statement.class);
+//    ResultSet resultSet = createNiceMock(ResultSet.class);
+//    ResultSetMetaData resultSetMetaData = createNiceMock(ResultSetMetaData.class);
+//
+//    expect(connectionFactory.getConnection()).andReturn(connection).once();
+//    expect(connection.getMetaData()).andReturn(databaseMetaData).once();
+//    expect(databaseMetaData.getImportedKeys((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(metaDataResultSet).atLeastOnce();
+//    expect(metaDataResultSet.next()).andReturn(false).atLeastOnce();
+//    expect(connection.createStatement()).andReturn(statement).once();
+//    expect(statement.executeQuery("select Clusters.state, Clusters.cluster_name from Clusters where Clusters.cluster_name = \"MyCluster\"")).andReturn(resultSet).once();
+//    expect(resultSet.getMetaData()).andReturn(resultSetMetaData).once();
+//    expect(resultSetMetaData.getColumnCount()).andReturn(2).once();
+//    expect(resultSet.next()).andReturn(true).once();
+//    expect(resultSetMetaData.getColumnName(1)).andReturn("state").once();
+//    expect(resultSetMetaData.getTableName(1)).andReturn("Clusters").once();
+//    expect(resultSet.getString(1)).andReturn("running").once();
+//    expect(resultSetMetaData.getColumnName(2)).andReturn("cluster_name").once();
+//    expect(resultSetMetaData.getTableName(2)).andReturn("Clusters").once();
+//    expect(resultSet.getString(2)).andReturn("MyCluster").once();
+//    expect(resultSet.next()).andReturn(false).once();
+//
+//    replay(connectionFactory, connection, databaseMetaData, metaDataResultSet, statement, resultSet, resultSetMetaData);
+//
+//    JDBCManagementController controller =  new JDBCManagementController(connectionFactory, ClusterControllerHelper.RESOURCE_TABLES);
+//
+//    Predicate predicate = new PredicateBuilder().property("cluster_name", "Clusters").equals("MyCluster").toPredicate();
+//
+//    Set<PropertyId> propertyIds = new LinkedHashSet<PropertyId>();
+//    propertyIds.add(PropertyHelper.getPropertyId("state", "Clusters"));
+//
+//    Request request = new RequestImpl(propertyIds, null);
+//
+//    Set<Resource> resources = controller.getClusters(request, predicate);
+//
+//    Assert.assertEquals(1, resources.size());
+//
+//    Resource resource = resources.iterator().next();
+//
+//    Assert.assertEquals(Resource.Type.Cluster, resource.getType());
+//
+//    Assert.assertEquals("running", resource.getPropertyValue(PropertyHelper.getPropertyId("state", "Clusters")));
+//
+//    verify(connectionFactory, connection, databaseMetaData, metaDataResultSet, statement, resultSet, resultSetMetaData);
+//  }
+//
+//  @Test
+//  public void testGetServices() throws Exception{
+//
+//    ConnectionFactory connectionFactory = createNiceMock(ConnectionFactory.class);
+//    Connection connection = createNiceMock(Connection.class);
+//    DatabaseMetaData databaseMetaData = createNiceMock(DatabaseMetaData.class);
+//    ResultSet metaDataResultSet = createNiceMock(ResultSet.class);
+//    Statement statement = createNiceMock(Statement.class);
+//    ResultSet resultSet = createNiceMock(ResultSet.class);
+//    ResultSetMetaData resultSetMetaData = createNiceMock(ResultSetMetaData.class);
+//
+//    expect(connectionFactory.getConnection()).andReturn(connection).once();
+//    expect(connection.getMetaData()).andReturn(databaseMetaData).atLeastOnce();
+//    expect(databaseMetaData.getImportedKeys((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(metaDataResultSet).atLeastOnce();
+//    expect(metaDataResultSet.next()).andReturn(true).once();
+//    expect(metaDataResultSet.getString("PKCOLUMN_NAME")).andReturn("service_name").once();
+//    expect(metaDataResultSet.getString("PKTABLE_NAME")).andReturn("ServiceInfo").once();
+//    expect(metaDataResultSet.getString("FKCOLUMN_NAME")).andReturn("service_name").once();
+//    expect(metaDataResultSet.getString("FKTABLE_NAME")).andReturn("Services").once();
+//    expect(metaDataResultSet.next()).andReturn(false).once();
+//    expect(connection.createStatement()).andReturn(statement).once();
+//    expect(statement.executeQuery("select ServiceInfo.service_name, Services.description from Services, ServiceInfo where ServiceInfo.service_name = \"MyService\" AND ServiceInfo.service_name = Services.service_name")).andReturn(resultSet).once();
+//    expect(resultSet.getMetaData()).andReturn(resultSetMetaData).once();
+//    expect(resultSetMetaData.getColumnCount()).andReturn(2).once();
+//    expect(resultSet.next()).andReturn(true).once();
+//    expect(resultSetMetaData.getColumnName(1)).andReturn("service_name").once();
+//    expect(resultSetMetaData.getTableName(1)).andReturn("ServiceInfo").once();
+//    expect(resultSet.getString(1)).andReturn("MyService").once();
+//    expect(resultSetMetaData.getColumnName(2)).andReturn("description").once();
+//    expect(resultSetMetaData.getTableName(2)).andReturn("Services").once();
+//    expect(resultSet.getString(2)).andReturn("some description").once();
+//    expect(resultSet.next()).andReturn(false).once();
+//
+//    replay(connectionFactory, connection, databaseMetaData, metaDataResultSet, statement, resultSet, resultSetMetaData);
+//
+//    JDBCManagementController controller =  new JDBCManagementController(connectionFactory, ClusterControllerHelper.RESOURCE_TABLES);
+//
+//    Predicate predicate = new PredicateBuilder().property("service_name", "ServiceInfo").equals("MyService").toPredicate();
+//
+//    Set<PropertyId> propertyIds = new LinkedHashSet<PropertyId>();
+//    propertyIds.add(PropertyHelper.getPropertyId("service_name", "ServiceInfo"));
+//    propertyIds.add(PropertyHelper.getPropertyId("description", "Services"));
+//
+//    Request request = new RequestImpl(propertyIds, null);
+//
+//    Set<Resource> resources = controller.getServices(request, predicate);
+//
+//    Assert.assertEquals(1, resources.size());
+//
+//    Resource resource = resources.iterator().next();
+//
+//    Assert.assertEquals(Resource.Type.Service, resource.getType());
+//
+//    Assert.assertEquals("MyService", resource.getPropertyValue(PropertyHelper.getPropertyId("service_name", "ServiceInfo")));
+//    Assert.assertEquals("some description", resource.getPropertyValue(PropertyHelper.getPropertyId("description", "Services")));
+//
+//    verify(connectionFactory, connection, databaseMetaData, metaDataResultSet, statement, resultSet, resultSetMetaData);
+//  }
+//
+//  @Test
+//  public void testGetComponents() throws Exception{
+//
+//    ConnectionFactory connectionFactory = createNiceMock(ConnectionFactory.class);
+//    Connection connection = createNiceMock(Connection.class);
+//    DatabaseMetaData databaseMetaData = createNiceMock(DatabaseMetaData.class);
+//    ResultSet metaDataResultSet = createNiceMock(ResultSet.class);
+//    Statement statement = createNiceMock(Statement.class);
+//    ResultSet resultSet = createNiceMock(ResultSet.class);
+//    ResultSetMetaData resultSetMetaData = createNiceMock(ResultSetMetaData.class);
+//
+//    expect(connectionFactory.getConnection()).andReturn(connection).once();
+//    expect(connection.getMetaData()).andReturn(databaseMetaData).atLeastOnce();
+//    expect(databaseMetaData.getImportedKeys((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(metaDataResultSet).atLeastOnce();
+//    expect(metaDataResultSet.next()).andReturn(true).once();
+//    expect(metaDataResultSet.getString("PKCOLUMN_NAME")).andReturn("component_name").once();
+//    expect(metaDataResultSet.getString("PKTABLE_NAME")).andReturn("ServiceComponentInfo").once();
+//    expect(metaDataResultSet.getString("FKCOLUMN_NAME")).andReturn("component_name").once();
+//    expect(metaDataResultSet.getString("FKTABLE_NAME")).andReturn("ServiceComponents").once();
+//    expect(metaDataResultSet.next()).andReturn(false).once();
+//    expect(connection.createStatement()).andReturn(statement).once();
+//    expect(statement.executeQuery("select ServiceComponentInfo.component_name, ServiceComponents.description from ServiceComponentInfo, ServiceComponents where ServiceComponentInfo.component_name = \"MyService\" AND ServiceComponentInfo.component_name = ServiceComponents.component_name")).andReturn(resultSet).once();
+//    expect(resultSet.getMetaData()).andReturn(resultSetMetaData).once();
+//    expect(resultSetMetaData.getColumnCount()).andReturn(2).once();
+//    expect(resultSet.next()).andReturn(true).once();
+//    expect(resultSetMetaData.getColumnName(1)).andReturn("component_name").once();
+//    expect(resultSetMetaData.getTableName(1)).andReturn("ServiceComponentInfo").once();
+//    expect(resultSet.getString(1)).andReturn("MyService").once();
+//    expect(resultSetMetaData.getColumnName(2)).andReturn("description").once();
+//    expect(resultSetMetaData.getTableName(2)).andReturn("ServiceComponents").once();
+//    expect(resultSet.getString(2)).andReturn("some description").once();
+//    expect(resultSet.next()).andReturn(false).once();
+//
+//    replay(connectionFactory, connection, databaseMetaData, metaDataResultSet, statement, resultSet, resultSetMetaData);
+//
+//    JDBCManagementController controller =  new JDBCManagementController(connectionFactory, ClusterControllerHelper.RESOURCE_TABLES);
+//
+//    Predicate predicate = new PredicateBuilder().property("component_name", "ServiceComponentInfo").equals("MyService").toPredicate();
+//
+//    Set<PropertyId> propertyIds = new LinkedHashSet<PropertyId>();
+//    propertyIds.add(PropertyHelper.getPropertyId("component_name", "ServiceComponentInfo"));
+//    propertyIds.add(PropertyHelper.getPropertyId("description", "ServiceComponents"));
+//
+//    Request request = new RequestImpl(propertyIds, null);
+//
+//    Set<Resource> resources = controller.getComponents(request, predicate);
+//
+//    Assert.assertEquals(1, resources.size());
+//
+//    Resource resource = resources.iterator().next();
+//
+//    Assert.assertEquals(Resource.Type.Component, resource.getType());
+//
+//    Assert.assertEquals("MyService", resource.getPropertyValue(PropertyHelper.getPropertyId("component_name", "ServiceComponentInfo")));
+//    Assert.assertEquals("some description", resource.getPropertyValue(PropertyHelper.getPropertyId("description", "ServiceComponents")));
+//
+//    verify(connectionFactory, connection, databaseMetaData, metaDataResultSet, statement, resultSet, resultSetMetaData);
+//  }
+//
+//  @Test
+//  public void testGetHosts() throws Exception{
+//
+//    ConnectionFactory connectionFactory = createNiceMock(ConnectionFactory.class);
+//    Connection connection = createNiceMock(Connection.class);
+//    DatabaseMetaData databaseMetaData = createNiceMock(DatabaseMetaData.class);
+//    ResultSet metaDataResultSet = createNiceMock(ResultSet.class);
+//    Statement statement = createNiceMock(Statement.class);
+//    ResultSet resultSet = createNiceMock(ResultSet.class);
+//    ResultSetMetaData resultSetMetaData = createNiceMock(ResultSetMetaData.class);
+//
+//    expect(connectionFactory.getConnection()).andReturn(connection).once();
+//    expect(connection.getMetaData()).andReturn(databaseMetaData).once();
+//    expect(databaseMetaData.getImportedKeys((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(metaDataResultSet).atLeastOnce();
+//    expect(metaDataResultSet.next()).andReturn(false).atLeastOnce();
+//    expect(connection.createStatement()).andReturn(statement).once();
+//    expect(statement.executeQuery("select Hosts.cpu_count, Hosts.host_name from Hosts where Hosts.host_name = \"MyHost\"")).andReturn(resultSet).once();
+//    expect(resultSet.getMetaData()).andReturn(resultSetMetaData).once();
+//    expect(resultSetMetaData.getColumnCount()).andReturn(2).once();
+//    expect(resultSet.next()).andReturn(true).once();
+//    expect(resultSetMetaData.getColumnName(1)).andReturn("cpu_count").once();
+//    expect(resultSetMetaData.getTableName(1)).andReturn("Hosts").once();
+//    expect(resultSet.getString(1)).andReturn("4").once();
+//    expect(resultSetMetaData.getColumnName(2)).andReturn("host_name").once();
+//    expect(resultSetMetaData.getTableName(2)).andReturn("Hosts").once();
+//    expect(resultSet.getString(2)).andReturn("MyHost").once();
+//    expect(resultSet.next()).andReturn(false).once();
+//
+//    replay(connectionFactory, connection, databaseMetaData, metaDataResultSet, statement, resultSet, resultSetMetaData);
+//
+//    JDBCManagementController controller =  new JDBCManagementController(connectionFactory, ClusterControllerHelper.RESOURCE_TABLES);
+//
+//    Predicate predicate = new PredicateBuilder().property("host_name", "Hosts").equals("MyHost").toPredicate();
+//
+//    Set<PropertyId> propertyIds = new LinkedHashSet<PropertyId>();
+//    propertyIds.add(PropertyHelper.getPropertyId("cpu_count", "Hosts"));
+//
+//    Request request = new RequestImpl(propertyIds, null);
+//
+//    Set<Resource> resources = controller.getHosts(request, predicate);
+//
+//    Assert.assertEquals(1, resources.size());
+//
+//    Resource resource = resources.iterator().next();
+//
+//    Assert.assertEquals(Resource.Type.Host, resource.getType());
+//
+//    Assert.assertEquals("4", resource.getPropertyValue(PropertyHelper.getPropertyId("cpu_count", "Hosts")));
+//
+//    verify(connectionFactory, connection, databaseMetaData, metaDataResultSet, statement, resultSet, resultSetMetaData);
+//  }
+//
+//  @Test
+//  public void testGetHostComponents() throws Exception{
+//
+//    ConnectionFactory connectionFactory = createNiceMock(ConnectionFactory.class);
+//    Connection connection = createNiceMock(Connection.class);
+//    DatabaseMetaData databaseMetaData = createNiceMock(DatabaseMetaData.class);
+//    ResultSet metaDataResultSet = createNiceMock(ResultSet.class);
+//    Statement statement = createNiceMock(Statement.class);
+//    ResultSet resultSet = createNiceMock(ResultSet.class);
+//    ResultSetMetaData resultSetMetaData = createNiceMock(ResultSetMetaData.class);
+//
+//    expect(connectionFactory.getConnection()).andReturn(connection).once();
+//    expect(connection.getMetaData()).andReturn(databaseMetaData).once();
+//    expect(databaseMetaData.getImportedKeys((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(metaDataResultSet).atLeastOnce();
+//    expect(metaDataResultSet.next()).andReturn(false).atLeastOnce();
+//    expect(connection.createStatement()).andReturn(statement).once();
+//    expect(statement.executeQuery("select HostRoles.host_name, HostRoles.state from HostRoles where HostRoles.host_name = \"MyHost\"")).andReturn(resultSet).once();
+//    expect(resultSet.getMetaData()).andReturn(resultSetMetaData).once();
+//    expect(resultSetMetaData.getColumnCount()).andReturn(2).once();
+//    expect(resultSet.next()).andReturn(true).once();
+//    expect(resultSetMetaData.getColumnName(1)).andReturn("state").once();
+//    expect(resultSetMetaData.getTableName(1)).andReturn("HostRoles").once();
+//    expect(resultSet.getString(1)).andReturn("running").once();
+//    expect(resultSetMetaData.getColumnName(2)).andReturn("host_name").once();
+//    expect(resultSetMetaData.getTableName(2)).andReturn("HostRoles").once();
+//    expect(resultSet.getString(2)).andReturn("MyHost").once();
+//    expect(resultSet.next()).andReturn(false).once();
+//
+//    replay(connectionFactory, connection, databaseMetaData, metaDataResultSet, statement, resultSet, resultSetMetaData);
+//
+//    JDBCManagementController controller =  new JDBCManagementController(connectionFactory, ClusterControllerHelper.RESOURCE_TABLES);
+//
+//    Predicate predicate = new PredicateBuilder().property("host_name", "HostRoles").equals("MyHost").toPredicate();
+//
+//    Set<PropertyId> propertyIds = new LinkedHashSet<PropertyId>();
+//    propertyIds.add(PropertyHelper.getPropertyId("state", "HostRoles"));
+//
+//    Request request = new RequestImpl(propertyIds, null);
+//
+//    Set<Resource> resources = controller.getHostComponents(request, predicate);
+//
+//    Assert.assertEquals(1, resources.size());
+//
+//    Resource resource = resources.iterator().next();
+//
+//    Assert.assertEquals(Resource.Type.HostComponent, resource.getType());
+//
+//    Assert.assertEquals("running", resource.getPropertyValue(PropertyHelper.getPropertyId("state", "HostRoles")));
+//
+//    verify(connectionFactory, connection, databaseMetaData, metaDataResultSet, statement, resultSet, resultSetMetaData);
+//  }
+}
+

Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/jdbc/TestJDBCResourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/jdbc/TestJDBCResourceProvider.java?rev=1396481&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/jdbc/TestJDBCResourceProvider.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/jdbc/TestJDBCResourceProvider.java Wed Oct 10 06:34:22 2012
@@ -0,0 +1,41 @@
+/**
+ * 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.controller.jdbc;
+
+import org.apache.ambari.server.controller.spi.PropertyId;
+import org.apache.ambari.server.controller.spi.PropertyProvider;
+import org.apache.ambari.server.controller.spi.Resource;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ *
+ */
+public class TestJDBCResourceProvider extends JDBCResourceProvider{
+  public TestJDBCResourceProvider(ConnectionFactory connectionFactory, Resource.Type type, List<PropertyProvider> propertyProviders, Set<PropertyId> propertyIds, Map<Resource.Type, PropertyId> keyPropertyIds) {
+    super(connectionFactory, type, propertyProviders, propertyIds, keyPropertyIds);
+  }
+
+  @Override
+  public List<PropertyProvider> getPropertyProviders() {
+    return super.getPropertyProviders();
+  }
+}

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/JMXPropertyProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/JMXPropertyProviderTest.java?rev=1396481&r1=1396480&r2=1396481&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/JMXPropertyProviderTest.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/JMXPropertyProviderTest.java Wed Oct 10 06:34:22 2012
@@ -24,15 +24,10 @@ import org.apache.ambari.server.controll
 import org.apache.ambari.server.controller.spi.Request;
 import org.apache.ambari.server.controller.spi.Resource;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
-import org.apache.ambari.server.controller.utilities.StreamProvider;
 import org.junit.Assert;
 import org.junit.Test;
 
-import java.io.IOException;
-import java.io.InputStream;
 import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
 import java.util.Set;
 
 /**
@@ -40,24 +35,7 @@ import java.util.Set;
  */
 public class JMXPropertyProviderTest {
 
-  private static Map<String, String> HOST_MAPPING = new HashMap<String, String>();
-
-  static {
-    HOST_MAPPING.put("domU-12-31-39-0E-34-E1.compute-1.internal", "ec2-50-17-129-192.compute-1.amazonaws.com");
-    HOST_MAPPING.put("ip-10-190-186-15.ec2.internal",             "ec2-23-21-8-226.compute-1.amazonaws.com");
-    HOST_MAPPING.put("domU-12-31-39-14-EE-B3.compute-1.internal", "ec2-23-23-71-42.compute-1.amazonaws.com");
-    HOST_MAPPING.put("ip-10-110-157-51.ec2.internal",             "ec2-107-22-121-67.compute-1.amazonaws.com");
-  }
-
-  private static Map<String, String> FILE_MAPPING = new HashMap<String, String>();
-
-  static {
-    FILE_MAPPING.put("http://ec2-23-21-8-226.compute-1.amazonaws.com:50070/jmx?qry=Hadoop:*", "hdfs_namenode_jmx.json");
-    FILE_MAPPING.put("http://ec2-23-23-71-42.compute-1.amazonaws.com:50075/jmx?qry=Hadoop:*", "hdfs_datanode_jmx.json");
-    FILE_MAPPING.put("http://ec2-23-23-71-42.compute-1.amazonaws.com:50030/jmx?qry=Hadoop:*", "mapreduce_jobtracker_jmx.json");
-  }
-
-  @Test
+    @Test
   public void testGetResources() throws Exception {
 
     Set< PropertyId >       propertyIds     = PropertyHelper.getPropertyIds(Resource.Type.HostComponent, "JMX");
@@ -71,7 +49,7 @@ public class JMXPropertyProviderTest {
     // namenode
     Resource resource = new ResourceImpl(Resource.Type.HostComponent);
 
-    resource.setProperty(JMXPropertyProvider.HOST_COMPONENT_HOST_NAME_PROPERTY_ID, "ip-10-190-186-15.ec2.internal");
+    resource.setProperty(JMXPropertyProvider.HOST_COMPONENT_HOST_NAME_PROPERTY_ID, "domU-12-31-39-0E-34-E1.compute-1.internal");
     resource.setProperty(JMXPropertyProvider.HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID, "NAMENODE");
 
     // request with an empty set should get all supported properties
@@ -79,7 +57,7 @@ public class JMXPropertyProviderTest {
 
     Assert.assertEquals(1, propertyProvider.populateResources(Collections.singleton(resource), request, null).size());
 
-    Assert.assertEquals(JMXPropertyProvider.getSpec("ec2-23-21-8-226.compute-1.amazonaws.com:50070"), streamProvider.getLastSpec());
+    Assert.assertEquals(JMXPropertyProvider.getSpec("ec2-50-17-129-192.compute-1.amazonaws.com:50070"), streamProvider.getLastSpec());
 
     // see test/resources/hdfs_namenode_jmx.json for values
     Assert.assertEquals("1084287",  resource.getPropertyValue(PropertyHelper.getPropertyId("ReceivedBytes", "rpc")));
@@ -124,31 +102,4 @@ public class JMXPropertyProviderTest {
     Assert.assertEquals("59", resource.getPropertyValue(PropertyHelper.getPropertyId("threadsWaiting", "jvm")));
     Assert.assertNull(resource.getPropertyValue(PropertyHelper.getPropertyId("gcCount", "jvm")));
   }
-
-
-  public static class TestStreamProvider implements StreamProvider {
-    private String lastSpec;
-
-    @Override
-    public InputStream readFrom(String spec) throws IOException {
-      lastSpec = spec;
-      String filename = FILE_MAPPING.get(spec);
-      if (filename == null) {
-        throw new IOException("Can't find JMX source for " + spec);
-      }
-      InputStream resourceAsStream = ClassLoader.getSystemResourceAsStream(filename);
-      return resourceAsStream;
-    }
-
-    public String getLastSpec() {
-      return lastSpec;
-    }
-  }
-
-  public static class TestHostMappingProvider implements HostMappingProvider {
-    @Override
-    public Map<String, String> getHostMap() {
-      return HOST_MAPPING;
-    }
-  }
 }

Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/TestHostMappingProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/TestHostMappingProvider.java?rev=1396481&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/TestHostMappingProvider.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/TestHostMappingProvider.java Wed Oct 10 06:34:22 2012
@@ -0,0 +1,42 @@
+/**
+ * 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.controller.jmx;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ *
+ */
+public class TestHostMappingProvider implements HostMappingProvider {
+
+  private static Map<String, String> HOST_MAPPING = new HashMap<String, String>();
+
+  static {
+    HOST_MAPPING.put("domU-12-31-39-0E-34-E1.compute-1.internal", "ec2-50-17-129-192.compute-1.amazonaws.com");
+    HOST_MAPPING.put("ip-10-190-186-15.ec2.internal",             "ec2-23-21-8-226.compute-1.amazonaws.com");
+    HOST_MAPPING.put("domU-12-31-39-14-EE-B3.compute-1.internal", "ec2-23-23-71-42.compute-1.amazonaws.com");
+    HOST_MAPPING.put("ip-10-110-157-51.ec2.internal",             "ec2-107-22-121-67.compute-1.amazonaws.com");
+  }
+
+  @Override
+  public Map<String, String> getHostMap() {
+    return HOST_MAPPING;
+  }
+}
\ No newline at end of file

Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/TestStreamProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/TestStreamProvider.java?rev=1396481&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/TestStreamProvider.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/TestStreamProvider.java Wed Oct 10 06:34:22 2012
@@ -0,0 +1,61 @@
+/**
+ * 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.controller.jmx;
+
+import org.apache.ambari.server.controller.utilities.StreamProvider;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+public class TestStreamProvider implements StreamProvider {
+
+  protected static Map<String, String> FILE_MAPPING = new HashMap<String, String>();
+
+  static {
+    FILE_MAPPING.put("50070", "hdfs_namenode_jmx.json");
+    FILE_MAPPING.put("50075", "hdfs_datanode_jmx.json");
+    FILE_MAPPING.put("50030", "mapreduce_jobtracker_jmx.json");
+    FILE_MAPPING.put("50060", "mapreduce_tasktracker_jmx.json");
+  }
+
+  private String lastSpec;
+
+  @Override
+  public InputStream readFrom(String spec) throws IOException {
+    lastSpec = spec;
+    String filename = FILE_MAPPING.get(getPort(spec));
+    if (filename == null) {
+      throw new IOException("Can't find JMX source for " + spec);
+    }
+    return ClassLoader.getSystemResourceAsStream(filename);
+  }
+
+  public String getLastSpec() {
+    return lastSpec;
+  }
+
+  private String getPort(String spec) {
+    int n = spec.indexOf(":", 5);
+    return spec.substring(n + 1, n + 6);
+  }
+
+
+}

Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/resources/data.db
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/resources/data.db?rev=1396481&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/resources/data.db
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



Mime
View raw message