Return-Path: X-Original-To: apmail-logging-commits-archive@minotaur.apache.org Delivered-To: apmail-logging-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 45D3AE2BD for ; Tue, 1 Jan 2013 10:39:42 +0000 (UTC) Received: (qmail 83308 invoked by uid 500); 1 Jan 2013 10:39:42 -0000 Delivered-To: apmail-logging-commits-archive@logging.apache.org Received: (qmail 83233 invoked by uid 500); 1 Jan 2013 10:39:39 -0000 Mailing-List: contact commits-help@logging.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@logging.apache.org Delivered-To: mailing list commits@logging.apache.org Received: (qmail 83188 invoked by uid 99); 1 Jan 2013 10:39:38 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Jan 2013 10:39:38 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 71218821472; Tue, 1 Jan 2013 10:39:38 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ihabunek@apache.org To: commits@logging.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [3/4] git commit: LOG4PHP-203; tests for capped collections in mongo appender. Message-Id: <20130101103938.71218821472@tyr.zones.apache.org> Date: Tue, 1 Jan 2013 10:39:38 +0000 (UTC) LOG4PHP-203; tests for capped collections in mongo appender. Signed-off-by: Vladimir Gorej Signed-off-by: Ivan Habunek Project: http://git-wip-us.apache.org/repos/asf/logging-log4php/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4php/commit/aab1162a Tree: http://git-wip-us.apache.org/repos/asf/logging-log4php/tree/aab1162a Diff: http://git-wip-us.apache.org/repos/asf/logging-log4php/diff/aab1162a Branch: refs/heads/develop Commit: aab1162ab48c1bce4f57404290ee7ef2f5904220 Parents: 7be8215 Author: Vladimir Gorej Authored: Mon Dec 31 12:13:54 2012 +0100 Committer: Ivan Habunek Committed: Tue Jan 1 11:35:11 2013 +0100 ---------------------------------------------------------------------- .../php/appenders/LoggerAppenderMongoDBTest.php | 138 ++++++++++----- 1 files changed, 90 insertions(+), 48 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/aab1162a/src/test/php/appenders/LoggerAppenderMongoDBTest.php ---------------------------------------------------------------------- diff --git a/src/test/php/appenders/LoggerAppenderMongoDBTest.php b/src/test/php/appenders/LoggerAppenderMongoDBTest.php index b659a6f..b29d5b9 100644 --- a/src/test/php/appenders/LoggerAppenderMongoDBTest.php +++ b/src/test/php/appenders/LoggerAppenderMongoDBTest.php @@ -56,7 +56,7 @@ class LoggerAppenderMongoDBTest extends PHPUnit_Framework_TestCase { $result = $this->appender->getHost(); $this->assertEquals($expected, $result); } - + public function testPort() { $expected = 27017; $this->appender->setPort($expected); @@ -70,21 +70,21 @@ class LoggerAppenderMongoDBTest extends PHPUnit_Framework_TestCase { $result = $this->appender->getDatabaseName(); $this->assertEquals($expected, $result); } - + public function testCollectionName() { $expected = 'logs'; $this->appender->setCollectionName($expected); $result = $this->appender->getCollectionName(); $this->assertEquals($expected, $result); } - + public function testUserName() { $expected = 'char0n'; $this->appender->setUserName($expected); $result = $this->appender->getUserName(); $this->assertEquals($expected, $result); } - + public function testPassword() { $expected = 'secret pass'; $this->appender->setPassword($expected); @@ -99,6 +99,27 @@ class LoggerAppenderMongoDBTest extends PHPUnit_Framework_TestCase { $this->assertEquals($expected, $result); } + public function testCapped() { + $expected = true; + $this->appender->setCapped($expected); + $result = $this->appender->getCapped(); + $this->assertEquals($expected, $result); + } + + public function testCappedMax() { + $expected = 20; + $this->appender->setCappedMax($expected); + $result = $this->appender->getCappedMax(); + $this->assertEquals($expected, $result); + } + + public function testCappedSize() { + $expected = 10000; + $this->appender->setCappedSize($expected); + $result = $this->appender->getCappedSize(); + $this->assertEquals($expected, $result); + } + public function testActivateOptions() { $this->appender->activateOptions(); $this->assertInstanceOf('Mongo', $this->appender->getConnection()); @@ -113,19 +134,27 @@ class LoggerAppenderMongoDBTest extends PHPUnit_Framework_TestCase { $this->assertInstanceOf('MongoCollection', $this->appender->getCollection()); } + public function testActivateOptionsCappedCollection() { + $this->appender->setCollectionName('logs_capped'); + $this->appender->setCapped(true); + $this->appender->activateOptions(); + $this->assertInstanceOf('Mongo', $this->appender->getConnection()); + $this->assertInstanceOf('MongoCollection', $this->appender->getCollection()); + } + public function testFormat() { $this->appender->activateOptions(); $record = $this->logOne($this->event); - + $this->assertEquals('ERROR', $record['level']); $this->assertEquals('mongo logging event', $record['message']); $this->assertEquals('test_mongo', $record['loggerName']); - - $this->assertEquals('NA', $record['fileName']); + + $this->assertEquals('NA', $record['fileName']); $this->assertEquals('getLocationInformation', $record['method']); $this->assertEquals('NA', $record['lineNumber']); $this->assertEquals('LoggerLoggingEvent', $record['className']); - + $this->assertTrue(is_int($record['thread'])); $this->assertSame(getmypid(), $record['thread']); $this->assertTrue(is_int($record['lineNumber']) || $record['lineNumber'] == 'NA'); @@ -141,53 +170,66 @@ class LoggerAppenderMongoDBTest extends PHPUnit_Framework_TestCase { microtime(true), new Exception('test exception', 1) ); - + $record = $this->logOne($event); - + $this->assertArrayHasKey('exception', $record); $this->assertEquals(1, $record['exception']['code']); $this->assertEquals('test exception', $record['exception']['message']); $this->assertContains('[internal function]: LoggerAppenderMongoDBTest', $record['exception']['stackTrace']); } - public function testFormatThrowableInfoWithInnerException() { - - // Skip test if PHP version is lower than 5.3.0 (no inner exception support) - if (version_compare(PHP_VERSION, '5.3.0') < 0) { - $this->markTestSkipped(); - } - - $this->appender->activateOptions(); - $event = new LoggerLoggingEvent( - 'testFqcn', - new Logger('test.Logger'), - LoggerLevel::getLevelWarn(), - 'test message', - microtime(true), - new Exception('test exception', 1, new Exception('test exception inner', 2)) - ); - - $record = $this->logOne($event); - - $this->assertArrayHasKey('exception', $record); - $this->assertEquals(1, $record['exception']['code']); - $this->assertEquals('test exception', $record['exception']['message']); - $this->assertContains('[internal function]: LoggerAppenderMongoDBTest', $record['exception']['stackTrace']); - - $this->assertArrayHasKey('innerException', $record['exception']); - $this->assertEquals(2, $record['exception']['innerException']['code']); - $this->assertEquals('test exception inner', $record['exception']['innerException']['message']); - } - - - public function testClose() { - $this->appender->activateOptions(); - $this->assertInstanceOf('Mongo', $this->appender->getConnection()); - $this->assertInstanceOf('MongoCollection', $this->appender->getCollection()); - $this->appender->close(); - $this->assertNull($this->appender->getConnection()); - $this->assertNull($this->appender->getCollection()); - } + public function testFormatThrowableInfoWithInnerException() { + // Skip test if PHP version is lower than 5.3.0 (no inner exception support) + if (version_compare(PHP_VERSION, '5.3.0') < 0) { + $this->markTestSkipped(); + } + + $this->appender->activateOptions(); + $event = new LoggerLoggingEvent( + 'testFqcn', + new Logger('test.Logger'), + LoggerLevel::getLevelWarn(), + 'test message', + microtime(true), + new Exception('test exception', 1, new Exception('test exception inner', 2)) + ); + + $record = $this->logOne($event); + + $this->assertArrayHasKey('exception', $record); + $this->assertEquals(1, $record['exception']['code']); + $this->assertEquals('test exception', $record['exception']['message']); + $this->assertContains('[internal function]: LoggerAppenderMongoDBTest', $record['exception']['stackTrace']); + + $this->assertArrayHasKey('innerException', $record['exception']); + $this->assertEquals(2, $record['exception']['innerException']['code']); + $this->assertEquals('test exception inner', $record['exception']['innerException']['message']); + } + + public function testCappedCollection() { + $expected = 2; + $this->appender->setCollectionName('logs_capped'); + $this->appender->setCapped(true); + $this->appender->setCappedMax($expected); + $this->appender->activateOptions(); + + // Log 10 events into capped collection. + for ($i = 0; $i < 10; $i += 1) { + $this->appender->append($this->event); + } + + $this->assertEquals($expected, $this->appender->getCollection()->count()); + } + + public function testClose() { + $this->appender->activateOptions(); + $this->assertInstanceOf('Mongo', $this->appender->getConnection()); + $this->assertInstanceOf('MongoCollection', $this->appender->getCollection()); + $this->appender->close(); + $this->assertNull($this->appender->getConnection()); + $this->assertNull($this->appender->getCollection()); + } /** * Logs the event and returns the record from the database.