Commit 0f848cbd authored by Jeremy Mikola's avatar Jeremy Mikola

Refactor CommandObserver to track all three APM events

parent 2a288a03
......@@ -123,7 +123,8 @@ class CollectionFunctionalTest extends FunctionalTestCase
]
);
},
function(stdClass $command) {
function(array $event) {
$command = $event['started']->getCommand();
$this->assertObjectHasAttribute('lsid', $command);
$this->assertObjectHasAttribute('maxTimeMS', $command);
$this->assertObjectHasAttribute('writeConcern', $command);
......
......@@ -38,14 +38,16 @@ class CommandObserver implements CommandSubscriber
public function commandStarted(CommandStartedEvent $event)
{
$this->commands[] = $event->getCommand();
$this->commands[$event->getRequestId()]['started'] = $event;
}
public function commandSucceeded(CommandSucceededEvent $event)
{
$this->commands[$event->getRequestId()]['succeeded'] = $event;
}
public function commandFailed(CommandFailedEvent $event)
{
$this->commands[$event->getRequestId()]['failed'] = $event;
}
}
......@@ -221,8 +221,8 @@ class ReadableStreamFunctionalTest extends FunctionalTestCase
$stream->seek($offset);
$this->assertSame($expectedBytes, $stream->readBytes($length));
},
function(stdClass $command) use (&$commands) {
$commands[] = key((array) $command);
function(array $event) use (&$commands) {
$commands[] = $event['started']->getCommandName();
}
);
......@@ -257,8 +257,8 @@ class ReadableStreamFunctionalTest extends FunctionalTestCase
$stream->seek($offset);
$this->assertSame($expectedBytes, $stream->readBytes($length));
},
function(stdClass $command) use (&$commands) {
$commands[] = key((array) $command);
function(array $event) use (&$commands) {
$commands[] = $event['started']->getCommandName();
}
);
......@@ -291,8 +291,8 @@ class ReadableStreamFunctionalTest extends FunctionalTestCase
$stream->seek($offset);
$this->assertSame($expectedBytes, $stream->readBytes($length));
},
function(stdClass $command) use (&$commands) {
$commands[] = key((array) $command);
function(array $event) use (&$commands) {
$commands[] = $event['started']->getCommandName();
}
);
......
......@@ -28,8 +28,8 @@ class AggregateFunctionalTest extends FunctionalTestCase
$operation->execute($this->getPrimaryServer());
},
function(stdClass $command) {
$this->assertSame(1, $command->aggregate);
function(array $event) {
$this->assertSame(1, $event['started']->getCommand()->aggregate);
}
);
}
......@@ -47,8 +47,8 @@ class AggregateFunctionalTest extends FunctionalTestCase
$operation->execute($this->getPrimaryServer());
},
function(stdClass $command) {
$this->assertObjectNotHasAttribute('readConcern', $command);
function(array $event) {
$this->assertObjectNotHasAttribute('readConcern', $event['started']->getCommand());
}
);
}
......@@ -66,8 +66,8 @@ class AggregateFunctionalTest extends FunctionalTestCase
$operation->execute($this->getPrimaryServer());
},
function(stdClass $command) {
$this->assertObjectNotHasAttribute('writeConcern', $command);
function(array $event) {
$this->assertObjectNotHasAttribute('writeConcern', $event['started']->getCommand());
}
);
}
......@@ -112,8 +112,8 @@ class AggregateFunctionalTest extends FunctionalTestCase
$operation->execute($this->getPrimaryServer());
},
function(stdClass $command) {
$this->assertObjectHasAttribute('lsid', $command);
function(array $event) {
$this->assertObjectHasAttribute('lsid', $event['started']->getCommand());
}
);
}
......@@ -185,8 +185,8 @@ class AggregateFunctionalTest extends FunctionalTestCase
$this->assertCount(1, $results);
$this->assertObjectHasAttribute('stages', current($results));
},
function(stdClass $command) {
$this->assertObjectNotHasAttribute('writeConcern', $command);
function(array $event) {
$this->assertObjectNotHasAttribute('writeConcern', $event['started']->getCommand());
}
);
......
......@@ -299,8 +299,8 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
$operation->execute($this->getPrimaryServer());
},
function(stdClass $command) {
$this->assertObjectHasAttribute('lsid', $command);
function(array $event) {
$this->assertObjectHasAttribute('lsid', $event['started']->getCommand());
}
);
}
......
......@@ -23,8 +23,8 @@ class CountFunctionalTest extends FunctionalTestCase
$operation->execute($this->getPrimaryServer());
},
function(stdClass $command) {
$this->assertObjectNotHasAttribute('readConcern', $command);
function(array $event) {
$this->assertObjectNotHasAttribute('readConcern', $event['started']->getCommand());
}
);
}
......@@ -87,8 +87,8 @@ class CountFunctionalTest extends FunctionalTestCase
$operation->execute($this->getPrimaryServer());
},
function(stdClass $command) {
$this->assertObjectHasAttribute('lsid', $command);
function(array $event) {
$this->assertObjectHasAttribute('lsid', $event['started']->getCommand());
}
);
}
......
......@@ -20,8 +20,8 @@ class CreateCollectionFunctionalTest extends FunctionalTestCase
$operation->execute($this->getPrimaryServer());
},
function(stdClass $command) {
$this->assertObjectNotHasAttribute('writeConcern', $command);
function(array $event) {
$this->assertObjectNotHasAttribute('writeConcern', $event['started']->getCommand());
}
);
}
......@@ -42,8 +42,8 @@ class CreateCollectionFunctionalTest extends FunctionalTestCase
$operation->execute($this->getPrimaryServer());
},
function(stdClass $command) {
$this->assertObjectHasAttribute('lsid', $command);
function(array $event) {
$this->assertObjectHasAttribute('lsid', $event['started']->getCommand());
}
);
}
......
......@@ -140,8 +140,8 @@ class CreateIndexesFunctionalTest extends FunctionalTestCase
$operation->execute($this->getPrimaryServer());
},
function(stdClass $command) {
$this->assertObjectNotHasAttribute('writeConcern', $command);
function(array $event) {
$this->assertObjectNotHasAttribute('writeConcern', $event['started']->getCommand());
}
);
}
......@@ -163,8 +163,8 @@ class CreateIndexesFunctionalTest extends FunctionalTestCase
$operation->execute($this->getPrimaryServer());
},
function(stdClass $command) {
$this->assertObjectHasAttribute('lsid', $command);
function(array $event) {
$this->assertObjectHasAttribute('lsid', $event['started']->getCommand());
}
);
}
......
......@@ -24,8 +24,8 @@ class DatabaseCommandFunctionalTest extends FunctionalTestCase
$operation->execute($this->getPrimaryServer());
},
function(stdClass $command) {
$this->assertObjectHasAttribute('lsid', $command);
function(array $event) {
$this->assertObjectHasAttribute('lsid', $event['started']->getCommand());
}
);
}
......
......@@ -79,8 +79,8 @@ class DeleteFunctionalTest extends FunctionalTestCase
$operation->execute($this->getPrimaryServer());
},
function(stdClass $command) {
$this->assertObjectHasAttribute('lsid', $command);
function(array $event) {
$this->assertObjectHasAttribute('lsid', $event['started']->getCommand());
}
);
}
......
......@@ -22,8 +22,8 @@ class DistinctFunctionalTest extends FunctionalTestCase
$operation->execute($this->getPrimaryServer());
},
function(stdClass $command) {
$this->assertObjectNotHasAttribute('readConcern', $command);
function(array $event) {
$this->assertObjectNotHasAttribute('readConcern', $event['started']->getCommand());
}
);
}
......@@ -46,8 +46,8 @@ class DistinctFunctionalTest extends FunctionalTestCase
$operation->execute($this->getPrimaryServer());
},
function(stdClass $command) {
$this->assertObjectHasAttribute('lsid', $command);
function(array $event) {
$this->assertObjectHasAttribute('lsid', $event['started']->getCommand());
}
);
}
......
......@@ -22,8 +22,8 @@ class DropCollectionFunctionalTest extends FunctionalTestCase
$operation->execute($this->getPrimaryServer());
},
function(stdClass $command) {
$this->assertObjectNotHasAttribute('writeConcern', $command);
function(array $event) {
$this->assertObjectNotHasAttribute('writeConcern', $event['started']->getCommand());
}
);
}
......@@ -69,8 +69,8 @@ class DropCollectionFunctionalTest extends FunctionalTestCase
$operation->execute($this->getPrimaryServer());
},
function(stdClass $command) {
$this->assertObjectHasAttribute('lsid', $command);
function(array $event) {
$this->assertObjectHasAttribute('lsid', $event['started']->getCommand());
}
);
}
......
......@@ -22,8 +22,8 @@ class DropDatabaseFunctionalTest extends FunctionalTestCase
$operation->execute($this->getPrimaryServer());
},
function(stdClass $command) {
$this->assertObjectNotHasAttribute('writeConcern', $command);
function(array $event) {
$this->assertObjectNotHasAttribute('writeConcern', $event['started']->getCommand());
}
);
}
......@@ -73,8 +73,8 @@ class DropDatabaseFunctionalTest extends FunctionalTestCase
$operation->execute($this->getPrimaryServer());
},
function(stdClass $command) {
$this->assertObjectHasAttribute('lsid', $command);
function(array $event) {
$this->assertObjectHasAttribute('lsid', $event['started']->getCommand());
}
);
}
......
......@@ -28,8 +28,8 @@ class DropIndexesFunctionalTest extends FunctionalTestCase
$operation->execute($this->getPrimaryServer());
},
function(stdClass $command) {
$this->assertObjectNotHasAttribute('writeConcern', $command);
function(array $event) {
$this->assertObjectNotHasAttribute('writeConcern', $event['started']->getCommand());
}
);
}
......@@ -137,8 +137,8 @@ class DropIndexesFunctionalTest extends FunctionalTestCase
$operation->execute($this->getPrimaryServer());
},
function(stdClass $command) {
$this->assertObjectHasAttribute('lsid', $command);
function(array $event) {
$this->assertObjectHasAttribute('lsid', $event['started']->getCommand());
}
);
}
......
......@@ -182,7 +182,8 @@ class ExplainFunctionalTest extends FunctionalTestCase
$explainOperation = new Explain($this->getDatabaseName(), $operation, ['typeMap' => ['root' => 'array', 'document' => 'array']]);
$explainOperation->execute($this->getPrimaryServer());
},
function(stdClass $command) {
function(array $event) {
$command = $event['started']->getCommand();
$this->assertObjectNotHasAttribute('maxAwaitTimeMS', $command->explain);
$this->assertObjectHasAttribute('tailable', $command->explain);
$this->assertObjectHasAttribute('awaitData', $command->explain);
......@@ -206,7 +207,8 @@ class ExplainFunctionalTest extends FunctionalTestCase
$explainOperation = new Explain($this->getDatabaseName(), $operation, ['typeMap' => ['root' => 'array', 'document' => 'array']]);
$explainOperation->execute($this->getPrimaryServer());
},
function(stdClass $command) {
function(array $event) {
$command = $event['started']->getCommand();
$this->assertObjectHasAttribute('sort', $command->explain);
$this->assertObjectNotHasAttribute('modifiers', $command->explain);
}
......
......@@ -30,8 +30,8 @@ class FindAndModifyFunctionalTest extends FunctionalTestCase
$operation->execute($server);
},
function(stdClass $command) {
$this->assertObjectNotHasAttribute('readConcern', $command);
function(array $event) {
$this->assertObjectNotHasAttribute('readConcern', $event['started']->getCommand());
}
);
}
......@@ -48,8 +48,8 @@ class FindAndModifyFunctionalTest extends FunctionalTestCase
$operation->execute($this->getPrimaryServer());
},
function(stdClass $command) {
$this->assertObjectNotHasAttribute('writeConcern', $command);
function(array $event) {
$this->assertObjectNotHasAttribute('writeConcern', $event['started']->getCommand());
}
);
}
......@@ -70,8 +70,8 @@ class FindAndModifyFunctionalTest extends FunctionalTestCase
$operation->execute($this->getPrimaryServer());
},
function(stdClass $command) {
$this->assertObjectHasAttribute('lsid', $command);
function(array $event) {
$this->assertObjectHasAttribute('lsid', $event['started']->getCommand());
}
);
}
......
......@@ -25,8 +25,8 @@ class FindFunctionalTest extends FunctionalTestCase
$operation->execute($this->getPrimaryServer());
},
function(stdClass $command) {
$this->assertObjectNotHasAttribute('readConcern', $command);
function(array $event) {
$this->assertObjectNotHasAttribute('readConcern', $event['started']->getCommand());
}
);
}
......@@ -99,8 +99,8 @@ class FindFunctionalTest extends FunctionalTestCase
$operation->execute($this->getPrimaryServer());
},
function(stdClass $command) {
$this->assertObjectHasAttribute('lsid', $command);
function(array $event) {
$this->assertObjectHasAttribute('lsid', $event['started']->getCommand());
}
);
}
......
......@@ -70,8 +70,8 @@ class InsertManyFunctionalTest extends FunctionalTestCase
$operation->execute($this->getPrimaryServer());
},
function(stdClass $command) {
$this->assertObjectHasAttribute('lsid', $command);
function(array $event) {
$this->assertObjectHasAttribute('lsid', $event['started']->getCommand());
}
);
}
......
......@@ -85,8 +85,8 @@ class InsertOneFunctionalTest extends FunctionalTestCase
$operation->execute($this->getPrimaryServer());
},
function(stdClass $command) {
$this->assertObjectHasAttribute('lsid', $command);
function(array $event) {
$this->assertObjectHasAttribute('lsid', $event['started']->getCommand());
}
);
}
......
......@@ -86,8 +86,8 @@ class ListCollectionsFunctionalTest extends FunctionalTestCase
$operation->execute($this->getPrimaryServer());
},
function(stdClass $command) {
$this->assertObjectHasAttribute('lsid', $command);
function(array $event) {
$this->assertObjectHasAttribute('lsid', $event['started']->getCommand());
}
);
}
......
......@@ -66,8 +66,8 @@ class ListDatabasesFunctionalTest extends FunctionalTestCase
$operation->execute($this->getPrimaryServer());
},
function(stdClass $command) {
$this->assertObjectHasAttribute('lsid', $command);
function(array $event) {
$this->assertObjectHasAttribute('lsid', $event['started']->getCommand());
}
);
}
......
......@@ -59,8 +59,8 @@ class ListIndexesFunctionalTest extends FunctionalTestCase
$operation->execute($this->getPrimaryServer());
},
function(stdClass $command) {
$this->assertObjectHasAttribute('lsid', $command);
function(array $event) {
$this->assertObjectHasAttribute('lsid', $event['started']->getCommand());
}
);
}
......
......@@ -31,8 +31,8 @@ class MapReduceFunctionalTest extends FunctionalTestCase
$operation->execute($this->getPrimaryServer());
},
function(stdClass $command) {
$this->assertObjectNotHasAttribute('readConcern', $command);
function(array $event) {
$this->assertObjectNotHasAttribute('readConcern', $event['started']->getCommand());
}
);
}
......@@ -55,8 +55,8 @@ class MapReduceFunctionalTest extends FunctionalTestCase
$operation->execute($this->getPrimaryServer());
},
function(stdClass $command) {
$this->assertObjectNotHasAttribute('writeConcern', $command);
function(array $event) {
$this->assertObjectNotHasAttribute('writeConcern', $event['started']->getCommand());
}
);
......@@ -150,8 +150,8 @@ class MapReduceFunctionalTest extends FunctionalTestCase
$operation->execute($this->getPrimaryServer());
},
function(stdClass $command) {
$this->assertObjectHasAttribute('lsid', $command);
function(array $event) {
$this->assertObjectHasAttribute('lsid', $event['started']->getCommand());
}
);
}
......
......@@ -40,8 +40,8 @@ class UpdateFunctionalTest extends FunctionalTestCase
$operation->execute($this->getPrimaryServer());
},
function(stdClass $command) {
$this->assertObjectHasAttribute('lsid', $command);
function(array $event) {
$this->assertObjectHasAttribute('lsid', $event['started']->getCommand());
}
);
}
......
......@@ -98,8 +98,8 @@ class WatchFunctionalTest extends FunctionalTestCase
function() use ($changeStream) {
$changeStream->next();
},
function(stdClass $command) use (&$commands) {
$commands[] = key((array) $command);
function(array $event) use (&$commands) {
$commands[] = $event['started']->getCommandName();
}
);
$this->fail('ConnectionTimeoutException was not thrown');
......@@ -148,8 +148,8 @@ class WatchFunctionalTest extends FunctionalTestCase
function() use ($changeStream) {
$changeStream->rewind();
},
function(stdClass $command) use (&$commands) {
$commands[] = key((array) $command);
function(array $event) use (&$commands) {
$commands[] = $event['started']->getCommandName();
}
);
$this->fail('ConnectionTimeoutException was not thrown');
......@@ -592,9 +592,10 @@ class WatchFunctionalTest extends FunctionalTestCase
function() use ($operation, &$changeStream) {
$changeStream = $operation->execute($this->getPrimaryServer());
},
function($changeStream) use (&$originalSession) {
if (isset($changeStream->aggregate)) {
$originalSession = bin2hex((string) $changeStream->lsid->id);
function(array $event) use (&$originalSession) {
$command = $event['started']->getCommand();
if (isset($command->aggregate)) {
$originalSession = bin2hex((string) $command->lsid->id);
}
}
);
......@@ -606,9 +607,9 @@ class WatchFunctionalTest extends FunctionalTestCase
function() use (&$changeStream) {
$changeStream->next();
},
function ($changeStream) use (&$sessionAfterResume, &$commands) {
$commands[] = key((array) $changeStream);
$sessionAfterResume[] = bin2hex((string) $changeStream->lsid->id);
function (array $event) use (&$sessionAfterResume, &$commands) {
$commands[] = $event['started']->getCommandName();
$sessionAfterResume[] = bin2hex((string) $event['started']->getCommand()->lsid->id);
}
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment