Skip to content

Commit

Permalink
speed up the unittests and the monitor app
Browse files Browse the repository at this point in the history
  • Loading branch information
gjerokrsteski committed Mar 8, 2013
1 parent c038d92 commit 504463b
Show file tree
Hide file tree
Showing 27 changed files with 24 additions and 48 deletions.
Empty file modified .editorconfig 100644 → 100755
Empty file.
Empty file modified .gitignore 100644 → 100755
Empty file.
Empty file modified .travis.yml 100644 → 100755
Empty file.
Empty file modified app/.htaccess 100644 → 100755
Empty file.
Empty file modified app/bootstrap-responsive.min.css 100644 → 100755
Empty file.
Empty file modified app/bootstrap.min.css 100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion app/config.php 100644 → 100755
Expand Up @@ -21,7 +21,7 @@
* of the libraries required by the other handlers,
* and when you cannot use bundled cdb handler.
*/
'handler' => 'gdbm',
'handler' => 'db4',

/*
* The mode for read/write access, database creation if it doesn't currently exist.
Expand Down
Empty file modified app/favicon.ico 100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion app/index.php 100644 → 100755
Expand Up @@ -291,7 +291,7 @@ function bsize($s) {
<button class="btn btn-success" type="submit" name="create-test-entry">Create Test Entry</button>

<? if ($authenticated === false) : ?>
<button class="btn btn-success" type="submit" name="login">Login and Sweep</button>
<button class="btn btn-info" type="submit" name="login">Login and Sweep</button>
<? endif; ?>

<? if ($authenticated === true && $cache->erasable()) : ?>
Expand Down
Empty file modified bootstrap.php 100644 → 100755
Empty file.
Empty file modified src/Cache.php 100644 → 100755
Empty file.
Empty file modified src/Capsule.php 100644 → 100755
Empty file.
Empty file modified src/Serializer.php 100644 → 100755
Empty file.
Empty file modified src/Sweeper.php 100644 → 100755
Empty file.
10 changes: 5 additions & 5 deletions tests/CacheDbaHandlersTest.php
Expand Up @@ -2,7 +2,7 @@
require_once dirname(__FILE__) .'/DummyFixtures.php';


class CacheDbaHandlersTest extends PHPUnit_Framework_TestCase
class CacheHandlersTest extends PHPUnit_Framework_TestCase
{
/**
* @var stdClass
Expand Down Expand Up @@ -53,15 +53,15 @@ public function testOracleBerkeleyDb4HandlerSupportWithoutPersistantConnection()
$this->markTestSkipped($e->getMessage());
}

$this->assertInstanceOf('CacheDba', $cache);
$this->assertInstanceOf('Cache', $cache);

$cache->put($this->_identifier, $this->_object);

$this->assertInstanceOf('stdClass', $cache->get($this->_identifier));
}

/**
* @depends CacheDbaHandlersTest::testOracleBerkeleyDb4HandlerSupportWithoutPersistantConnection
* @depends CacheHandlersTest::testOracleBerkeleyDb4HandlerSupportWithoutPersistantConnection
*/
public function testOracleBerkeleyDb4HandlerBeSupportedWithPersistantConnection()
{
Expand All @@ -71,7 +71,7 @@ public function testOracleBerkeleyDb4HandlerBeSupportedWithPersistantConnection(
$this->markTestSkipped($e->getMessage());
}

$this->assertInstanceOf('CacheDba', $cache);
$this->assertInstanceOf('Cache', $cache);

$cache->put($this->_identifier, $this->_object);

Expand All @@ -92,7 +92,7 @@ public function testCanCdbHandlerOnlyNewAndReadBeSupportedWithPersistantConnecti
$this->markTestSkipped($e->getMessage());
}

$this->assertInstanceOf('CacheDba', $cacheMake);
$this->assertInstanceOf('Cache', $cacheMake);

$this->assertTrue($cacheMake->put(md5('test123'), $this->_object));

Expand Down
5 changes: 2 additions & 3 deletions tests/CacheDbaTest.php
Expand Up @@ -2,7 +2,7 @@
require_once dirname(__FILE__) .'/DummyFixtures.php';


class CacheDbaTest extends PHPUnit_Framework_TestCase
class CacheTest extends PHPUnit_Framework_TestCase
{
/**
* @var Cache
Expand Down Expand Up @@ -62,7 +62,6 @@ public function objectsProvider()
}

/**
* @depends CacheDbaTest::testCreateNewCacheObjectNoException
* @dataProvider objectsProvider
*/
public function testPutSomeObjectsIntoTheCache($identifier, $object)
Expand All @@ -77,7 +76,7 @@ public function testPutSomeObjectsIntoTheCache($identifier, $object)
}

