You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ih...@apache.org on 2013/01/01 11:39:38 UTC

[3/4] git commit: LOG4PHP-203; tests for capped collections in mongo appender.

LOG4PHP-203; tests for capped collections in mongo appender.

Signed-off-by: Vladimir Gorej <go...@codescale.net>
Signed-off-by: Ivan Habunek <ih...@apache.org>


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 <go...@codescale.net>
Authored: Mon Dec 31 12:13:54 2012 +0100
Committer: Ivan Habunek <ih...@apache.org>
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.