From e26855e2849960951fd27fcb394c19a5b4bb2755 Mon Sep 17 00:00:00 2001 From: Nitin Mehta Date: Thu, 31 Jul 2014 16:36:33 -0700 Subject: [PATCH] CLOUDSTACK-6594: Improve the logging in the util functions utilized by db upgrades currently. If the exception is to be ignored, dont log the stack trace and also dont log it in warn. Making them debug just to be little verbose during upgrade scenario. Correcting all the unit tests accordingly. --- .../upgrade/dao/DatabaseAccessObject.java | 6 ++-- .../upgrade/dao/DatabaseAccessObjectTest.java | 36 +++++++------------ 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/engine/schema/src/com/cloud/upgrade/dao/DatabaseAccessObject.java b/engine/schema/src/com/cloud/upgrade/dao/DatabaseAccessObject.java index 1e620a5a584..5d0edddb02e 100644 --- a/engine/schema/src/com/cloud/upgrade/dao/DatabaseAccessObject.java +++ b/engine/schema/src/com/cloud/upgrade/dao/DatabaseAccessObject.java @@ -39,7 +39,7 @@ public class DatabaseAccessObject { pstmt.executeUpdate(); s_logger.debug("Key " + key + " is dropped successfully from the table " + tableName); } catch (SQLException e) { - s_logger.warn("Ignored SQL Exception when trying to drop " + (isForeignKey ? "foreign " : "") + "key " + key + " on table " + tableName, e); + s_logger.debug("Ignored SQL Exception when trying to drop " + (isForeignKey ? "foreign " : "") + "key " + key + " on table " + tableName + " exception: " + e.getMessage()); } } @@ -49,7 +49,7 @@ public class DatabaseAccessObject { pstmt.executeUpdate(); s_logger.debug("Primary key is dropped successfully from the table " + tableName); } catch (SQLException e) { - s_logger.warn("Ignored SQL Exception when trying to drop primary key on table " + tableName, e); + s_logger.debug("Ignored SQL Exception when trying to drop primary key on table " + tableName + " exception: " + e.getMessage()); } } @@ -68,7 +68,7 @@ public class DatabaseAccessObject { pstmt.executeQuery(); columnExists = true; } catch (SQLException e) { - s_logger.warn("Field " + columnName + " doesn't exist in " + tableName, e); + s_logger.debug("Field " + columnName + " doesn't exist in " + tableName + " ignoring exception: " + e.getMessage()); } return columnExists; } diff --git a/engine/schema/test/com/cloud/upgrade/dao/DatabaseAccessObjectTest.java b/engine/schema/test/com/cloud/upgrade/dao/DatabaseAccessObjectTest.java index 5d37fbf326a..9a2115e9629 100644 --- a/engine/schema/test/com/cloud/upgrade/dao/DatabaseAccessObjectTest.java +++ b/engine/schema/test/com/cloud/upgrade/dao/DatabaseAccessObjectTest.java @@ -70,8 +70,7 @@ public class DatabaseAccessObjectTest { verify(connectionMock, times(1)).prepareStatement(anyString()); verify(preparedStatementMock, times(1)).executeUpdate(); verify(preparedStatementMock, times(1)).close(); - verify(loggerMock, times(1)).debug(anyString()); - verify(loggerMock, times(0)).warn(anyString(), any(Throwable.class)); + verify(loggerMock, times(1)).debug(contains("successfully")); } @Test(expected = NullPointerException.class) @@ -100,8 +99,7 @@ public class DatabaseAccessObjectTest { verify(connectionMock, times(1)).prepareStatement(anyString()); verify(preparedStatementMock, times(1)).executeUpdate(); verify(preparedStatementMock, times(1)).close(); - verify(loggerMock, times(0)).debug(anyString()); - verify(loggerMock, times(1)).warn(anyString(), eq(sqlException)); + verify(loggerMock, times(1)).debug(contains("Exception")); } @Test @@ -120,8 +118,7 @@ public class DatabaseAccessObjectTest { verify(connectionMock, times(1)).prepareStatement(anyString()); verify(preparedStatementMock, times(1)).executeUpdate(); verify(preparedStatementMock, times(1)).close(); - verify(loggerMock, times(0)).debug(anyString()); - verify(loggerMock, times(1)).warn(anyString(), eq(sqlException)); + verify(loggerMock, times(1)).debug(contains("Exception")); } @Test @@ -138,8 +135,7 @@ public class DatabaseAccessObjectTest { verify(connectionMock, times(1)).prepareStatement(anyString()); verify(preparedStatementMock, times(1)).executeUpdate(); verify(preparedStatementMock, times(1)).close(); - verify(loggerMock, times(1)).debug(anyString()); - verify(loggerMock, times(0)).warn(anyString(), any(Throwable.class)); + verify(loggerMock, times(1)).debug(contains("successfully")); } @Test @@ -157,8 +153,7 @@ public class DatabaseAccessObjectTest { verify(connectionMock, times(1)).prepareStatement(anyString()); verify(preparedStatementMock, times(0)).executeUpdate(); verify(preparedStatementMock, times(0)).close(); - verify(loggerMock, times(0)).debug(anyString()); - verify(loggerMock, times(1)).warn(anyString(), eq(sqlException)); + verify(loggerMock, times(1)).debug(contains("Exception")); } @Test @@ -177,8 +172,7 @@ public class DatabaseAccessObjectTest { verify(connectionMock, times(1)).prepareStatement(anyString()); verify(preparedStatementMock, times(1)).executeUpdate(); verify(preparedStatementMock, times(1)).close(); - verify(loggerMock, times(0)).debug(anyString()); - verify(loggerMock, times(1)).warn(anyString(), eq(sqlException)); + verify(loggerMock, times(1)).debug(contains("Exception")); } @SuppressWarnings("static-access") @@ -231,8 +225,7 @@ public class DatabaseAccessObjectTest { verify(connectionMock, times(1)).prepareStatement(anyString()); verify(preparedStatementMock, times(1)).executeUpdate(); verify(preparedStatementMock, times(1)).close(); - verify(loggerMock, times(1)).debug(anyString()); - verify(loggerMock, times(0)).warn(anyString(), any(Throwable.class)); + verify(loggerMock, times(1)).debug(contains("successfully")); } @Test(expected = NullPointerException.class) @@ -257,8 +250,7 @@ public class DatabaseAccessObjectTest { verify(connectionMock, times(1)).prepareStatement(anyString()); verify(preparedStatementMock, times(1)).executeUpdate(); verify(preparedStatementMock, times(1)).close(); - verify(loggerMock, times(0)).debug(anyString()); - verify(loggerMock, times(1)).warn(anyString(), eq(sqlException)); + verify(loggerMock, times(1)).debug(contains("Exception")); } @Test @@ -274,8 +266,7 @@ public class DatabaseAccessObjectTest { verify(connectionMock, times(1)).prepareStatement(anyString()); verify(preparedStatementMock, times(0)).executeUpdate(); verify(preparedStatementMock, times(0)).close(); - verify(loggerMock, times(0)).debug(anyString()); - verify(loggerMock, times(1)).warn(anyString(), eq(sqlException)); + verify(loggerMock, times(1)).debug(contains("Exception")); } @Test @@ -292,8 +283,7 @@ public class DatabaseAccessObjectTest { verify(connectionMock, times(1)).prepareStatement(anyString()); verify(preparedStatementMock, times(1)).executeUpdate(); verify(preparedStatementMock, times(1)).close(); - verify(loggerMock, times(0)).debug(anyString()); - verify(loggerMock, times(1)).warn(anyString(), eq(sqlException)); + verify(loggerMock, times(1)).debug(contains("Exception")); } @Test @@ -309,7 +299,7 @@ public class DatabaseAccessObjectTest { verify(connectionMock, times(1)).prepareStatement(anyString()); verify(preparedStatementMock, times(1)).executeQuery(); verify(preparedStatementMock, times(1)).close(); - verify(loggerMock, times(0)).warn(anyString(), any(Throwable.class)); + verify(loggerMock, times(0)).debug(anyString(), any(Throwable.class)); } @Test(expected = NullPointerException.class) @@ -336,7 +326,7 @@ public class DatabaseAccessObjectTest { verify(connectionMock, times(1)).prepareStatement(anyString()); verify(preparedStatementMock, times(1)).executeQuery(); verify(preparedStatementMock, times(1)).close(); - verify(loggerMock, times(1)).warn(anyString(), eq(sqlException)); + verify(loggerMock, times(1)).debug(anyString()); } @Test @@ -354,7 +344,7 @@ public class DatabaseAccessObjectTest { verify(connectionMock, times(1)).prepareStatement(anyString()); verify(preparedStatementMock, times(1)).executeQuery(); verify(preparedStatementMock, times(1)).close(); - verify(loggerMock, times(1)).warn(anyString(), eq(sqlException)); + verify(loggerMock, times(1)).debug(anyString()); } @Test