/**
* @depends CacheDbaTest::testPutSomeObjectsIntoTheCache
* @depends CacheTest::testPutSomeObjectsIntoTheCache
* @dataProvider objectsProvider
*/
public function testGetSomeObjectsFromTheCacheAndCompareEachother($identifier, $expectedObject)
Expand Down
52 changes: 14 additions & 38 deletions tests/CacheGarbageCollectorTest.php
Expand Up @@ -15,10 +15,10 @@ protected function setUp()
{
parent::setUp();

$path = dirname(dirname(__FILE__)) . '/tests/_drafts/garbage-collection-test-cache.flat';
$path = dirname(dirname(__FILE__)) . '/tests/_drafts/garbage-collection-test-cache.inifile';

try {
$this->_cache = new Cache($path);
$this->_cache = new Cache($path, 'inifile');
} catch(RuntimeException $e) {
$this->markTestSkipped($e->getMessage());
}
Expand All @@ -39,7 +39,7 @@ public function testCreatingGarbageCollectionObject()
{
$garbageCollection = new Sweeper($this->_cache);

$this->assertInstanceOf('CacheGarbageCollector', $garbageCollection);
$this->assertInstanceOf('Sweeper', $garbageCollection);
}

/**
Expand All @@ -57,44 +57,21 @@ public function testCleanAllFromTheGarbageCollection()
$stdClass->body = 'Yes, it works!';

// put some data to the cache.
$this->_cache->put(md5('stdClass'), $stdClass);
$this->_cache->put(md5('ZipArchive'), new ZipArchive());
$this->_cache->put(md5('XMLReader'), new XMLReader());

$garbageCollection = new Sweeper($this->_cache);
$garbageCollection->cleanAll();
$this->_cache->put(md5('stdClass'), $stdClass, 1);
$this->_cache->put(md5('ZipArchive'), new ZipArchive(), 1);
$this->_cache->put(md5('XMLReader'), new XMLReader(), 1);

$this->assertFalse(dba_fetch(md5('stdClass'), $dba));
$this->assertFalse(dba_fetch(md5('ZipArchive'), $dba));
$this->assertFalse(dba_fetch(md5('XMLReader'), $dba));
}

/**
* @depends CacheGarbageCollectorTest::testCreatingGarbageCollectionObject
*/
public function testCleanTheGarbageCollectionBySuitableExpirationTime()
{
// prepare data.
$stdClass = new stdClass();
$stdClass->title = 'I am cached.';
$stdClass->from = 'Mike';
$stdClass->to = 'Gates';
$stdClass->body = 'Yes, it works fine!';
sleep(1);

// put some data to the cache.
$this->_cache->put(md5('stdClass'), $stdClass, 2);
$this->_cache->put(md5('ZipArchive'), new ZipArchive(), 2);
$this->_cache->put(md5('XMLReader'), new XMLReader(), 2);
$garbageCollection = new Sweeper($this->_cache);
$garbageCollection->cleanAll();

// wait two seconds to force the expiration-time-calculation.
sleep(2);
$this->assertFalse($this->_cache->get(md5('stdClass')));

$garbageCollection = new Sweeper($this->_cache);
$garbageCollection->cleanOld();
$this->assertFalse($this->_cache->get(md5('ZipArchive')));

$this->assertFalse($this->_cache->has(md5('stdClass')));
$this->assertFalse($this->_cache->has(md5('ZipArchive')));
$this->assertFalse($this->_cache->has(md5('XMLReader')));
$this->assertFalse($this->_cache->get(md5('XMLReader')));
}

/**
Expand Down Expand Up @@ -140,7 +117,7 @@ public function testCleanTheGarbageCollectionWithCdbHandler()
$this->markTestSkipped($e->getMessage());
}

$this->assertInstanceOf('CacheDba', $cacheMake);
$this->assertInstanceOf('Cache', $cacheMake);

$testIdentifier1 = md5('ZipArchive' . time());
$testIdentifier2 = md5('XMLReader' . time());
Expand Down Expand Up @@ -188,7 +165,7 @@ public function testCleanTheGarbageCollectionWithDb4Handler()
$this->markTestSkipped($e->getMessage());
}

$this->assertInstanceOf('CacheDba', $cache);
$this->assertInstanceOf('Cache', $cache);

$cache->put(md5('ZipArchive'), new ZipArchive());
$cache->put(md5('XMLReader'), new XMLReader());
Expand All @@ -211,7 +188,6 @@ public function testUtilMethods()
{
$garbageCollection = new Sweeper($this->_cache);

$this->assertTrue(($garbageCollection->getFillingPercentage() > 0));
$this->assertTrue($garbageCollection->flush());
}
}
Empty file modified tests/_drafts/backend-penetration-test-info.log 100644 → 100755
Empty file.
Empty file modified tests/_drafts/backend-penetration-test.flat 100644 → 100755
Empty file.
Binary file modified tests/_drafts/cache.flat 100644 → 100755
Binary file not shown.
Binary file removed tests/_drafts/simple-xml-test-cache-on-cdb.db
Binary file not shown.
Empty file modified tests/_drafts/simple-xml-test-cache.db4 100644 → 100755
Empty file.
Binary file modified tests/_drafts/test-cache-cdb2.cdb 100644 → 100755
Binary file not shown.
Binary file modified tests/_drafts/test-cache-insert.flat 100644 → 100755
Binary file not shown.
Binary file removed tests/_drafts/test-cache-with-simplexml.db4
Binary file not shown.
Binary file removed tests/_drafts/test-cache.db4
Binary file not shown.
1 change: 1 addition & 0 deletions tests/simple-xml-test.php
Expand Up @@ -20,6 +20,7 @@
$identifier = md5('simplexml_identifier');

$path = dirname(dirname(__FILE__)).'/tests/_drafts/simple-xml-test-cache.db4';

$cache = new Cache($path, 'db4');

$cache->put($identifier, $simplexml, 60);
Expand Down

0 comments on commit 504463b

Please sign in to comment.