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.
This commit is contained in:
Nitin Mehta 2014-07-31 16:36:33 -07:00
parent 4d952d0a09
commit e26855e284
2 changed files with 16 additions and 26 deletions

View File

@ -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;
}

View File

@ -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