### Question:
ConnectRandomlyToServerGroupStrategy extends UpstreamDatabaseSelectionStrategy { @Override public Optional<MemberId> upstreamDatabase() { return strategyImpl.upstreamDatabase(); } ConnectRandomlyToServerGroupStrategy(); @Override void init(); @Override Optional<MemberId> upstreamDatabase();  }### Answer:
@Test public void shouldConnectToGroupDefinedInStrategySpecificConfig() { final String targetServerGroup = "target_server_group"; Config configWithTargetServerGroup = Config.defaults( CausalClusteringSettings.connect_randomly_to_server_group_strategy, targetServerGroup ); MemberId[] targetGroupMemberIds = memberIDs( 10 ); TopologyService topologyService = ConnectRandomlyToServerGroupStrategyImplTest.getTopologyService( Collections.singletonList( targetServerGroup ), targetGroupMemberIds, Collections.singletonList( "your_server_group" ) ); ConnectRandomlyToServerGroupStrategy strategy = new ConnectRandomlyToServerGroupStrategy(); strategy.inject( topologyService, configWithTargetServerGroup, NullLogProvider.getInstance(), targetGroupMemberIds[0] ); Optional<MemberId> result = strategy.upstreamDatabase(); assertThat( result, contains( isIn( targetGroupMemberIds ) ) ); }
@Test public void doesNotConnectToSelf() { ConnectRandomlyToServerGroupStrategy connectRandomlyToServerGroupStrategy = new ConnectRandomlyToServerGroupStrategy(); MemberId myself = new MemberId( new UUID( 1234, 5678 ) ); LogProvider logProvider = NullLogProvider.getInstance(); Config config = Config.defaults(); config.augment( CausalClusteringSettings.connect_randomly_to_server_group_strategy, "firstGroup" ); TopologyService topologyService = new TopologyServiceThatPrioritisesItself( myself, "firstGroup" ); connectRandomlyToServerGroupStrategy.inject( topologyService, config, logProvider, myself ); Optional<MemberId> found = connectRandomlyToServerGroupStrategy.upstreamDatabase(); assertTrue( found.isPresent() ); assertNotEquals( myself, found.get() ); }