|
|
|
|
@@ -18,6 +18,8 @@ package org.springframework.batch.core.listener;
|
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
|
import static org.junit.Assert.fail;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import org.junit.Before;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
import org.springframework.batch.core.StepExecution;
|
|
|
|
|
@@ -26,44 +28,48 @@ import org.springframework.batch.repeat.ExitStatus;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author Dave Syer
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public class MulticasterBatchListenerTests {
|
|
|
|
|
|
|
|
|
|
private MulticasterBatchListener multicast = new MulticasterBatchListener();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private MulticasterBatchListener<String> multicast = new MulticasterBatchListener<String>();
|
|
|
|
|
|
|
|
|
|
private int count = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean error = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Before
|
|
|
|
|
public void setUp() {
|
|
|
|
|
multicast.register(new CountingStepListenerSupport());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test method for {@link org.springframework.batch.core.listener.MulticasterBatchListener#setListeners(org.springframework.batch.core.StepListener[])}.
|
|
|
|
|
* Test method for
|
|
|
|
|
* {@link org.springframework.batch.core.listener.MulticasterBatchListener#setListeners(org.springframework.batch.core.StepListener[])}
|
|
|
|
|
* .
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void testSetListeners() {
|
|
|
|
|
multicast.setListeners(new StepListener[] { new StepListenerSupport() {
|
|
|
|
|
multicast.setListeners(new StepListener[] { new StepListenerSupport<String>() {
|
|
|
|
|
@Override
|
|
|
|
|
public ExitStatus afterStep(StepExecution stepExecution) {
|
|
|
|
|
count++;
|
|
|
|
|
return super.afterStep(stepExecution);
|
|
|
|
|
}
|
|
|
|
|
}});
|
|
|
|
|
} });
|
|
|
|
|
multicast.afterStep(null);
|
|
|
|
|
// setListeners is cumulative (should be OK if used for DI)
|
|
|
|
|
assertEquals(2, count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test method for {@link org.springframework.batch.core.listener.MulticasterBatchListener#register(org.springframework.batch.core.StepListener)}.
|
|
|
|
|
* Test method for
|
|
|
|
|
* {@link org.springframework.batch.core.listener.MulticasterBatchListener#register(org.springframework.batch.core.StepListener)}
|
|
|
|
|
* .
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void testRegister() {
|
|
|
|
|
multicast.register(new StepListenerSupport() {
|
|
|
|
|
multicast.register(new StepListenerSupport<String>() {
|
|
|
|
|
@Override
|
|
|
|
|
public ExitStatus afterStep(StepExecution stepExecution) {
|
|
|
|
|
count++;
|
|
|
|
|
@@ -75,7 +81,9 @@ public class MulticasterBatchListenerTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test method for {@link org.springframework.batch.core.listener.MulticasterBatchListener#afterStep(org.springframework.batch.core.StepExecution)}.
|
|
|
|
|
* Test method for
|
|
|
|
|
* {@link org.springframework.batch.core.listener.MulticasterBatchListener#afterStep(org.springframework.batch.core.StepExecution)}
|
|
|
|
|
* .
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void testAfterStepFails() {
|
|
|
|
|
@@ -83,17 +91,19 @@ public class MulticasterBatchListenerTests {
|
|
|
|
|
try {
|
|
|
|
|
multicast.afterStep(null);
|
|
|
|
|
fail("Expected StepListenerFailedException");
|
|
|
|
|
} catch (StepListenerFailedException e) {
|
|
|
|
|
}
|
|
|
|
|
catch (StepListenerFailedException e) {
|
|
|
|
|
// expected
|
|
|
|
|
String message = e.getCause().getMessage();
|
|
|
|
|
assertEquals("Wrong message: "+message, "listener error", message);
|
|
|
|
|
assertEquals("Wrong message: " + message, "listener error", message);
|
|
|
|
|
}
|
|
|
|
|
assertEquals(1, count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test method for {@link org.springframework.batch.core.listener.MulticasterBatchListener#beforeStep(org.springframework.batch.core.StepExecution)}.
|
|
|
|
|
* Test method for
|
|
|
|
|
* {@link org.springframework.batch.core.listener.MulticasterBatchListener#beforeStep(org.springframework.batch.core.StepExecution)}
|
|
|
|
|
* .
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void testBeforeStep() {
|
|
|
|
|
@@ -102,7 +112,9 @@ public class MulticasterBatchListenerTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test method for {@link org.springframework.batch.core.listener.MulticasterBatchListener#beforeStep(org.springframework.batch.core.StepExecution)}.
|
|
|
|
|
* Test method for
|
|
|
|
|
* {@link org.springframework.batch.core.listener.MulticasterBatchListener#beforeStep(org.springframework.batch.core.StepExecution)}
|
|
|
|
|
* .
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void testBeforeStepFails() {
|
|
|
|
|
@@ -110,16 +122,19 @@ public class MulticasterBatchListenerTests {
|
|
|
|
|
try {
|
|
|
|
|
multicast.beforeStep(null);
|
|
|
|
|
fail("Expected StepListenerFailedException");
|
|
|
|
|
} catch (StepListenerFailedException e) {
|
|
|
|
|
}
|
|
|
|
|
catch (StepListenerFailedException e) {
|
|
|
|
|
// expected
|
|
|
|
|
String message = e.getCause().getMessage();
|
|
|
|
|
assertEquals("Wrong message: "+message, "listener error", message);
|
|
|
|
|
assertEquals("Wrong message: " + message, "listener error", message);
|
|
|
|
|
}
|
|
|
|
|
assertEquals(1, count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test method for {@link org.springframework.batch.core.listener.MulticasterBatchListener#onErrorInStep(org.springframework.batch.core.StepExecution, java.lang.Throwable)}.
|
|
|
|
|
* Test method for
|
|
|
|
|
* {@link org.springframework.batch.core.listener.MulticasterBatchListener#onErrorInStep(org.springframework.batch.core.StepExecution, java.lang.Throwable)}
|
|
|
|
|
* .
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void testOnErrorInStep() {
|
|
|
|
|
@@ -128,7 +143,9 @@ public class MulticasterBatchListenerTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test method for {@link org.springframework.batch.core.listener.MulticasterBatchListener#onErrorInStep(org.springframework.batch.core.StepExecution, java.lang.Throwable)}.
|
|
|
|
|
* Test method for
|
|
|
|
|
* {@link org.springframework.batch.core.listener.MulticasterBatchListener#onErrorInStep(org.springframework.batch.core.StepExecution, java.lang.Throwable)}
|
|
|
|
|
* .
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void testOnErrorInStepFails() {
|
|
|
|
|
@@ -136,16 +153,19 @@ public class MulticasterBatchListenerTests {
|
|
|
|
|
try {
|
|
|
|
|
multicast.onErrorInStep(null, new RuntimeException("foo"));
|
|
|
|
|
fail("Expected StepListenerFailedException");
|
|
|
|
|
} catch (StepListenerFailedException e) {
|
|
|
|
|
}
|
|
|
|
|
catch (StepListenerFailedException e) {
|
|
|
|
|
// expected
|
|
|
|
|
String message = e.getCause().getMessage();
|
|
|
|
|
assertEquals("Wrong message: "+message, "foo", message);
|
|
|
|
|
assertEquals("Wrong message: " + message, "foo", message);
|
|
|
|
|
}
|
|
|
|
|
assertEquals(1, count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test method for {@link org.springframework.batch.core.listener.MulticasterBatchListener#afterChunk()}.
|
|
|
|
|
* Test method for
|
|
|
|
|
* {@link org.springframework.batch.core.listener.MulticasterBatchListener#afterChunk()}
|
|
|
|
|
* .
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void testAfterChunk() {
|
|
|
|
|
@@ -154,7 +174,9 @@ public class MulticasterBatchListenerTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test method for {@link org.springframework.batch.core.listener.MulticasterBatchListener#afterChunk()}.
|
|
|
|
|
* Test method for
|
|
|
|
|
* {@link org.springframework.batch.core.listener.MulticasterBatchListener#afterChunk()}
|
|
|
|
|
* .
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void testAfterChunkFails() {
|
|
|
|
|
@@ -162,16 +184,19 @@ public class MulticasterBatchListenerTests {
|
|
|
|
|
try {
|
|
|
|
|
multicast.afterChunk();
|
|
|
|
|
fail("Expected StepListenerFailedException");
|
|
|
|
|
} catch (StepListenerFailedException e) {
|
|
|
|
|
}
|
|
|
|
|
catch (StepListenerFailedException e) {
|
|
|
|
|
// expected
|
|
|
|
|
String message = e.getCause().getMessage();
|
|
|
|
|
assertEquals("Wrong message: "+message, "listener error", message);
|
|
|
|
|
assertEquals("Wrong message: " + message, "listener error", message);
|
|
|
|
|
}
|
|
|
|
|
assertEquals(1, count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test method for {@link org.springframework.batch.core.listener.MulticasterBatchListener#beforeChunk()}.
|
|
|
|
|
* Test method for
|
|
|
|
|
* {@link org.springframework.batch.core.listener.MulticasterBatchListener#beforeChunk()}
|
|
|
|
|
* .
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void testBeforeChunk() {
|
|
|
|
|
@@ -180,7 +205,9 @@ public class MulticasterBatchListenerTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test method for {@link org.springframework.batch.core.listener.MulticasterBatchListener#beforeChunk()}.
|
|
|
|
|
* Test method for
|
|
|
|
|
* {@link org.springframework.batch.core.listener.MulticasterBatchListener#beforeChunk()}
|
|
|
|
|
* .
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void testBeforeChunkFails() {
|
|
|
|
|
@@ -188,16 +215,19 @@ public class MulticasterBatchListenerTests {
|
|
|
|
|
try {
|
|
|
|
|
multicast.beforeChunk();
|
|
|
|
|
fail("Expected StepListenerFailedException");
|
|
|
|
|
} catch (StepListenerFailedException e) {
|
|
|
|
|
}
|
|
|
|
|
catch (StepListenerFailedException e) {
|
|
|
|
|
// expected
|
|
|
|
|
String message = e.getCause().getMessage();
|
|
|
|
|
assertEquals("Wrong message: "+message, "listener error", message);
|
|
|
|
|
assertEquals("Wrong message: " + message, "listener error", message);
|
|
|
|
|
}
|
|
|
|
|
assertEquals(1, count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test method for {@link org.springframework.batch.core.listener.MulticasterBatchListener#afterRead(java.lang.Object)}.
|
|
|
|
|
* Test method for
|
|
|
|
|
* {@link org.springframework.batch.core.listener.MulticasterBatchListener#afterRead(java.lang.Object)}
|
|
|
|
|
* .
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void testAfterRead() {
|
|
|
|
|
@@ -206,7 +236,9 @@ public class MulticasterBatchListenerTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test method for {@link org.springframework.batch.core.listener.MulticasterBatchListener#afterRead(java.lang.Object)}.
|
|
|
|
|
* Test method for
|
|
|
|
|
* {@link org.springframework.batch.core.listener.MulticasterBatchListener#afterRead(java.lang.Object)}
|
|
|
|
|
* .
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void testAfterReadFails() {
|
|
|
|
|
@@ -214,16 +246,19 @@ public class MulticasterBatchListenerTests {
|
|
|
|
|
try {
|
|
|
|
|
multicast.afterRead(null);
|
|
|
|
|
fail("Expected StepListenerFailedException");
|
|
|
|
|
} catch (StepListenerFailedException e) {
|
|
|
|
|
}
|
|
|
|
|
catch (StepListenerFailedException e) {
|
|
|
|
|
// expected
|
|
|
|
|
String message = e.getCause().getMessage();
|
|
|
|
|
assertEquals("Wrong message: "+message, "listener error", message);
|
|
|
|
|
assertEquals("Wrong message: " + message, "listener error", message);
|
|
|
|
|
}
|
|
|
|
|
assertEquals(1, count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test method for {@link org.springframework.batch.core.listener.MulticasterBatchListener#beforeRead()}.
|
|
|
|
|
* Test method for
|
|
|
|
|
* {@link org.springframework.batch.core.listener.MulticasterBatchListener#beforeRead()}
|
|
|
|
|
* .
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void testBeforeRead() {
|
|
|
|
|
@@ -232,7 +267,9 @@ public class MulticasterBatchListenerTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test method for {@link org.springframework.batch.core.listener.MulticasterBatchListener#beforeRead()}.
|
|
|
|
|
* Test method for
|
|
|
|
|
* {@link org.springframework.batch.core.listener.MulticasterBatchListener#beforeRead()}
|
|
|
|
|
* .
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void testBeforeReadFails() {
|
|
|
|
|
@@ -240,16 +277,19 @@ public class MulticasterBatchListenerTests {
|
|
|
|
|
try {
|
|
|
|
|
multicast.beforeRead();
|
|
|
|
|
fail("Expected StepListenerFailedException");
|
|
|
|
|
} catch (StepListenerFailedException e) {
|
|
|
|
|
}
|
|
|
|
|
catch (StepListenerFailedException e) {
|
|
|
|
|
// expected
|
|
|
|
|
String message = e.getCause().getMessage();
|
|
|
|
|
assertEquals("Wrong message: "+message, "listener error", message);
|
|
|
|
|
assertEquals("Wrong message: " + message, "listener error", message);
|
|
|
|
|
}
|
|
|
|
|
assertEquals(1, count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test method for {@link org.springframework.batch.core.listener.MulticasterBatchListener#onReadError(java.lang.Exception)}.
|
|
|
|
|
* Test method for
|
|
|
|
|
* {@link org.springframework.batch.core.listener.MulticasterBatchListener#onReadError(java.lang.Exception)}
|
|
|
|
|
* .
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void testOnReadError() {
|
|
|
|
|
@@ -258,7 +298,9 @@ public class MulticasterBatchListenerTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test method for {@link org.springframework.batch.core.listener.MulticasterBatchListener#onReadError(java.lang.Exception)}.
|
|
|
|
|
* Test method for
|
|
|
|
|
* {@link org.springframework.batch.core.listener.MulticasterBatchListener#onReadError(java.lang.Exception)}
|
|
|
|
|
* .
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void testOnReadErrorFails() {
|
|
|
|
|
@@ -266,16 +308,19 @@ public class MulticasterBatchListenerTests {
|
|
|
|
|
try {
|
|
|
|
|
multicast.onReadError(new RuntimeException("foo"));
|
|
|
|
|
fail("Expected StepListenerFailedException");
|
|
|
|
|
} catch (StepListenerFailedException e) {
|
|
|
|
|
}
|
|
|
|
|
catch (StepListenerFailedException e) {
|
|
|
|
|
// expected
|
|
|
|
|
String message = e.getCause().getMessage();
|
|
|
|
|
assertEquals("Wrong message: "+message, "foo", message);
|
|
|
|
|
assertEquals("Wrong message: " + message, "foo", message);
|
|
|
|
|
}
|
|
|
|
|
assertEquals(1, count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test method for {@link org.springframework.batch.core.listener.MulticasterBatchListener#afterWrite(java.lang.Object)}.
|
|
|
|
|
* Test method for
|
|
|
|
|
* {@link org.springframework.batch.core.listener.MulticasterBatchListener#afterWrite(java.util.List)}
|
|
|
|
|
* .
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void testAfterWrite() {
|
|
|
|
|
@@ -284,7 +329,9 @@ public class MulticasterBatchListenerTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test method for {@link org.springframework.batch.core.listener.MulticasterBatchListener#afterWrite(java.lang.Object)}.
|
|
|
|
|
* Test method for
|
|
|
|
|
* {@link org.springframework.batch.core.listener.MulticasterBatchListener#afterWrite(java.util.List)}
|
|
|
|
|
* .
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void testAfterWriteFails() {
|
|
|
|
|
@@ -292,16 +339,19 @@ public class MulticasterBatchListenerTests {
|
|
|
|
|
try {
|
|
|
|
|
multicast.afterWrite(null);
|
|
|
|
|
fail("Expected StepListenerFailedException");
|
|
|
|
|
} catch (StepListenerFailedException e) {
|
|
|
|
|
}
|
|
|
|
|
catch (StepListenerFailedException e) {
|
|
|
|
|
// expected
|
|
|
|
|
String message = e.getCause().getMessage();
|
|
|
|
|
assertEquals("Wrong message: "+message, "listener error", message);
|
|
|
|
|
assertEquals("Wrong message: " + message, "listener error", message);
|
|
|
|
|
}
|
|
|
|
|
assertEquals(1, count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test method for {@link org.springframework.batch.core.listener.MulticasterBatchListener#beforeWrite(java.lang.Object)}.
|
|
|
|
|
* Test method for
|
|
|
|
|
* {@link org.springframework.batch.core.listener.MulticasterBatchListener#beforeWrite(List)}
|
|
|
|
|
* .
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void testBeforeWrite() {
|
|
|
|
|
@@ -310,7 +360,9 @@ public class MulticasterBatchListenerTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test method for {@link org.springframework.batch.core.listener.MulticasterBatchListener#beforeWrite(java.lang.Object)}.
|
|
|
|
|
* Test method for
|
|
|
|
|
* {@link org.springframework.batch.core.listener.MulticasterBatchListener#beforeWrite(List)}
|
|
|
|
|
* .
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void testBeforeWriteFails() {
|
|
|
|
|
@@ -318,16 +370,19 @@ public class MulticasterBatchListenerTests {
|
|
|
|
|
try {
|
|
|
|
|
multicast.beforeWrite(null);
|
|
|
|
|
fail("Expected StepListenerFailedException");
|
|
|
|
|
} catch (StepListenerFailedException e) {
|
|
|
|
|
}
|
|
|
|
|
catch (StepListenerFailedException e) {
|
|
|
|
|
// expected
|
|
|
|
|
String message = e.getCause().getMessage();
|
|
|
|
|
assertEquals("Wrong message: "+message, "listener error", message);
|
|
|
|
|
assertEquals("Wrong message: " + message, "listener error", message);
|
|
|
|
|
}
|
|
|
|
|
assertEquals(1, count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test method for {@link org.springframework.batch.core.listener.MulticasterBatchListener#onWriteError(java.lang.Exception, java.lang.Object)}.
|
|
|
|
|
* Test method for
|
|
|
|
|
* {@link org.springframework.batch.core.listener.MulticasterBatchListener#onWriteError(Exception, java.util.List)}
|
|
|
|
|
* .
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void testOnWriteError() {
|
|
|
|
|
@@ -336,7 +391,9 @@ public class MulticasterBatchListenerTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test method for {@link org.springframework.batch.core.listener.MulticasterBatchListener#onWriteError(java.lang.Exception, java.lang.Object)}.
|
|
|
|
|
* Test method for
|
|
|
|
|
* {@link org.springframework.batch.core.listener.MulticasterBatchListener#onWriteError(Exception, java.util.List)}
|
|
|
|
|
* .
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void testOnWriteErrorFails() {
|
|
|
|
|
@@ -344,16 +401,19 @@ public class MulticasterBatchListenerTests {
|
|
|
|
|
try {
|
|
|
|
|
multicast.onWriteError(new RuntimeException("foo"), null);
|
|
|
|
|
fail("Expected StepListenerFailedException");
|
|
|
|
|
} catch (StepListenerFailedException e) {
|
|
|
|
|
}
|
|
|
|
|
catch (StepListenerFailedException e) {
|
|
|
|
|
// expected
|
|
|
|
|
String message = e.getCause().getMessage();
|
|
|
|
|
assertEquals("Wrong message: "+message, "foo", message);
|
|
|
|
|
assertEquals("Wrong message: " + message, "foo", message);
|
|
|
|
|
}
|
|
|
|
|
assertEquals(1, count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test method for {@link org.springframework.batch.core.listener.MulticasterBatchListener#onSkipInRead(java.lang.Throwable)}.
|
|
|
|
|
* Test method for
|
|
|
|
|
* {@link org.springframework.batch.core.listener.MulticasterBatchListener#onSkipInRead(java.lang.Throwable)}
|
|
|
|
|
* .
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void testOnSkipInRead() {
|
|
|
|
|
@@ -369,7 +429,9 @@ public class MulticasterBatchListenerTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test method for {@link org.springframework.batch.core.listener.MulticasterBatchListener#onSkipInRead(java.lang.Throwable)}.
|
|
|
|
|
* Test method for
|
|
|
|
|
* {@link org.springframework.batch.core.listener.MulticasterBatchListener#onSkipInRead(java.lang.Throwable)}
|
|
|
|
|
* .
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void testOnSkipInReadFails() {
|
|
|
|
|
@@ -383,16 +445,19 @@ public class MulticasterBatchListenerTests {
|
|
|
|
|
try {
|
|
|
|
|
multicast.onSkipInRead(new RuntimeException("bar"));
|
|
|
|
|
fail("Expected RuntimeException");
|
|
|
|
|
} catch (RuntimeException e) {
|
|
|
|
|
}
|
|
|
|
|
catch (RuntimeException e) {
|
|
|
|
|
// expected
|
|
|
|
|
String message = e.getMessage();
|
|
|
|
|
assertEquals("Wrong message: "+message, "foo", message);
|
|
|
|
|
assertEquals("Wrong message: " + message, "foo", message);
|
|
|
|
|
}
|
|
|
|
|
assertEquals(1, count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test method for {@link org.springframework.batch.core.listener.MulticasterBatchListener#onSkipInWrite(java.lang.Object, java.lang.Throwable)}.
|
|
|
|
|
* Test method for
|
|
|
|
|
* {@link org.springframework.batch.core.listener.MulticasterBatchListener#onSkipInWrite(java.lang.Object, java.lang.Throwable)}
|
|
|
|
|
* .
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void testOnSkipInWrite() {
|
|
|
|
|
@@ -408,7 +473,9 @@ public class MulticasterBatchListenerTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test method for {@link org.springframework.batch.core.listener.MulticasterBatchListener#onSkipInWrite(java.lang.Object, java.lang.Throwable)}.
|
|
|
|
|
* Test method for
|
|
|
|
|
* {@link org.springframework.batch.core.listener.MulticasterBatchListener#onSkipInWrite(java.lang.Object, java.lang.Throwable)}
|
|
|
|
|
* .
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void testOnSkipInWriteFails() {
|
|
|
|
|
@@ -422,19 +489,20 @@ public class MulticasterBatchListenerTests {
|
|
|
|
|
try {
|
|
|
|
|
multicast.onSkipInWrite(null, new RuntimeException("bar"));
|
|
|
|
|
fail("Expected RuntimeException");
|
|
|
|
|
} catch (RuntimeException e) {
|
|
|
|
|
}
|
|
|
|
|
catch (RuntimeException e) {
|
|
|
|
|
// expected
|
|
|
|
|
String message = e.getMessage();
|
|
|
|
|
assertEquals("Wrong message: "+message, "foo", message);
|
|
|
|
|
assertEquals("Wrong message: " + message, "foo", message);
|
|
|
|
|
}
|
|
|
|
|
assertEquals(1, count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author Dave Syer
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
private final class CountingStepListenerSupport extends StepListenerSupport {
|
|
|
|
|
private final class CountingStepListenerSupport extends StepListenerSupport<String> {
|
|
|
|
|
@Override
|
|
|
|
|
public void onReadError(Exception ex) {
|
|
|
|
|
count++;
|
|
|
|
|
@@ -444,8 +512,12 @@ public class MulticasterBatchListenerTests {
|
|
|
|
|
super.onReadError(ex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
|
* @see org.springframework.batch.core.listener.StepListenerSupport#afterChunk()
|
|
|
|
|
/*
|
|
|
|
|
* (non-Javadoc)
|
|
|
|
|
*
|
|
|
|
|
* @see
|
|
|
|
|
* org.springframework.batch.core.listener.StepListenerSupport#afterChunk
|
|
|
|
|
* ()
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void afterChunk() {
|
|
|
|
|
@@ -456,8 +528,12 @@ public class MulticasterBatchListenerTests {
|
|
|
|
|
super.afterChunk();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
|
* @see org.springframework.batch.core.listener.StepListenerSupport#afterRead(java.lang.Object)
|
|
|
|
|
/*
|
|
|
|
|
* (non-Javadoc)
|
|
|
|
|
*
|
|
|
|
|
* @see
|
|
|
|
|
* org.springframework.batch.core.listener.StepListenerSupport#afterRead
|
|
|
|
|
* (java.lang.Object)
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void afterRead(Object item) {
|
|
|
|
|
@@ -468,8 +544,12 @@ public class MulticasterBatchListenerTests {
|
|
|
|
|
super.afterRead(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
|
* @see org.springframework.batch.core.listener.StepListenerSupport#afterStep(org.springframework.batch.core.StepExecution)
|
|
|
|
|
/*
|
|
|
|
|
* (non-Javadoc)
|
|
|
|
|
*
|
|
|
|
|
* @see
|
|
|
|
|
* org.springframework.batch.core.listener.StepListenerSupport#afterStep
|
|
|
|
|
* (org.springframework.batch.core.StepExecution)
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public ExitStatus afterStep(StepExecution stepExecution) {
|
|
|
|
|
@@ -480,20 +560,12 @@ public class MulticasterBatchListenerTests {
|
|
|
|
|
return super.afterStep(stepExecution);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
|
* @see org.springframework.batch.core.listener.StepListenerSupport#afterWrite(java.lang.Object)
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void afterWrite(Object item) {
|
|
|
|
|
count++;
|
|
|
|
|
if (error) {
|
|
|
|
|
throw new RuntimeException("listener error");
|
|
|
|
|
}
|
|
|
|
|
super.afterWrite(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
|
* @see org.springframework.batch.core.listener.StepListenerSupport#beforeChunk()
|
|
|
|
|
/*
|
|
|
|
|
* (non-Javadoc)
|
|
|
|
|
*
|
|
|
|
|
* @see
|
|
|
|
|
* org.springframework.batch.core.listener.StepListenerSupport#beforeChunk
|
|
|
|
|
* ()
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void beforeChunk() {
|
|
|
|
|
@@ -504,8 +576,12 @@ public class MulticasterBatchListenerTests {
|
|
|
|
|
super.beforeChunk();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
|
* @see org.springframework.batch.core.listener.StepListenerSupport#beforeRead()
|
|
|
|
|
/*
|
|
|
|
|
* (non-Javadoc)
|
|
|
|
|
*
|
|
|
|
|
* @see
|
|
|
|
|
* org.springframework.batch.core.listener.StepListenerSupport#beforeRead
|
|
|
|
|
* ()
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void beforeRead() {
|
|
|
|
|
@@ -516,8 +592,12 @@ public class MulticasterBatchListenerTests {
|
|
|
|
|
super.beforeRead();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
|
* @see org.springframework.batch.core.listener.StepListenerSupport#beforeStep(org.springframework.batch.core.StepExecution)
|
|
|
|
|
/*
|
|
|
|
|
* (non-Javadoc)
|
|
|
|
|
*
|
|
|
|
|
* @see
|
|
|
|
|
* org.springframework.batch.core.listener.StepListenerSupport#beforeStep
|
|
|
|
|
* (org.springframework.batch.core.StepExecution)
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void beforeStep(StepExecution stepExecution) {
|
|
|
|
|
@@ -528,20 +608,44 @@ public class MulticasterBatchListenerTests {
|
|
|
|
|
super.beforeStep(stepExecution);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
|
* @see org.springframework.batch.core.listener.StepListenerSupport#beforeWrite(java.lang.Object)
|
|
|
|
|
/*
|
|
|
|
|
* (non-Javadoc)
|
|
|
|
|
*
|
|
|
|
|
* @see
|
|
|
|
|
* org.springframework.batch.core.listener.StepListenerSupport#afterWrite
|
|
|
|
|
* (java.util.List)
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void beforeWrite(Object item) {
|
|
|
|
|
public void afterWrite(List<? extends String> items) {
|
|
|
|
|
count++;
|
|
|
|
|
if (error) {
|
|
|
|
|
throw new RuntimeException("listener error");
|
|
|
|
|
}
|
|
|
|
|
super.beforeWrite(item);
|
|
|
|
|
super.afterWrite(items);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
|
* @see org.springframework.batch.core.listener.StepListenerSupport#onErrorInStep(org.springframework.batch.core.StepExecution, java.lang.Throwable)
|
|
|
|
|
/*
|
|
|
|
|
* (non-Javadoc)
|
|
|
|
|
*
|
|
|
|
|
* @see
|
|
|
|
|
* org.springframework.batch.core.listener.StepListenerSupport#beforeWrite
|
|
|
|
|
* (java.util.List)
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void beforeWrite(List<? extends String> items) {
|
|
|
|
|
count++;
|
|
|
|
|
if (error) {
|
|
|
|
|
throw new RuntimeException("listener error");
|
|
|
|
|
}
|
|
|
|
|
super.beforeWrite(items);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* (non-Javadoc)
|
|
|
|
|
*
|
|
|
|
|
* @see
|
|
|
|
|
* org.springframework.batch.core.listener.StepListenerSupport#onErrorInStep
|
|
|
|
|
* (org.springframework.batch.core.StepExecution, java.lang.Throwable)
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public ExitStatus onErrorInStep(StepExecution stepExecution, Throwable e) {
|
|
|
|
|
@@ -552,18 +656,22 @@ public class MulticasterBatchListenerTests {
|
|
|
|
|
return super.onErrorInStep(stepExecution, e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
|
* @see org.springframework.batch.core.listener.StepListenerSupport#onWriteError(java.lang.Exception, java.lang.Object)
|
|
|
|
|
/*
|
|
|
|
|
* (non-Javadoc)
|
|
|
|
|
*
|
|
|
|
|
* @see
|
|
|
|
|
* org.springframework.batch.core.listener.StepListenerSupport#onWriteError
|
|
|
|
|
* (java.lang.Exception, java.util.List)
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void onWriteError(Exception ex, Object item) {
|
|
|
|
|
public void onWriteError(Exception exception, List<? extends String> items) {
|
|
|
|
|
count++;
|
|
|
|
|
if (error) {
|
|
|
|
|
throw new RuntimeException("listener error");
|
|
|
|
|
}
|
|
|
|
|
super.onWriteError(ex, item);
|
|
|
|
|
super.onWriteError(exception, items);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|