Conversation
…es to do the clean-up. Tweaks in readability of the code.
…comply better to the DatabaseL2 one.
| "sami-install": "mkdir -p $HOME/bin && curl --output $HOME/bin/sami.phar http://get.sensiolabs.org/sami.phar && chmod +x $HOME/bin/sami.phar", | ||
| "test": "phpunit" | ||
| "test": "phpunit", | ||
| "test-failing": "phpunit --group failing" |
There was a problem hiding this comment.
This was added, so when a new annotation is added to a test like:
@group failing
The composer test-failing command will trigger only that test.
Useful when debugging a single test.
…gativeCache check.
…L1's. APCu is failing.
src/DatabaseL2.php
Outdated
| $sth = $this->dbh->prepare($sql); | ||
| foreach (array_keys($this->address_delete_queue) as $i => $address) { | ||
| $event_id = $this->address_delete_queue[$address]; | ||
| $sth->bindValue($i * 2 + 1, $event_id, \PDO::PARAM_INT); |
There was a problem hiding this comment.
A very small micro-optimisation could be to swap th *2 to <<1.
…incompatability. Fixed an issue in DatabaseL2.
src/DatabaseL2.php
Outdated
| $sql = 'SELECT "event_id", "pool", "address", "value", "created", "expiration"' | ||
| . ' FROM ' . $this->eventsTable | ||
| . ' WHERE "event_id" > :last_applied_event_id' | ||
| . ' AND "pool" <> :exclude_pool' |
There was a problem hiding this comment.
This was changed to make both L2 drivers to behave consistently.
Though this change is causing small performance regressions, it is behaving as the StaticL2 does at the moment.
There is a non-merged implementation that makes them like the DB here
I will maintain both branches until it is decided how L2::applyEvents should behave and merge the correct version.
There was a problem hiding this comment.
I will review and decide today.
… delete method. Improved docks.
…e L2 logical implementation.
…incompatability in StaticL2.
…rovements in DatabaseL2::exists db query.
|
The disablement will cause that the parameter to be ignored and collect ALL garbage instead of only LIMIT items. |
…ch as possible. Overloaded for DatabaseL2 test to pass.
…r the delete in DatabaseL2::set, as it will fail on the insert first.
|
|
||
| namespace LCache; | ||
|
|
||
| final class Integrated |
There was a problem hiding this comment.
many of the Integration level tests were implemented by knowing the inner workings of L1 and L2 and tweaking the inner objects directly, ruining the encapsulation idea of the class and also consistent factory interface implementation for all the tests.
By removing the final here I did a descendant (IntegratedMock) that added many of the needed accessors to port the tests as close as possible.
| $state = $hasApcu ? new StateL1APCu("sqlite-$pool") : new StateL1Static(); | ||
| $cache = new SQLiteL1($pool, $state); | ||
| return $cache; | ||
| $stateDriver = function_exists('apcu_fetch') ? 'apcu' : 'sqlite'; |
There was a problem hiding this comment.
Added APCu and SQLite as this are the ones that need to be done at some point. I am trusting the fall-back in the factory to instantiate static instead of SQLite state manager for now.
| * @return boolean | ||
| * True on success. | ||
| */ | ||
| public function pruneReplacedEvents() |
There was a problem hiding this comment.
Consider moving this to the base L2 class.
| $this->assertFalse($this->getEntry(1)->isExpired()); | ||
|
|
||
| // TODO: How to classify this one? | ||
| $this->assertFalse($this->getEntry(0)->isExpired()); |
There was a problem hiding this comment.
Is expired and getTTL are a bit strange for relative times. They are the same for older and newer times, bu the difference comes from the current moment in time. The function getTTL says it has no time to live (but it is not dead yet) and the isExpired follows the same idea at the moment.
There was a problem hiding this comment.
I would prefer to remove the concept of TTLs everywhere possible. They're harder to reason about and test than plain expiration timestamps.
| . '"created" INTEGER NOT NULL)'); | ||
| $this->dbh->exec('CREATE INDEX ' . $prefix . 'latest_entry ON ' . $prefix . 'lcache_events ("address", "event_id")'); | ||
|
|
||
| // @TODO: Set a proper primary key and foreign key relationship. |
There was a problem hiding this comment.
Is this still relevant? There are already PK and FK and an index.
There was a problem hiding this comment.
Yes. It's to establish a proper CASCADE DELETE. If you don't have that, tags on expired and deleted items will currently persist. That's fine for testing (as you won't get incorrect data), but it would leave orphaned data in production.
To fix it, we need to add REFERENCES lcache_events(event_id) ON DELETE CASCADE (observing $prefix for lcache_events) to the column lcache_tags.event_id.
There was a problem hiding this comment.
For the tests it's already there some lines below... So is the TODO still relevant?
FOREIGN KEY("event_id") REFERENCES ' . $prefix . 'lcache_events("event_id") ON DELETE CASCADE)');
The cascade delete is used and proven working in the tag delete tests for DatabaseL2 here in this PR.
|
I'm doing a bunch of work on this now, including some major refactoring. It's mostly hierarchical namespaces and isolating the synchronization status from hit/miss statistics. I'm working from the branch for this pull request (taken earlier today), but it might be tough to incorporate other changes until I've finished the work. Just letting you know. |
|
Nice to hear :) that the PR is going in, one way or the other. |
|
Are your changes ready? Any chances for this to be merged at some point? If so, we can push this a bit more and make Memcached / Redis L1 drivers and make this one a production ready library. |
Overview
This pull request is continuing the work on tests outlined in #43, namely L2 and the Integration parts.
All the tests from LCacheTest class are ported to the new structure.
The whole thing is open for reviews.
Additional things included:
It would be nice to have reviews at some point, as I will not have much time to fix stuff starting from next week :).
Summary
There is a new L2CcheTest base class. It is used for generic L2 tests. Specific ones are implemented in either the tests/L2/StaticTest (0) or tests/L2/DatabaseTest (2) classes.
All quirks needed to have DB connection and schema are implemented in a trait and moved out of the new test classes. This trait should be reusable on the Integration layer tests in near future.
There is a new factory class that is to be used with L2 hierarchy. POC for using the factory is done on the newly created tests.
Successfully moved tests to the new L2 structure are removed from the LCacheTest class.
Current implementation follows this idea:
Issues faced (for now)