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
- corrected test: InitializeWithErrorsDataSourceRtTest;
- change type catch from IOException to Throwable;
  • Loading branch information
Limraj committed Feb 27, 2024
1 parent 59772a7 commit 1f01b33
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ else if ("st".equals(headerParts[i]))

returnToNormal(DATA_SOURCE_EXCEPTION_EVENT, System.currentTimeMillis());
}
catch (IOException e) {
catch (Throwable e) {
raiseEvent(DATA_SOURCE_EXCEPTION_EVENT, System.currentTimeMillis(), true, new LocalizableMessage(
"event.initializationError", e.getMessage()));
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.serotonin.mango.rt.dataSource.ebro.EBI25DataSourceRT;
import com.serotonin.mango.rt.dataSource.galil.GalilDataSourceRT;
import com.serotonin.mango.rt.dataSource.http.HttpReceiverDataSourceRT;
import com.serotonin.mango.rt.dataSource.modbus.ModbusDataSource;
import com.serotonin.mango.rt.dataSource.modbus.ModbusIpDataSource;
import com.serotonin.mango.rt.dataSource.modbus.ModbusSerialDataSource;
import com.serotonin.mango.rt.dataSource.nmea.NmeaDataSourceRT;
Expand All @@ -51,7 +50,6 @@
import com.serotonin.mango.vo.dataSource.viconics.ViconicsDataSourceVO;
import com.serotonin.mango.vo.dataSource.vmstat.VMStatDataSourceVO;
import com.serotonin.mango.web.ContextWrapper;
import org.apache.derby.iapi.services.i18n.MessageService;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
Expand All @@ -65,14 +63,15 @@
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import org.scada_lts.ds.messaging.MessagingDataSourceRT;
import org.scada_lts.ds.messaging.exception.MessagingServiceException;
import org.scada_lts.ds.messaging.protocol.amqp.AmqpDataSourceVO;
import org.scada_lts.ds.messaging.protocol.mqtt.MqttDataSourceVO;
import org.scada_lts.ds.messaging.service.MessagingService;
import org.scada_lts.ds.messaging.service.MessagingServiceFactory;

import java.io.IOException;
import java.util.function.Supplier;

import static com.serotonin.mango.util.InitializeDataSourceRtMockUtils.modbusMock;
import static com.serotonin.mango.util.InitializeDataSourceRtMockUtils.wrap;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
Expand Down Expand Up @@ -103,7 +102,7 @@ public static Object[][] data() {

MessagingService messageServiceMock = mock(MessagingService.class);
doAnswer(a -> {
throw new RuntimeException();
throw new MessagingServiceException();
}).when(messageServiceMock).open();

return new Object[][] {
Expand Down Expand Up @@ -166,6 +165,18 @@ public void config() {
}

reset(eventManager);

java.lang.Runtime runtimeMock = mock(Runtime.class);
try {
doAnswer(a -> {
throw new IOException();
}).when(runtimeMock).exec(anyString());
PowerMockito.mockStatic(java.lang.Runtime.class);
when(java.lang.Runtime.getRuntime()).thenReturn(runtimeMock);

} catch (Exception e) {
throw new RuntimeException(e);
}
}

@After
Expand Down Expand Up @@ -209,5 +220,4 @@ public void when_invoke_initialize_with_errors_then_never_returnToNormal() {
//then:
Mockito.verify(eventManager, never()).returnToNormal(any(), anyLong());
}

}

0 comments on commit 1f01b33

Please sign in to comment.