3333
3434import java .io .Closeable ;
3535import java .util .ArrayList ;
36+ import java .util .Arrays ;
3637import java .util .Collections ;
38+ import java .util .List ;
3739import java .util .Map ;
3840import java .util .concurrent .atomic .AtomicInteger ;
3941import java .util .function .Function ;
@@ -52,11 +54,17 @@ public void testLogsAtDebugOnDisconnectionDuringBan() throws Exception {
5254 }
5355 connection .sendRequest (requestId , action , request , options );
5456 },
55- childNode -> new MockLogAppender .SeenEventExpectation (
56- "cannot send message" ,
57- TaskCancellationService .class .getName (),
58- Level .DEBUG ,
59- "*cannot send ban for tasks*" + childNode .getId () + "*" ));
57+ childNode -> Arrays .asList (
58+ new MockLogAppender .SeenEventExpectation (
59+ "cannot send ban" ,
60+ TaskCancellationService .class .getName (),
61+ Level .DEBUG ,
62+ "*cannot send ban for tasks*" + childNode .getId () + "*" ),
63+ new MockLogAppender .SeenEventExpectation (
64+ "cannot remove ban" ,
65+ TaskCancellationService .class .getName (),
66+ Level .DEBUG ,
67+ "*failed to remove ban for tasks*" + childNode .getId () + "*" )));
6068 }
6169
6270 @ TestLogging (reason = "testing logging at DEBUG" , value = "org.elasticsearch.tasks.TaskCancellationService:DEBUG" )
@@ -69,16 +77,22 @@ public void testLogsAtDebugOnDisconnectionDuringBanRemoval() throws Exception {
6977 }
7078 connection .sendRequest (requestId , action , request , options );
7179 },
72- childNode -> new MockLogAppender .SeenEventExpectation (
73- "cannot send message" ,
74- TaskCancellationService .class .getName (),
75- Level .DEBUG ,
76- "*failed to remove ban for tasks*" + childNode .getId () + "*" ));
80+ childNode -> Arrays .asList (
81+ new MockLogAppender .UnseenEventExpectation (
82+ "cannot send ban" ,
83+ TaskCancellationService .class .getName (),
84+ Level .DEBUG ,
85+ "*cannot send ban for tasks*" + childNode .getId () + "*" ),
86+ new MockLogAppender .SeenEventExpectation (
87+ "cannot remove ban" ,
88+ TaskCancellationService .class .getName (),
89+ Level .DEBUG ,
90+ "*failed to remove ban for tasks*" + childNode .getId () + "*" )));
7791 }
7892
7993 private void runTest (
8094 StubbableTransport .SendRequestBehavior sendRequestBehavior ,
81- Function <DiscoveryNode , MockLogAppender .SeenEventExpectation > expectation ) throws Exception {
95+ Function <DiscoveryNode , List < MockLogAppender .LoggingExpectation >> expectations ) throws Exception {
8296
8397 final ArrayList <Closeable > resources = new ArrayList <>(3 );
8498
@@ -140,7 +154,9 @@ public Task createTask(long id, String type, String action, TaskId parentTaskId,
140154 Loggers .addAppender (LogManager .getLogger (TaskCancellationService .class ), appender );
141155 resources .add (() -> Loggers .removeAppender (LogManager .getLogger (TaskCancellationService .class ), appender ));
142156
143- appender .addExpectation (expectation .apply (childTransportService .getLocalDiscoNode ()));
157+ for (MockLogAppender .LoggingExpectation expectation : expectations .apply (childTransportService .getLocalDiscoNode ())) {
158+ appender .addExpectation (expectation );
159+ }
144160
145161 final PlainActionFuture <Void > cancellationFuture = new PlainActionFuture <>();
146162 parentTransportService .getTaskManager ().cancelTaskAndDescendants (parentTask , "test" , true , cancellationFuture );
0 commit comments