mirror of
https://github.com/Qortal/qortal.git
synced 2025-07-23 04:36:50 +00:00
Added test for bootstrap random host selection.
This commit is contained in:
@@ -22,6 +22,7 @@ import java.nio.file.NoSuchFileException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
@@ -181,6 +182,28 @@ public class BootstrapTests extends Common {
|
||||
repository.saveChanges();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRandomHost() {
|
||||
String[] bootstrapHosts = Settings.getInstance().getBootstrapHosts();
|
||||
List<String> uniqueHosts = new ArrayList<>();
|
||||
|
||||
for (int i=0; i<1000; i++) {
|
||||
Bootstrap bootstrap = new Bootstrap();
|
||||
String randomHost = bootstrap.getRandomHost();
|
||||
assertNotNull(randomHost);
|
||||
|
||||
if (!uniqueHosts.contains(randomHost)){
|
||||
uniqueHosts.add(randomHost);
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure we have more than one bootstrap host in the settings
|
||||
assertTrue(Arrays.asList(bootstrapHosts).size() > 1);
|
||||
|
||||
// Ensure that all have been given the opportunity to be used
|
||||
assertEquals(uniqueHosts.size(), Arrays.asList(bootstrapHosts).size());
|
||||
}
|
||||
|
||||
private void deleteBootstraps() throws IOException {
|
||||
try {
|
||||
Path path = Paths.get(String.format("%s%s", Settings.getInstance().getBootstrapFilenamePrefix(), "bootstrap-archive.7z"));
|
||||
|
Reference in New Issue
Block a user