Skip to content

Fix handling of missing aimed departure time - #5865

Merged
vpaturet merged 5 commits into
opentripplanner:dev-2.xfrom
entur:fix_missing_aimed_departure_time_handling
May 29, 2024
Merged

vpaturet merged 5 commits into
opentripplanner:dev-2.xfrom
entur:fix_missing_aimed_departure_time_handling

Conversation

@vpaturet

@vpaturet vpaturet commented May 24, 2024

Copy link
Copy Markdown
Contributor

Summary

As detailed in #5864 , some SIRI updates fail with a NullPointerException. The root cause is a missing aimed departure date on the first call in the estimated vehicle journey (mandatory field in the Nordic SIRI profile).
This PR:

  • improve the error message when aimed departure date is missing on the first call.
  • add test coverage for additional use cases (SIRI updates matched by framed vehicle journey ref, fuzzy-matching)

Note: the null-check on aimed departure date is moved early enough in the process to provide context for the error message, but without changing the outcome.

Note: the SIRI test framework is extended to support:

  • the creation of invalid SIRI messages (missing mandatory date fields),
  • the creation of SIRI messages matched by framed vehicle journey ref,
  • the testing of fuzzy-matching.

Issue

Closes #5864

Unit tests

Added unit tests

Documentation

No

@codecov

codecov Bot commented May 24, 2024

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 77.77778% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 68.46%. Comparing base (b1314cd) to head (61f9fd9).
Report is 25 commits behind head on dev-2.x.

Current head 61f9fd9 differs from pull request most recent head 3a12663

Please upload reports for the commit 3a12663 to get more accurate results.

Files Patch % Lines
...opentripplanner/ext/siri/SiriFuzzyTripMatcher.java 77.77% 2 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             dev-2.x    #5865      +/-   ##
=============================================
+ Coverage      68.37%   68.46%   +0.08%     
- Complexity     16676    16690      +14     
=============================================
  Files           1914     1914              
  Lines          72652    72654       +2     
  Branches        7452     7453       +1     
=============================================
+ Hits           49677    49742      +65     
+ Misses         20418    20341      -77     
- Partials        2557     2571      +14     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@vpaturet
vpaturet marked this pull request as ready for review May 24, 2024 09:47
@vpaturet
vpaturet requested a review from a team as a code owner May 24, 2024 09:47
@vpaturet
vpaturet requested a review from lassetyr May 24, 2024 09:47
@vpaturet

Copy link
Copy Markdown
Contributor Author

@lassetyr In this specific case, does the error need to be reported in the OTP logs? Is this useful for debugging?
There is a number of other edge cases where missing/incomplete data is silently ignored.

@lassetyr

Copy link
Copy Markdown
Contributor

I do not see the need for logging this error, so it can fail silently.

@leonardehrenfried

Copy link
Copy Markdown
Member

It's great that we now have a way to write tests for all these kinds strange edge cases. Well done, @habrahamsson-skanetrafiken

@vpaturet vpaturet added +Real-Time The issue/PR is related to RealTime updates !Bug Apply to issues describing a bug and PRs witch fixes it. labels May 28, 2024
@vpaturet vpaturet self-assigned this May 28, 2024
call.setExpectedArrivalTime(dateTimeHelper.zonedDateTime(expectedTime));
call.setAimedArrivalTime(aimedTime == null ? null : dateTimeHelper.zonedDateTime(aimedTime));
call.setExpectedArrivalTime(
expectedTime == null ? null : dateTimeHelper.zonedDateTime(expectedTime)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a method to the date time helper to extract the repeated null checks?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think an even better solution would be to only set the fields if the values are non-null.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed it sounds simpler to wrap the calls in if( not null)) statements.

Comment on lines +46 to +49
@BeforeEach
void setUp() {
env = new RealtimeTestEnvironment();
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more a matter of style so I will not insist, but I actually preferred @habrahamsson-skanetrafiken's way of instantiating. He can have the final say on it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing I like about having it in each test is that each test is self-contained and it makes it very easy to parametrize the environment, like if you want to setup some test with a different timezone for example.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me that it reduces code duplication while leaving the possibility to customize the environment in each test (since the environment is recreated before each test and is mutable).
I have anyway no strong opinion about this, so I will revert to the previous way of instantiating.


private Trip createTrip(String id, Route route, List<Stop> stops) {
var trip = Trip.of(id(id)).withRoute(route).build();
var trip = Trip.of(id(id)).withRoute(route).withServiceId(SERVICE_ID).build();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I need this in the GTFS tests as well.

@leonardehrenfried leonardehrenfried left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a few small requests.

@vpaturet
vpaturet force-pushed the fix_missing_aimed_departure_time_handling branch from f17eb1a to 3d8a392 Compare May 28, 2024 14:24

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some minor comments

Comment thread src/ext-test/java/org/opentripplanner/ext/siri/SiriEtBuilder.java Outdated
Comment thread src/ext-test/java/org/opentripplanner/ext/siri/SiriEtBuilder.java Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@vpaturet
vpaturet merged commit 8f632f1 into opentripplanner:dev-2.x May 29, 2024
t2gran pushed a commit that referenced this pull request May 29, 2024
@t2gran t2gran added this to the 2.6 (next release) milestone Jul 23, 2024
@t2gran
t2gran deleted the fix_missing_aimed_departure_time_handling branch January 30, 2025 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

!Bug Apply to issues describing a bug and PRs witch fixes it. +Real-Time The issue/PR is related to RealTime updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NullPointerException in SIRI fuzzy matching

5 participants