10
10
11
11
import org .apache .logging .log4j .Level ;
12
12
import org .apache .logging .log4j .LogManager ;
13
+ import org .apache .logging .log4j .core .LogEvent ;
13
14
import org .elasticsearch .ElasticsearchException ;
14
15
import org .elasticsearch .Version ;
15
16
import org .elasticsearch .action .ActionListener ;
@@ -740,13 +741,52 @@ public void testTimesOutAndRetriesConnectionsToBlackholedNodes() {
740
741
assertFoundPeers (nodeToFind , otherNode );
741
742
}
742
743
743
- @ TestLogging (reason = "testing logging at levels DEBUG and above " , value ="org.elasticsearch.discovery:DEBUG " )
744
+ @ TestLogging (reason = "testing logging at WARN level " , value ="org.elasticsearch.discovery:WARN " )
744
745
public void testLogsWarningsIfActiveForLongEnough () throws IllegalAccessException {
745
746
final DiscoveryNode otherNode = newDiscoveryNode ("node-from-hosts-list" );
746
747
747
748
providedAddresses .add (otherNode .getAddress ());
748
749
transportAddressConnector .unreachableAddresses .add (otherNode .getAddress ());
749
750
751
+ peerFinder .activate (lastAcceptedNodes );
752
+ final long endTime
753
+ = deterministicTaskQueue .getCurrentTimeMillis () + VERBOSITY_INCREASE_TIMEOUT_SETTING .get (Settings .EMPTY ).millis ();
754
+
755
+ MockLogAppender appender = new MockLogAppender ();
756
+ try {
757
+ appender .start ();
758
+ Loggers .addAppender (LogManager .getLogger ("org.elasticsearch.discovery.PeerFinder" ), appender );
759
+
760
+ appender .addExpectation (new MockLogAppender .SeenEventExpectation (
761
+ "connection failed" ,
762
+ "org.elasticsearch.discovery.PeerFinder" ,
763
+ Level .WARN ,
764
+ "address [" + otherNode .getAddress () + "]* connection failed: cannot connect to*" )
765
+ {
766
+ @ Override
767
+ public boolean innerMatch (LogEvent event ) {
768
+ return event .getThrown () == null ; // no stack trace at this log level
769
+ }
770
+ });
771
+ while (deterministicTaskQueue .getCurrentTimeMillis () <= endTime ) {
772
+ deterministicTaskQueue .advanceTime ();
773
+ runAllRunnableTasks ();
774
+ }
775
+ appender .assertAllExpectationsMatched ();
776
+
777
+ } finally {
778
+ Loggers .removeAppender (LogManager .getLogger ("org.elasticsearch.discovery.PeerFinder" ), appender );
779
+ appender .stop ();
780
+ }
781
+ }
782
+
783
+ @ TestLogging (reason = "testing logging at DEBUG level" , value ="org.elasticsearch.discovery:DEBUG" )
784
+ public void testLogsStackTraceInConnectionFailedMessages () throws IllegalAccessException {
785
+ final DiscoveryNode otherNode = newDiscoveryNode ("node-from-hosts-list" );
786
+
787
+ providedAddresses .add (otherNode .getAddress ());
788
+ transportAddressConnector .unreachableAddresses .add (otherNode .getAddress ());
789
+
750
790
peerFinder .activate (lastAcceptedNodes );
751
791
final long endTime
752
792
= deterministicTaskQueue .getCurrentTimeMillis () + VERBOSITY_INCREASE_TIMEOUT_SETTING .get (Settings .EMPTY ).millis ();
@@ -759,7 +799,12 @@ public void testLogsWarningsIfActiveForLongEnough() throws IllegalAccessExceptio
759
799
"connection failed" ,
760
800
"org.elasticsearch.discovery.PeerFinder" ,
761
801
Level .DEBUG ,
762
- "*connection failed*" ));
802
+ "address [" + otherNode .getAddress () + "]* connection failed*" ) {
803
+ @ Override
804
+ public boolean innerMatch (LogEvent event ) {
805
+ return event .getThrown () instanceof IOException && event .getThrown ().getMessage ().startsWith ("cannot connect to" );
806
+ }
807
+ });
763
808
764
809
deterministicTaskQueue .advanceTime ();
765
810
runAllRunnableTasks ();
@@ -769,7 +814,13 @@ public void testLogsWarningsIfActiveForLongEnough() throws IllegalAccessExceptio
769
814
"connection failed" ,
770
815
"org.elasticsearch.discovery.PeerFinder" ,
771
816
Level .WARN ,
772
- "*connection failed: cannot connect to*" ));
817
+ "address [" + otherNode .getAddress () + "]* connection failed*" )
818
+ {
819
+ @ Override
820
+ public boolean innerMatch (LogEvent event ) {
821
+ return event .getThrown () instanceof IOException && event .getThrown ().getMessage ().startsWith ("cannot connect to" );
822
+ }
823
+ });
773
824
while (deterministicTaskQueue .getCurrentTimeMillis () <= endTime ) {
774
825
deterministicTaskQueue .advanceTime ();
775
826
runAllRunnableTasks ();
0 commit comments