From 30be5ce6f93e28eac4d0e3311aa0431a156bd3e6 Mon Sep 17 00:00:00 2001 From: Benjamin Phillippe Date: Wed, 27 Mar 2013 17:12:52 -0500 Subject: [PATCH] Issue #1802 Fixes related to DD transaction refactor Change-Id: Ia2a7a4ce990d424ed1e365bd7003fd2ab8630fd1 Former-commit-id: 2a14245dce91d795cac072fbf4fe162d6f31709b [formerly 393a469e2f65894a6dd5b58c1431c3d727951eda] Former-commit-id: 115dc12790204a7817f4c29bba1ee52d8de9e721 --- .../ebxml/FactoryRegistryHandler.java | 8 +- .../edex/database/dao/SessionManagedDao.java | 12 +- .../res/spring/bandwidth-datadelivery.xml | 198 +++++++++--------- .../bandwidth/retrieval/RetrievalManager.java | 8 +- .../res/spring/event-datadelivery-ingest.xml | 67 +++--- .../event/handler/NotificationHandler.java | 9 +- .../META-INF/MANIFEST.MF | 3 +- .../spring/retrieval-datadelivery-daos.xml | 31 ++- .../retrieval/handlers/RetrievalHandler.java | 40 +++- .../res/spring/event-common.xml | 33 +-- .../uf/edex/event/handler/LogHandler.java | 9 +- .../res/spring/stats-common.xml | 11 + .../res/spring/stats-graph-request.xml | 26 ++- .../uf/edex/stats/AggregateManager.java | 9 +- .../uf/edex/stats/handler/StatsHandler.java | 11 +- .../ebxml/FactoryRegistryHandlerTest.java | 183 ++++------------ .../ebxml/TestableFactoryRegistryHandler.java | 29 +-- .../SubscriptionRetrievalAgentTest.java | 2 + .../handlers/RetrievalHandlerTest.java | 7 +- .../retrieval/handlers/RetrievalTaskTest.java | 5 + .../uf/edex/stats/AggregateManagerTest.java | 8 +- 21 files changed, 338 insertions(+), 371 deletions(-) diff --git a/edexOsgi/com.raytheon.uf.common.registry.ebxml/src/com/raytheon/uf/common/registry/ebxml/FactoryRegistryHandler.java b/edexOsgi/com.raytheon.uf.common.registry.ebxml/src/com/raytheon/uf/common/registry/ebxml/FactoryRegistryHandler.java index 107648c833..3424d459cd 100644 --- a/edexOsgi/com.raytheon.uf.common.registry.ebxml/src/com/raytheon/uf/common/registry/ebxml/FactoryRegistryHandler.java +++ b/edexOsgi/com.raytheon.uf.common.registry.ebxml/src/com/raytheon/uf/common/registry/ebxml/FactoryRegistryHandler.java @@ -36,6 +36,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; 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.IResultFormatter; 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. * Feb 26, 2013 1643 djohnson Remove registry manager debug toggle. * 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 * * * @@ -264,8 +266,8 @@ public class FactoryRegistryHandler implements RegistryHandler { * the response object to populate on error * @return the response */ - private , U> T processRequest( - Callable request, T response) { + , U> T processRequest(Callable request, + T response) { T calledResponse = null; try { calledResponse = request.call(); @@ -274,7 +276,7 @@ public class FactoryRegistryHandler implements RegistryHandler { calledResponse = RegistryUtil.getFailedResponse(response, new RegistryException( RegistryUtil.UNABLE_TO_CONNECT_TO_REGISTRY, e)); - } catch (Exception e) { + } catch (CommunicationException e) { calledResponse = RegistryUtil.getFailedResponse(response, e); } catch (Throwable e) { calledResponse = RegistryUtil.getFailedResponse(response, e); diff --git a/edexOsgi/com.raytheon.uf.edex.database/src/com/raytheon/uf/edex/database/dao/SessionManagedDao.java b/edexOsgi/com.raytheon.uf.edex.database/src/com/raytheon/uf/edex/database/dao/SessionManagedDao.java index 4751b898a0..ef7ebb4029 100644 --- a/edexOsgi/com.raytheon.uf.edex.database/src/com/raytheon/uf/edex/database/dao/SessionManagedDao.java +++ b/edexOsgi/com.raytheon.uf.edex.database/src/com/raytheon/uf/edex/database/dao/SessionManagedDao.java @@ -57,6 +57,7 @@ import com.raytheon.uf.edex.database.DataAccessLayerException; * ------------ ---------- ----------- -------------------------- * Feb 07, 2013 1543 djohnson Initial creation * 3/18/2013 1802 bphillip Added additional database functions. Enforcing mandatory transaction propogation + * 3/27/2013 1802 bphillip Changed transaction propagation of query methods * * * @@ -141,6 +142,7 @@ public abstract class SessionManagedDao entityClass = getEntityClass(); return entityClass.cast(template.get(entityClass, id)); @@ -150,6 +152,7 @@ public abstract class SessionManagedDao getAll() { return query("from " + getEntityClass().getSimpleName(), Collections. emptyMap()); @@ -162,11 +165,13 @@ public abstract class SessionManagedDao query(String queryString, Map params) { return query(queryString, params, 0); } @SuppressWarnings("unchecked") + @Transactional(propagation = Propagation.REQUIRED) protected List query(String queryString, Map params, int maxResults) { final int numberOfParams = params.size(); @@ -193,6 +198,7 @@ public abstract class SessionManagedDao params) { final List results = query(queryString, params); if (results.isEmpty()) { @@ -215,6 +221,7 @@ public abstract class SessionManagedDao List executeHQLQuery(String queryString) throws DataAccessLayerException { return executeHQLQuery(queryString, true, null); @@ -231,6 +238,7 @@ public abstract class SessionManagedDao executeHQLQuery(StringBuilder queryString) throws DataAccessLayerException { return executeHQLQuery(queryString.toString(), true, null); @@ -253,6 +261,7 @@ public abstract class SessionManagedDao executeHQLQuery(String queryString, Map params) throws DataAccessLayerException { return executeHQLQuery(queryString, true, params); @@ -272,6 +281,7 @@ public abstract class SessionManagedDao List executeHQLQuery(final String queryString, boolean eager, final Map params) throws DataAccessLayerException { @@ -360,7 +370,6 @@ public abstract class SessionManagedDao params) throws DataAccessLayerException { try { @@ -393,6 +402,7 @@ public abstract class SessionManagedDao List executeCriteriaQuery( final DetachedCriteria criteria) throws DataAccessLayerException { if (criteria == null) { diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery.xml b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery.xml index eb325183a4..835821a24f 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery.xml +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery.xml @@ -1,112 +1,122 @@ + 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"> - - - - classpath:/com.raytheon.uf.edex.datadelivery.bandwidth.properties - - - - + + + + classpath:/com.raytheon.uf.edex.datadelivery.bandwidth.properties + + + + - + - + - - + + - + - - - - - - - - + + + + + + + + - - - + + + - - - - - - - - - + + + + + + + + + - - - - + + + + - - - + + + - - - + + + - - - - - + + + + + - - + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + + + + + + + + + + diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/RetrievalManager.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/RetrievalManager.java index 7b53433675..6a15637fbd 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/RetrievalManager.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/RetrievalManager.java @@ -6,8 +6,6 @@ import java.util.List; import java.util.Map; import java.util.TreeMap; -import javax.annotation.PostConstruct; - import com.google.common.eventbus.Subscribe; import com.raytheon.uf.common.datadelivery.registry.Network; 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 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/13/2013 1802 bphillip Moved event bus registration from post-construct to spring static method call * * * @@ -65,11 +64,6 @@ public class RetrievalManager { this.notifier = notifier; } - @PostConstruct - public void registerWithEventBus() { - EventBus.register(this); - } - public Map getRetrievalPlans() { return retrievalPlans; } diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.event/res/spring/event-datadelivery-ingest.xml b/edexOsgi/com.raytheon.uf.edex.datadelivery.event/res/spring/event-datadelivery-ingest.xml index c02b5a5889..e014a75014 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.event/res/spring/event-datadelivery-ingest.xml +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.event/res/spring/event-datadelivery-ingest.xml @@ -1,39 +1,52 @@ - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - - - + + + + + - + - + java.lang.Throwable - + - + \ No newline at end of file diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.event/src/com/raytheon/uf/edex/datadelivery/event/handler/NotificationHandler.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.event/src/com/raytheon/uf/edex/datadelivery/event/handler/NotificationHandler.java index 2c7165a11a..51898a8311 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.event/src/com/raytheon/uf/edex/datadelivery/event/handler/NotificationHandler.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.event/src/com/raytheon/uf/edex/datadelivery/event/handler/NotificationHandler.java @@ -1,12 +1,9 @@ package com.raytheon.uf.edex.datadelivery.event.handler; -import javax.annotation.PostConstruct; - import com.google.common.eventbus.AllowConcurrentEvents; import com.google.common.eventbus.Subscribe; import com.raytheon.uf.common.datadelivery.event.INotifiableEvent; import com.raytheon.uf.common.datadelivery.event.notification.NotificationRecord; -import com.raytheon.uf.common.event.EventBus; 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. * Feb 05, 2013 1580 mpduff EventBus refactor. * 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 * * * @@ -47,11 +45,6 @@ public class NotificationHandler extends AbstractHandler { super(); } - @PostConstruct - public void registerWithEventBus() { - EventBus.register(this); - } - /** * Creates a new handler object and registers this object with the * DataDeliveryEventBus diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.retrieval/META-INF/MANIFEST.MF b/edexOsgi/com.raytheon.uf.edex.datadelivery.retrieval/META-INF/MANIFEST.MF index c04dbf1113..7f35914cc9 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.retrieval/META-INF/MANIFEST.MF +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.retrieval/META-INF/MANIFEST.MF @@ -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.edex.event;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-ActivationPolicy: lazy Export-Package: com.raytheon.uf.edex.datadelivery.retrieval; diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.retrieval/res/spring/retrieval-datadelivery-daos.xml b/edexOsgi/com.raytheon.uf.edex.datadelivery.retrieval/res/spring/retrieval-datadelivery-daos.xml index 7f50acd91b..b12b628828 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.retrieval/res/spring/retrieval-datadelivery-daos.xml +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.retrieval/res/spring/retrieval-datadelivery-daos.xml @@ -1,12 +1,31 @@ - - - + + + + + PROPAGATION_REQUIRED + + + + + + + + + retrievalTransactionInterceptor + + + + + + + \ No newline at end of file diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.retrieval/src/com/raytheon/uf/edex/datadelivery/retrieval/handlers/RetrievalHandler.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.retrieval/src/com/raytheon/uf/edex/datadelivery/retrieval/handlers/RetrievalHandler.java index e37dc83a1d..5e13d4e38c 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.retrieval/src/com/raytheon/uf/edex/datadelivery/retrieval/handlers/RetrievalHandler.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.retrieval/src/com/raytheon/uf/edex/datadelivery/retrieval/handlers/RetrievalHandler.java @@ -31,6 +31,7 @@ import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.time.domain.api.IDuration; import com.raytheon.uf.edex.datadelivery.retrieval.db.IRetrievalDao; +import com.raytheon.uf.edex.registry.ebxml.init.RegistryInitializedListener; /** * Provider Retrieval Handler @@ -43,6 +44,7 @@ import com.raytheon.uf.edex.datadelivery.retrieval.db.IRetrievalDao; * Jan 07, 2011 dhladky Initial creation * Aug 09, 2012 1022 djohnson Use {@link ExecutorService} for retrieval. * 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 * * * @@ -50,7 +52,7 @@ import com.raytheon.uf.edex.datadelivery.retrieval.db.IRetrievalDao; * @version 1.0 */ @Service -public class RetrievalHandler { +public class RetrievalHandler implements RegistryInitializedListener { private static final IUFStatusHandler statusHandler = UFStatus .getHandler(RetrievalHandler.class); @@ -59,22 +61,24 @@ public class RetrievalHandler { private final List retrievalTasks; + private IRetrievalDao retrievalDao; + + private IDuration retrievalTaskFrequency; + + private IDuration subnotifyTaskFrequency; + + private SubscriptionNotifyTask subNotifyTask; + public RetrievalHandler(ScheduledExecutorService executorService, IRetrievalDao retrievalDao, List retrievalTasks, SubscriptionNotifyTask subNotifyTask, IDuration retrievalTaskFrequency, IDuration subnotifyTaskFrequency) { this.executorService = executorService; this.retrievalTasks = retrievalTasks; - - // set all Running state retrievals to pending - retrievalDao.resetRunningRetrievalsToPending(); - - for (RetrievalTask retrievalTask : retrievalTasks) { - executorService.scheduleWithFixedDelay(retrievalTask, 1, - retrievalTaskFrequency.getMillis(), TimeUnit.MILLISECONDS); - } - executorService.scheduleWithFixedDelay(subNotifyTask, 1, - subnotifyTaskFrequency.getMillis(), TimeUnit.MILLISECONDS); + this.retrievalDao = retrievalDao; + this.retrievalTaskFrequency = retrievalTaskFrequency; + this.subnotifyTaskFrequency = subnotifyTaskFrequency; + this.subNotifyTask = subNotifyTask; } public void notify(List subscriptions) { @@ -84,4 +88,18 @@ public class RetrievalHandler { 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); + + } } diff --git a/edexOsgi/com.raytheon.uf.edex.event/res/spring/event-common.xml b/edexOsgi/com.raytheon.uf.edex.event/res/spring/event-common.xml index d1b016bc44..895cea80c9 100644 --- a/edexOsgi/com.raytheon.uf.edex.event/res/spring/event-common.xml +++ b/edexOsgi/com.raytheon.uf.edex.event/res/spring/event-common.xml @@ -1,15 +1,24 @@ - - - - - - - - + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/edexOsgi/com.raytheon.uf.edex.event/src/com/raytheon/uf/edex/event/handler/LogHandler.java b/edexOsgi/com.raytheon.uf.edex.event/src/com/raytheon/uf/edex/event/handler/LogHandler.java index 8c94252b78..76a5ee117e 100644 --- a/edexOsgi/com.raytheon.uf.edex.event/src/com/raytheon/uf/edex/event/handler/LogHandler.java +++ b/edexOsgi/com.raytheon.uf.edex.event/src/com/raytheon/uf/edex/event/handler/LogHandler.java @@ -1,14 +1,11 @@ package com.raytheon.uf.edex.event.handler; -import javax.annotation.PostConstruct; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.google.common.eventbus.AllowConcurrentEvents; import com.google.common.eventbus.Subscribe; 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. * Feb 05, 2013 1580 mpduff EventBus refactor. * 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 * * * @@ -41,11 +39,6 @@ public class LogHandler { logger = LogFactory.getLog("Event"); } - @PostConstruct - public void registerWithEventBus() { - EventBus.register(this); - } - /** * Listens for any DataDeliveryEvent object published on the event bus * diff --git a/edexOsgi/com.raytheon.uf.edex.stats/res/spring/stats-common.xml b/edexOsgi/com.raytheon.uf.edex.stats/res/spring/stats-common.xml index 3c7f6afd03..382c125aa8 100644 --- a/edexOsgi/com.raytheon.uf.edex.stats/res/spring/stats-common.xml +++ b/edexOsgi/com.raytheon.uf.edex.stats/res/spring/stats-common.xml @@ -20,6 +20,17 @@ + + + + + + + + + diff --git a/edexOsgi/com.raytheon.uf.edex.stats/res/spring/stats-graph-request.xml b/edexOsgi/com.raytheon.uf.edex.stats/res/spring/stats-graph-request.xml index 717528c4d9..4de2dff0c5 100644 --- a/edexOsgi/com.raytheon.uf.edex.stats/res/spring/stats-graph-request.xml +++ b/edexOsgi/com.raytheon.uf.edex.stats/res/spring/stats-graph-request.xml @@ -1,14 +1,18 @@ - - - - - - - + + + + + + + + + + + + diff --git a/edexOsgi/com.raytheon.uf.edex.stats/src/com/raytheon/uf/edex/stats/AggregateManager.java b/edexOsgi/com.raytheon.uf.edex.stats/src/com/raytheon/uf/edex/stats/AggregateManager.java index aa2abdab5a..58dce9911f 100644 --- a/edexOsgi/com.raytheon.uf.edex.stats/src/com/raytheon/uf/edex/stats/AggregateManager.java +++ b/edexOsgi/com.raytheon.uf.edex.stats/src/com/raytheon/uf/edex/stats/AggregateManager.java @@ -74,6 +74,7 @@ import com.raytheon.uf.edex.stats.util.ConfigLoader; * Jan 07, 2013 1451 djohnson Use newGmtCalendar(). * 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/27/2013 1802 bphillip Made jaxb manager static and changed visibility of a method * * * @author jsanchez @@ -89,7 +90,7 @@ public class AggregateManager { private static final Object[] EMPTY_OBJ_ARR = new Object[0]; - private JAXBManager jaxbManager; + private static JAXBManager jaxbManager; /** In minutes */ private int bucketInterval; @@ -101,6 +102,10 @@ public class AggregateManager { @SuppressWarnings("unused") private static final int defaultScanInterval = 15; + public AggregateManager() { + + } + public AggregateManager(String bucketInterval) { validateIntervals(bucketInterval); } @@ -310,7 +315,7 @@ public class AggregateManager { } @VisibleForTesting - private String determineGroupRepresentationForEvent( + static String determineGroupRepresentationForEvent( StatisticsEvent statEvent, Event event) throws IllegalAccessException, InvocationTargetException, JAXBException { diff --git a/edexOsgi/com.raytheon.uf.edex.stats/src/com/raytheon/uf/edex/stats/handler/StatsHandler.java b/edexOsgi/com.raytheon.uf.edex.stats/src/com/raytheon/uf/edex/stats/handler/StatsHandler.java index 40114d99bd..6745d01e41 100644 --- a/edexOsgi/com.raytheon.uf.edex.stats/src/com/raytheon/uf/edex/stats/handler/StatsHandler.java +++ b/edexOsgi/com.raytheon.uf.edex.stats/src/com/raytheon/uf/edex/stats/handler/StatsHandler.java @@ -24,15 +24,12 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import javax.annotation.PostConstruct; - import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.google.common.eventbus.AllowConcurrentEvents; import com.google.common.eventbus.Subscribe; 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.SerializationUtil; 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. * Nov 07, 2012 1317 mpduff Updated config files. * 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 * * * @@ -94,11 +92,6 @@ public class StatsHandler { loadEventValidTypes(); } - @PostConstruct - public void registerWithEventBus() { - EventBus.register(this); - } - /** * Loads the stats configuration to determine the events to track. * diff --git a/tests/unit/com/raytheon/uf/common/registry/ebxml/FactoryRegistryHandlerTest.java b/tests/unit/com/raytheon/uf/common/registry/ebxml/FactoryRegistryHandlerTest.java index 5058bdc039..932df80058 100644 --- a/tests/unit/com/raytheon/uf/common/registry/ebxml/FactoryRegistryHandlerTest.java +++ b/tests/unit/com/raytheon/uf/common/registry/ebxml/FactoryRegistryHandlerTest.java @@ -26,9 +26,9 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; -import java.util.Collections; import java.util.List; import java.util.Set; +import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; import javax.xml.ws.WebServiceException; @@ -90,144 +90,58 @@ public class FactoryRegistryHandlerTest { @Test public void testGetObjectsReturnsFailedStatusIfWebServiceExceptionThrown() { - RegistryResponse response = getExceptionThrowingHandler( - WEB_SERVICE_EXCEPTION).getObjects(null); - + Callable> callable = new Callable>() { + @Override + public RegistryResponse call() throws Exception { + throw WEB_SERVICE_EXCEPTION; + } + }; + RegistryResponse response = new FactoryRegistryHandler() + .processRequest(callable, new RegistryResponse()); assertEquals(OperationStatus.FAILED, response.getStatus()); } @Test public void testGetObjectsReturnsUnableToConnectMessageIfWebServiceExceptionThrown() { - RegistryResponse response = getExceptionThrowingHandler( - WEB_SERVICE_EXCEPTION).getObjects(null); - + Callable> callable = new Callable>() { + @Override + public RegistryResponse call() throws Exception { + throw WEB_SERVICE_EXCEPTION; + } + }; + RegistryResponse response = new FactoryRegistryHandler() + .processRequest(callable, new RegistryResponse()); assertEquals(RegistryUtil.UNABLE_TO_CONNECT_TO_REGISTRY, response .getErrors().iterator().next().getMessage()); } - @Test - public void testRemoveObjectsWithQueryReturnsUnableToConnectMessageIfHttpHostConnectExceptionThrown() { - RegistryResponse response = getExceptionThrowingHandler( - WEB_SERVICE_EXCEPTION).removeObjects(null); - - assertEquals(RegistryUtil.UNABLE_TO_CONNECT_TO_REGISTRY, response - .getErrors().iterator().next().getMessage()); - } - - @Test - public void testRemoveObjectsWithObjectsReturnsUnableToConnectMessageIfHttpHostConnectExceptionThrown() { - RegistryResponse 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 response = getExceptionThrowingHandler( - WEB_SERVICE_EXCEPTION).storeObject(null); - - assertEquals(RegistryUtil.UNABLE_TO_CONNECT_TO_REGISTRY, response - .getErrors().iterator().next().getMessage()); - } - - @Test - public void testRemoveObjectsWithQueryReturnsFailedStatusIfHttpHostConnectExceptionThrown() { - RegistryResponse response = getExceptionThrowingHandler( - WEB_SERVICE_EXCEPTION).removeObjects(null); - - assertEquals(OperationStatus.FAILED, response.getStatus()); - } - - @Test - public void testRemoveObjectsWithObjectsReturnsFailedStatusIfHttpHostConnectExceptionThrown() { - RegistryResponse response = getExceptionThrowingHandler( - WEB_SERVICE_EXCEPTION).removeObjects("someUsername", - Collections.emptyList()); - - assertEquals(OperationStatus.FAILED, response.getStatus()); - } - - @Test - public void testStoreObjectReturnsFailedStatusIfHttpHostConnectExceptionThrown() { - RegistryResponse response = getExceptionThrowingHandler( - WEB_SERVICE_EXCEPTION).storeObject(null); - - assertEquals(OperationStatus.FAILED, response.getStatus()); - } - @Test public void testGetObjectsReturnsFailedStatusIfCommunicationExceptionThrown() { - RegistryResponse response = getExceptionThrowingHandler( - COMMUNICATION_EXCEPTION).getObjects(null); - + Callable> callable = new Callable>() { + @Override + public RegistryResponse call() throws Exception { + throw COMMUNICATION_EXCEPTION; + } + }; + RegistryResponse response = new FactoryRegistryHandler() + .processRequest(callable, new RegistryResponse()); assertEquals(OperationStatus.FAILED, response.getStatus()); } @Test public void testGetObjectsReturnsFailedToConnectToTheDatabaseIfCommunicationExceptionThrown() { - RegistryResponse response = getExceptionThrowingHandler( - COMMUNICATION_EXCEPTION).getObjects(null); - + Callable> callable = new Callable>() { + @Override + public RegistryResponse call() throws Exception { + throw COMMUNICATION_EXCEPTION; + } + }; + RegistryResponse response = new FactoryRegistryHandler() + .processRequest(callable, new RegistryResponse()); assertEquals(RegistryUtil.FAILED_TO_CONNECT_TO_DATABASE, response .getErrors().iterator().next().getMessage()); } - @Test - public void testRemoveObjectsWithQueryReturnsUnableToConnectMessageIfCommunicationExceptionThrown() { - RegistryResponse response = getExceptionThrowingHandler( - COMMUNICATION_EXCEPTION).removeObjects(null); - - assertEquals(RegistryUtil.FAILED_TO_CONNECT_TO_DATABASE, response - .getErrors().iterator().next().getMessage()); - } - - @Test - public void testRemoveObjectsWithObjectsReturnsUnableToConnectMessageIfCommunicationExceptionThrown() { - RegistryResponse 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 response = getExceptionThrowingHandler( - COMMUNICATION_EXCEPTION).storeObject(null); - - assertEquals(RegistryUtil.FAILED_TO_CONNECT_TO_DATABASE, response - .getErrors().iterator().next().getMessage()); - } - - @Test - public void testRemoveObjectsWithQueryReturnsFailedStatusIfCommunicationExceptionThrown() { - RegistryResponse response = getExceptionThrowingHandler( - COMMUNICATION_EXCEPTION).removeObjects(null); - - assertEquals(OperationStatus.FAILED, response.getStatus()); - } - - @Test - public void testRemoveObjectsWithObjectsReturnsFailedStatusIfCommunicationExceptionThrown() { - RegistryResponse response = getExceptionThrowingHandler( - COMMUNICATION_EXCEPTION).removeObjects("someUsername", - Collections.emptyList()); - - assertEquals(OperationStatus.FAILED, response.getStatus()); - } - - @Test - public void testStoreObjectReturnsFailedStatusIfCommunicationExceptionThrown() { - RegistryResponse response = getExceptionThrowingHandler( - COMMUNICATION_EXCEPTION).storeObject(null); - - assertEquals(OperationStatus.FAILED, response.getStatus()); - } - @Test public void testNonResultFormatterWillReturnDecodedRegistryObjects() throws SerializationException { @@ -256,14 +170,17 @@ public class FactoryRegistryHandlerTest { @Test public void testResultFormatterThatReturnsSingleResultWillReturnsAllSingleResults() { - final String[] results = new String[]{"one", "two", "three"}; - final List registryObjectTypes = java.util.Arrays.asList(new RegistryObjectType(), new RegistryObjectType(), new RegistryObjectType()); + final String[] results = new String[] { "one", "two", "three" }; + final List registryObjectTypes = java.util.Arrays + .asList(new RegistryObjectType(), new RegistryObjectType(), + new RegistryObjectType()); StringResultsQuery query = new StringResultsQuery(results); List filteredResults = FactoryRegistryHandler.filterResults( 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) { assertTrue("The filtered results should have contained result [" @@ -376,26 +293,4 @@ public class FactoryRegistryHandlerTest { FactoryRegistryHandler.statusHandler = oldHandler; } } - - private static 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; - } } diff --git a/tests/unit/com/raytheon/uf/common/registry/ebxml/TestableFactoryRegistryHandler.java b/tests/unit/com/raytheon/uf/common/registry/ebxml/TestableFactoryRegistryHandler.java index eed3f3bbbd..e576669504 100644 --- a/tests/unit/com/raytheon/uf/common/registry/ebxml/TestableFactoryRegistryHandler.java +++ b/tests/unit/com/raytheon/uf/common/registry/ebxml/TestableFactoryRegistryHandler.java @@ -19,10 +19,6 @@ **/ 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.MsgRegistryException; 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.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. * @@ -50,12 +50,11 @@ import oasis.names.tc.ebxml.regrep.xsd.rs.v4.RegistryResponseType; * @version 1.0 */ public class TestableFactoryRegistryHandler extends FactoryRegistryHandler - implements LifecycleManagerFactory, QueryManagerFactory, - RegistryTxManager, QueryManager, LifecycleManager { + implements LifecycleManagerFactory, QueryManagerFactory, QueryManager, + LifecycleManager { public TestableFactoryRegistryHandler() { setLcmFactory(this); setQueryFactory(this); - setTxManager(this); } /** @@ -69,22 +68,6 @@ public class TestableFactoryRegistryHandler extends FactoryRegistryHandler return response; } - /** - * {@inheritDoc} - */ - @Override - public TxManager getTxManager() { - return new TxManager() { - @Override - public void startTransaction() throws Exception { - } - - @Override - public void closeTransaction() { - } - }; - } - /** * {@inheritDoc} */ diff --git a/tests/unit/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/SubscriptionRetrievalAgentTest.java b/tests/unit/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/SubscriptionRetrievalAgentTest.java index 843fbb41fd..f4b2c958ff 100644 --- a/tests/unit/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/SubscriptionRetrievalAgentTest.java +++ b/tests/unit/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/SubscriptionRetrievalAgentTest.java @@ -33,6 +33,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; 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.junit4.SpringJUnit4ClassRunner; @@ -79,6 +80,7 @@ import com.raytheon.uf.edex.datadelivery.retrieval.db.RetrievalRequestRecord.Sta public class SubscriptionRetrievalAgentTest { @Autowired + @Qualifier(value = "retrievalDao") private IRetrievalDao retrievalDao; @Before diff --git a/tests/unit/com/raytheon/uf/edex/datadelivery/retrieval/handlers/RetrievalHandlerTest.java b/tests/unit/com/raytheon/uf/edex/datadelivery/retrieval/handlers/RetrievalHandlerTest.java index 67898d87f9..294cdd5c5b 100644 --- a/tests/unit/com/raytheon/uf/edex/datadelivery/retrieval/handlers/RetrievalHandlerTest.java +++ b/tests/unit/com/raytheon/uf/edex/datadelivery/retrieval/handlers/RetrievalHandlerTest.java @@ -78,6 +78,7 @@ public class RetrievalHandlerTest { @Test public void testAllRunningRetrievalsAreResetToPendingOnConstruction() { + handler.executeAfterRegistryInit(); verify(mockDao).resetRunningRetrievalsToPending(); } @@ -90,13 +91,15 @@ public class RetrievalHandlerTest { @Test public void testRetrievalTaskIsScheduledPerConstructorParameter() { - verify(executorService).scheduleWithFixedDelay(retrievalTask, 1, + handler.executeAfterRegistryInit(); + verify(executorService).scheduleWithFixedDelay(retrievalTask, 30000, RETRIEVAL_TASK_FREQUENCY.getMillis(), TimeUnit.MILLISECONDS); } @Test public void testSubscriptionNotifyTaskIsScheduledPerConstructorParameter() { - verify(executorService).scheduleWithFixedDelay(subNotifyTask, 1, + handler.executeAfterRegistryInit(); + verify(executorService).scheduleWithFixedDelay(subNotifyTask, 30000, SUBNOTIFY_TASK_FREQUENCY.getMillis(), TimeUnit.MILLISECONDS); } } diff --git a/tests/unit/com/raytheon/uf/edex/datadelivery/retrieval/handlers/RetrievalTaskTest.java b/tests/unit/com/raytheon/uf/edex/datadelivery/retrieval/handlers/RetrievalTaskTest.java index 29b8f7f087..423515279b 100644 --- a/tests/unit/com/raytheon/uf/edex/datadelivery/retrieval/handlers/RetrievalTaskTest.java +++ b/tests/unit/com/raytheon/uf/edex/datadelivery/retrieval/handlers/RetrievalTaskTest.java @@ -38,10 +38,12 @@ import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; 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.ClassMode; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.transaction.annotation.Transactional; import com.google.common.eventbus.Subscribe; import com.raytheon.uf.common.datadelivery.event.retrieval.DataRetrievalEvent; @@ -144,6 +146,7 @@ public class RetrievalTaskTest { private RetrievalRequestRecord sbnRetrieval; @Autowired + @Qualifier(value = "retrievalDao") private IRetrievalDao dao; private final PlaceInCollectionProcessor retrievedDataProcessor = new PlaceInCollectionProcessor(); @@ -266,7 +269,9 @@ public class RetrievalTaskTest { /** * Stage the retrievals in the database. */ + @Transactional private void stageRetrievals() { + dao.create(opsnetRetrieval); dao.create(sbnRetrieval); } diff --git a/tests/unit/com/raytheon/uf/edex/stats/AggregateManagerTest.java b/tests/unit/com/raytheon/uf/edex/stats/AggregateManagerTest.java index 5590fa147e..b93706abdb 100644 --- a/tests/unit/com/raytheon/uf/edex/stats/AggregateManagerTest.java +++ b/tests/unit/com/raytheon/uf/edex/stats/AggregateManagerTest.java @@ -107,8 +107,12 @@ public class AggregateManagerTest { final String expectedGroupRepresentation = jaxbManager .marshalToXml(column); - final String actualGroupRepresentation = AggregateManager.determineGroupRepresentationForEvent( - statisticsConfig.getEvents().iterator().next(), mockEvent); + JAXBManager aggregateManagerJaxbManager = new JAXBManager( + StatsGroupingColumn.class); + new AggregateManager("60").setJaxbManager(aggregateManagerJaxbManager); + final String actualGroupRepresentation = AggregateManager + .determineGroupRepresentationForEvent(statisticsConfig + .getEvents().iterator().next(), mockEvent); assertThat(actualGroupRepresentation, is(equalTo(expectedGroupRepresentation))); }