mirror of
https://github.com/symfony/cache.git
synced 2026-03-23 23:22:07 +01:00
[Cache] Recognize commit events as writes in CacheDataCollector
This commit is contained in:
committed by
Nicolas Grekas
parent
f021d84781
commit
81eb494fc2
@@ -143,6 +143,8 @@ class CacheDataCollector extends DataCollector implements LateDataCollectorInter
|
||||
}
|
||||
} elseif ('save' === $call->name) {
|
||||
++$statistics[$name]['writes'];
|
||||
} elseif ('saveDeferred' === $call->name) {
|
||||
++$statistics[$name]['writes'];
|
||||
} elseif ('deleteItem' === $call->name) {
|
||||
++$statistics[$name]['deletes'];
|
||||
}
|
||||
|
||||
@@ -86,6 +86,46 @@ class CacheDataCollectorTest extends TestCase
|
||||
$this->assertEquals($statistics[self::INSTANCE_NAME]['writes'], 1, 'writes');
|
||||
}
|
||||
|
||||
public function testSaveDeferredEventWithoutExplicitCommitDataCollector()
|
||||
{
|
||||
$traceableAdapterEvent = new \stdClass();
|
||||
$traceableAdapterEvent->name = 'saveDeferred';
|
||||
$traceableAdapterEvent->start = 0;
|
||||
$traceableAdapterEvent->end = 0;
|
||||
|
||||
$statistics = $this->getCacheDataCollectorStatisticsFromEvents([$traceableAdapterEvent]);
|
||||
|
||||
$this->assertSame(1, $statistics[self::INSTANCE_NAME]['calls'], 'calls');
|
||||
$this->assertSame(0, $statistics[self::INSTANCE_NAME]['reads'], 'reads');
|
||||
$this->assertSame(0, $statistics[self::INSTANCE_NAME]['hits'], 'hits');
|
||||
$this->assertSame(0, $statistics[self::INSTANCE_NAME]['misses'], 'misses');
|
||||
$this->assertSame(1, $statistics[self::INSTANCE_NAME]['writes'], 'writes');
|
||||
}
|
||||
|
||||
public function testSaveDeferredEventWithExplicitCommitDataCollector()
|
||||
{
|
||||
$traceableAdapterSaveDeferredEvent = new \stdClass();
|
||||
$traceableAdapterSaveDeferredEvent->name = 'saveDeferred';
|
||||
$traceableAdapterSaveDeferredEvent->start = 0;
|
||||
$traceableAdapterSaveDeferredEvent->end = 0;
|
||||
|
||||
$traceableAdapterCommitEvent = new \stdClass();
|
||||
$traceableAdapterCommitEvent->name = 'commit';
|
||||
$traceableAdapterCommitEvent->start = 0;
|
||||
$traceableAdapterCommitEvent->end = 0;
|
||||
|
||||
$statistics = $this->getCacheDataCollectorStatisticsFromEvents([
|
||||
$traceableAdapterSaveDeferredEvent,
|
||||
$traceableAdapterCommitEvent,
|
||||
]);
|
||||
|
||||
$this->assertSame(2, $statistics[self::INSTANCE_NAME]['calls'], 'calls');
|
||||
$this->assertSame(0, $statistics[self::INSTANCE_NAME]['reads'], 'reads');
|
||||
$this->assertSame(0, $statistics[self::INSTANCE_NAME]['hits'], 'hits');
|
||||
$this->assertSame(0, $statistics[self::INSTANCE_NAME]['misses'], 'misses');
|
||||
$this->assertSame(1, $statistics[self::INSTANCE_NAME]['writes'], 'writes');
|
||||
}
|
||||
|
||||
public function testCollectBeforeEnd()
|
||||
{
|
||||
$adapter = new TraceableAdapter(new NullAdapter());
|
||||
|
||||
Reference in New Issue
Block a user