Skip to content

Commit

Permalink
#2755 Signaling the data source that has a problem:
Browse files Browse the repository at this point in the history
- fixed generate many events by: Pop3DataSourceRT, PachubeDataSourceRT, NmeaDataSourceRT, HttpRetrieverDataSourceRT, BACnetIPDataSourceRT, change to active events;
- change logging fatal to debug level in methods: MBusDataSourceRT.initialize(), MBusDataSourceRT.terminate();
- fixed DataPointUnreliableUtilsTest, InitializeDataSourceRtTest, InitializeWithErrorsDataSourceRtTest, mocking TimeoutTask;
  • Loading branch information
Limraj committed Feb 28, 2024
1 parent 1690c7c commit e5884bf
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ protected void pollFeed(int feedId, List<DataPointRT> 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);
}
Expand Down
16 changes: 9 additions & 7 deletions src/com/serotonin/mango/rt/dataSource/pop3/Pop3DataSourceRT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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<T extends DataSourceRT> {
Expand Down Expand Up @@ -157,7 +160,7 @@ public InitializeDataSourceRtTest(String name, Supplier<T> mockConfig, int retur
private EventManager eventManager;

@Before
public void config() throws Exception {
public void config() {
eventManager = mock(EventManager.class);
HttpReceiverMulticaster multicastListener = mock(HttpReceiverMulticaster.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions test/utils/mock/RuntimeMockUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit e5884bf

Please sign in to comment.