Issue #1802 Fixes related to DD transaction refactor

Change-Id: Ia2a7a4ce990d424ed1e365bd7003fd2ab8630fd1

Former-commit-id: 2a14245dce [formerly 393a469e2f65894a6dd5b58c1431c3d727951eda]
Former-commit-id: 115dc12790
This commit is contained in:
Benjamin Phillippe 2013-03-27 17:12:52 -05:00
parent 9b527de11a
commit 30be5ce6f9
21 changed files with 338 additions and 371 deletions

View file

@ -36,6 +36,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.raytheon.uf.common.comm.CommunicationException;
import com.raytheon.uf.common.registry.IMultipleResultFormatter; import com.raytheon.uf.common.registry.IMultipleResultFormatter;
import com.raytheon.uf.common.registry.IResultFormatter; import com.raytheon.uf.common.registry.IResultFormatter;
import com.raytheon.uf.common.registry.OperationStatus; import com.raytheon.uf.common.registry.OperationStatus;
@ -71,6 +72,7 @@ import com.raytheon.uf.common.util.ReflectionException;
* Sep 14, 2012 1169 djohnson Add use of create only mode. * Sep 14, 2012 1169 djohnson Add use of create only mode.
* Feb 26, 2013 1643 djohnson Remove registry manager debug toggle. * Feb 26, 2013 1643 djohnson Remove registry manager debug toggle.
* 3/18/2013 1802 bphillip Implemented transaction boundaries * 3/18/2013 1802 bphillip Implemented transaction boundaries
* 3/27/2013 1802 bphillip Changed visibility of processRequest and fixed catch block to catch the correct Exception type
* *
* </pre> * </pre>
* *
@ -264,8 +266,8 @@ public class FactoryRegistryHandler implements RegistryHandler {
* the response object to populate on error * the response object to populate on error
* @return the response * @return the response
*/ */
private <T extends RegistryResponse<U>, U> T processRequest( <T extends RegistryResponse<U>, U> T processRequest(Callable<T> request,
Callable<T> request, T response) { T response) {
T calledResponse = null; T calledResponse = null;
try { try {
calledResponse = request.call(); calledResponse = request.call();
@ -274,7 +276,7 @@ public class FactoryRegistryHandler implements RegistryHandler {
calledResponse = RegistryUtil.getFailedResponse(response, calledResponse = RegistryUtil.getFailedResponse(response,
new RegistryException( new RegistryException(
RegistryUtil.UNABLE_TO_CONNECT_TO_REGISTRY, e)); RegistryUtil.UNABLE_TO_CONNECT_TO_REGISTRY, e));
} catch (Exception e) { } catch (CommunicationException e) {
calledResponse = RegistryUtil.getFailedResponse(response, e); calledResponse = RegistryUtil.getFailedResponse(response, e);
} catch (Throwable e) { } catch (Throwable e) {
calledResponse = RegistryUtil.getFailedResponse(response, e); calledResponse = RegistryUtil.getFailedResponse(response, e);

View file

@ -57,6 +57,7 @@ import com.raytheon.uf.edex.database.DataAccessLayerException;
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Feb 07, 2013 1543 djohnson Initial creation * Feb 07, 2013 1543 djohnson Initial creation
* 3/18/2013 1802 bphillip Added additional database functions. Enforcing mandatory transaction propogation * 3/18/2013 1802 bphillip Added additional database functions. Enforcing mandatory transaction propogation
* 3/27/2013 1802 bphillip Changed transaction propagation of query methods
* *
* </pre> * </pre>
* *
@ -141,6 +142,7 @@ public abstract class SessionManagedDao<IDENTIFIER extends Serializable, ENTITY
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
@Transactional(propagation = Propagation.REQUIRED)
public ENTITY getById(Serializable id) { public ENTITY getById(Serializable id) {
final Class<ENTITY> entityClass = getEntityClass(); final Class<ENTITY> entityClass = getEntityClass();
return entityClass.cast(template.get(entityClass, id)); return entityClass.cast(template.get(entityClass, id));
@ -150,6 +152,7 @@ public abstract class SessionManagedDao<IDENTIFIER extends Serializable, ENTITY
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
@Transactional(propagation = Propagation.REQUIRED)
public List<ENTITY> getAll() { public List<ENTITY> getAll() {
return query("from " + getEntityClass().getSimpleName(), return query("from " + getEntityClass().getSimpleName(),
Collections.<String, Object> emptyMap()); Collections.<String, Object> emptyMap());
@ -162,11 +165,13 @@ public abstract class SessionManagedDao<IDENTIFIER extends Serializable, ENTITY
* @param params * @param params
* @return * @return
*/ */
@Transactional(propagation = Propagation.REQUIRED)
protected List<ENTITY> query(String queryString, Map<String, Object> params) { protected List<ENTITY> query(String queryString, Map<String, Object> params) {
return query(queryString, params, 0); return query(queryString, params, 0);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Transactional(propagation = Propagation.REQUIRED)
protected List<ENTITY> query(String queryString, protected List<ENTITY> query(String queryString,
Map<String, Object> params, int maxResults) { Map<String, Object> params, int maxResults) {
final int numberOfParams = params.size(); final int numberOfParams = params.size();
@ -193,6 +198,7 @@ public abstract class SessionManagedDao<IDENTIFIER extends Serializable, ENTITY
* @param params * @param params
* @return * @return
*/ */
@Transactional(propagation = Propagation.REQUIRED)
protected ENTITY uniqueResult(String queryString, Map<String, Object> params) { protected ENTITY uniqueResult(String queryString, Map<String, Object> params) {
final List<ENTITY> results = query(queryString, params); final List<ENTITY> results = query(queryString, params);
if (results.isEmpty()) { if (results.isEmpty()) {
@ -215,6 +221,7 @@ public abstract class SessionManagedDao<IDENTIFIER extends Serializable, ENTITY
* @throws DataAccessLayerException * @throws DataAccessLayerException
* If errors are encountered during the HQL query * If errors are encountered during the HQL query
*/ */
@Transactional(propagation = Propagation.REQUIRED)
public <T extends Object> List<T> executeHQLQuery(String queryString) public <T extends Object> List<T> executeHQLQuery(String queryString)
throws DataAccessLayerException { throws DataAccessLayerException {
return executeHQLQuery(queryString, true, null); return executeHQLQuery(queryString, true, null);
@ -231,6 +238,7 @@ public abstract class SessionManagedDao<IDENTIFIER extends Serializable, ENTITY
* @throws DataAccessLayerException * @throws DataAccessLayerException
* If Hibernate errors occur during execution of the query * If Hibernate errors occur during execution of the query
*/ */
@Transactional(propagation = Propagation.REQUIRED)
public List<ENTITY> executeHQLQuery(StringBuilder queryString) public List<ENTITY> executeHQLQuery(StringBuilder queryString)
throws DataAccessLayerException { throws DataAccessLayerException {
return executeHQLQuery(queryString.toString(), true, null); return executeHQLQuery(queryString.toString(), true, null);
@ -253,6 +261,7 @@ public abstract class SessionManagedDao<IDENTIFIER extends Serializable, ENTITY
* @throws DataAccessLayerException * @throws DataAccessLayerException
* If Hibernate errors occur during the execution of the query * If Hibernate errors occur during the execution of the query
*/ */
@Transactional(propagation = Propagation.REQUIRED)
public List<ENTITY> executeHQLQuery(String queryString, public List<ENTITY> executeHQLQuery(String queryString,
Map<String, Object> params) throws DataAccessLayerException { Map<String, Object> params) throws DataAccessLayerException {
return executeHQLQuery(queryString, true, params); return executeHQLQuery(queryString, true, params);
@ -272,6 +281,7 @@ public abstract class SessionManagedDao<IDENTIFIER extends Serializable, ENTITY
* if errors are encountered during the HQL query * if errors are encountered during the HQL query
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Transactional(propagation = Propagation.REQUIRED)
public <T extends Object> List<T> executeHQLQuery(final String queryString, public <T extends Object> List<T> executeHQLQuery(final String queryString,
boolean eager, final Map<String, Object> params) boolean eager, final Map<String, Object> params)
throws DataAccessLayerException { throws DataAccessLayerException {
@ -360,7 +370,6 @@ public abstract class SessionManagedDao<IDENTIFIER extends Serializable, ENTITY
* @throws DataAccessLayerException * @throws DataAccessLayerException
* if errors are encountered during the HQL query * if errors are encountered during the HQL query
*/ */
@SuppressWarnings("unchecked")
public int executeHQLStatement(final String queryString, boolean eager, public int executeHQLStatement(final String queryString, boolean eager,
final Map<String, Object> params) throws DataAccessLayerException { final Map<String, Object> params) throws DataAccessLayerException {
try { try {
@ -393,6 +402,7 @@ public abstract class SessionManagedDao<IDENTIFIER extends Serializable, ENTITY
* If errors occur in Hibernate while executing the query * If errors occur in Hibernate while executing the query
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Transactional(propagation = Propagation.REQUIRED)
public <T extends Object> List<T> executeCriteriaQuery( public <T extends Object> List<T> executeCriteriaQuery(
final DetachedCriteria criteria) throws DataAccessLayerException { final DetachedCriteria criteria) throws DataAccessLayerException {
if (criteria == null) { if (criteria == null) {

View file

@ -1,112 +1,122 @@
<beans xmlns="http://www.springframework.org/schema/beans" <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="propertyPlaceholderConfigurer" <bean id="propertyPlaceholderConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations"> <property name="locations">
<list> <list>
<value>classpath:/com.raytheon.uf.edex.datadelivery.bandwidth.properties <value>classpath:/com.raytheon.uf.edex.datadelivery.bandwidth.properties
</value> </value>
</list> </list>
</property> </property>
</bean> </bean>
<bean id="bandwidthDao" factory-bean="bandwidthContextFactory" <bean id="bandwidthDao" factory-bean="bandwidthContextFactory"
factory-method="getBandwidthDao" /> factory-method="getBandwidthDao" />
<bean id="bandwidthDbInit" factory-bean="bandwidthContextFactory" <bean id="bandwidthDbInit" factory-bean="bandwidthContextFactory"
factory-method="getBandwidthDbInit" init-method="init" /> factory-method="getBandwidthDbInit" init-method="init" />
<bean id="bandwidthManagerInitializer" factory-bean="bandwidthContextFactory" <bean id="bandwidthManagerInitializer" factory-bean="bandwidthContextFactory"
factory-method="getBandwidthInitializer" depends-on="registryManagerInstanceInitializer"> factory-method="getBandwidthInitializer" depends-on="registryManagerInstanceInitializer">
</bean> </bean>
<bean id="bandwidthMapConfigFile" factory-bean="bandwidthContextFactory" <bean id="bandwidthMapConfigFile" factory-bean="bandwidthContextFactory"
factory-method="getBandwidthMapConfigFile" /> factory-method="getBandwidthMapConfigFile" />
<bean id="bandwidthManager" factory-bean="bandwidthContextFactory" <bean id="bandwidthManager" factory-bean="bandwidthContextFactory"
factory-method="getBandwidthManager" factory-method="getBandwidthManager"
depends-on="BandwidthEventBusConfig,bandwidthUtil,registerDataDeliveryHandlers" depends-on="BandwidthEventBusConfig,bandwidthUtil,registerDataDeliveryHandlers"
init-method="init"> init-method="init">
<constructor-arg ref="bandwidthDbInit" /> <constructor-arg ref="bandwidthDbInit" />
<constructor-arg ref="bandwidthDao" /> <constructor-arg ref="bandwidthDao" />
<constructor-arg ref="retrievalManager" /> <constructor-arg ref="retrievalManager" />
<constructor-arg ref="bandwidthDaoUtil" /> <constructor-arg ref="bandwidthDaoUtil" />
<property name="aggregator" ref="aggregator" /> <property name="aggregator" ref="aggregator" />
<property name="initializer" ref="bandwidthManagerInitializer" /> <property name="initializer" ref="bandwidthManagerInitializer" />
</bean> </bean>
<bean id="dataSetAvailabilityCalculator" <bean id="dataSetAvailabilityCalculator"
class="com.raytheon.uf.edex.datadelivery.bandwidth.util.SimpleAvailablityCalculator"> class="com.raytheon.uf.edex.datadelivery.bandwidth.util.SimpleAvailablityCalculator">
<property name="delay" <property name="delay"
value="${bandwidth.dataSetAvailabilityCalculator.delay}" /> value="${bandwidth.dataSetAvailabilityCalculator.delay}" />
</bean> </bean>
<bean id="bandwidthUtil" <bean id="bandwidthUtil"
class="com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil" class="com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil"
factory-method="getInstance"> factory-method="getInstance">
<property name="dataSetAvailabilityCalculator" ref="dataSetAvailabilityCalculator" /> <property name="dataSetAvailabilityCalculator" ref="dataSetAvailabilityCalculator" />
<property name="subscriptionLatencyCalculator"> <property name="subscriptionLatencyCalculator">
<bean <bean
class="com.raytheon.uf.edex.datadelivery.bandwidth.util.SubscriptionValueLatencyCalculator" /> class="com.raytheon.uf.edex.datadelivery.bandwidth.util.SubscriptionValueLatencyCalculator" />
</property> </property>
<property name="subscriptionRescheduleStrategy"> <property name="subscriptionRescheduleStrategy">
<bean <bean
class="com.raytheon.uf.edex.datadelivery.bandwidth.util.AlwaysRescheduleSubscriptions" /> class="com.raytheon.uf.edex.datadelivery.bandwidth.util.AlwaysRescheduleSubscriptions" />
</property> </property>
</bean> </bean>
<bean id="bandwidthDaoUtil" <bean id="bandwidthDaoUtil"
class="com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthDaoUtil"> class="com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthDaoUtil">
<constructor-arg ref="bandwidthDao" /> <constructor-arg ref="bandwidthDao" />
<constructor-arg ref="retrievalManager" /> <constructor-arg ref="retrievalManager" />
</bean> </bean>
<bean id="BandwidthMap" <bean id="BandwidthMap"
class="com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.BandwidthMap" class="com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.BandwidthMap"
factory-method="load"> factory-method="load">
<constructor-arg ref="bandwidthMapConfigFile" /> <constructor-arg ref="bandwidthMapConfigFile" />
</bean> </bean>
<bean id="aggregator" <bean id="aggregator"
class="com.raytheon.uf.edex.datadelivery.bandwidth.processing.SimpleSubscriptionAggregator"> class="com.raytheon.uf.edex.datadelivery.bandwidth.processing.SimpleSubscriptionAggregator">
<constructor-arg ref="bandwidthDao" /> <constructor-arg ref="bandwidthDao" />
</bean> </bean>
<bean id="BandwidthEventBusConfig" <bean id="BandwidthEventBusConfig"
class="com.raytheon.uf.edex.datadelivery.bandwidth.notification.BandwidthEventBusConfig"> class="com.raytheon.uf.edex.datadelivery.bandwidth.notification.BandwidthEventBusConfig">
<property name="dataSetMetaDataPoolSize" value="${bandwidth.dataSetMetaDataPoolSize}" /> <property name="dataSetMetaDataPoolSize" value="${bandwidth.dataSetMetaDataPoolSize}" />
<property name="retrievalPoolSize" value="${bandwidth.retrievalPoolSize}" /> <property name="retrievalPoolSize" value="${bandwidth.retrievalPoolSize}" />
<property name="subscriptionPoolSize" value="${bandwidth.subscriptionPoolSize}" /> <property name="subscriptionPoolSize" value="${bandwidth.subscriptionPoolSize}" />
</bean> </bean>
<!-- The shared monitor object between the RetrievalAgentManager and <!-- The shared monitor object between the RetrievalAgentManager and its
its Agents --> Agents -->
<bean id="retrievalAgentNotifier" class="java.lang.Object" /> <bean id="retrievalAgentNotifier" class="java.lang.Object" />
<bean id="retrievalAgentManager" <bean id="retrievalAgentManager"
class="com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalAgentManager" class="com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalAgentManager"
init-method="start"> init-method="start">
<constructor-arg ref="retrievalAgentNotifier" /> <constructor-arg ref="retrievalAgentNotifier" />
<constructor-arg ref="retrievalAgents" /> <constructor-arg ref="retrievalAgents" />
<constructor-arg ref="retrievalDao" /> <constructor-arg ref="retrievalDao" />
</bean> </bean>
<bean id="retrievalManager" <bean id="retrievalManager"
class="com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalManager" class="com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalManager"
depends-on="bandwidthDbInit"> depends-on="bandwidthDbInit">
<constructor-arg ref="bandwidthDao" /> <constructor-arg ref="bandwidthDao" />
<constructor-arg ref="retrievalAgentNotifier" /> <constructor-arg ref="retrievalAgentNotifier" />
<property name="retrievalPlans" ref="retrievalPlans" /> <property name="retrievalPlans" ref="retrievalPlans" />
</bean> </bean>
<bean id="BandwidthManagerProcessor" <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
class="com.raytheon.uf.edex.datadelivery.bandwidth.processing.Processor" /> <property name="staticMethod"
<bean id="BandwidthManagerRetrieval" value="com.raytheon.uf.common.event.EventBus.register" />
class="com.raytheon.uf.edex.datadelivery.retrieval.RetrievalGenerationHandler"> <property name="arguments">
<constructor-arg ref="retrievalDao" /> <list>
</bean> <ref bean="retrievalManager" />
<bean id="SubscriptionBundleSeparator" </list>
class="com.raytheon.uf.edex.datadelivery.bandwidth.separator.SubscriptionBundleSeparator" /> </property>
</bean>
<bean id="BandwidthManagerProcessor"
class="com.raytheon.uf.edex.datadelivery.bandwidth.processing.Processor" />
<bean id="BandwidthManagerRetrieval"
class="com.raytheon.uf.edex.datadelivery.retrieval.RetrievalGenerationHandler">
<constructor-arg ref="retrievalDao" />
</bean>
<bean id="SubscriptionBundleSeparator"
class="com.raytheon.uf.edex.datadelivery.bandwidth.separator.SubscriptionBundleSeparator" />
</beans> </beans>

View file

@ -6,8 +6,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import javax.annotation.PostConstruct;
import com.google.common.eventbus.Subscribe; import com.google.common.eventbus.Subscribe;
import com.raytheon.uf.common.datadelivery.registry.Network; import com.raytheon.uf.common.datadelivery.registry.Network;
import com.raytheon.uf.common.event.EventBus; import com.raytheon.uf.common.event.EventBus;
@ -36,6 +34,7 @@ import com.raytheon.uf.edex.datadelivery.retrieval.RetrievalManagerNotifyEvent;
* Feb 05, 2013 1580 mpduff EventBus refactor. * Feb 05, 2013 1580 mpduff EventBus refactor.
* Feb 14, 2013 1596 djohnson Warn log when unable to find a SubscriptionRetrieval. * Feb 14, 2013 1596 djohnson Warn log when unable to find a SubscriptionRetrieval.
* 3/18/2013 1802 bphillip Event bus registration is now a post-construct operation to ensure proxy is registered with bus * 3/18/2013 1802 bphillip Event bus registration is now a post-construct operation to ensure proxy is registered with bus
* 3/13/2013 1802 bphillip Moved event bus registration from post-construct to spring static method call
* *
* </pre> * </pre>
* *
@ -65,11 +64,6 @@ public class RetrievalManager {
this.notifier = notifier; this.notifier = notifier;
} }
@PostConstruct
public void registerWithEventBus() {
EventBus.register(this);
}
public Map<Network, RetrievalPlan> getRetrievalPlans() { public Map<Network, RetrievalPlan> getRetrievalPlans() {
return retrievalPlans; return retrievalPlans;
} }

View file

@ -1,39 +1,52 @@
<beans <beans xmlns="http://www.springframework.org/schema/beans"
xmlns="http://www.springframework.org/schema/beans" xmlns:amq="http://activemq.apache.org/schema/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:amq="http://activemq.apache.org/schema/core" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<bean id="notificationHandler" class="com.raytheon.uf.edex.datadelivery.event.handler.NotificationHandler"> <bean id="notificationHandler"
<constructor-arg type="java.lang.String" value="jms-generic:topic:notify.msg?destinationResolver=#qpidDurableResolver"/> class="com.raytheon.uf.edex.datadelivery.event.handler.NotificationHandler">
<property name="notificationDao" ref="notificationDao"/> <constructor-arg type="java.lang.String"
</bean> value="jms-generic:topic:notify.msg?destinationResolver=#qpidDurableResolver" />
<property name="notificationDao" ref="notificationDao" />
<!-- verify text product info for site, spawns in separate thread to not delay start up --> </bean>
<bean id="notificationPurge" class="com.raytheon.uf.edex.datadelivery.event.notification.NotificationPurge" depends-on="ddEventRegister"/>
<bean
<bean id="noitfyCamelRegistered" factory-bean="contextManager" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="staticMethod"
value="com.raytheon.uf.common.event.EventBus.register" />
<property name="arguments">
<list>
<ref bean="notificationHandler" />
</list>
</property>
</bean>
<!-- verify text product info for site, spawns in separate thread to not
delay start up -->
<bean id="notificationPurge"
class="com.raytheon.uf.edex.datadelivery.event.notification.NotificationPurge"
depends-on="ddEventRegister" />
<bean id="noitfyCamelRegistered" factory-bean="contextManager"
factory-method="register" depends-on="persistCamelRegistered"> factory-method="register" depends-on="persistCamelRegistered">
<constructor-arg ref="ddNotify-camel"/> <constructor-arg ref="ddNotify-camel" />
</bean> </bean>
<camelContext id="ddNotify-camel" <camelContext id="ddNotify-camel" xmlns="http://camel.apache.org/schema/spring"
xmlns="http://camel.apache.org/schema/spring" errorHandlerRef="errorHandler" autoStartup="false">
errorHandlerRef="errorHandler"
autoStartup="false">
<route id="notificationPurgeRoute"> <route id="notificationPurgeRoute">
<from uri="timer://notifiyPurge?period=60s" /> <from uri="timer://notifiyPurge?period=60s" />
<doTry> <doTry>
<bean ref="notificationPurge" method="purge"/> <bean ref="notificationPurge" method="purge" />
<doCatch> <doCatch>
<exception>java.lang.Throwable</exception> <exception>java.lang.Throwable</exception>
<to uri="log:purge?level=ERROR&amp;showBody=false&amp;showCaughtException=true&amp;showStackTrace=true"/> <to
uri="log:purge?level=ERROR&amp;showBody=false&amp;showCaughtException=true&amp;showStackTrace=true" />
</doCatch> </doCatch>
</doTry> </doTry>
</route> </route>
</camelContext> </camelContext>
</beans> </beans>

View file

@ -1,12 +1,9 @@
package com.raytheon.uf.edex.datadelivery.event.handler; package com.raytheon.uf.edex.datadelivery.event.handler;
import javax.annotation.PostConstruct;
import com.google.common.eventbus.AllowConcurrentEvents; import com.google.common.eventbus.AllowConcurrentEvents;
import com.google.common.eventbus.Subscribe; import com.google.common.eventbus.Subscribe;
import com.raytheon.uf.common.datadelivery.event.INotifiableEvent; import com.raytheon.uf.common.datadelivery.event.INotifiableEvent;
import com.raytheon.uf.common.datadelivery.event.notification.NotificationRecord; import com.raytheon.uf.common.datadelivery.event.notification.NotificationRecord;
import com.raytheon.uf.common.event.EventBus;
import com.raytheon.uf.common.registry.event.RemoveRegistryEvent; import com.raytheon.uf.common.registry.event.RemoveRegistryEvent;
/** /**
@ -29,6 +26,7 @@ import com.raytheon.uf.common.registry.event.RemoveRegistryEvent;
* Dec 07, 2012 1104 djohnson Changed to use INotifiableEvent for events with notifications. * Dec 07, 2012 1104 djohnson Changed to use INotifiableEvent for events with notifications.
* Feb 05, 2013 1580 mpduff EventBus refactor. * Feb 05, 2013 1580 mpduff EventBus refactor.
* 3/18/2013 1802 bphillip Modified to use transactional boundaries and spring injection of daos * 3/18/2013 1802 bphillip Modified to use transactional boundaries and spring injection of daos
* 3/27/2013 1802 bphillip Moved event bus registration from PostConstruct method to Spring static method call
* *
* </pre> * </pre>
* *
@ -47,11 +45,6 @@ public class NotificationHandler extends AbstractHandler {
super(); super();
} }
@PostConstruct
public void registerWithEventBus() {
EventBus.register(this);
}
/** /**
* Creates a new handler object and registers this object with the * Creates a new handler object and registers this object with the
* DataDeliveryEventBus * DataDeliveryEventBus

View file

@ -29,7 +29,8 @@ Require-Bundle: com.raytheon.uf.common.status;bundle-version="1.12.1174",
com.raytheon.uf.common.parameter;bundle-version="1.0.0", com.raytheon.uf.common.parameter;bundle-version="1.0.0",
com.raytheon.uf.edex.event;bundle-version="1.0.0", com.raytheon.uf.edex.event;bundle-version="1.0.0",
com.raytheon.uf.common.stats;bundle-version="1.0.0", com.raytheon.uf.common.stats;bundle-version="1.0.0",
com.raytheon.uf.edex.decodertools;bundle-version="1.12.1174" com.raytheon.uf.edex.decodertools;bundle-version="1.12.1174",
com.raytheon.uf.edex.registry.ebxml;bundle-version="1.0.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy Bundle-ActivationPolicy: lazy
Export-Package: com.raytheon.uf.edex.datadelivery.retrieval; Export-Package: com.raytheon.uf.edex.datadelivery.retrieval;

View file

@ -1,12 +1,31 @@
<beans xmlns="http://www.springframework.org/schema/beans" <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<bean id="retrievalDao" <bean id="retrievalTransactionInterceptor"
class="com.raytheon.uf.edex.datadelivery.retrieval.db.RetrievalDao"> class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="sessionFactory" ref="metadataSessionFactory" /> <property name="transactionManager" ref="metadataTxManager" />
</bean> <property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean id="retrievalDao" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target" ref="retrievalDaoImpl" />
<property name="interceptorNames">
<list>
<value>retrievalTransactionInterceptor</value>
</list>
</property>
</bean>
<bean id="retrievalDaoImpl"
class="com.raytheon.uf.edex.datadelivery.retrieval.db.RetrievalDao">
<property name="sessionFactory" ref="metadataSessionFactory" />
</bean>
</beans> </beans>

View file

@ -31,6 +31,7 @@ import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.time.domain.api.IDuration; import com.raytheon.uf.common.time.domain.api.IDuration;
import com.raytheon.uf.edex.datadelivery.retrieval.db.IRetrievalDao; import com.raytheon.uf.edex.datadelivery.retrieval.db.IRetrievalDao;
import com.raytheon.uf.edex.registry.ebxml.init.RegistryInitializedListener;
/** /**
* Provider Retrieval Handler * Provider Retrieval Handler
@ -43,6 +44,7 @@ import com.raytheon.uf.edex.datadelivery.retrieval.db.IRetrievalDao;
* Jan 07, 2011 dhladky Initial creation * Jan 07, 2011 dhladky Initial creation
* Aug 09, 2012 1022 djohnson Use {@link ExecutorService} for retrieval. * Aug 09, 2012 1022 djohnson Use {@link ExecutorService} for retrieval.
* Mar 04, 2013 1647 djohnson RetrievalTasks are now scheduled via constructor parameter. * Mar 04, 2013 1647 djohnson RetrievalTasks are now scheduled via constructor parameter.
* Mar 27, 2013 1802 bphillip Scheduling of retrieval tasks now occurs after camel/spring have been initialized
* *
* </pre> * </pre>
* *
@ -50,7 +52,7 @@ import com.raytheon.uf.edex.datadelivery.retrieval.db.IRetrievalDao;
* @version 1.0 * @version 1.0
*/ */
@Service @Service
public class RetrievalHandler { public class RetrievalHandler implements RegistryInitializedListener {
private static final IUFStatusHandler statusHandler = UFStatus private static final IUFStatusHandler statusHandler = UFStatus
.getHandler(RetrievalHandler.class); .getHandler(RetrievalHandler.class);
@ -59,22 +61,24 @@ public class RetrievalHandler {
private final List<RetrievalTask> retrievalTasks; private final List<RetrievalTask> retrievalTasks;
private IRetrievalDao retrievalDao;
private IDuration retrievalTaskFrequency;
private IDuration subnotifyTaskFrequency;
private SubscriptionNotifyTask subNotifyTask;
public RetrievalHandler(ScheduledExecutorService executorService, public RetrievalHandler(ScheduledExecutorService executorService,
IRetrievalDao retrievalDao, List<RetrievalTask> retrievalTasks, IRetrievalDao retrievalDao, List<RetrievalTask> retrievalTasks,
SubscriptionNotifyTask subNotifyTask, SubscriptionNotifyTask subNotifyTask,
IDuration retrievalTaskFrequency, IDuration subnotifyTaskFrequency) { IDuration retrievalTaskFrequency, IDuration subnotifyTaskFrequency) {
this.executorService = executorService; this.executorService = executorService;
this.retrievalTasks = retrievalTasks; this.retrievalTasks = retrievalTasks;
this.retrievalDao = retrievalDao;
// set all Running state retrievals to pending this.retrievalTaskFrequency = retrievalTaskFrequency;
retrievalDao.resetRunningRetrievalsToPending(); this.subnotifyTaskFrequency = subnotifyTaskFrequency;
this.subNotifyTask = subNotifyTask;
for (RetrievalTask retrievalTask : retrievalTasks) {
executorService.scheduleWithFixedDelay(retrievalTask, 1,
retrievalTaskFrequency.getMillis(), TimeUnit.MILLISECONDS);
}
executorService.scheduleWithFixedDelay(subNotifyTask, 1,
subnotifyTaskFrequency.getMillis(), TimeUnit.MILLISECONDS);
} }
public void notify(List<String> subscriptions) { public void notify(List<String> subscriptions) {
@ -84,4 +88,18 @@ public class RetrievalHandler {
executorService.execute(retrievalTask); executorService.execute(retrievalTask);
} }
} }
@Override
public void executeAfterRegistryInit() {
// set all Running state retrievals to pending
retrievalDao.resetRunningRetrievalsToPending();
for (RetrievalTask retrievalTask : retrievalTasks) {
executorService.scheduleWithFixedDelay(retrievalTask, 30000,
retrievalTaskFrequency.getMillis(), TimeUnit.MILLISECONDS);
}
executorService.scheduleWithFixedDelay(subNotifyTask, 30000,
subnotifyTaskFrequency.getMillis(), TimeUnit.MILLISECONDS);
}
} }

View file

@ -1,15 +1,24 @@
<beans <beans xmlns="http://www.springframework.org/schema/beans"
xmlns="http://www.springframework.org/schema/beans" xmlns:amq="http://activemq.apache.org/schema/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:amq="http://activemq.apache.org/schema/core" xsi:schemaLocation="http://www.springframework.org/schema/beans
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<bean id="logHandler" class="com.raytheon.uf.edex.event.handler.LogHandler"/> <bean id="logHandler" class="com.raytheon.uf.edex.event.handler.LogHandler" />
<bean
<bean id="eventPublishHandler" class="com.raytheon.uf.edex.event.handler.EventPublishHandler"/> class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<bean factory-bean="handlerRegistry" factory-method="register"> <property name="staticMethod"
<constructor-arg value="com.raytheon.uf.common.event.EventPublishRequest"/> value="com.raytheon.uf.common.event.EventBus.register" />
<constructor-arg ref="eventPublishHandler"/> <property name="arguments">
</bean> <list>
<ref bean="logHandler" />
</list>
</property>
</bean>
<bean id="eventPublishHandler" class="com.raytheon.uf.edex.event.handler.EventPublishHandler" />
<bean factory-bean="handlerRegistry" factory-method="register">
<constructor-arg value="com.raytheon.uf.common.event.EventPublishRequest" />
<constructor-arg ref="eventPublishHandler" />
</bean>
</beans> </beans>

View file

@ -1,14 +1,11 @@
package com.raytheon.uf.edex.event.handler; package com.raytheon.uf.edex.event.handler;
import javax.annotation.PostConstruct;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import com.google.common.eventbus.AllowConcurrentEvents; import com.google.common.eventbus.AllowConcurrentEvents;
import com.google.common.eventbus.Subscribe; import com.google.common.eventbus.Subscribe;
import com.raytheon.uf.common.event.Event; import com.raytheon.uf.common.event.Event;
import com.raytheon.uf.common.event.EventBus;
/** /**
* *
@ -24,6 +21,7 @@ import com.raytheon.uf.common.event.EventBus;
* Nov 5, 2012 #1305 bgonzale Added log level Event logging. * Nov 5, 2012 #1305 bgonzale Added log level Event logging.
* Feb 05, 2013 1580 mpduff EventBus refactor. * Feb 05, 2013 1580 mpduff EventBus refactor.
* 3/13/2013 bphillip Modified to make event bus registration a post construct operation * 3/13/2013 bphillip Modified to make event bus registration a post construct operation
* 3/27/2013 1802 bphillip Moved event bus registration from a PostConstruct method to Spring static method
* *
* </pre> * </pre>
* *
@ -41,11 +39,6 @@ public class LogHandler {
logger = LogFactory.getLog("Event"); logger = LogFactory.getLog("Event");
} }
@PostConstruct
public void registerWithEventBus() {
EventBus.register(this);
}
/** /**
* Listens for any DataDeliveryEvent object published on the event bus * Listens for any DataDeliveryEvent object published on the event bus
* *

View file

@ -20,6 +20,17 @@
<property name="statsDao" ref="statsDao" /> <property name="statsDao" ref="statsDao" />
</bean> </bean>
<bean
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="staticMethod"
value="com.raytheon.uf.common.event.EventBus.register" />
<property name="arguments">
<list>
<ref bean="statsHandler" />
</list>
</property>
</bean>
<bean id="statsDao" class="com.raytheon.uf.edex.stats.dao.StatsDao"> <bean id="statsDao" class="com.raytheon.uf.edex.stats.dao.StatsDao">

View file

@ -1,14 +1,18 @@
<beans <beans xmlns="http://www.springframework.org/schema/beans"
xmlns="http://www.springframework.org/schema/beans" xmlns:amq="http://activemq.apache.org/schema/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:amq="http://activemq.apache.org/schema/core" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<bean id="statsGraphDataHandler" class="com.raytheon.uf.edex.stats.handler.GraphDataHandler"/> <bean id="statsGraphDataHandler" class="com.raytheon.uf.edex.stats.handler.GraphDataHandler" >
<bean factory-bean="handlerRegistry" factory-method="register"> <property name="aggregateRecordDao" ref="graphDataHandlerAggregateRecordDao" />
<constructor-arg value="com.raytheon.uf.common.stats.GraphDataRequest"/> </bean>
<constructor-arg ref="statsGraphDataHandler"/>
<property name="aggregateRecordDao" ref="aggregateRecordDao"/> <bean factory-bean="handlerRegistry" factory-method="register">
</bean> <constructor-arg value="com.raytheon.uf.common.stats.GraphDataRequest" />
<constructor-arg ref="statsGraphDataHandler" />
</bean>
<bean id="graphDataHandlerAggregateRecordDao" class="com.raytheon.uf.edex.stats.dao.AggregateRecordDao">
<property name="sessionFactory" ref="metadataSessionFactory" />
</bean>
</beans> </beans>

View file

@ -74,6 +74,7 @@ import com.raytheon.uf.edex.stats.util.ConfigLoader;
* Jan 07, 2013 1451 djohnson Use newGmtCalendar(). * Jan 07, 2013 1451 djohnson Use newGmtCalendar().
* Jan 15, 2013 1487 djohnson Use xml for the grouping information on an {@link AggregateRecord}. * Jan 15, 2013 1487 djohnson Use xml for the grouping information on an {@link AggregateRecord}.
* 3/13/2013 bphillip Updated to use spring injection of dao * 3/13/2013 bphillip Updated to use spring injection of dao
* 3/27/2013 1802 bphillip Made jaxb manager static and changed visibility of a method
* </pre> * </pre>
* *
* @author jsanchez * @author jsanchez
@ -89,7 +90,7 @@ public class AggregateManager {
private static final Object[] EMPTY_OBJ_ARR = new Object[0]; private static final Object[] EMPTY_OBJ_ARR = new Object[0];
private JAXBManager jaxbManager; private static JAXBManager jaxbManager;
/** In minutes */ /** In minutes */
private int bucketInterval; private int bucketInterval;
@ -101,6 +102,10 @@ public class AggregateManager {
@SuppressWarnings("unused") @SuppressWarnings("unused")
private static final int defaultScanInterval = 15; private static final int defaultScanInterval = 15;
public AggregateManager() {
}
public AggregateManager(String bucketInterval) { public AggregateManager(String bucketInterval) {
validateIntervals(bucketInterval); validateIntervals(bucketInterval);
} }
@ -310,7 +315,7 @@ public class AggregateManager {
} }
@VisibleForTesting @VisibleForTesting
private String determineGroupRepresentationForEvent( static String determineGroupRepresentationForEvent(
StatisticsEvent statEvent, Event event) StatisticsEvent statEvent, Event event)
throws IllegalAccessException, InvocationTargetException, throws IllegalAccessException, InvocationTargetException,
JAXBException { JAXBException {

View file

@ -24,15 +24,12 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import javax.annotation.PostConstruct;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import com.google.common.eventbus.AllowConcurrentEvents; import com.google.common.eventbus.AllowConcurrentEvents;
import com.google.common.eventbus.Subscribe; import com.google.common.eventbus.Subscribe;
import com.raytheon.uf.common.event.Event; import com.raytheon.uf.common.event.Event;
import com.raytheon.uf.common.event.EventBus;
import com.raytheon.uf.common.serialization.SerializationException; import com.raytheon.uf.common.serialization.SerializationException;
import com.raytheon.uf.common.serialization.SerializationUtil; import com.raytheon.uf.common.serialization.SerializationUtil;
import com.raytheon.uf.common.stats.StatsRecord; import com.raytheon.uf.common.stats.StatsRecord;
@ -55,7 +52,8 @@ import com.raytheon.uf.edex.stats.util.ConfigLoader;
* Aug 21, 2012 jsanchez Removed instance variable of event bus. * Aug 21, 2012 jsanchez Removed instance variable of event bus.
* Nov 07, 2012 1317 mpduff Updated config files. * Nov 07, 2012 1317 mpduff Updated config files.
* Feb 05, 2013 1580 mpduff EventBus refactor. * Feb 05, 2013 1580 mpduff EventBus refactor.
* 3/18/2013 1082 bphillip Modified to make transactional and use spring injection * 3/18/2013 1802 bphillip Modified to make transactional and use spring injection
* 3/27/2013 1802 bphillip Moved event bus registration from PostConstruct method to Spring static method call
* *
* </pre> * </pre>
* *
@ -94,11 +92,6 @@ public class StatsHandler {
loadEventValidTypes(); loadEventValidTypes();
} }
@PostConstruct
public void registerWithEventBus() {
EventBus.register(this);
}
/** /**
* Loads the stats configuration to determine the events to track. * Loads the stats configuration to determine the events to track.
* *

View file

@ -26,9 +26,9 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.xml.ws.WebServiceException; import javax.xml.ws.WebServiceException;
@ -90,144 +90,58 @@ public class FactoryRegistryHandlerTest {
@Test @Test
public void testGetObjectsReturnsFailedStatusIfWebServiceExceptionThrown() { public void testGetObjectsReturnsFailedStatusIfWebServiceExceptionThrown() {
RegistryResponse<Object> response = getExceptionThrowingHandler( Callable<RegistryResponse<Object>> callable = new Callable<RegistryResponse<Object>>() {
WEB_SERVICE_EXCEPTION).getObjects(null); @Override
public RegistryResponse<Object> call() throws Exception {
throw WEB_SERVICE_EXCEPTION;
}
};
RegistryResponse<Object> response = new FactoryRegistryHandler()
.processRequest(callable, new RegistryResponse<Object>());
assertEquals(OperationStatus.FAILED, response.getStatus()); assertEquals(OperationStatus.FAILED, response.getStatus());
} }
@Test @Test
public void testGetObjectsReturnsUnableToConnectMessageIfWebServiceExceptionThrown() { public void testGetObjectsReturnsUnableToConnectMessageIfWebServiceExceptionThrown() {
RegistryResponse<Object> response = getExceptionThrowingHandler( Callable<RegistryResponse<Object>> callable = new Callable<RegistryResponse<Object>>() {
WEB_SERVICE_EXCEPTION).getObjects(null); @Override
public RegistryResponse<Object> call() throws Exception {
throw WEB_SERVICE_EXCEPTION;
}
};
RegistryResponse<Object> response = new FactoryRegistryHandler()
.processRequest(callable, new RegistryResponse<Object>());
assertEquals(RegistryUtil.UNABLE_TO_CONNECT_TO_REGISTRY, response assertEquals(RegistryUtil.UNABLE_TO_CONNECT_TO_REGISTRY, response
.getErrors().iterator().next().getMessage()); .getErrors().iterator().next().getMessage());
} }
@Test
public void testRemoveObjectsWithQueryReturnsUnableToConnectMessageIfHttpHostConnectExceptionThrown() {
RegistryResponse<Object> response = getExceptionThrowingHandler(
WEB_SERVICE_EXCEPTION).removeObjects(null);
assertEquals(RegistryUtil.UNABLE_TO_CONNECT_TO_REGISTRY, response
.getErrors().iterator().next().getMessage());
}
@Test
public void testRemoveObjectsWithObjectsReturnsUnableToConnectMessageIfHttpHostConnectExceptionThrown() {
RegistryResponse<Object> response = getExceptionThrowingHandler(
WEB_SERVICE_EXCEPTION).removeObjects("someUsername",
Collections.emptyList());
assertEquals(RegistryUtil.UNABLE_TO_CONNECT_TO_REGISTRY, response
.getErrors().iterator().next().getMessage());
}
@Test
public void testStoreObjectReturnsUnableToConnectMessageIfHttpHostConnectExceptionThrown() {
RegistryResponse<Object> response = getExceptionThrowingHandler(
WEB_SERVICE_EXCEPTION).storeObject(null);
assertEquals(RegistryUtil.UNABLE_TO_CONNECT_TO_REGISTRY, response
.getErrors().iterator().next().getMessage());
}
@Test
public void testRemoveObjectsWithQueryReturnsFailedStatusIfHttpHostConnectExceptionThrown() {
RegistryResponse<Object> response = getExceptionThrowingHandler(
WEB_SERVICE_EXCEPTION).removeObjects(null);
assertEquals(OperationStatus.FAILED, response.getStatus());
}
@Test
public void testRemoveObjectsWithObjectsReturnsFailedStatusIfHttpHostConnectExceptionThrown() {
RegistryResponse<Object> response = getExceptionThrowingHandler(
WEB_SERVICE_EXCEPTION).removeObjects("someUsername",
Collections.emptyList());
assertEquals(OperationStatus.FAILED, response.getStatus());
}
@Test
public void testStoreObjectReturnsFailedStatusIfHttpHostConnectExceptionThrown() {
RegistryResponse<Object> response = getExceptionThrowingHandler(
WEB_SERVICE_EXCEPTION).storeObject(null);
assertEquals(OperationStatus.FAILED, response.getStatus());
}
@Test @Test
public void testGetObjectsReturnsFailedStatusIfCommunicationExceptionThrown() { public void testGetObjectsReturnsFailedStatusIfCommunicationExceptionThrown() {
RegistryResponse<Object> response = getExceptionThrowingHandler( Callable<RegistryResponse<Object>> callable = new Callable<RegistryResponse<Object>>() {
COMMUNICATION_EXCEPTION).getObjects(null); @Override
public RegistryResponse<Object> call() throws Exception {
throw COMMUNICATION_EXCEPTION;
}
};
RegistryResponse<Object> response = new FactoryRegistryHandler()
.processRequest(callable, new RegistryResponse<Object>());
assertEquals(OperationStatus.FAILED, response.getStatus()); assertEquals(OperationStatus.FAILED, response.getStatus());
} }
@Test @Test
public void testGetObjectsReturnsFailedToConnectToTheDatabaseIfCommunicationExceptionThrown() { public void testGetObjectsReturnsFailedToConnectToTheDatabaseIfCommunicationExceptionThrown() {
RegistryResponse<Object> response = getExceptionThrowingHandler( Callable<RegistryResponse<Object>> callable = new Callable<RegistryResponse<Object>>() {
COMMUNICATION_EXCEPTION).getObjects(null); @Override
public RegistryResponse<Object> call() throws Exception {
throw COMMUNICATION_EXCEPTION;
}
};
RegistryResponse<Object> response = new FactoryRegistryHandler()
.processRequest(callable, new RegistryResponse<Object>());
assertEquals(RegistryUtil.FAILED_TO_CONNECT_TO_DATABASE, response assertEquals(RegistryUtil.FAILED_TO_CONNECT_TO_DATABASE, response
.getErrors().iterator().next().getMessage()); .getErrors().iterator().next().getMessage());
} }
@Test
public void testRemoveObjectsWithQueryReturnsUnableToConnectMessageIfCommunicationExceptionThrown() {
RegistryResponse<Object> response = getExceptionThrowingHandler(
COMMUNICATION_EXCEPTION).removeObjects(null);
assertEquals(RegistryUtil.FAILED_TO_CONNECT_TO_DATABASE, response
.getErrors().iterator().next().getMessage());
}
@Test
public void testRemoveObjectsWithObjectsReturnsUnableToConnectMessageIfCommunicationExceptionThrown() {
RegistryResponse<Object> response = getExceptionThrowingHandler(
COMMUNICATION_EXCEPTION).removeObjects("someUsername",
Collections.emptyList());
assertEquals(RegistryUtil.FAILED_TO_CONNECT_TO_DATABASE, response
.getErrors().iterator().next().getMessage());
}
@Test
public void testStoreObjectReturnsUnableToConnectMessageIfCommunicationExceptionThrown() {
RegistryResponse<Object> response = getExceptionThrowingHandler(
COMMUNICATION_EXCEPTION).storeObject(null);
assertEquals(RegistryUtil.FAILED_TO_CONNECT_TO_DATABASE, response
.getErrors().iterator().next().getMessage());
}
@Test
public void testRemoveObjectsWithQueryReturnsFailedStatusIfCommunicationExceptionThrown() {
RegistryResponse<Object> response = getExceptionThrowingHandler(
COMMUNICATION_EXCEPTION).removeObjects(null);
assertEquals(OperationStatus.FAILED, response.getStatus());
}
@Test
public void testRemoveObjectsWithObjectsReturnsFailedStatusIfCommunicationExceptionThrown() {
RegistryResponse<Object> response = getExceptionThrowingHandler(
COMMUNICATION_EXCEPTION).removeObjects("someUsername",
Collections.emptyList());
assertEquals(OperationStatus.FAILED, response.getStatus());
}
@Test
public void testStoreObjectReturnsFailedStatusIfCommunicationExceptionThrown() {
RegistryResponse<Object> response = getExceptionThrowingHandler(
COMMUNICATION_EXCEPTION).storeObject(null);
assertEquals(OperationStatus.FAILED, response.getStatus());
}
@Test @Test
public void testNonResultFormatterWillReturnDecodedRegistryObjects() public void testNonResultFormatterWillReturnDecodedRegistryObjects()
throws SerializationException { throws SerializationException {
@ -256,14 +170,17 @@ public class FactoryRegistryHandlerTest {
@Test @Test
public void testResultFormatterThatReturnsSingleResultWillReturnsAllSingleResults() { public void testResultFormatterThatReturnsSingleResultWillReturnsAllSingleResults() {
final String[] results = new String[]{"one", "two", "three"}; final String[] results = new String[] { "one", "two", "three" };
final List<RegistryObjectType> registryObjectTypes = java.util.Arrays.asList(new RegistryObjectType(), new RegistryObjectType(), new RegistryObjectType()); final List<RegistryObjectType> registryObjectTypes = java.util.Arrays
.asList(new RegistryObjectType(), new RegistryObjectType(),
new RegistryObjectType());
StringResultsQuery query = new StringResultsQuery(results); StringResultsQuery query = new StringResultsQuery(results);
List<String> filteredResults = FactoryRegistryHandler.filterResults( List<String> filteredResults = FactoryRegistryHandler.filterResults(
query, registryObjectTypes); query, registryObjectTypes);
assertEquals("Incorrect number of results were returned!", results.length, filteredResults.size()); assertEquals("Incorrect number of results were returned!",
results.length, filteredResults.size());
for (String result : results) { for (String result : results) {
assertTrue("The filtered results should have contained result [" assertTrue("The filtered results should have contained result ["
@ -376,26 +293,4 @@ public class FactoryRegistryHandlerTest {
FactoryRegistryHandler.statusHandler = oldHandler; FactoryRegistryHandler.statusHandler = oldHandler;
} }
} }
private static <T extends Exception> FactoryRegistryHandler getExceptionThrowingHandler(
final T t) {
FactoryRegistryHandler handler = new FactoryRegistryHandler();
handler.setTxManager(new RegistryTxManager() {
@Override
public TxManager getTxManager() {
return new TxManager() {
@Override
public void startTransaction() throws Exception {
throw t;
}
@Override
public void closeTransaction() {
}
};
}
});
return handler;
}
} }

View file

@ -19,10 +19,6 @@
**/ **/
package com.raytheon.uf.common.registry.ebxml; package com.raytheon.uf.common.registry.ebxml;
import com.raytheon.uf.common.registry.OperationStatus;
import com.raytheon.uf.common.registry.RegistryQuery;
import com.raytheon.uf.common.registry.RegistryQueryResponse;
import oasis.names.tc.ebxml.regrep.wsdl.registry.services.v4.LifecycleManager; import oasis.names.tc.ebxml.regrep.wsdl.registry.services.v4.LifecycleManager;
import oasis.names.tc.ebxml.regrep.wsdl.registry.services.v4.MsgRegistryException; import oasis.names.tc.ebxml.regrep.wsdl.registry.services.v4.MsgRegistryException;
import oasis.names.tc.ebxml.regrep.wsdl.registry.services.v4.QueryManager; import oasis.names.tc.ebxml.regrep.wsdl.registry.services.v4.QueryManager;
@ -33,6 +29,10 @@ import oasis.names.tc.ebxml.regrep.xsd.query.v4.QueryRequest;
import oasis.names.tc.ebxml.regrep.xsd.query.v4.QueryResponse; import oasis.names.tc.ebxml.regrep.xsd.query.v4.QueryResponse;
import oasis.names.tc.ebxml.regrep.xsd.rs.v4.RegistryResponseType; import oasis.names.tc.ebxml.regrep.xsd.rs.v4.RegistryResponseType;
import com.raytheon.uf.common.registry.OperationStatus;
import com.raytheon.uf.common.registry.RegistryQuery;
import com.raytheon.uf.common.registry.RegistryQueryResponse;
/** /**
* Extends {@link FactoryRegistryHandler} to allow it to be testable. * Extends {@link FactoryRegistryHandler} to allow it to be testable.
* *
@ -50,12 +50,11 @@ import oasis.names.tc.ebxml.regrep.xsd.rs.v4.RegistryResponseType;
* @version 1.0 * @version 1.0
*/ */
public class TestableFactoryRegistryHandler extends FactoryRegistryHandler public class TestableFactoryRegistryHandler extends FactoryRegistryHandler
implements LifecycleManagerFactory, QueryManagerFactory, implements LifecycleManagerFactory, QueryManagerFactory, QueryManager,
RegistryTxManager, QueryManager, LifecycleManager { LifecycleManager {
public TestableFactoryRegistryHandler() { public TestableFactoryRegistryHandler() {
setLcmFactory(this); setLcmFactory(this);
setQueryFactory(this); setQueryFactory(this);
setTxManager(this);
} }
/** /**
@ -69,22 +68,6 @@ public class TestableFactoryRegistryHandler extends FactoryRegistryHandler
return response; return response;
} }
/**
* {@inheritDoc}
*/
@Override
public TxManager getTxManager() {
return new TxManager() {
@Override
public void startTransaction() throws Exception {
}
@Override
public void closeTransaction() {
}
};
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */

View file

@ -33,6 +33,7 @@ import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@ -79,6 +80,7 @@ import com.raytheon.uf.edex.datadelivery.retrieval.db.RetrievalRequestRecord.Sta
public class SubscriptionRetrievalAgentTest { public class SubscriptionRetrievalAgentTest {
@Autowired @Autowired
@Qualifier(value = "retrievalDao")
private IRetrievalDao retrievalDao; private IRetrievalDao retrievalDao;
@Before @Before

View file

@ -78,6 +78,7 @@ public class RetrievalHandlerTest {
@Test @Test
public void testAllRunningRetrievalsAreResetToPendingOnConstruction() { public void testAllRunningRetrievalsAreResetToPendingOnConstruction() {
handler.executeAfterRegistryInit();
verify(mockDao).resetRunningRetrievalsToPending(); verify(mockDao).resetRunningRetrievalsToPending();
} }
@ -90,13 +91,15 @@ public class RetrievalHandlerTest {
@Test @Test
public void testRetrievalTaskIsScheduledPerConstructorParameter() { public void testRetrievalTaskIsScheduledPerConstructorParameter() {
verify(executorService).scheduleWithFixedDelay(retrievalTask, 1, handler.executeAfterRegistryInit();
verify(executorService).scheduleWithFixedDelay(retrievalTask, 30000,
RETRIEVAL_TASK_FREQUENCY.getMillis(), TimeUnit.MILLISECONDS); RETRIEVAL_TASK_FREQUENCY.getMillis(), TimeUnit.MILLISECONDS);
} }
@Test @Test
public void testSubscriptionNotifyTaskIsScheduledPerConstructorParameter() { public void testSubscriptionNotifyTaskIsScheduledPerConstructorParameter() {
verify(executorService).scheduleWithFixedDelay(subNotifyTask, 1, handler.executeAfterRegistryInit();
verify(executorService).scheduleWithFixedDelay(subNotifyTask, 30000,
SUBNOTIFY_TASK_FREQUENCY.getMillis(), TimeUnit.MILLISECONDS); SUBNOTIFY_TASK_FREQUENCY.getMillis(), TimeUnit.MILLISECONDS);
} }
} }

View file

@ -38,10 +38,12 @@ import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode; import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import com.google.common.eventbus.Subscribe; import com.google.common.eventbus.Subscribe;
import com.raytheon.uf.common.datadelivery.event.retrieval.DataRetrievalEvent; import com.raytheon.uf.common.datadelivery.event.retrieval.DataRetrievalEvent;
@ -144,6 +146,7 @@ public class RetrievalTaskTest {
private RetrievalRequestRecord sbnRetrieval; private RetrievalRequestRecord sbnRetrieval;
@Autowired @Autowired
@Qualifier(value = "retrievalDao")
private IRetrievalDao dao; private IRetrievalDao dao;
private final PlaceInCollectionProcessor retrievedDataProcessor = new PlaceInCollectionProcessor(); private final PlaceInCollectionProcessor retrievedDataProcessor = new PlaceInCollectionProcessor();
@ -266,7 +269,9 @@ public class RetrievalTaskTest {
/** /**
* Stage the retrievals in the database. * Stage the retrievals in the database.
*/ */
@Transactional
private void stageRetrievals() { private void stageRetrievals() {
dao.create(opsnetRetrieval); dao.create(opsnetRetrieval);
dao.create(sbnRetrieval); dao.create(sbnRetrieval);
} }

View file

@ -107,8 +107,12 @@ public class AggregateManagerTest {
final String expectedGroupRepresentation = jaxbManager final String expectedGroupRepresentation = jaxbManager
.marshalToXml(column); .marshalToXml(column);
final String actualGroupRepresentation = AggregateManager.determineGroupRepresentationForEvent( JAXBManager aggregateManagerJaxbManager = new JAXBManager(
statisticsConfig.getEvents().iterator().next(), mockEvent); StatsGroupingColumn.class);
new AggregateManager("60").setJaxbManager(aggregateManagerJaxbManager);
final String actualGroupRepresentation = AggregateManager
.determineGroupRepresentationForEvent(statisticsConfig
.getEvents().iterator().next(), mockEvent);
assertThat(actualGroupRepresentation, assertThat(actualGroupRepresentation,
is(equalTo(expectedGroupRepresentation))); is(equalTo(expectedGroupRepresentation)));
} }