Dhairya-007 opened a new pull request, #29957:
URL: https://github.com/apache/camel/pull/29957

   ## Problem
   
   `JGroupsRaftConstants` documents a consumer header for the leader's address:
   
   ```java
   @Metadata(label = "consumer", description = "The Address of Raft Leader or 
not.", javaType = "org.jgroups.Address")
   public static final String HEADER_JGROUPSRAFT_LEADER_ADDRESS = 
"CamelJGroupsRaftLeaderAddress";
   ```
   
   `JGroupsRaftEndpoint.populateJGroupsRaftHeaders` sets the other six headers 
from the raft handle and skips this one:
   
   ```java
   
exchange.getIn().setHeader(JGroupsRaftConstants.HEADER_JGROUPSRAFT_COMMIT_INDEX,
 resolvedRaftHandle.commitIndex());
   
exchange.getIn().setHeader(JGroupsRaftConstants.HEADER_JGROUPSRAFT_CURRENT_TERM,
 resolvedRaftHandle.currentTerm());
   
exchange.getIn().setHeader(JGroupsRaftConstants.HEADER_JGROUPSRAFT_IS_LEADER, 
resolvedRaftHandle.isLeader());
   
exchange.getIn().setHeader(JGroupsRaftConstants.HEADER_JGROUPSRAFT_LAST_APPLIED,
 resolvedRaftHandle.lastApplied());
   exchange.getIn().setHeader(JGroupsRaftConstants.HEADER_JGROUPSRAFT_LOG_SIZE, 
resolvedRaftHandle.logSize());
   exchange.getIn().setHeader(JGroupsRaftConstants.HEADER_JGROUPSRAFT_RAFT_ID, 
resolvedRaftHandle.raftId());
   ```
   
   `CamelJGroupsRaftLeaderAddress` is set nowhere else either, so a route can 
learn *whether* this node is the leader (`CamelJGroupsRaftIsLeader`) but never 
*which* node is, although the catalog lists the header.
   
   The gap was noticed at some point and worked around instead of fixed - 
`JGroupsRaftAbstractTest.checkHeaders` asserts the other six and keeps this one 
commented out, referring to an `Address` type the file does not import:
   
   ```java
   
assertNotNull(exchange.getIn().getHeader(JGroupsRaftConstants.HEADER_JGROUPSRAFT_LAST_APPLIED,
 int.class));
   
//assertNotNull(exchange.getIn().getHeader(JGroupsRaftConstants.HEADER_JGROUPSRAFT_LEADER_ADDRESS,
 Address.class));
   
assertNotNull(exchange.getIn().getHeader(JGroupsRaftConstants.HEADER_JGROUPSRAFT_LOG_SIZE,
 int.class));
   ```
   
   ## Fix
   
   Set the header from `resolvedRaftHandle.leader()`, the same handle the other 
six come from. Nothing is renamed and no existing header changes, so this only 
fills in the one that was missing.
   
   The assertion goes back in, but as a separate `checkLeaderAddressHeader` 
called from `JGroupsRaftProducerTest` rather than from `checkHeaders`. The 
leader address is only known once an election has finished, and 
`JGroupsRaftConsumerTest` deliberately picks the exchange of a `LEADER` role 
change event, whose headers were populated while the election was still running 
- that one may legitimately carry no address, which is presumably why the 
assertion was commented out rather than moved. The producer test creates its 
exchanges after `waitForLeader` has confirmed that every handle knows the 
leader, so there it holds.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to