Skip to content

Commit e26855e

Browse files
committed
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.
1 parent 4d952d0 commit e26855e

2 files changed

Lines changed: 16 additions & 26 deletions

File tree

engine/schema/src/com/cloud/upgrade/dao/DatabaseAccessObject.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void dropKey(Connection conn, String tableName, String key, boolean isFor
3939
pstmt.executeUpdate();
4040
s_logger.debug("Key " + key + " is dropped successfully from the table " + tableName);
4141
} catch (SQLException e) {
42-
s_logger.warn("Ignored SQL Exception when trying to drop " + (isForeignKey ? "foreign " : "") + "key " + key + " on table " + tableName, e);
42+
s_logger.debug("Ignored SQL Exception when trying to drop " + (isForeignKey ? "foreign " : "") + "key " + key + " on table " + tableName + " exception: " + e.getMessage());
4343

4444
}
4545
}
@@ -49,7 +49,7 @@ public void dropPrimaryKey(Connection conn, String tableName) {
4949
pstmt.executeUpdate();
5050
s_logger.debug("Primary key is dropped successfully from the table " + tableName);
5151
} catch (SQLException e) {
52-
s_logger.warn("Ignored SQL Exception when trying to drop primary key on table " + tableName, e);
52+
s_logger.debug("Ignored SQL Exception when trying to drop primary key on table " + tableName + " exception: " + e.getMessage());
5353
}
5454
}
5555

@@ -68,7 +68,7 @@ public boolean columnExists(Connection conn, String tableName, String columnName
6868
pstmt.executeQuery();
6969
columnExists = true;
7070
} catch (SQLException e) {
71-
s_logger.warn("Field " + columnName + " doesn't exist in " + tableName, e);
71+
s_logger.debug("Field " + columnName + " doesn't exist in " + tableName + " ignoring exception: " + e.getMessage());
7272
}
7373
return columnExists;
7474
}

engine/schema/test/com/cloud/upgrade/dao/DatabaseAccessObjectTest.java

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ public void testDropKey() throws Exception {
7070
verify(connectionMock, times(1)).prepareStatement(anyString());
7171
verify(preparedStatementMock, times(1)).executeUpdate();
7272
verify(preparedStatementMock, times(1)).close();
73-
verify(loggerMock, times(1)).debug(anyString());
74-
verify(loggerMock, times(0)).warn(anyString(), any(Throwable.class));
73+
verify(loggerMock, times(1)).debug(contains("successfully"));
7574
}
7675

7776
@Test(expected = NullPointerException.class)
@@ -100,8 +99,7 @@ public void testDropKeyWhenTableNameIsNull() throws Exception {
10099
verify(connectionMock, times(1)).prepareStatement(anyString());
101100
verify(preparedStatementMock, times(1)).executeUpdate();
102101
verify(preparedStatementMock, times(1)).close();
103-
verify(loggerMock, times(0)).debug(anyString());
104-
verify(loggerMock, times(1)).warn(anyString(), eq(sqlException));
102+
verify(loggerMock, times(1)).debug(contains("Exception"));
105103
}
106104

107105
@Test
@@ -120,8 +118,7 @@ public void testDropKeyWhenKeyIsNull() throws Exception {
120118
verify(connectionMock, times(1)).prepareStatement(anyString());
121119
verify(preparedStatementMock, times(1)).executeUpdate();
122120
verify(preparedStatementMock, times(1)).close();
123-
verify(loggerMock, times(0)).debug(anyString());
124-
verify(loggerMock, times(1)).warn(anyString(), eq(sqlException));
121+
verify(loggerMock, times(1)).debug(contains("Exception"));
125122
}
126123

127124
@Test
@@ -138,8 +135,7 @@ public void testDropKeyWhenKeysAreForeignKeys() throws Exception {
138135
verify(connectionMock, times(1)).prepareStatement(anyString());
139136
verify(preparedStatementMock, times(1)).executeUpdate();
140137
verify(preparedStatementMock, times(1)).close();
141-
verify(loggerMock, times(1)).debug(anyString());
142-
verify(loggerMock, times(0)).warn(anyString(), any(Throwable.class));
138+
verify(loggerMock, times(1)).debug(contains("successfully"));
143139
}
144140

145141
@Test
@@ -157,8 +153,7 @@ public void testDropKeyWhenPrepareStatementResultsInException() throws Exception
157153
verify(connectionMock, times(1)).prepareStatement(anyString());
158154
verify(preparedStatementMock, times(0)).executeUpdate();
159155
verify(preparedStatementMock, times(0)).close();
160-
verify(loggerMock, times(0)).debug(anyString());
161-
verify(loggerMock, times(1)).warn(anyString(), eq(sqlException));
156+
verify(loggerMock, times(1)).debug(contains("Exception"));
162157
}
163158

164159
@Test
@@ -177,8 +172,7 @@ public void testDropKeyWhenExecuteUpdateResultsInException() throws Exception {
177172
verify(connectionMock, times(1)).prepareStatement(anyString());
178173
verify(preparedStatementMock, times(1)).executeUpdate();
179174
verify(preparedStatementMock, times(1)).close();
180-
verify(loggerMock, times(0)).debug(anyString());
181-
verify(loggerMock, times(1)).warn(anyString(), eq(sqlException));
175+
verify(loggerMock, times(1)).debug(contains("Exception"));
182176
}
183177

184178
@SuppressWarnings("static-access")
@@ -231,8 +225,7 @@ public void testDropPrimaryKey() throws Exception {
231225
verify(connectionMock, times(1)).prepareStatement(anyString());
232226
verify(preparedStatementMock, times(1)).executeUpdate();
233227
verify(preparedStatementMock, times(1)).close();
234-
verify(loggerMock, times(1)).debug(anyString());
235-
verify(loggerMock, times(0)).warn(anyString(), any(Throwable.class));
228+
verify(loggerMock, times(1)).debug(contains("successfully"));
236229
}
237230

238231
@Test(expected = NullPointerException.class)
@@ -257,8 +250,7 @@ public void testDropPrimaryKeyWhenTableNameIsNull() throws Exception {
257250
verify(connectionMock, times(1)).prepareStatement(anyString());
258251
verify(preparedStatementMock, times(1)).executeUpdate();
259252
verify(preparedStatementMock, times(1)).close();
260-
verify(loggerMock, times(0)).debug(anyString());
261-
verify(loggerMock, times(1)).warn(anyString(), eq(sqlException));
253+
verify(loggerMock, times(1)).debug(contains("Exception"));
262254
}
263255

264256
@Test
@@ -274,8 +266,7 @@ public void testDropPrimaryKeyWhenPrepareStatementResultsInException() throws Ex
274266
verify(connectionMock, times(1)).prepareStatement(anyString());
275267
verify(preparedStatementMock, times(0)).executeUpdate();
276268
verify(preparedStatementMock, times(0)).close();
277-
verify(loggerMock, times(0)).debug(anyString());
278-
verify(loggerMock, times(1)).warn(anyString(), eq(sqlException));
269+
verify(loggerMock, times(1)).debug(contains("Exception"));
279270
}
280271

281272
@Test
@@ -292,8 +283,7 @@ public void testDropPrimaryKeyWhenExecuteUpdateResultsInException() throws Excep
292283
verify(connectionMock, times(1)).prepareStatement(anyString());
293284
verify(preparedStatementMock, times(1)).executeUpdate();
294285
verify(preparedStatementMock, times(1)).close();
295-
verify(loggerMock, times(0)).debug(anyString());
296-
verify(loggerMock, times(1)).warn(anyString(), eq(sqlException));
286+
verify(loggerMock, times(1)).debug(contains("Exception"));
297287
}
298288

299289
@Test
@@ -309,7 +299,7 @@ public void testColumnExists() throws Exception {
309299
verify(connectionMock, times(1)).prepareStatement(anyString());
310300
verify(preparedStatementMock, times(1)).executeQuery();
311301
verify(preparedStatementMock, times(1)).close();
312-
verify(loggerMock, times(0)).warn(anyString(), any(Throwable.class));
302+
verify(loggerMock, times(0)).debug(anyString(), any(Throwable.class));
313303
}
314304

315305
@Test(expected = NullPointerException.class)
@@ -336,7 +326,7 @@ public void testColumnExistsWhenTableNameIsNull() throws Exception {
336326
verify(connectionMock, times(1)).prepareStatement(anyString());
337327
verify(preparedStatementMock, times(1)).executeQuery();
338328
verify(preparedStatementMock, times(1)).close();
339-
verify(loggerMock, times(1)).warn(anyString(), eq(sqlException));
329+
verify(loggerMock, times(1)).debug(anyString());
340330
}
341331

342332
@Test
@@ -354,7 +344,7 @@ public void testColumnExistsWhenColumnNameIsNull() throws Exception {
354344
verify(connectionMock, times(1)).prepareStatement(anyString());
355345
verify(preparedStatementMock, times(1)).executeQuery();
356346
verify(preparedStatementMock, times(1)).close();
357-
verify(loggerMock, times(1)).warn(anyString(), eq(sqlException));
347+
verify(loggerMock, times(1)).debug(anyString());
358348
}
359349

360350
@Test

0 commit comments

Comments
 (0)