54
54
import java .util .concurrent .atomic .AtomicBoolean ;
55
55
import java .util .concurrent .atomic .AtomicReference ;
56
56
import java .util .function .Function ;
57
+ import java .util .function .UnaryOperator ;
57
58
import java .util .stream .Collectors ;
58
59
59
60
import static java .util .Collections .emptyMap ;
@@ -1602,6 +1603,13 @@ public void testClusterRecoversAfterExceptionDuringSerialization() {
1602
1603
value = "org.elasticsearch.cluster.coordination.ClusterFormationFailureHelper:WARN"
1603
1604
)
1604
1605
public void testLogsWarningPeriodicallyIfClusterNotFormed () {
1606
+ testLogsWarningPeriodicallyIfClusterNotFormed (
1607
+ "master not discovered or elected yet, an election requires at least 2 nodes with ids from [" ,
1608
+ nodeId -> "*have only discovered non-quorum *" + nodeId + "*discovery will continue*"
1609
+ );
1610
+ }
1611
+
1612
+ protected void testLogsWarningPeriodicallyIfClusterNotFormed (String expectedMessageStart , UnaryOperator <String > discoveryMessageFn ) {
1605
1613
final long warningDelayMillis ;
1606
1614
final Settings settings ;
1607
1615
if (randomBoolean ()) {
@@ -1645,10 +1653,7 @@ public void testLogsWarningPeriodicallyIfClusterNotFormed() {
1645
1653
@ Override
1646
1654
public void match (LogEvent event ) {
1647
1655
final String message = event .getMessage ().getFormattedMessage ();
1648
- assertThat (
1649
- message ,
1650
- startsWith ("master not discovered or elected yet, an election requires at least 2 nodes with ids from [" )
1651
- );
1656
+ assertThat (message , startsWith (expectedMessageStart ));
1652
1657
1653
1658
final List <ClusterNode > matchingNodes = cluster .clusterNodes .stream ()
1654
1659
.filter (
@@ -1659,13 +1664,7 @@ public void match(LogEvent event) {
1659
1664
.toList ();
1660
1665
assertThat (matchingNodes , hasSize (1 ));
1661
1666
1662
- assertTrue (
1663
- message ,
1664
- Regex .simpleMatch (
1665
- "*have only discovered non-quorum *" + matchingNodes .get (0 ).toString () + "*discovery will continue*" ,
1666
- message
1667
- )
1668
- );
1667
+ assertTrue (message , Regex .simpleMatch (discoveryMessageFn .apply (matchingNodes .get (0 ).toString ()), message ));
1669
1668
1670
1669
nodesLogged .add (matchingNodes .get (0 ).getLocalNode ());
1671
1670
}
0 commit comments