You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sm...@apache.org on 2013/07/01 19:38:58 UTC
svn commit: r1498603 - in /incubator/ambari/trunk/contrib/ambari-log4j/src:
main/java/org/apache/ambari/log4j/common/store/
test/java/org/apache/ambari/log4j/ test/java/org/apache/ambari/log4j/common/
test/java/org/apache/ambari/log4j/common/store/
Author: smohanty
Date: Mon Jul 1 17:38:58 2013
New Revision: 1498603
URL: http://svn.apache.org/r1498603
Log:
AMBARI-2526. NPE in the ambari log4j when the threads are shutting down. (smohanty)
Added:
incubator/ambari/trunk/contrib/ambari-log4j/src/test/java/org/apache/ambari/log4j/
incubator/ambari/trunk/contrib/ambari-log4j/src/test/java/org/apache/ambari/log4j/common/
incubator/ambari/trunk/contrib/ambari-log4j/src/test/java/org/apache/ambari/log4j/common/store/
incubator/ambari/trunk/contrib/ambari-log4j/src/test/java/org/apache/ambari/log4j/common/store/TestDatabaseStore.java
Modified:
incubator/ambari/trunk/contrib/ambari-log4j/src/main/java/org/apache/ambari/log4j/common/store/DatabaseStore.java
Modified: incubator/ambari/trunk/contrib/ambari-log4j/src/main/java/org/apache/ambari/log4j/common/store/DatabaseStore.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/contrib/ambari-log4j/src/main/java/org/apache/ambari/log4j/common/store/DatabaseStore.java?rev=1498603&r1=1498602&r2=1498603&view=diff
==============================================================================
--- incubator/ambari/trunk/contrib/ambari-log4j/src/main/java/org/apache/ambari/log4j/common/store/DatabaseStore.java (original)
+++ incubator/ambari/trunk/contrib/ambari-log4j/src/main/java/org/apache/ambari/log4j/common/store/DatabaseStore.java Mon Jul 1 17:38:58 2013
@@ -96,10 +96,12 @@ public class DatabaseStore implements Lo
@Override
public void close() throws IOException {
try {
- connection.close();
+ if (this.initialized && this.connection != null) {
+ connection.close();
+ }
} catch (SQLException sqle) {
throw new IOException(
- "Failed to close connectionto database " + this.database, sqle);
+ "Failed to close connection to database " + this.database, sqle);
}
}
}
Added: incubator/ambari/trunk/contrib/ambari-log4j/src/test/java/org/apache/ambari/log4j/common/store/TestDatabaseStore.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/contrib/ambari-log4j/src/test/java/org/apache/ambari/log4j/common/store/TestDatabaseStore.java?rev=1498603&view=auto
==============================================================================
--- incubator/ambari/trunk/contrib/ambari-log4j/src/test/java/org/apache/ambari/log4j/common/store/TestDatabaseStore.java (added)
+++ incubator/ambari/trunk/contrib/ambari-log4j/src/test/java/org/apache/ambari/log4j/common/store/TestDatabaseStore.java Mon Jul 1 17:38:58 2013
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.log4j.common.store;
+
+import junit.framework.TestCase;
+import org.apache.ambari.log4j.common.LogStoreUpdateProvider;
+import org.apache.log4j.spi.LoggingEvent;
+
+import java.io.IOException;
+import java.sql.Connection;
+
+public class TestDatabaseStore extends TestCase {
+
+ class SampleLogStoreUpdateProvider implements LogStoreUpdateProvider {
+ public void init(Connection connection) throws IOException {
+ }
+
+ public void update(LoggingEvent originalEvent, Object parsedEvent)
+ throws IOException {
+ }
+ }
+
+ public void testDatabaseStore() throws IOException {
+ DatabaseStore store = new DatabaseStore(TestDatabaseStore.class.getName(), "", "", "",
+ new SampleLogStoreUpdateProvider());
+ store.close();
+ }
+}