ClusterImpl implements Cluster { @Override public Map<String, Object> getSessionAttributes() { Map<String, Object> attributes = (Map<String, Object>) getSessionManager().getAttribute(getClusterSessionAttributeName()); return attributes == null ? Collections.<String, Object>emptyMap() : attributes; } @Inject  ClusterImpl(@Assisted ClusterEntity clusterEntity, Injector injector,
      AmbariEventPublisher eventPublisher); @Override void addConfigGroup(ConfigGroup configGroup); @Override Map<Long, ConfigGroup> getConfigGroups(); @Override Map<Long, ConfigGroup> getConfigGroupsByHostname(String hostname); @Override void addRequestExecution(RequestExecution requestExecution); @Override Map<Long, RequestExecution> getAllRequestExecutions(); @Override void deleteRequestExecution(Long id); @Override void deleteConfigGroup(Long id); ServiceComponentHost getServiceComponentHost(String serviceName,
      String serviceComponentName, String hostname); @Override String getClusterName(); @Override void setClusterName(String clusterName); @Override Long getResourceId(); @Override @Transactional void addServiceComponentHosts(Collection<ServiceComponentHost> serviceComponentHosts); void addServiceComponentHost(ServiceComponentHost svcCompHost); @Override void removeServiceComponentHost(ServiceComponentHost svcCompHost); @Override long getClusterId(); @Override List<ServiceComponentHost> getServiceComponentHosts(String hostname); @Override Map<String, Set<String>> getServiceComponentHostMap(Set<String> hostNames, Set<String> serviceNames); @Override List<ServiceComponentHost> getServiceComponentHosts(String serviceName, String componentName); @Override void addService(Service service); @Override Service addService(String serviceName); @Override Service getService(String serviceName); @Override Map<String, Service> getServices(); @Override StackId getDesiredStackVersion(); @Override void setDesiredStackVersion(StackId stackId); @Override void setDesiredStackVersion(StackId stackId, boolean cascade); @Override StackId getCurrentStackVersion(); @Override State getProvisioningState(); @Override void setProvisioningState(State provisioningState); @Override SecurityType getSecurityType(); @Override void setSecurityType(SecurityType securityType); @Override ClusterVersionEntity getCurrentClusterVersion(); @Override UpgradeEntity getUpgradeInProgress(); @Override ClusterVersionEntity getEffectiveClusterVersion(); @Override Collection<ClusterVersionEntity> getAllClusterVersions(); @Override void mapHostVersions(Set<String> hostNames, ClusterVersionEntity currentClusterVersion, RepositoryVersionState desiredState); @Override void transitionHosts(ClusterVersionEntity sourceClusterVersion,
      RepositoryVersionState state); @Override void recalculateClusterVersionState(RepositoryVersionEntity repositoryVersion); @Override @Transactional HostVersionEntity transitionHostVersionState(HostEntity host, final RepositoryVersionEntity repositoryVersion, final StackId stack); @Override void recalculateAllClusterVersionStates(); @Override void createClusterVersion(StackId stackId, String version,
      String userName, RepositoryVersionState state); @Override @Transactional void transitionClusterVersion(StackId stackId, String version,
      RepositoryVersionState state); @Override @Transactional void setCurrentStackVersion(StackId stackId); @Override Map<String, Config> getConfigsByType(String configType); @Override Config getConfig(String configType, String versionTag); @Override Config getConfigByVersion(String configType, Long configVersion); @Override void addConfig(Config config); @Override Collection<Config> getAllConfigs(); @Override ClusterResponse convertToResponse(); @Override void debugDump(StringBuilder sb); @Override @Transactional void refresh(); @Override @Transactional void deleteAllServices(); @Override void deleteService(String serviceName); @Override boolean canBeRemoved(); @Override @Transactional void delete(); @Override ServiceConfigVersionResponse addDesiredConfig(String user, Set<Config> configs); @Override ServiceConfigVersionResponse addDesiredConfig(String user, Set<Config> configs, String serviceConfigVersionNote); @Override Map<String, Set<DesiredConfig>> getAllDesiredConfigVersions(); @Override Map<String, DesiredConfig> getDesiredConfigs(); @Override ServiceConfigVersionResponse createServiceConfigVersion(
      String serviceName, String user, String note, ConfigGroup configGroup); @Override String getServiceForConfigTypes(Collection<String> configTypes); @Override String getServiceByConfigType(String configType); @Override ServiceConfigVersionResponse setServiceConfigVersion(String serviceName, Long version, String user, String note); @Override Map<String, Collection<ServiceConfigVersionResponse>> getActiveServiceConfigVersions(); @Override List<ServiceConfigVersionResponse> getServiceConfigVersions(); @Override List<ServiceConfigVersionResponse> getActiveServiceConfigVersionResponse(String serviceName); @Override Config getDesiredConfigByType(String configType); @Override boolean isConfigTypeExists(String configType); @Override Map<Long, Map<String, DesiredConfig>> getHostsDesiredConfigs(Collection<Long> hostIds); @Override Map<Long, Map<String, DesiredConfig>> getAllHostsDesiredConfigs(); @Override Long getNextConfigVersion(String type); @Override Map<ServiceComponentHostEvent, String> processServiceComponentHostEvents(ListMultimap<String, ServiceComponentHostEvent> eventMap); @Override Set<String> getHosts(String serviceName, String componentName); @Override Collection<Host> getHosts(); @Override boolean checkPermission(PrivilegeEntity privilegeEntity, boolean readOnly); @Override void addSessionAttributes(Map<String, Object> attributes); @Override void setSessionAttribute(String key, Object value); @Override void removeSessionAttribute(String key); @Override Map<String, Object> getSessionAttributes(); @Override @Transactional void applyLatestConfigurations(StackId stackId); @Override Map<PropertyInfo.PropertyType, Set<String>> getConfigPropertiesTypes(String configType); @Override void removeConfigurations(StackId stackId); @Override boolean isBluePrintDeployed(); @Override int getClusterSize(); @Override UpgradeEntity getUpgradeEntity(); @Override @Transactional void setUpgradeEntity(UpgradeEntity upgradeEntity); @Override boolean isUpgradeSuspended(); @Override String getClusterProperty(String propertyName, String defaultValue); @Subscribe void handleClusterEnvConfigChangedEvent(ClusterConfigChangedEvent event); @Override RoleCommandOrder getRoleCommandOrder(); @Override void addSuspendedUpgradeParameters(Map<String, String> commandParams,
      Map<String, String> roleParams);  }
@Test public void testGetSessionAttributes() throws Exception { Map<String, Object> attributes = new HashMap<String, Object>(); attributes.put("foo", "bar"); AmbariSessionManager sessionManager = createMock(AmbariSessionManager.class); ClusterImpl cluster = createMockBuilder(ClusterImpl.class). addMockedMethod("getSessionManager"). addMockedMethod("getClusterName"). createMock(); expect(cluster.getSessionManager()).andReturn(sessionManager).anyTimes(); expect(cluster.getClusterName()).andReturn("c1").anyTimes(); expect(sessionManager.getAttribute("cluster_session_attributes:c1")).andReturn(attributes); expect(sessionManager.getAttribute("cluster_session_attributes:c1")).andReturn(null); replay(sessionManager, cluster); assertEquals(attributes, cluster.getSessionAttributes()); assertEquals(Collections.<String, Object>emptyMap(), cluster.getSessionAttributes()); verify(sessionManager, cluster); }