Added test for bootstrap random host selection.

This commit is contained in:
CalDescent
2021-10-06 18:23:17 +01:00
parent 2f6a8f793b
commit 8d6dffb3ff
2 changed files with 32 additions and 4 deletions

View File

@@ -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"));