diff --git a/src/com/serotonin/mango/rt/dataSource/bacnet/BACnetIPDataSourceRT.java b/src/com/serotonin/mango/rt/dataSource/bacnet/BACnetIPDataSourceRT.java index db191de006..c7d156fc65 100644 --- a/src/com/serotonin/mango/rt/dataSource/bacnet/BACnetIPDataSourceRT.java +++ b/src/com/serotonin/mango/rt/dataSource/bacnet/BACnetIPDataSourceRT.java @@ -674,15 +674,15 @@ private void fireMessageExceptionEvent(Throwable t) { } private void fireMessageExceptionEvent(String key, String... args) { - raiseEvent(MESSAGE_EXCEPTION_EVENT, System.currentTimeMillis(), false, new LocalizableMessage(key, (Object[]) args)); + raiseEvent(MESSAGE_EXCEPTION_EVENT, System.currentTimeMillis(), true, new LocalizableMessage(key, (Object[]) args)); } private void fireMessageExceptionEvent(DataPointRT dataPointRT, String key, String... args) { - raiseEvent(MESSAGE_EXCEPTION_EVENT, System.currentTimeMillis(), false, new LocalizableMessage(key, (Object[]) args), dataPointRT); + raiseEvent(MESSAGE_EXCEPTION_EVENT, System.currentTimeMillis(), true, new LocalizableMessage(key, (Object[]) args), dataPointRT); } private void fireDeviceExceptionEvent(DataPointRT dataPointRT, String key, String... args) { - raiseEvent(DEVICE_EXCEPTION_EVENT, System.currentTimeMillis(), false, new LocalizableMessage(key, (Object[]) args), dataPointRT); + raiseEvent(DEVICE_EXCEPTION_EVENT, System.currentTimeMillis(), true, new LocalizableMessage(key, (Object[]) args), dataPointRT); } private void returnToNormal() { diff --git a/src/com/serotonin/mango/rt/dataSource/http/HttpRetrieverDataSourceRT.java b/src/com/serotonin/mango/rt/dataSource/http/HttpRetrieverDataSourceRT.java index 556a8ad05a..50ac0ebed0 100644 --- a/src/com/serotonin/mango/rt/dataSource/http/HttpRetrieverDataSourceRT.java +++ b/src/com/serotonin/mango/rt/dataSource/http/HttpRetrieverDataSourceRT.java @@ -125,7 +125,7 @@ protected void doPoll(long time) { } if (parseErrorMessage != null) - raiseEvent(PARSE_EXCEPTION_EVENT, time, false, parseErrorMessage); + raiseEvent(PARSE_EXCEPTION_EVENT, time, true, parseErrorMessage); else returnToNormal(PARSE_EXCEPTION_EVENT, time); } diff --git a/src/com/serotonin/mango/rt/dataSource/mbus/MBusDataSourceRT.java b/src/com/serotonin/mango/rt/dataSource/mbus/MBusDataSourceRT.java index b6d687fed2..72e673ab08 100644 --- a/src/com/serotonin/mango/rt/dataSource/mbus/MBusDataSourceRT.java +++ b/src/com/serotonin/mango/rt/dataSource/mbus/MBusDataSourceRT.java @@ -61,13 +61,13 @@ public MBusDataSourceRT(MBusDataSourceVO vo) { @Override public void initialize() { - LOG.fatal("INITIALIZE MBusaDataSourceRT" + Thread.getAllStackTraces().get(Thread.currentThread())); + LOG.debug("INITIALIZE MBusaDataSourceRT" + Thread.getAllStackTraces().get(Thread.currentThread())); super.initialize(); } @Override public void terminate() { - LOG.fatal("TERMINATE MBusaDataSourceRT" + Thread.getAllStackTraces().get(Thread.currentThread())); + LOG.debug("TERMINATE MBusaDataSourceRT" + Thread.getAllStackTraces().get(Thread.currentThread())); super.terminate(); } diff --git a/src/com/serotonin/mango/rt/dataSource/nmea/NmeaDataSourceRT.java b/src/com/serotonin/mango/rt/dataSource/nmea/NmeaDataSourceRT.java index 1a958bd4c1..b48c6247ae 100644 --- a/src/com/serotonin/mango/rt/dataSource/nmea/NmeaDataSourceRT.java +++ b/src/com/serotonin/mango/rt/dataSource/nmea/NmeaDataSourceRT.java @@ -135,7 +135,9 @@ public void receivedMessage(NmeaMessage message) { } if (parseError != null) - raiseEvent(PARSE_EXCEPTION_EVENT, time, false, parseError); + raiseEvent(PARSE_EXCEPTION_EVENT, time, true, parseError); + else + returnToNormal(PARSE_EXCEPTION_EVENT, time); } private void receivedMessageImpl(DataPointRT dp, NmeaMessage message, long time) throws Exception { diff --git a/src/com/serotonin/mango/rt/dataSource/pachube/PachubeDataSourceRT.java b/src/com/serotonin/mango/rt/dataSource/pachube/PachubeDataSourceRT.java index 0f4e8f16e3..140ca7cce5 100644 --- a/src/com/serotonin/mango/rt/dataSource/pachube/PachubeDataSourceRT.java +++ b/src/com/serotonin/mango/rt/dataSource/pachube/PachubeDataSourceRT.java @@ -212,7 +212,7 @@ protected void pollFeed(int feedId, List points, long time) { } if (parseErrorMessage != null) - raiseEvent(PARSE_EXCEPTION_EVENT, time, false, parseErrorMessage); + raiseEvent(PARSE_EXCEPTION_EVENT, time, true, parseErrorMessage); else returnToNormal(PARSE_EXCEPTION_EVENT, time); } diff --git a/src/com/serotonin/mango/rt/dataSource/pop3/Pop3DataSourceRT.java b/src/com/serotonin/mango/rt/dataSource/pop3/Pop3DataSourceRT.java index 92a79326b9..99d30e1292 100644 --- a/src/com/serotonin/mango/rt/dataSource/pop3/Pop3DataSourceRT.java +++ b/src/com/serotonin/mango/rt/dataSource/pop3/Pop3DataSourceRT.java @@ -123,19 +123,21 @@ protected void doPoll(long time) { returnToNormal(INBOX_EXCEPTION_EVENT, time); if (messagesRead) { - if (messageReadError != null) - raiseEvent(MESSAGE_READ_EXCEPTION_EVENT, time, false, messageReadError); - else + if (messageReadError != null) { + raiseEvent(MESSAGE_READ_EXCEPTION_EVENT, time, true, messageReadError); + return; + } else returnToNormal(MESSAGE_READ_EXCEPTION_EVENT, time); - if (parseError != null) - raiseEvent(PARSE_EXCEPTION_EVENT, time, false, parseError); - else + if (parseError != null) { + raiseEvent(PARSE_EXCEPTION_EVENT, time, true, parseError); + return; + } else returnToNormal(PARSE_EXCEPTION_EVENT, time); } } catch (Exception e) { - raiseEvent(INBOX_EXCEPTION_EVENT, time, false, new LocalizableMessage("common.default", e.getMessage())); + raiseEvent(INBOX_EXCEPTION_EVENT, time, true, new LocalizableMessage("common.default", e.getMessage())); } finally { try { diff --git a/test/com/serotonin/mango/rt/dataSource/DataPointUnreliableUtilsTest.java b/test/com/serotonin/mango/rt/dataSource/DataPointUnreliableUtilsTest.java index 4cdb810e19..167ebcd17a 100644 --- a/test/com/serotonin/mango/rt/dataSource/DataPointUnreliableUtilsTest.java +++ b/test/com/serotonin/mango/rt/dataSource/DataPointUnreliableUtilsTest.java @@ -42,7 +42,7 @@ @RunWith(PowerMockRunner.class) @PrepareForTest({WebContextFactory.class, Common.class, MiscDwr.class, SystemSettingsDAO.class, ContentGenerator.class, PointValueCache.class, DataPointRT.class, RuntimeManager.class, DataPointDao.class, - PointValueDao.class, ApplicationBeans.class}) + PointValueDao.class, ApplicationBeans.class, PollingDataSource.class}) @PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "org.w3c.*", "com.sun.org.apache.xalan.*", "javax.activation.*", "javax.management.*"}) public class DataPointUnreliableUtilsTest { diff --git a/test/com/serotonin/mango/rt/dataSource/InitializeDataSourceRtTest.java b/test/com/serotonin/mango/rt/dataSource/InitializeDataSourceRtTest.java index 2be4d05b89..1c004ab372 100644 --- a/test/com/serotonin/mango/rt/dataSource/InitializeDataSourceRtTest.java +++ b/test/com/serotonin/mango/rt/dataSource/InitializeDataSourceRtTest.java @@ -41,6 +41,7 @@ import com.serotonin.mango.rt.dataSource.vmstat.VMStatDataSourceRT; import com.serotonin.mango.util.InitializeDataSourceRtMockUtils; import com.serotonin.mango.util.SqlDataSourceUtils; +import com.serotonin.mango.util.timeout.TimeoutTask; import com.serotonin.mango.vo.dataSource.http.HttpImageDataSourceVO; import com.serotonin.mango.vo.dataSource.http.HttpRetrieverDataSourceVO; import com.serotonin.mango.vo.dataSource.internal.InternalDataSourceVO; @@ -80,6 +81,8 @@ import static com.serotonin.mango.util.InitializeDataSourceRtMockUtils.supplier; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; +import static org.powermock.api.mockito.PowerMockito.mock; +import static org.powermock.api.mockito.PowerMockito.whenNew; @RunWith(PowerMockRunner.class) @@ -88,7 +91,7 @@ Alpha2Master.class, BACnetIPDataSourceRT.class, Dnp3IpDataSource.class, Dnp3SerialDataSource.class, EBI25DataSourceRT.class, EBI25Constants.class, NmeaDataSourceRT.class, Runtime.class, VMStatDataSourceRT.class, ViconicsDataSourceRT.class, GalilDataSourceRT.class, IEC101EthernetDataSource.class, IEC101SerialDataSource.class, - ModbusFactory.class, OPCDataSource.class, OneWireDataSourceRT.class, SqlDataSourceUtils.class}) + ModbusFactory.class, OPCDataSource.class, OneWireDataSourceRT.class, SqlDataSourceUtils.class, PollingDataSource.class}) @PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "org.w3c.*", "com.sun.org.apache.xalan.*", "javax.activation.*", "javax.management.*"}) public class InitializeDataSourceRtTest { @@ -157,7 +160,7 @@ public InitializeDataSourceRtTest(String name, Supplier mockConfig, int retur private EventManager eventManager; @Before - public void config() throws Exception { + public void config() { eventManager = mock(EventManager.class); HttpReceiverMulticaster multicastListener = mock(HttpReceiverMulticaster.class); diff --git a/test/com/serotonin/mango/rt/dataSource/InitializeWithErrorsDataSourceRtTest.java b/test/com/serotonin/mango/rt/dataSource/InitializeWithErrorsDataSourceRtTest.java index 29bed5ffbc..39c6746c53 100644 --- a/test/com/serotonin/mango/rt/dataSource/InitializeWithErrorsDataSourceRtTest.java +++ b/test/com/serotonin/mango/rt/dataSource/InitializeWithErrorsDataSourceRtTest.java @@ -35,6 +35,7 @@ import com.serotonin.mango.rt.dataSource.sql.SqlDataSourceRT; import com.serotonin.mango.rt.dataSource.viconics.ViconicsDataSourceRT; import com.serotonin.mango.rt.dataSource.vmstat.VMStatDataSourceRT; +import com.serotonin.mango.util.timeout.TimeoutTask; import com.serotonin.mango.vo.dataSource.bacnet.BACnetIPDataSourceVO; import com.serotonin.mango.vo.dataSource.ebro.EBI25DataSourceVO; import com.serotonin.mango.vo.dataSource.galil.GalilDataSourceVO; @@ -75,11 +76,13 @@ import static com.serotonin.mango.util.InitializeDataSourceRtMockUtils.supplier; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; +import static org.powermock.api.mockito.PowerMockito.mock; +import static org.powermock.api.mockito.PowerMockito.whenNew; @RunWith(PowerMockRunner.class) @PowerMockRunnerDelegate(Parameterized.class) -@PrepareForTest({Common.class, Runtime.class, VMStatDataSourceRT.class}) +@PrepareForTest({Common.class, Runtime.class, VMStatDataSourceRT.class, PollingDataSource.class}) @PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "org.w3c.*", "com.sun.org.apache.xalan.*", "javax.activation.*", "javax.management.*"}) public class InitializeWithErrorsDataSourceRtTest { @@ -164,6 +167,14 @@ public void config() { dataSourceRT1.initialize(); } + TimeoutTask timeoutTaskMock = mock(TimeoutTask.class); + try { + whenNew(TimeoutTask.class).withAnyArguments() + .thenReturn(timeoutTaskMock); + } catch (Exception e) { + throw new RuntimeException(e); + } + reset(eventManager); if(dataSourceRT instanceof VMStatDataSourceRT) { diff --git a/test/utils/mock/RuntimeMockUtils.java b/test/utils/mock/RuntimeMockUtils.java index 347a4e6c5f..6fd56c22d4 100644 --- a/test/utils/mock/RuntimeMockUtils.java +++ b/test/utils/mock/RuntimeMockUtils.java @@ -4,6 +4,7 @@ import com.serotonin.mango.rt.EventManager; import com.serotonin.mango.rt.RuntimeManager; import com.serotonin.mango.rt.maint.BackgroundProcessing; +import com.serotonin.mango.util.timeout.TimeoutTask; import com.serotonin.mango.web.ContextWrapper; import org.powermock.api.mockito.PowerMockito; import org.scada_lts.dao.SystemSettingsDAO; @@ -54,6 +55,10 @@ public static void runtimeManagerMock(RuntimeManager runtimeManager, EventManage when(contextWrapper.getEventManager()).thenReturn(eventManager); when(contextWrapper.getBackgroundProcessing()).thenReturn(backgroundProcessing); + TimeoutTask timeoutTaskMock = mock(TimeoutTask.class); + whenNew(TimeoutTask.class).withAnyArguments() + .thenReturn(timeoutTaskMock); + Common.ctx = contextWrapper; Common.timer.init();