This repository was archived by the owner on Apr 12, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 10 files changed +130
-5
lines changed
main/java/net.jspiner.executor
test/java/net.jspiner.executor Expand file tree Collapse file tree 10 files changed +130
-5
lines changed Original file line number Diff line number Diff line change 1+ Thanks for creating issue.
2+ Please don't file issues directly, use one of our available templates:
3+
4+ [ find a bug?] ( https://github.com/JSpiner/SafeExecutor/issues/new?template=bug.md )
5+ [ hava a question?] ( https://github.com/JSpiner/SafeExecutor/issues/new?template=question.md )
Original file line number Diff line number Diff line change 1+ Thanks for creating bug issue.
2+
3+ - library version : (x.x.x)
4+ - platform : (sdk 26)
5+ - etc : (run on background...)
6+
7+ ## Expected Behavior
8+
9+
10+ ## Actual Behavior
11+
12+
13+ ## Steps to Reproduce the Problem
14+ 1 .
15+ 1 .
16+ 1 .
Original file line number Diff line number Diff line change 1+ Thanks for creating question issue.
2+
3+ - library version : (x.x.x)
4+ - platform : (sdk 26)
5+ - etc : (run on background...)
6+
7+ ## Question
Original file line number Diff line number Diff line change 1+ Thanks for pull request.
2+ Please don't create PR directly, use one of our available templates:
3+
4+ [ new feature or bug resolve?] ( ?template=feature.md )
5+ [ new release?] ( ?template=release.md )
Original file line number Diff line number Diff line change 1+ ## Description
2+
3+ ## Proposed Changes
4+ -
5+ -
6+ -
7+
8+ ## Related Issues
9+ -
10+ -
11+ -
Original file line number Diff line number Diff line change 1+ Release Version : x.x.x
2+
3+ ## Proposed Changes
4+ -
5+ -
6+ -
7+
8+ ## Related Pull Requests
9+ -
10+ -
11+ -
Original file line number Diff line number Diff line change 44
55SafeExecutor is event-based error handler.
66
7+ [ find a bug?] ( https://github.com/JSpiner/SafeExecutor/issues/new?template=bug.md )
8+ [ hava a question?] ( https://github.com/JSpiner/SafeExecutor/issues/new?template=question.md )
9+
10+
711# STILL DEVELOPING !!!
812### now support
913- error listener
Original file line number Diff line number Diff line change 44 xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
55 <modelVersion >4.0.0</modelVersion >
66
7- <groupId >net.jspiner</groupId >
7+ <groupId >net.jspiner.executor </groupId >
88 <artifactId >safeexecutor</artifactId >
9- <version >0.3 </version >
9+ <version >0.4 </version >
1010
1111 <name >SafeExecutor</name >
1212 <description >event based error handler </description >
Original file line number Diff line number Diff line change 22
33import java .util .ArrayList ;
44
5- public class SafeExecutor {
5+ public final class SafeExecutor {
66
77 public SafeExecutor (){
88 throw new RuntimeException ("create SafeExecutor() is not allowed. use SafeExecutor.build();" );
@@ -12,10 +12,11 @@ public static SafeExecutorBuilder build() {
1212 return new SafeExecutorBuilder ();
1313 }
1414
15- public static class SafeExecutorBuilder {
15+ public static final class SafeExecutorBuilder {
1616
1717 private ArrayList <Executable > executableList ;
1818 private ErrorListener errorListener ;
19+ private boolean ignore ;
1920
2021 private SafeExecutorBuilder () {
2122 executableList = new ArrayList <>();
@@ -27,16 +28,24 @@ public SafeExecutorBuilder add(Executable executable) {
2728 }
2829
2930 public SafeExecutorBuilder onError (ErrorListener errorListener ) {
31+ this .ignore = false ;
3032 this .errorListener = errorListener ;
3133 return this ;
3234 }
3335
36+ public SafeExecutorBuilder ignore () {
37+ this .ignore = true ;
38+ return this ;
39+ }
40+
3441 public void run () {
3542 for (Executable executable : executableList ) {
3643 try {
3744 executable .execute ();
3845 } catch (Exception error ) {
39- executeError (error );
46+ if (!ignore ) {
47+ executeError (error );
48+ }
4049 }
4150 }
4251 }
Original file line number Diff line number Diff line change 1+ package net .jspiner .executor ;
2+
3+ import org .junit .Test ;
4+
5+ public class IgnoreErrorTest {
6+
7+ @ Test (expected = RuntimeException .class )
8+ public void notIgnoreTest () {
9+ SafeExecutor .build ()
10+ .add (() -> {
11+ throw new RuntimeException ("test error" );
12+ }
13+ ).run ();
14+ }
15+
16+ @ Test
17+ public void ignoreExceptionTest () {
18+ SafeExecutor .build ()
19+ .add (() -> {
20+ throw new RuntimeException ("test error" );
21+ }
22+ ).ignore ()
23+ .run ();
24+ }
25+
26+ @ Test
27+ public void ignoreNoExceptionTest () {
28+ SafeExecutor .build ()
29+ .add (() -> doNothing ())
30+ .ignore ()
31+ .run ();
32+ }
33+
34+ @ Test
35+ public void ignoreMultipleExceptionTest () {
36+ SafeExecutor .build ()
37+ .add (() -> {
38+ throw new RuntimeException ("test error" );
39+ })
40+ .add (() -> {
41+ throw new RuntimeException ("test error" );
42+ })
43+ .add (() -> {
44+ throw new RuntimeException ("test error" );
45+ })
46+ .add (() -> {
47+ throw new RuntimeException ("test error" );
48+ })
49+ .ignore ()
50+ .run ();
51+ }
52+
53+ private void doNothing () {
54+ // do nothing for test
55+ }
56+
57+ }
You can’t perform that action at this time.
0 commit comments