Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pool: fix ftp mover to provide better logging when failing to connect
The FTP mover suffers from a log-and-throw anti-pattern resulting in problems being logged twice. Another issue is the lack of information about which address(es) could not be contacted. This patch addresses these two failures: the resulting transfer failure is logged once (rather than twice) and connection errors now also include the IP address and port number. Patch: https://rb.dcache.org/r/8356 Acked-by: Albert Rossi Acked-by: Gerd Behrmann Target: master Request: 2.13 Request: 2.12 Request: 2.11 Request: 2.10
- Loading branch information
1 parent
7df8d99
commit b1693c5
Showing
4 changed files
with
233 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
modules/cells/src/test/java/dmg/util/ExceptionsTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package dmg.util; | ||
|
||
import ch.qos.logback.classic.Level; | ||
import ch.qos.logback.classic.Logger; | ||
import ch.qos.logback.classic.LoggerContext; | ||
import ch.qos.logback.classic.spi.ILoggingEvent; | ||
import ch.qos.logback.core.read.ListAppender; | ||
import org.ietf.jgss.GSSException; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
import java.net.SocketException; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertThat; | ||
import static org.hamcrest.Matchers.*; | ||
|
||
/** | ||
* Tests for utility methods in Exceptions. | ||
*/ | ||
public class ExceptionsTests | ||
{ | ||
private List<ILoggingEvent> _log; | ||
|
||
@Before | ||
public void setup() | ||
{ | ||
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); | ||
context.reset(); | ||
|
||
ListAppender<ILoggingEvent> appender = new ListAppender<>(); | ||
appender.setContext(context); | ||
appender.setName("appender"); | ||
appender.start(); | ||
_log = appender.list; | ||
|
||
Logger logger = context.getLogger(Logger.ROOT_LOGGER_NAME); | ||
logger.addAppender(appender); | ||
logger.setLevel(Level.WARN); | ||
} | ||
|
||
@Test | ||
public void shouldWrapWithCauseInSimpleCase() | ||
{ | ||
IOException cause = new IOException("Something went wrong"); | ||
|
||
IOException wrapped = Exceptions.wrap("Wrapped message", cause, IOException.class); | ||
|
||
assertThat(wrapped, is(notNullValue())); | ||
assertThat(wrapped.getMessage(), is(equalTo("Wrapped message"))); | ||
assertThat(wrapped.getCause(), is(cause)); | ||
assertThat(wrapped.getClass(), is(equalTo(IOException.class))); | ||
|
||
assertThat(_log, is(empty())); | ||
} | ||
|
||
@Test | ||
public void shouldWrapWithCauseInBroaderContext() | ||
{ | ||
IOException cause = new IOException("Something went wrong"); | ||
|
||
Exception wrapped = Exceptions.wrap("Wrapped message", cause, Exception.class); | ||
|
||
assertThat(wrapped, is(notNullValue())); | ||
assertThat(wrapped.getMessage(), is(equalTo("Wrapped message"))); | ||
assertThat(wrapped.getCause(), is(cause)); | ||
assertThat(wrapped.getClass(), is(equalTo(IOException.class))); | ||
|
||
assertThat(_log, is(empty())); | ||
} | ||
|
||
@Test | ||
public void shouldWapWithMessageIfExceptionHasNoStringThrowableConstructor() | ||
{ | ||
// Note: SocketException has no (String,Throwable) constructor, but has | ||
// a (String) constructor. | ||
|
||
SocketException cause = new SocketException("Something went wrong"); | ||
|
||
Exception wrapped = Exceptions.wrap("Wrapped message", cause, SocketException.class); | ||
|
||
assertThat(wrapped, is(notNullValue())); | ||
assertThat(wrapped.getMessage(), is(equalTo("Wrapped message"))); | ||
assertThat(wrapped.getCause(), is(nullValue())); | ||
assertThat(wrapped.getClass(), is(equalTo(SocketException.class))); | ||
|
||
assertThat(_log, is(empty())); | ||
} | ||
|
||
@Test | ||
public void shouldUseBroaderExceptionIfCannotWrap() | ||
{ | ||
// Note: GSSException has neither a (String,Throwable) constructor, nor | ||
// a (String) constructor. | ||
GSSException cause = new GSSException(GSSException.BAD_MECH); | ||
|
||
Exception wrapped = Exceptions.wrap("Wrapped message", cause, Exception.class); | ||
|
||
assertThat(wrapped, is(notNullValue())); | ||
assertThat(wrapped.getMessage(), is(equalTo("Wrapped message"))); | ||
assertThat(wrapped.getCause(), is(cause)); | ||
assertThat(wrapped.getClass(), is(equalTo(Exception.class))); | ||
|
||
assertThat(_log, is(empty())); | ||
} | ||
|
||
@Test | ||
public void shouldUseCauseIfCannotWrap() | ||
{ | ||
// Note: GSSException has neither a (String,Throwable) constructor, nor | ||
// a (String) constructor. | ||
GSSException cause = new GSSException(GSSException.BAD_MECH); | ||
|
||
GSSException wrapped = Exceptions.wrap("Wrapped message", cause, GSSException.class); | ||
|
||
assertThat(wrapped, is(cause)); | ||
|
||
assertThat(_log, is(not(empty()))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters