### Question:
ConnectRandomlyWithinServerGroupStrategy extends UpstreamDatabaseSelectionStrategy { @Override public Optional<MemberId> upstreamDatabase() { return strategyImpl.upstreamDatabase(); } ConnectRandomlyWithinServerGroupStrategy(); @Override void init(); @Override Optional<MemberId> upstreamDatabase(); static final String IDENTITY; }### Answer:
@Test public void shouldUseServerGroupsFromConfig() { final String myServerGroup = "my_server_group"; Config configWithMyServerGroup = Config.defaults( CausalClusteringSettings.server_groups, myServerGroup ); MemberId[] myGroupMemberIds = memberIDs( 10 ); TopologyService topologyService = ConnectRandomlyToServerGroupStrategyImplTest.getTopologyService( Collections.singletonList( myServerGroup ), myGroupMemberIds, Collections.singletonList( "your_server_group" ) ); ConnectRandomlyWithinServerGroupStrategy strategy = new ConnectRandomlyWithinServerGroupStrategy(); strategy.inject( topologyService, configWithMyServerGroup, NullLogProvider.getInstance(), myGroupMemberIds[0] ); Optional<MemberId> result = strategy.upstreamDatabase(); assertThat( result, contains( isIn( myGroupMemberIds ) ) ); }
@Test public void filtersSelf() { String groupName = "groupName"; Config config = Config.defaults(); config.augment( CausalClusteringSettings.server_groups, groupName ); ConnectRandomlyWithinServerGroupStrategy connectRandomlyWithinServerGroupStrategy = new ConnectRandomlyWithinServerGroupStrategy(); MemberId myself = new MemberId( new UUID( 123, 456 ) ); connectRandomlyWithinServerGroupStrategy.inject( new TopologyServiceThatPrioritisesItself( myself, groupName ), config, NullLogProvider.getInstance(), myself ); Optional<MemberId> result = connectRandomlyWithinServerGroupStrategy.upstreamDatabase(); Assert.assertTrue( result.isPresent() ); Assert.assertNotEquals( myself, result.get() ); }