Mwalker has uploaded a new change for review.
https://gerrit.wikimedia.org/r/74275
Change subject: STOMP Datastore Correctly Switches Selectors
......................................................................
STOMP Datastore Correctly Switches Selectors
Using the new TestDatastore maintenance script the StompDatastore
now correctly processes selector switches and recreates subscriptions.
This means that the refresh-connections setting does not help, but
I'll leave it just in case.
Change-Id: I6279567e45361a97a05b2cffcbf2ef010573650f
---
M SmashPig/Core/DataStores/StompDataStore.php
A SmashPig/Maintenance/TestDatastore.php
M SmashPig/config_defaults.php
3 files changed, 105 insertions(+), 3 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/PaymentsListeners
refs/changes/75/74275/1
diff --git a/SmashPig/Core/DataStores/StompDataStore.php
b/SmashPig/Core/DataStores/StompDataStore.php
index 7e75995..afa8fb0 100644
--- a/SmashPig/Core/DataStores/StompDataStore.php
+++ b/SmashPig/Core/DataStores/StompDataStore.php
@@ -300,7 +300,7 @@
Logger::debug( "Detected tail eating! Stopping
queue consumption." );
return null;
} else {
- Logger::info( "Pulled new object from STOMP
queue" );
+ Logger::debug( "Pulled new object from STOMP
queue {$this->queue_id}" );
return $this->queueMsg;
}
} else {
@@ -323,7 +323,7 @@
'ack' => 'client-individual',
);
- if ( $this->subscribed && ( ( $sType === $type ) || ( $sId ===
$id ) ) ) {
+ if ( $this->subscribed && ( $sType === $type ) && ( $sId ===
$id ) ) {
// Same subscription; just return
return;
} elseif ( $this->subscribed ) {
@@ -333,6 +333,7 @@
if ( $this->refreshConnection ) {
// Apparently the backend STOMP library has
some issues clearing
// out its buffer so we get old stuff :(
+ Logger::debug( "Refreshing STOMP connection
object on selector change. refresh-connection = true" );
$this->createBackingObject();
}
}
diff --git a/SmashPig/Maintenance/TestDatastore.php
b/SmashPig/Maintenance/TestDatastore.php
new file mode 100644
index 0000000..e3d1cbf
--- /dev/null
+++ b/SmashPig/Maintenance/TestDatastore.php
@@ -0,0 +1,101 @@
+<?php namespace SmashPig\Maintenance;
+
+require( 'MaintenanceBase.php' );
+
+use SmashPig\Core\Configuration;
+use SmashPig\Core\DataStores\KeyedOpaqueStorableObject;
+use SmashPig\Core\Logging\Logger;
+use SmashPig\Core\SmashPigException;
+use SmashPig\Core\DataStores\KeyedOpaqueDataStore;
+
+$maintClass = '\SmashPig\Maintenance\TestDatastore';
+
+/**
+ * Test a datastore connection to ensure that it can store and retrieve objects
+ * correctly.
+ */
+class TestDatastore extends MaintenanceBase {
+
+ /** @var KeyedOpaqueDataStore */
+ protected $datastore = null;
+
+ /** @var TestObject $testObjects */
+ protected $testObjects = array();
+
+ public function __construct() {
+ parent::__construct();
+ $this->addArgument( 'queue', 'Queue datastore to test', true );
+ }
+
+ /**
+ * Do the actual work of the script.
+ */
+ public function execute() {
+ $this->datastore = Configuration::getDefaultConfig()->obj(
+ 'data-store/' . $this->getArgument( 0, 'test' ),
+ false
+ );
+
+ // Generate a whole bunch of random data
+ while ( count( $this->testObjects ) < 10 ) {
+ $this->testObjects[] = TestObject::factory();
+ }
+ // And repeat the objects and inject so we have something else
to find
+ foreach( $this->testObjects as $obj ) {
+ $this->datastore->addObject( $obj );
+ $this->datastore->addObject( TestObject::factory(
$obj->correlationId ) );
+ }
+
+ // Mix up the order of the objects to simulate real life
+ shuffle( $this->testObjects );
+
+ // Now attempt to find them and their pairs!
+ $this->datastore = Configuration::getDefaultConfig()->obj(
+ 'data-store/' . $this->getArgument( 0, 'test' ),
+ false
+ );
+ foreach( $this->testObjects as $obj ) {
+ $obj1 = $this->datastore->queueGetObject( null,
$obj->correlationId );
+ if ( $obj1 !== null ) {
$this->datastore->queueAckObject(); }
+ else { $this->error( "Could not find original object
with id {$obj->correlationId}" ); continue; }
+
+ $obj2 = $this->datastore->queueGetObject( null,
$obj->correlationId );
+ if ( $obj2 !== null ) {
$this->datastore->queueAckObject(); }
+ else { $this->error( "Could not find secondary object
with id {$obj->correlationId}" ); continue; }
+
+ $obj3 = $this->datastore->queueGetObject( null,
$obj->correlationId );
+ if ( $obj3 !== null ) {
+ $this->datastore->queueAckObject();
+ $this->error( "Found tertiary object with id
{$obj3->correlationId} while looking for id {$obj->correlationId}" );
+ continue;
+ }
+
+ Logger::info( "Successfully found id
{$obj->correlationId}" );
+ }
+
+ Logger::info( "Done" );
+ }
+
+ protected function throwException() {
+ throw new SmashPigException( 'TestException!' );
+ }
+}
+
+class TestObject extends KeyedOpaqueStorableObject {
+ /** @var array List of object properties that can be considered
'identifying' or 'filtering' properties */
+ protected $propertiesExportedAsKeys = array( 'correlationId',
'testkey1', 'testkey2' );
+
+ public $testkey1 = null;
+ public $testkey2 = null;
+
+ public static function factory( $id = null ) {
+ $obj = new TestObject();
+ $obj->correlationId = ( $id !== null ) ? $id : mt_rand();
+ $obj->testkey1 = mt_rand();
+ $obj->testkey2 = mt_rand();
+
+ return $obj;
+ }
+}
+
+require( RUN_MAINTENANCE_IF_MAIN );
diff --git a/SmashPig/config_defaults.php b/SmashPig/config_defaults.php
index 404a93c..2ff526a 100644
--- a/SmashPig/config_defaults.php
+++ b/SmashPig/config_defaults.php
@@ -35,7 +35,7 @@
'uri' => 'tcp://localhost:61613',
'timeout' => 1,
- 'refresh-connection' => true,
+ 'refresh-connection' => false,
'queues' => array(
'limbo' => '/queue/limbo',
--
To view, visit https://gerrit.wikimedia.org/r/74275
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6279567e45361a97a05b2cffcbf2ef010573650f
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/PaymentsListeners
Gerrit-Branch: master
Gerrit-Owner: Mwalker <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits