HBASE-7452 Change ForeignExceptionListener#receive(String, FE) to only be #receive(FE)
git-svn-id: https://svn.apache.org/repos/asf/hbase/branches/hbase-7290@1445811 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8d1cf84aa0
commit
8da4eec9a4
|
@ -59,29 +59,21 @@ public class ForeignExceptionDispatcher implements ForeignExceptionListener, For
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void receive(String message) {
|
|
||||||
receive(new ForeignException(name, message));
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized void receive(ForeignException e) {
|
|
||||||
receive(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void receive(String message, ForeignException e) {
|
public synchronized void receive(ForeignException e) {
|
||||||
// if we already have an exception, then ignore it
|
// if we already have an exception, then ignore it
|
||||||
if (exception != null) return;
|
if (exception != null) return;
|
||||||
|
|
||||||
LOG.debug(name + " accepting received error:" + message);
|
LOG.debug(name + " accepting received exception" , e);
|
||||||
// mark that we got the error
|
// mark that we got the error
|
||||||
if (e != null) {
|
if (e != null) {
|
||||||
exception = e;
|
exception = e;
|
||||||
} else {
|
} else {
|
||||||
exception = new ForeignException(name, message);
|
exception = new ForeignException(name, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// notify all the listeners
|
// notify all the listeners
|
||||||
dispatch(message, e);
|
dispatch(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -108,11 +100,11 @@ public class ForeignExceptionDispatcher implements ForeignExceptionListener, For
|
||||||
* @param message human readable message passed to the listener
|
* @param message human readable message passed to the listener
|
||||||
* @param e {@link ForeignException} containing the cause. Can be null.
|
* @param e {@link ForeignException} containing the cause. Can be null.
|
||||||
*/
|
*/
|
||||||
private void dispatch(String message, ForeignException e) {
|
private void dispatch(ForeignException e) {
|
||||||
// update all the listeners with the passed error
|
// update all the listeners with the passed error
|
||||||
LOG.debug(name + " Recieved error, notifying listeners...");
|
LOG.debug(name + " Recieved error, notifying listeners...");
|
||||||
for (ForeignExceptionListener l: listeners) {
|
for (ForeignExceptionListener l: listeners) {
|
||||||
l.receive(message, e);
|
l.receive(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,5 +37,5 @@ public interface ForeignExceptionListener {
|
||||||
* @param message reason for the error
|
* @param message reason for the error
|
||||||
* @param e exception causing the error. Implementations must accept and handle null here.
|
* @param e exception causing the error. Implementations must accept and handle null here.
|
||||||
*/
|
*/
|
||||||
public void receive(String message, ForeignException e);
|
public void receive(ForeignException e);
|
||||||
}
|
}
|
|
@ -69,7 +69,7 @@ public class TimeoutExceptionInjector {
|
||||||
TimeoutException tee = new TimeoutException(
|
TimeoutException tee = new TimeoutException(
|
||||||
"Timeout caused Foreign Exception", start, end, maxTime);
|
"Timeout caused Foreign Exception", start, end, maxTime);
|
||||||
String source = "timer-" + timer;
|
String source = "timer-" + timer;
|
||||||
listener.receive("Timeout elapsed!", new ForeignException(source, tee));
|
listener.receive(new ForeignException(source, tee));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,12 +56,11 @@ public class TestForeignExceptionDispatcher {
|
||||||
dispatcher.addListener(listener2);
|
dispatcher.addListener(listener2);
|
||||||
|
|
||||||
// create an artificial error
|
// create an artificial error
|
||||||
String message = "Some error";
|
dispatcher.receive(EXTEXN);
|
||||||
dispatcher.receive(message, EXTEXN);
|
|
||||||
|
|
||||||
// make sure the listeners got the error
|
// make sure the listeners got the error
|
||||||
Mockito.verify(listener1, Mockito.times(1)).receive(message, EXTEXN);
|
Mockito.verify(listener1, Mockito.times(1)).receive(EXTEXN);
|
||||||
Mockito.verify(listener2, Mockito.times(1)).receive(message, EXTEXN);
|
Mockito.verify(listener2, Mockito.times(1)).receive(EXTEXN);
|
||||||
|
|
||||||
// make sure that we get an exception
|
// make sure that we get an exception
|
||||||
try {
|
try {
|
||||||
|
@ -73,10 +72,9 @@ public class TestForeignExceptionDispatcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
// push another error, which should be not be passed to listeners
|
// push another error, which should be not be passed to listeners
|
||||||
message = "another error";
|
dispatcher.receive(EXTEXN2);
|
||||||
dispatcher.receive(message, EXTEXN2);
|
Mockito.verify(listener1, Mockito.never()).receive(EXTEXN2);
|
||||||
Mockito.verify(listener1, Mockito.never()).receive(message, EXTEXN2);
|
Mockito.verify(listener2, Mockito.never()).receive(EXTEXN2);
|
||||||
Mockito.verify(listener2, Mockito.never()).receive(message, EXTEXN2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -97,8 +95,8 @@ public class TestForeignExceptionDispatcher {
|
||||||
assertTrue("Monitor didn't get timeout", monitor.hasException());
|
assertTrue("Monitor didn't get timeout", monitor.hasException());
|
||||||
|
|
||||||
// verify that that we propagated the error
|
// verify that that we propagated the error
|
||||||
Mockito.verify(listener1).receive(Mockito.anyString(), Mockito.any(ForeignException.class));
|
Mockito.verify(listener1).receive(Mockito.any(ForeignException.class));
|
||||||
Mockito.verify(listener2).receive(Mockito.anyString(), Mockito.any(ForeignException.class));
|
Mockito.verify(listener2).receive(Mockito.any(ForeignException.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -119,9 +117,7 @@ public class TestForeignExceptionDispatcher {
|
||||||
timer.start();
|
timer.start();
|
||||||
timer.trigger();
|
timer.trigger();
|
||||||
// make sure that we got the timer error
|
// make sure that we got the timer error
|
||||||
Mockito.verify(listener1, Mockito.times(1)).receive(Mockito.anyString(),
|
Mockito.verify(listener1, Mockito.times(1)).receive(Mockito.any(ForeignException.class));
|
||||||
Mockito.any(ForeignException.class));
|
Mockito.verify(listener2, Mockito.times(1)).receive(Mockito.any(ForeignException.class));
|
||||||
Mockito.verify(listener2, Mockito.times(1)).receive(Mockito.anyString(),
|
|
||||||
Mockito.any(ForeignException.class));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -44,8 +44,7 @@ public class TestTimeoutExceptionInjector {
|
||||||
TimeoutExceptionInjector timer = new TimeoutExceptionInjector(listener, time);
|
TimeoutExceptionInjector timer = new TimeoutExceptionInjector(listener, time);
|
||||||
timer.start();
|
timer.start();
|
||||||
timer.trigger();
|
timer.trigger();
|
||||||
Mockito.verify(listener, Mockito.times(1)).receive(Mockito.anyString(),
|
Mockito.verify(listener, Mockito.times(1)).receive(Mockito.any(ForeignException.class));
|
||||||
Mockito.any(ForeignException.class));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -58,7 +57,7 @@ public class TestTimeoutExceptionInjector {
|
||||||
TimeoutExceptionInjector timer = new TimeoutExceptionInjector(listener, time);
|
TimeoutExceptionInjector timer = new TimeoutExceptionInjector(listener, time);
|
||||||
timer.start();
|
timer.start();
|
||||||
timer.trigger();
|
timer.trigger();
|
||||||
Mockito.verify(listener).receive(Mockito.anyString(), Mockito.any(ForeignException.class));
|
Mockito.verify(listener).receive(Mockito.any(ForeignException.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -98,8 +97,7 @@ public class TestTimeoutExceptionInjector {
|
||||||
LOG.debug("Correctly failed timer: " + e.getMessage());
|
LOG.debug("Correctly failed timer: " + e.getMessage());
|
||||||
}
|
}
|
||||||
Thread.sleep(time * 2);
|
Thread.sleep(time * 2);
|
||||||
Mockito.verify(listener, Mockito.times(1)).receive(Mockito.anyString(),
|
Mockito.verify(listener, Mockito.times(1)).receive(Mockito.any(ForeignException.class));
|
||||||
Mockito.any(ForeignException.class));
|
|
||||||
Mockito.verifyNoMoreInteractions(listener);
|
Mockito.verifyNoMoreInteractions(listener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue