From: Aaron Schulz Date: Fri, 5 Sep 2014 00:06:09 +0000 (-0700) Subject: Added a BloomCacheRedisTest class X-Git-Tag: 1.31.0-rc.0~14139^2 X-Git-Url: http://git.cyclocoop.org/%24href?a=commitdiff_plain;h=2d9d5fecf334264bcba05ad9624a377dfc29c067;p=lhc%2Fweb%2Fwiklou.git Added a BloomCacheRedisTest class Change-Id: Id0b8f6dfa96f5f56dcb77eebdca506c82a36a1c2 --- diff --git a/tests/phpunit/includes/cache/RedisBloomCacheTest.php b/tests/phpunit/includes/cache/RedisBloomCacheTest.php new file mode 100644 index 0000000000..3d491e9062 --- /dev/null +++ b/tests/phpunit/includes/cache/RedisBloomCacheTest.php @@ -0,0 +1,71 @@ +delete( "unit-testing-" . self::$suffix ); + } else { + $this->markTestSkipped( 'The main bloom cache is not redis.' ); + } + } + + public function testBloomCache() { + $key = "unit-testing-" . self::$suffix; + $fcache = BloomCache::get( 'main' ); + $count = 1500; + + $this->assertTrue( $fcache->delete( $key ), "OK delete of filter '$key'." ); + $this->assertTrue( $fcache->init( $key, $count, .001 ), "OK init of filter '$key'." ); + + $members = array(); + for ( $i = 0; $i < $count; ++$i ) { + $members[] = "$i-value-$i"; + } + $this->assertTrue( $fcache->add( $key, $members ), "Addition of members to '$key' OK." ); + + for ( $i = 0; $i < $count; ++$i ) { + $this->assertTrue( $fcache->isHit( $key, "$i-value-$i" ), "Hit on member '$i-value-$i'." ); + } + + $falsePositives = array(); + for ( $i = $count; $i < 2 * $count; ++$i ) { + if ( $fcache->isHit( $key, "value$i" ) ) { + $falsePositives[] = "value$i"; + } + } + + $eFalsePositives = array( + 'value1763', + 'value2245', + 'value2353', + 'value2791', + 'value2898', + 'value2975' + ); + $this->assertEquals( $eFalsePositives, $falsePositives, "Correct number of false positives found." ); + } + + protected function tearDown() { + parent::tearDown(); + + $fcache = BloomCache::get( 'main' ); + if ( $fcache instanceof BloomCacheRedis ) { + $fcache->delete( "unit-testing-" . self::$suffix ); + } + } +}