-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add DispatchingTermLookup #151
Conversation
93bf750
to
146ffdb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good at glance, generally follows the way other dispatching services have been proposed so far.
Found two minor things, one being my mistake actually.
I see you have separate tests for "entity from local repo" and "entity from foreign repo" cases. I am a bit torn on this (I originally also made such division in DispatchingEntityLookup
's tests). On one hand local repo case is a bit special and different from the foreign entity case. On the other hand, technically local repo and any foreign repo are pretty much the same thing for the dispatcher, so I started to think that maybe it would be enough to just check in tests that some things work for the known repo (be it local or foreign, it does not matter), and that for unknown repo exceptions are thrown etc.
I'd really appreciate other's opinions on this. We're getting more and more of those dispatchers, so it would be nice to have tests consistent at the early stage, I think.
According to docs all public methods of TermLookup
throw TermLookupException
. Those exception should not be caught be the dispatching wrapper. From looking at the code I can tell it does not happen but some small unit tests proving this would be nice too.
|
||
/** | ||
* @param TermLookup[] $lookups associative array with repository names (strings) as keys | ||
* and TermLookup objects as values. Empty-string key |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation is a bit off here and line below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
private function getLookupForEntityId( EntityId $entityId ) { | ||
$repo = $entityId->getRepositoryName(); | ||
if ( !isset( $this->lookups[$repo] ) ) { | ||
throw new UnknownForeignRepositoryException( $entityId, 'Unknown repository: ' . $repo ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just realized that the second parameter passed to the constructor could be possibly skipped in all dispatching service patches as it is not really relevant, ie. ''Unknown repository name: foo" vs "'Unknown repository: foo".
I'll remove it my patches. If shorter message is preferred, it should be changed in the exception. I have no preference here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed!
] ); | ||
|
||
$this->setExpectedException( UnknownForeignRepositoryException::class ); | ||
$lookup->$method( $item, $language ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's see if we will have @JeroenDeDauw ranting on this line :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:)
I was too lazy to write the same thing 4x but I'm fine with changing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for the negative test, this is ok.
Thanks @manicki for the review! I agree with what you said about testing the two cases for each method and would also like to hear a third opinion on it. I have no strong preference. Regarding |
Thanks for quick fixes! |
@@ -0,0 +1,92 @@ | |||
<?php |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this should be part of this PR, should it?
private function getLookupForEntityId( EntityId $entityId ) { | ||
$repo = $entityId->getRepositoryName(); | ||
if ( !isset( $this->lookups[$repo] ) ) { | ||
throw new UnknownForeignRepositoryException( $entityId ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First parameter to the constructor of UnknownForeignRepositoryException
is string $repoName
not an entity id.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, thanks!
Not sure what happened to this PR, but it seems there are to many commits and way to many changes in here. |
@mariushoch the PR looks like that because it's depending on @manicki's PR #150 and includes all of its commits. |
cca40ac
to
94bb198
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good, some small requests
Assert::parameter( | ||
!empty( $lookups ) && array_key_exists( '', $lookups ), | ||
'$lookups', | ||
'must must not be empty and must contain an empty-string key' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is that required? Do we rely on that anywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really, but that would require changes to the error handling so that it can handle that special case in a meaningful way.
In general, I could see that you want to treat all lookups equally "remote"… but I don't think that matches up with what was done in DM, does it?
] ); | ||
|
||
$this->setExpectedException( UnknownForeignRepositoryException::class ); | ||
$lookup->$method( $item, $language ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for the negative test, this is ok.
]; | ||
} | ||
|
||
public function testGetLabelFromLocalRepo() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dispatcher should not really know or care about local and foreign. It uses whatever prefix is in the ID - if the prefix is the empty string, it should just work like any other. That should be tested, but it doesn't need a separate function.
94bb198
to
41ab122
Compare
I'm confused about the Travis failures. It seems that it is using the old DataModel version for some test runs, but not for others... is there a way to re-trigger the test runs? |
Except for the Travis failures, I think this is good to merge now. |
@brightbyte travis config is fixed now. |
Assert::parameter( !empty( $lookups ), '$lookups', 'must must not be empty' ); | ||
Assert::parameterElementType( TermLookup::class, $lookups, '$lookups' ); | ||
Assert::parameterElementType( 'string', array_keys( $lookups ), 'array_keys( $lookups )' ); | ||
foreach ( array_keys( $lookups ) as $repositoryName ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should probably wait for #155, so we can get rid of this.
@jakobw do we have a ticket for this somewhere? |
@brightbyte Not yet, I'll create one. |
]; | ||
} | ||
|
||
public function testGetLabel() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a very descriptive name
As said above, the code is looking pretty good. I am just having some problems now to see this service being used in I am not sure if this PR is a right place to discuss such issues, if not let's have it somewhere else. |
As I said in https://phabricator.wikimedia.org/T148141#2760606, we indeed do need a DispatchingTermBuffer (which is also a dispatching TermLookup), but probably no "plain" DispatchingTermLookup. Sorry about that... |
Closed for the reasons mentioned in the comment above |
TermLookup
for the corresponding repository for a givenEntityId
UnknownForeignRepositoryException
Task on Phabricator: https://phabricator.wikimedia.org/T149583