QueueProcessor: survive on LOG.error in tests (more correct)

This commit is contained in:
Anton Makeev
2012-08-23 16:43:51 +02:00
parent d852a80fd6
commit e45ba162d0
@@ -77,18 +77,13 @@ public class QueueProcessor<T> {
private static <T> PairConsumer<T, Runnable> wrappingProcessor(final Consumer<T> processor) {
return new PairConsumer<T, Runnable>() {
@Override
public void consume(T item, Runnable runnable) {
try {
processor.consume(item);
}
catch (Throwable e) {
try {
LOG.error(e);
public void consume(final T item, Runnable runnable) {
runSafely(new Runnable() {
@Override
public void run() {
processor.consume(item);
}
catch (Exception ignore) {
// should survive assertions
}
}
});
runnable.run();
}
};
@@ -202,17 +197,12 @@ public class QueueProcessor<T> {
@Override
public void run() {
if (myDeathCondition.value(null)) return;
try {
myProcessor.consume(item, myContinuationContext);
}
catch (Throwable t) {
try {
LOG.error(t);
runSafely(new Runnable() {
@Override
public void run() {
myProcessor.consume(item, myContinuationContext);
}
catch (Throwable e2) {
e2.printStackTrace();
}
}
});
}
};
final Application application = ApplicationManager.getApplication();
@@ -231,6 +221,20 @@ public class QueueProcessor<T> {
return true;
}
public static void runSafely(Runnable run) {
try {
run.run();
}
catch (Throwable e) {
try {
LOG.error(e);
}
catch (Throwable e2) {
e2.printStackTrace();
}
}
}
public boolean isEmpty() {
synchronized (myQueue) {
return myQueue.isEmpty() && (!isProcessing);