WMDE-leszek has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/353299 )
Change subject: Add WikibaseServices interface and the "dispatching-aware"
implementation
......................................................................
Add WikibaseServices interface and the "dispatching-aware" implementation
Initially the interface of WikibaseServices is equal to the one of
DispatchingServiceFactory/EntityDataRetrievalServiceFactory.
MultipleRepositoryAwareWikibaseServices implements WikibaseServices
and uses the DispatchingServiceFactory instance to provide
"dispatching" instances of services.
Bug: T165039
Bug: T165041
Change-Id: I39316c1a2bc2de5540dbb570356e60a218b8e345
---
A data-access/src/MultipleRepositoryAwareWikibaseServices.php
A data-access/src/WikibaseServices.php
A data-access/tests/phpunit/MultipleRepositoryAwareWikibaseServicesTest.php
3 files changed, 294 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/99/353299/2
diff --git a/data-access/src/MultipleRepositoryAwareWikibaseServices.php
b/data-access/src/MultipleRepositoryAwareWikibaseServices.php
new file mode 100644
index 0000000..5076fcb
--- /dev/null
+++ b/data-access/src/MultipleRepositoryAwareWikibaseServices.php
@@ -0,0 +1,90 @@
+<?php
+
+
+namespace Wikibase\DataAccess;
+
+use MediaWiki\Services\ServiceContainer;
+use Wikibase\DataModel\Services\Entity\EntityPrefetcher;
+use Wikibase\DataModel\Services\Term\TermBuffer;
+use Wikibase\Lib\Interactors\TermSearchInteractorFactory;
+use Wikibase\Lib\Store\EntityInfoBuilderFactory;
+use Wikibase\Lib\Store\EntityRevisionLookup;
+use Wikibase\Lib\Store\PropertyInfoLookup;
+
+/**
+ * Top-level container/factory of data access services making use of the
"dispatching" pattern of
+ * services aware of multi-repository configuration that delegate their action
+ * to service instance configured for a particular repository.
+ *
+ * @license GPL-2.0+
+ */
+class MultipleRepositoryAwareWikibaseServices extends ServiceContainer
implements WikibaseServices {
+
+ public function __construct( DispatchingServiceFactory
$dispatchingServiceContainer ) {
+ parent::__construct();
+
+ $this->applyWiring( [
+ 'EntityInfoBuilderFactory' => function() use (
$dispatchingServiceContainer ) {
+ return
$dispatchingServiceContainer->getEntityInfoBuilderFactory();
+ },
+ 'EntityPrefetcher' => function() use (
$dispatchingServiceContainer ) {
+ return
$dispatchingServiceContainer->getEntityPrefetcher();
+ },
+ 'EntityRevisionLookup' => function() use (
$dispatchingServiceContainer ) {
+ return
$dispatchingServiceContainer->getEntityRevisionLookup();
+ },
+ 'PropertyInfoLookup' => function() use (
$dispatchingServiceContainer ) {
+ return
$dispatchingServiceContainer->getPropertyInfoLookup();
+ },
+ 'TermBuffer' => function() use (
$dispatchingServiceContainer ) {
+ return
$dispatchingServiceContainer->getTermBuffer();
+ },
+ 'TermSearchInteractorFactory' => function() use (
$dispatchingServiceContainer ) {
+ return
$dispatchingServiceContainer->getTermSearchInteractorFactory();
+ },
+ ] );
+ }
+
+ /**
+ * @return EntityInfoBuilderFactory
+ */
+ public function getEntityInfoBuilderFactory() {
+ return $this->getService( 'EntityInfoBuilderFactory' );
+ }
+
+ /**
+ * @return EntityPrefetcher
+ */
+ public function getEntityPrefetcher() {
+ return $this->getService( 'EntityPrefetcher' );
+ }
+
+ /**
+ * @return EntityRevisionLookup
+ */
+ public function getEntityRevisionLookup() {
+ return $this->getService( 'EntityRevisionLookup' );
+ }
+
+ /**
+ * @return PropertyInfoLookup
+ */
+ public function getPropertyInfoLookup() {
+ return $this->getService( 'PropertyInfoLookup' );
+ }
+
+ /**
+ * @return TermBuffer
+ */
+ public function getTermBuffer() {
+ return $this->getService( 'TermBuffer' );
+ }
+
+ /**
+ * @return TermSearchInteractorFactory
+ */
+ public function getTermSearchInteractorFactory() {
+ return $this->getService( 'TermSearchInteractorFactory' );
+ }
+
+}
diff --git a/data-access/src/WikibaseServices.php
b/data-access/src/WikibaseServices.php
new file mode 100644
index 0000000..cc6cb8d
--- /dev/null
+++ b/data-access/src/WikibaseServices.php
@@ -0,0 +1,55 @@
+<?php
+
+namespace Wikibase\DataAccess;
+
+use Wikibase\DataModel\Services\Entity\EntityPrefetcher;
+use Wikibase\DataModel\Services\Term\TermBuffer;
+use Wikibase\Lib\Interactors\TermSearchInteractorFactory;
+use Wikibase\Lib\Store\EntityInfoBuilderFactory;
+use Wikibase\Lib\Store\EntityRevisionLookup;
+use Wikibase\Lib\Store\PropertyInfoLookup;
+
+/**
+ * Interface of the top-level container/factory of data access services.
+ *
+ * @license GPL-2.0+
+ */
+interface WikibaseServices {
+
+ /**
+ * @return EntityInfoBuilderFactory
+ */
+ public function getEntityInfoBuilderFactory();
+
+ /**
+ * @return EntityPrefetcher
+ */
+ public function getEntityPrefetcher();
+
+ /**
+ * Note: Instance returned is not guaranteed to be a caching decorator.
+ * Callers should take care of caching themselves.
+ *
+ * @return EntityRevisionLookup
+ */
+ public function getEntityRevisionLookup();
+
+ /**
+ * Note: Instance returned is not guaranteed to be a caching decorator.
+ * Callers should take care of caching themselves.
+ *
+ * @return PropertyInfoLookup
+ */
+ public function getPropertyInfoLookup();
+
+ /**
+ * @return TermBuffer
+ */
+ public function getTermBuffer();
+
+ /**
+ * @return TermSearchInteractorFactory
+ */
+ public function getTermSearchInteractorFactory();
+
+}
diff --git
a/data-access/tests/phpunit/MultipleRepositoryAwareWikibaseServicesTest.php
b/data-access/tests/phpunit/MultipleRepositoryAwareWikibaseServicesTest.php
new file mode 100644
index 0000000..23a9c42
--- /dev/null
+++ b/data-access/tests/phpunit/MultipleRepositoryAwareWikibaseServicesTest.php
@@ -0,0 +1,149 @@
+<?php
+
+namespace Wikibase\DataAccess\Tests;
+
+use Wikibase\DataAccess\DispatchingServiceFactory;
+use Wikibase\DataAccess\MultipleRepositoryAwareWikibaseServices;
+use Wikibase\DataModel\Services\Entity\EntityPrefetcher;
+use Wikibase\DataModel\Services\Term\TermBuffer;
+use Wikibase\Lib\Interactors\TermSearchInteractorFactory;
+use Wikibase\Lib\Store\EntityInfoBuilderFactory;
+use Wikibase\Lib\Store\EntityRevisionLookup;
+use Wikibase\Lib\Store\PropertyInfoLookup;
+
+/**
+ * @covers Wikibase\DataAccess\MultipleRepositoryAwareWikibaseServices
+ *
+ * @group Wikibase
+ *
+ * @license GPL-2.0+
+ */
+class MultipleRepositoryAwareWikibaseServicesTest extends
\PHPUnit_Framework_TestCase {
+
+ /**
+ * @return DispatchingServiceFactory
+ */
+ private function getDispatchingServiceContainer() {
+ $dispatchingServiceContainer = $this->getMockBuilder(
DispatchingServiceFactory::class )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $dispatchingServiceContainer->method(
'getEntityInfoBuilderFactory' )
+ ->will(
+ $this->returnValue( $this->getMock(
EntityInfoBuilderFactory::class ) )
+ );
+ $dispatchingServiceContainer->method( 'getEntityPrefetcher' )
+ ->will(
+ $this->returnValue( $this->getMock(
EntityPrefetcher::class ) )
+ );
+ $dispatchingServiceContainer->method( 'getEntityRevisionLookup'
)
+ ->will(
+ $this->returnValue( $this->getMock(
EntityRevisionLookup::class ) )
+ );
+ $dispatchingServiceContainer->method( 'getPropertyInfoLookup' )
+ ->will(
+ $this->returnValue( $this->getMock(
PropertyInfoLookup::class ) )
+ );
+ $dispatchingServiceContainer->method( 'getTermBuffer' )
+ ->will(
+ $this->returnValue( $this->getMock(
TermBuffer::class ) )
+ );
+ $dispatchingServiceContainer->method(
'getTermSearchInteractorFactory' )
+ ->will(
+ $this->returnValue( $this->getMock(
TermSearchInteractorFactory::class ) )
+ );
+
+ return $dispatchingServiceContainer;
+ }
+
+ public function testGetEntityInfoBuilderFactory() {
+ $wikibaseServices = new
MultipleRepositoryAwareWikibaseServices(
$this->getDispatchingServiceContainer() );
+
+ $this->assertInstanceOf( EntityInfoBuilderFactory::class,
$wikibaseServices->getEntityInfoBuilderFactory() );
+ }
+
+ public function testGetEntityPrefetcher() {
+ $wikibaseServices = new
MultipleRepositoryAwareWikibaseServices(
$this->getDispatchingServiceContainer() );
+
+ $this->assertInstanceOf( EntityPrefetcher::class,
$wikibaseServices->getEntityPrefetcher() );
+
+ }
+
+ public function testGetEntityRevisionLookup() {
+ $wikibaseServices = new
MultipleRepositoryAwareWikibaseServices(
$this->getDispatchingServiceContainer() );
+
+ $this->assertInstanceOf( EntityRevisionLookup::class,
$wikibaseServices->getEntityRevisionLookup() );
+
+ }
+
+ public function testGetPropertyInfoLookup() {
+ $wikibaseServices = new
MultipleRepositoryAwareWikibaseServices(
$this->getDispatchingServiceContainer() );
+
+ $this->assertInstanceOf( PropertyInfoLookup::class,
$wikibaseServices->getPropertyInfoLookup() );
+
+ }
+
+ public function testGetTermBuffer() {
+ $wikibaseServices = new
MultipleRepositoryAwareWikibaseServices(
$this->getDispatchingServiceContainer() );
+
+ $this->assertInstanceOf( TermBuffer::class,
$wikibaseServices->getTermBuffer() );
+ }
+
+ public function testGetTermSearchInteractorFactory() {
+ $wikibaseServices = new
MultipleRepositoryAwareWikibaseServices(
$this->getDispatchingServiceContainer() );
+
+ $this->assertInstanceOf(
+ TermSearchInteractorFactory::class,
+ $wikibaseServices->getTermSearchInteractorFactory()
+ );
+ }
+
+ public function
testGetServicesIncludesServicesProvidedByDispatchingServiceContainer() {
+ $dispatchingServiceContainer = $this->getMockBuilder(
DispatchingServiceFactory::class )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $wikibaseServices = new
MultipleRepositoryAwareWikibaseServices( $dispatchingServiceContainer );
+
+ $serviceNames = $wikibaseServices->getServiceNames();
+
+ $this->assertContains( 'EntityInfoBuilderFactory',
$serviceNames );
+ $this->assertContains( 'EntityPrefetcher', $serviceNames );
+ $this->assertContains( 'EntityRevisionLookup', $serviceNames );
+ $this->assertContains( 'PropertyInfoLookup', $serviceNames );
+ $this->assertContains( 'TermBuffer', $serviceNames );
+ $this->assertContains( 'TermSearchInteractorFactory',
$serviceNames );
+ }
+
+ public function
testGetServiceReturnsSameServiceInstanceAsDispatchingServiceContainer() {
+ $dispatchingServiceContainer =
$this->getDispatchingServiceContainer();
+
+ $wikibaseServices = new
MultipleRepositoryAwareWikibaseServices( $dispatchingServiceContainer );
+
+ $this->assertSame(
+
$dispatchingServiceContainer->getEntityInfoBuilderFactory(),
+ $wikibaseServices->getEntityInfoBuilderFactory()
+ );
+ $this->assertSame(
+ $dispatchingServiceContainer->getEntityPrefetcher(),
+ $wikibaseServices->getEntityPrefetcher()
+ );
+ $this->assertSame(
+ $dispatchingServiceContainer->getEntityRevisionLookup(),
+ $wikibaseServices->getEntityRevisionLookup()
+ );
+ $this->assertSame(
+ $dispatchingServiceContainer->getPropertyInfoLookup(),
+ $wikibaseServices->getPropertyInfoLookup()
+ );
+ $this->assertSame(
+ $dispatchingServiceContainer->getTermBuffer(),
+ $wikibaseServices->getTermBuffer()
+ );
+ $this->assertSame(
+
$dispatchingServiceContainer->getTermSearchInteractorFactory(),
+ $wikibaseServices->getTermSearchInteractorFactory()
+ );
+ }
+
+}
--
To view, visit https://gerrit.wikimedia.org/r/353299
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I39316c1a2bc2de5540dbb570356e60a218b8e345
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: WMDE-leszek <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits