[smartmeter] Test fix (#13907)

Signed-off-by: Matthias Steigenberger <matthias.steigenberger@gmail.com>
This commit is contained in:
msteigenberger 2023-02-21 16:26:44 +01:00 committed by GitHub
parent 7c20a4804a
commit 1a01a0e021
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 13 deletions

View File

@ -18,13 +18,13 @@
<dependency>
<groupId>io.reactivex.rxjava2</groupId>
<artifactId>rxjava</artifactId>
<version>2.2.3</version>
<version>2.2.21</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.reactivestreams</groupId>
<artifactId>reactive-streams</artifactId>
<version>1.0.2</version>
<version>1.0.4</version>
<scope>compile</scope>
</dependency>
<dependency>
@ -36,8 +36,14 @@
<dependency>
<groupId>org.openmuc</groupId>
<artifactId>j62056</artifactId>
<version>2.1.0</version>
<version>2.2.0</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>org.openmuc</groupId>
<artifactId>jrxtx</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
@ -54,7 +60,7 @@
<phase>generate-sources</phase>
<configuration>
<sources>
<source>src/3rdparty</source>
<source>src/3rdparty/java</source>
</sources>
</configuration>
</execution>

View File

@ -54,10 +54,10 @@ public class TestMeterReading {
MeterDevice<Object> meter = getMeterDevice(connector);
MeterValueListener changeListener = Mockito.mock(MeterValueListener.class);
meter.addValueChangeListener(changeListener);
Disposable disposable = meter.readValues(5000, Executors.newScheduledThreadPool(1), period);
long executionTime = period.toMillis() * executionCount;
Disposable disposable = meter.readValues(executionTime, Executors.newScheduledThreadPool(1), period);
try {
verify(changeListener, after(executionCount * period.toMillis() + period.toMillis() / 2).never())
.errorOccurred(any());
verify(changeListener, after(executionTime + period.toMillis() / 2 + 50).never()).errorOccurred(any());
verify(changeListener, times(executionCount)).valueChanged(any());
} finally {
disposable.dispose();
@ -90,7 +90,7 @@ public class TestMeterReading {
final int timeout = 5000;
MockMeterReaderConnector connector = spy(getMockedConnector(true, () -> {
try {
Thread.sleep(timeout + 2000);
Thread.sleep(timeout);
} catch (InterruptedException e) {
}
return new Object();
@ -98,9 +98,9 @@ public class TestMeterReading {
MeterDevice<Object> meter = getMeterDevice(connector);
MeterValueListener changeListener = Mockito.mock(MeterValueListener.class);
meter.addValueChangeListener(changeListener);
Disposable disposable = meter.readValues(5000, Executors.newScheduledThreadPool(2), period);
Disposable disposable = meter.readValues(timeout / 2, Executors.newScheduledThreadPool(2), period);
try {
verify(changeListener, after(timeout + 3000).times(1)).errorOccurred(any(TimeoutException.class));
verify(changeListener, timeout(timeout)).errorOccurred(any(TimeoutException.class));
} finally {
disposable.dispose();
}
@ -112,7 +112,7 @@ public class TestMeterReading {
final int timeout = 5000;
MockMeterReaderConnector connector = spy(getMockedConnector(true, () -> {
try {
Thread.sleep(timeout + 2000);
Thread.sleep(timeout);
} catch (InterruptedException e) {
}
throw new RuntimeException(new IOException("fucked up"));
@ -122,9 +122,9 @@ public class TestMeterReading {
RxJavaPlugins.setErrorHandler(errorHandler);
MeterValueListener changeListener = Mockito.mock(MeterValueListener.class);
meter.addValueChangeListener(changeListener);
Disposable disposable = meter.readValues(5000, Executors.newScheduledThreadPool(2), period);
Disposable disposable = meter.readValues(timeout / 2, Executors.newScheduledThreadPool(2), period);
try {
verify(changeListener, after(timeout + 3000).times(1)).errorOccurred(any(TimeoutException.class));
verify(changeListener, timeout(timeout)).errorOccurred(any(TimeoutException.class));
verifyNoMoreInteractions(errorHandler);
} finally {
disposable.dispose();