RandomReplicaLoadBalanceAlgorithm implements ReplicaLoadBalanceAlgorithm { @Override public String getDataSource(final String name, final String primaryDataSourceName, final List<String> replicaDataSourceNames) { return replicaDataSourceNames.get(ThreadLocalRandom.current().nextInt(replicaDataSourceNames.size())); }  @Override String getDataSource(final String name, final String primaryDataSourceName, final List<String> replicaDataSourceNames); @Override String getType();  }
@Test public void assertGetDataSource() { String primaryDataSourceName = "test_primary_ds"; String replicaDataSourceName1 = "test_replica_ds_1"; String replicaDataSourceName2 = "test_replica_ds_2"; List<String> replicaDataSourceNames = Arrays.asList(replicaDataSourceName1, replicaDataSourceName2); assertTrue(replicaDataSourceNames.contains(randomReplicaLoadBalanceAlgorithm.getDataSource("ds", primaryDataSourceName, replicaDataSourceNames))); assertTrue(replicaDataSourceNames.contains(randomReplicaLoadBalanceAlgorithm.getDataSource("ds", primaryDataSourceName, replicaDataSourceNames))); assertTrue(replicaDataSourceNames.contains(randomReplicaLoadBalanceAlgorithm.getDataSource("ds", primaryDataSourceName, replicaDataSourceNames))); }