### Question:
ReadReplicaStatus extends BaseStatus { @Override public Response description() { Collection<MemberId> votingMembers = topologyService.allCoreRoles().keySet(); boolean isHealthy = dbHealth.isHealthy(); MemberId memberId = topologyService.myself(); MemberId leader = topologyService.allCoreRoles() .keySet() .stream() .filter( member -> RoleInfo.LEADER.equals( topologyService.allCoreRoles().get( member ) ) ) .findFirst() .orElse( null ); long lastAppliedRaftIndex = commandIndexTracker.getAppliedCommandIndex(); Duration millisSinceLastLeaderMessage = null; return statusResponse( lastAppliedRaftIndex, false, votingMembers, isHealthy, memberId, leader, millisSinceLastLeaderMessage, false ); } ReadReplicaStatus( OutputFormat output, ReadReplicaGraphDatabase db ); @Override Response discover(); @Override Response available(); @Override Response readonly(); @Override Response writable(); @Override Response description();  }### Answer:
@Test public void statusIncludesAppliedRaftLogIndex() throws IOException { commandIndexTracker.setAppliedCommandIndex( 321 ); Response description = status.description(); Map<String,Object> responseJson = responseAsMap( description ); assertEquals( 321, responseJson.get( "lastAppliedRaftIndex" ) ); }
@Test public void responseIncludesAllCoresAndReplicas() throws IOException { Response description = status.description(); assertEquals( Response.Status.OK.getStatusCode(), description.getStatus() ); ArrayList<String> expectedVotingMembers = topologyService.allCoreServers() .members() .keySet() .stream() .map( memberId -> memberId.getUuid().toString() ) .collect( Collectors.toCollection( ArrayList::new ) ); Map<String,Object> responseJson = responseAsMap( description ); List<String> actualVotingMembers = (List<String>) responseJson.get( "votingMembers" ); Collections.sort( expectedVotingMembers ); Collections.sort( actualVotingMembers ); assertEquals( expectedVotingMembers, actualVotingMembers ); }
@Test public void dbHealthIsIncludedInResponse() throws IOException { Response description = status.description(); assertEquals( true, responseAsMap( description ).get( "healthy" ) ); databaseHealth.panic( new RuntimeException() ); description = status.description(); assertEquals( false, responseAsMap( description ).get( "healthy" ) ); }
@Test public void includesMemberId() throws IOException { Response description = status.description(); assertEquals( myself.getUuid().toString(), responseAsMap( description ).get( "memberId" ) ); }
@Test public void leaderIsOptional() throws IOException { Response description = status.description(); assertFalse( responseAsMap( description ).containsKey( "leader" ) ); MemberId selectedLead = topologyService.allCoreServers() .members() .keySet() .stream() .findFirst() .orElseThrow( () -> new IllegalStateException( "No cores in topology" ) ); topologyService.replaceWithRole( selectedLead, RoleInfo.LEADER ); description = status.description(); assertEquals( selectedLead.getUuid().toString(), responseAsMap( description ).get( "leader" ) ); }
@Test public void isNotCore() throws IOException { Response description = status.description(); assertTrue( responseAsMap( description ).containsKey( "core" ) ); assertEquals( false, responseAsMap( status.description() ).get( "core" ) ); }