Skip to content
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

Closed
wants to merge 10 commits into from
Closed

Add DispatchingTermLookup #151

wants to merge 10 commits into from

Conversation

jakobw
Copy link
Member

@jakobw jakobw commented Oct 12, 2016

  • adds a service that picks a TermLookup for the corresponding repository for a given EntityId
  • implemented on top of Add DispatchingEntityLookup #150 in order to reuse UnknownForeignRepositoryException

Task on Phabricator: https://phabricator.wikimedia.org/T149583

Copy link
Member

@manicki manicki left a 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
Copy link
Member

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

Copy link
Member Author

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 );
Copy link
Member

@manicki manicki Oct 12, 2016

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.

Copy link
Member Author

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 );
Copy link
Member

@manicki manicki Oct 12, 2016

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 :)

Copy link
Member Author

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.

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.

@jakobw
Copy link
Member Author

jakobw commented Oct 12, 2016

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 TermLookupException I felt like it would be enough to have the @throws-tag and have people trust that it won't secretly be caught by the dispatching service. I'd also be fine with adding a test though.

@manicki
Copy link
Member

manicki commented Oct 12, 2016

Thanks for quick fixes!

@@ -0,0 +1,92 @@
<?php
Copy link
Member

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 );
Copy link
Member

@mariushoch mariushoch Oct 12, 2016

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed, thanks!

@mariushoch
Copy link
Member

Not sure what happened to this PR, but it seems there are to many commits and way to many changes in here.

@jakobw
Copy link
Member Author

jakobw commented Oct 13, 2016

@mariushoch the PR looks like that because it's depending on @manicki's PR #150 and includes all of its commits.

@jakobw
Copy link
Member Author

jakobw commented Oct 14, 2016

Rebased against #154 to avoid all the commits from #150 flying around.

Copy link

@brightbyte brightbyte left a 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'

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?

Copy link
Member

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 );

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() {

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.

@brightbyte
Copy link

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?

@brightbyte
Copy link

Except for the Travis failures, I think this is good to merge now.

@jakobw
Copy link
Member Author

jakobw commented Oct 31, 2016

@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 ) {

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.

@brightbyte
Copy link

@jakobw do we have a ticket for this somewhere?

@jakobw
Copy link
Member Author

jakobw commented Oct 31, 2016

@brightbyte Not yet, I'll create one.

];
}

public function testGetLabel() {
Copy link
Contributor

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

@manicki
Copy link
Member

manicki commented Nov 1, 2016

As said above, the code is looking pretty good. I am just having some problems now to see this service being used in WikibaseClient: https://phabricator.wikimedia.org/diffusion/EWBA/browse/master/client/includes/WikibaseClient.php
It seems to be that client mostly uses the BufferingTermLookup: https://phabricator.wikimedia.org/diffusion/EWBA/browse/master/lib/includes/Store/BufferingTermLookup.php
So I am now thinking do we want a separate buffering term lookup for each repository, or maybe rather a single buffer for multiple term lookups/term indexes? If the former is the case, we would probably rather need a dispatching buffering lookup service then?

I am not sure if this PR is a right place to discuss such issues, if not let's have it somewhere else.

@brightbyte
Copy link

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...

@jakobw
Copy link
Member Author

jakobw commented Nov 7, 2016

Closed for the reasons mentioned in the comment above

@jakobw jakobw closed this Nov 7, 2016
@Ladsgroup Ladsgroup deleted the dispatching-term-lookup branch January 8, 2020 04:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants