logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ihabu...@apache.org
Subject svn commit: r1222222 - in /logging/log4php/trunk/src: changes/changes.xml main/php/appenders/LoggerAppenderMongoDB.php site/xdoc/docs/appenders/mongodb.xml test/php/appenders/LoggerAppenderMongoDBTest.php
Date Thu, 22 Dec 2011 13:28:45 GMT
Author: ihabunek
Date: Thu Dec 22 13:28:44 2011
New Revision: 1222222

URL: http://svn.apache.org/viewvc?rev=1222222&view=rev
Log:
LOG4PHP-166: Added connection timeout parameter to MongoDB appender.
Also removed redundant tests from the test class.

Modified:
    logging/log4php/trunk/src/changes/changes.xml
    logging/log4php/trunk/src/main/php/appenders/LoggerAppenderMongoDB.php
    logging/log4php/trunk/src/site/xdoc/docs/appenders/mongodb.xml
    logging/log4php/trunk/src/test/php/appenders/LoggerAppenderMongoDBTest.php

Modified: logging/log4php/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/changes/changes.xml?rev=1222222&r1=1222221&r2=1222222&view=diff
==============================================================================
--- logging/log4php/trunk/src/changes/changes.xml (original)
+++ logging/log4php/trunk/src/changes/changes.xml Thu Dec 22 13:28:44 2011
@@ -20,6 +20,9 @@
 		<title>Apache log4php changelog</title>
 	</properties>
 	<body>
+	    <release version="2.3.0-SNAPSHOT" date="SVN">
+	        <action date="2011-12-22" type="update" issue="LOG4PHP-166" dev="Ivan Habunek"
due-to="David Hilowitz" due-to-email="dhilowitz at gmail dot com">Added connection timeout
parameter to MongoDB appender.</action>
+	    </release>
 	    <release version="2.2.0" date="2011-12-20">
 			<action date="2011-12-13" type="fix" issue="LOG4PHP-158" dev="Ivan Habunek">LoggerAppenderFile
throws wrong warning messages.</action>
 	    	<action date="2011-12-12" type="update" issue="LOG4PHP-161" dev="Ivan Habunek">All
configurable components should report errors when given invalid values</action>

Modified: logging/log4php/trunk/src/main/php/appenders/LoggerAppenderMongoDB.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/appenders/LoggerAppenderMongoDB.php?rev=1222222&r1=1222221&r2=1222222&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/appenders/LoggerAppenderMongoDB.php (original)
+++ logging/log4php/trunk/src/main/php/appenders/LoggerAppenderMongoDB.php Thu Dec 22 13:28:44
2011
@@ -52,6 +52,9 @@ class LoggerAppenderMongoDB extends Logg
 	/** Default value for {@link $collectionName} */
 	const DEFAULT_COLLECTION_NAME = 'logs';
 	
+	/** Default value for {@link $timeout} */
+	const DEFAULT_TIMEOUT_VALUE = 3000;
+	
 	// ******************************************
 	// ** Configurable parameters              **
 	// ******************************************
@@ -74,6 +77,9 @@ class LoggerAppenderMongoDB extends Logg
 	/** Password used to connect to the database. */
 	protected $password;
 	
+	/** Timeout value used when connecting to the database (in milliseconds). */
+	protected $timeout;
+	
 	// ******************************************
 	// ** Member variables                     **
 	// ******************************************
@@ -116,7 +122,7 @@ class LoggerAppenderMongoDB extends Logg
 	 */
 	public function activateOptions() {
 		try {
-			$this->connection = new Mongo(sprintf('%s:%d', $this->host, $this->port));
+			$this->connection = new Mongo(sprintf('%s:%d', $this->host, $this->port), array("timeout"
=> $this->timeout));
 			$db	= $this->connection->selectDB($this->databaseName);
 			if ($this->userName !== null && $this->password !== null) {
 				$authResult = $db->authenticate($this->userName, $this->password);
@@ -279,6 +285,15 @@ class LoggerAppenderMongoDB extends Logg
 		return $this->password;
 	}
 	
+	/** Sets the value of {@link $timeout} parameter. */
+	public function setTimeout($timeout) {
+		$this->setPositiveInteger('timeout', $timeout);
+	}
+
+	/** Returns the value of {@link $timeout} parameter. */
+	public function getTimeout() {
+		return $this->timeout;
+	}
 	/** 
 	 * Returns the mongodb connection.
 	 * @return Mongo

Modified: logging/log4php/trunk/src/site/xdoc/docs/appenders/mongodb.xml
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/site/xdoc/docs/appenders/mongodb.xml?rev=1222222&r1=1222221&r2=1222222&view=diff
==============================================================================
--- logging/log4php/trunk/src/site/xdoc/docs/appenders/mongodb.xml (original)
+++ logging/log4php/trunk/src/site/xdoc/docs/appenders/mongodb.xml Thu Dec 22 13:28:44 2011
@@ -87,7 +87,13 @@
 						<td>-</td>
 						<td>Password used to connect to the database.</td>
 					</tr>
-					
+				    <tr>
+				        <td>timeout</td>
+				        <td>integer</td>
+				        <td>No</td>
+				        <td>3000</td>
+				        <td>For how long the driver should try to connect to the database (in milliseconds).</td>
+				    </tr>
 				</table>
 				
 			</subsection>

Modified: logging/log4php/trunk/src/test/php/appenders/LoggerAppenderMongoDBTest.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/test/php/appenders/LoggerAppenderMongoDBTest.php?rev=1222222&r1=1222221&r2=1222222&view=diff
==============================================================================
--- logging/log4php/trunk/src/test/php/appenders/LoggerAppenderMongoDBTest.php (original)
+++ logging/log4php/trunk/src/test/php/appenders/LoggerAppenderMongoDBTest.php Thu Dec 22
13:28:44 2011
@@ -48,126 +48,77 @@ class LoggerAppenderMongoDBTest extends 
 	}
 	
 	protected function setUp() {
-		if (extension_loaded('mongo') == false) {
+		if (!extension_loaded('mongo')) {
 			$this->markTestSkipped(
 				'The Mongo extension is not available.'
 			);
 		}
 	}
 	
-	public function test__construct() {
-		$appender = new LoggerAppenderMongoDB('mongo_appender');
-		$this->assertTrue($appender instanceof LoggerAppenderMongoDB);
-	}
-	
-	public function testSetGetHost() {
+	public function testHost() {
 		$expected = 'mongodb://localhost';
 		self::$appender->setHost($expected);
 		$result = self::$appender->getHost();
-		$this->assertEquals($expected, $result, 'Host doesn\'t match expted value');
+		self::assertEquals($expected, $result);
 	}
 	
-	public function testSetGetHostMongoPrefix() {
-		$expected = 'mongodb://localhost';
-		self::$appender->setHost('localhost');
-		$result = self::$appender->getHost();
-		$this->assertEquals($expected, $result, 'Host doesn\'t match expted value');
-	}
-	
-	public function testSetPort() {
+	public function testPort() {
 		$expected = 27017;
 		self::$appender->setPort($expected);
 		$result = self::$appender->getPort();
-		$this->assertEquals($expected, $result, 'Port doesn\'t match expted value');
+		self::assertEquals($expected, $result);
 	}
 
-	public function testGetPort() {
-		$expected = 27017;
-		self::$appender->setPort($expected);
-		$result = self::$appender->getPort();
-		$this->assertEquals($expected, $result, 'Port doesn\'t match expted value');
-	}
-	
-	public function testSetDatabaseName() {
+	public function testDatabaseName() {
 		$expected = 'log4php_mongodb';
 		self::$appender->setDatabaseName($expected);
 		$result	= self::$appender->getDatabaseName();
-		$this->assertEquals($expected, $result, 'Database name doesn\'t match expted value');
+		self::assertEquals($expected, $result);
 	}
 	
-	public function testGetDatabaseName() {
-		$expected = 'log4php_mongodb';
-		self::$appender->setDatabaseName($expected);
-		$result	= self::$appender->getDatabaseName();
-		$this->assertEquals($expected, $result, 'Database name doesn\'t match expted value');
-	}		 
-	
-	public function testSetCollectionName() {
+	public function testCollectionName() {
 		$expected = 'logs';
 		self::$appender->setCollectionName($expected);
 		$result = self::$appender->getCollectionName();
-		$this->assertEquals($expected, $result, 'Collection name doesn\'t match expted value');
+		self::assertEquals($expected, $result);
 	}
 	
-	public function testGetCollectionName() {
-		$expected = 'logs';
-		self::$appender->setCollectionName($expected);
-		$result = self::$appender->getCollectionName();
-		$this->assertEquals($expected, $result, 'Collection name doesn\'t match expted value');
-	}	 
-	
-	public function testSetUserName() {
+	public function testUserName() {
 		$expected = 'char0n';
 		self::$appender->setUserName($expected);
 		$result = self::$appender->getUserName();
-		$this->assertEquals($expected, $result, 'UserName doesn\'t match expted value');
+		self::assertEquals($expected, $result);
 	}
 	
-	public function testGetUserName() {
-		$expected = 'char0n';
-		self::$appender->setUserName($expected);
-		$result	= self::$appender->getUserName();
-		$this->assertEquals($expected, $result, 'UserName doesn\'t match expted value');
-	}					 
-	
-	public function testSetPassword() {
+	public function testPassword() {
 		$expected = 'secret pass';
 		self::$appender->setPassword($expected);
 		$result	= self::$appender->getPassword();
-		$this->assertEquals($expected, $result, 'Password doesn\'t match expted value');
+		self::assertEquals($expected, $result);
 	}
 	
-	public function testGetPassword() {
-		$expected = 'secret pass';
-		self::$appender->setPassword($expected);
-		$result	= self::$appender->getPassword();
-		$this->assertEquals($expected, $result, 'Password doesn\'t match expted value');
-	} 
-	
 	public function testActivateOptionsNoCredentials() {
 		self::$appender->setUserName(null);
 		self::$appender->setPassword(null);
 		self::$appender->activateOptions();
 	}		
 	
-	public function testAppend() {
-		self::$appender->append(self::$event);
-	}
-	
 	public function testFormat() {
-		$record = $this->logOne(self::$event);
-		
-		$this->assertEquals('ERROR', $record['level']);
-		$this->assertEquals('testmessage', $record['message']);
-		$this->assertEquals('test.Logger', $record['loggerName']);
-		
-		$this->assertEquals('NA', $record['fileName']);		
-		$this->assertEquals('getLocationInformation', $record['method']);
-		$this->assertEquals('NA', $record['lineNumber']);
-		$this->assertEquals('LoggerLoggingEvent', $record['className']);
+		$event = LoggerTestHelper::getErrorEvent("testmessage");
+		$record = $this->logOne($event);
 		
-		$this->assertTrue(is_int($record['thread']));
-		$this->assertTrue(is_int($record['lineNumber']) || $record['lineNumber'] == 'NA');
+		self::assertEquals('ERROR', $record['level']);
+		self::assertEquals('testmessage', $record['message']);
+		self::assertEquals('test', $record['loggerName']);
+		
+		self::assertEquals('NA', $record['fileName']);		
+		self::assertEquals('getLocationInformation', $record['method']);
+		self::assertEquals('NA', $record['lineNumber']);
+		self::assertEquals('LoggerLoggingEvent', $record['className']);
+		
+		self::assertTrue(is_int($record['thread']));
+		self::assertSame(getmypid(), $record['thread']);
+		self::assertTrue(is_int($record['lineNumber']) || $record['lineNumber'] == 'NA');
 	}
 	
 	public function testFormatThrowableInfo() {
@@ -182,10 +133,10 @@ class LoggerAppenderMongoDBTest extends 
 		
 		$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']);
+		self::assertArrayHasKey('exception', $record);
+		self::assertEquals(1, $record['exception']['code']);
+		self::assertEquals('test exception', $record['exception']['message']);
+		self::assertContains('[internal function]: LoggerAppenderMongoDBTest', $record['exception']['stackTrace']);
 	}
 	
 	public function testFormatThrowableInfoWithInnerException() {
@@ -206,14 +157,14 @@ class LoggerAppenderMongoDBTest extends 
 		
 		$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->assertTrue(array_key_exists('innerException', $record['exception']));
-		$this->assertEquals(2, $record['exception']['innerException']['code']);
-		$this->assertEquals('test exception inner', $record['exception']['innerException']['message']);
+		self::assertArrayHasKey('exception', $record);
+		self::assertEquals(1, $record['exception']['code']);
+		self::assertEquals('test exception', $record['exception']['message']);
+		self::assertContains('[internal function]: LoggerAppenderMongoDBTest', $record['exception']['stackTrace']);
+		
+		self::assertTrue(array_key_exists('innerException', $record['exception']));
+		self::assertEquals(2, $record['exception']['innerException']['code']);
+		self::assertEquals('test exception inner', $record['exception']['innerException']['message']);
 	}
 	
 	public function testClose() {
@@ -223,20 +174,23 @@ class LoggerAppenderMongoDBTest extends 
 	/** Logs the event and returns the record from the database. */
 	private function logOne($event)
 	{
-		self::$appender = new LoggerAppenderMongoDB();
-		self::$appender->setHost('localhost');
-		self::$appender->activateOptions();
-		$mongo = self::$appender->getConnection();
+		$appender = new LoggerAppenderMongoDB();
+		$appender->setHost('localhost');
+		$appender->activateOptions();
+		
+		$mongo = $appender->getConnection();
 		$collection = $mongo->log4php_mongodb->logs;
 		
 		$result = $collection->drop();
 		self::assertSame((float) 1, $result['ok'], "Could not clear the collection before logging.");
 		
-		self::$appender->append($event);
+		$appender->append($event);
 		
 		$record = $collection->findOne();
 		self::assertNotNull($record, "Could not read the record from the database.");
 		
+		$appender->close();
+		
 		return $record;
 	}
 	



Mime
View raw message