diff options
author | Harald Musum <musum@verizonmedia.com> | 2020-07-29 15:48:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-29 15:48:39 +0200 |
commit | 1819c6fa4d0deb3f84871e74ec023ed1f4e5cc2b (patch) | |
tree | e90074e6d5bd889124238767232e24ab79f0e65c | |
parent | fb30d3667ab506976c776817aa3451f97ceed83a (diff) | |
parent | 426f7440c15e09854d75bc1835d205abaac03ec8 (diff) |
Merge pull request #13866 from vespa-engine/hmusum/less-hardcoding-in-mock
Do not hardcode entries and source host in mock
4 files changed, 23 insertions, 37 deletions
diff --git a/config-application-package/src/main/java/com/yahoo/config/model/application/provider/MockFileRegistry.java b/config-application-package/src/main/java/com/yahoo/config/model/application/provider/MockFileRegistry.java index e9c100938dd..b3d2b061430 100644 --- a/config-application-package/src/main/java/com/yahoo/config/model/application/provider/MockFileRegistry.java +++ b/config-application-package/src/main/java/com/yahoo/config/model/application/provider/MockFileRegistry.java @@ -3,37 +3,30 @@ package com.yahoo.config.model.application.provider; import com.yahoo.config.FileReference; import com.yahoo.config.application.api.FileRegistry; +import com.yahoo.net.HostName; import java.util.ArrayList; -import java.util.Collections; import java.util.List; -import java.util.Set; /** * A file registry for testing, and, it seems, doubling as a null registry in some code paths. * * @author Tony Vaagenes + * @author hmusum */ public class MockFileRegistry implements FileRegistry { + private final List<Entry> entries = new ArrayList<>(); public FileReference addFile(String relativePath) { - return new FileReference("0123456789abcdef"); + FileReference fileReference = new FileReference(relativePath); + entries.add(new Entry(relativePath, fileReference)); + return fileReference; } @Override - public String fileSourceHost() { - return "localhost.fortestingpurposesonly"; - } - - public static final Entry entry1 = new Entry("component/path1", new FileReference("1234")); - public static final Entry entry2 = new Entry("component/path2", new FileReference("56789")); + public String fileSourceHost() { return HostName.getLocalhost(); } - public List<Entry> export() { - List<Entry> result = new ArrayList<>(); - result.add(entry1); - result.add(entry2); - return result; - } + public List<Entry> export() { return entries; } @Override public FileReference addUri(String uri) { diff --git a/config-application-package/src/test/java/com/yahoo/config/model/application/provider/PreGeneratedFileRegistryTestCase.java b/config-application-package/src/test/java/com/yahoo/config/model/application/provider/PreGeneratedFileRegistryTestCase.java index e2b75542a5f..4b2f5890a4e 100644 --- a/config-application-package/src/test/java/com/yahoo/config/model/application/provider/PreGeneratedFileRegistryTestCase.java +++ b/config-application-package/src/test/java/com/yahoo/config/model/application/provider/PreGeneratedFileRegistryTestCase.java @@ -1,11 +1,13 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.config.model.application.provider; +import com.yahoo.config.FileReference; import com.yahoo.config.application.api.FileRegistry; import org.junit.Test; import java.io.StringReader; -import java.util.Arrays; +import java.util.List; +import java.util.Set; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -14,27 +16,21 @@ import static org.junit.Assert.assertTrue; * @author Tony Vaagenes */ public class PreGeneratedFileRegistryTestCase { + @Test public void importAndExport() { FileRegistry fileRegistry = new MockFileRegistry(); + fileRegistry.addFile("1234"); String serializedRegistry = PreGeneratedFileRegistry.exportRegistry(fileRegistry); - PreGeneratedFileRegistry importedRegistry = - PreGeneratedFileRegistry.importRegistry( - new StringReader(serializedRegistry)); - - assertTrue(importedRegistry.getPaths().containsAll( - Arrays.asList( - MockFileRegistry.entry1.relativePath, - MockFileRegistry.entry2.relativePath))); + PreGeneratedFileRegistry importedRegistry = PreGeneratedFileRegistry.importRegistry(new StringReader(serializedRegistry)); - assertEquals(2, importedRegistry.getPaths().size()); + assertEquals(Set.of("1234"), importedRegistry.getPaths()); - checkConsistentEntry(MockFileRegistry.entry1, importedRegistry); - checkConsistentEntry(MockFileRegistry.entry2, importedRegistry); + assertEquals(1, importedRegistry.getPaths().size()); - assertEquals(fileRegistry.fileSourceHost(), - importedRegistry.fileSourceHost()); + checkConsistentEntry(fileRegistry.export().get(0), importedRegistry); + assertEquals(fileRegistry.fileSourceHost(), importedRegistry.fileSourceHost()); } void checkConsistentEntry(FileRegistry.Entry entry, FileRegistry registry) { diff --git a/config-model/src/main/java/com/yahoo/vespa/model/HostSystem.java b/config-model/src/main/java/com/yahoo/vespa/model/HostSystem.java index 0192e9d42c6..6213f0592fd 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/HostSystem.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/HostSystem.java @@ -70,8 +70,7 @@ public class HostSystem extends AbstractConfigProducer<Host> { HostResource hostResource = hostname2host.get(name); if (hostResource == null) { // Create a new HostResource if this is the host this code is running on (as it is when running tests) - // TODO: please eliminate the ugly hack using "localhost.fortestingpurposesonly" - if (HostName.getLocalhost().equals(name) || "localhost.fortestingpurposesonly".equals(name)) { + if (HostName.getLocalhost().equals(name)) { if (! getChildren().containsKey(localhost)) { new Host(this, localhost); } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/filedistribution/FileDistributor.java b/config-model/src/main/java/com/yahoo/vespa/model/filedistribution/FileDistributor.java index 5ccf86f9ba8..fb9402614f6 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/filedistribution/FileDistributor.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/filedistribution/FileDistributor.java @@ -11,10 +11,10 @@ import com.yahoo.vespa.model.Host; import java.util.*; /** - * Sends RPC requests to hosts (tenant hosts and config servers) to start download of files. This is used during prepare - * of an application. Services themselves will also request files, the work done in this class is done so that hosts can - * start downloading files before services gets new config that needs these files. This also tries to make sure that - * all config servers (not just the one where the application was deployed) have the files available. + * Sends RPC requests to hosts (tenant hosts and config servers) asking them to start download of files. This is used + * during prepare of an application. Services themselves will also request files, the methods in this class are used + * so that hosts can start downloading files before services gets new config that needs these files. It also tries + * to make sure that all config servers (not just the one where the application was deployed) have the files available. * * @author Tony Vaagenes */ @@ -36,7 +36,6 @@ public class FileDistributor { /** * Adds the given file to the associated application packages' registry of file and marks the file * for distribution to the given host. - * <b>Note: This class receives ownership of the given collection.</b> * * @return the reference to the file, created by the application package */ @@ -47,7 +46,6 @@ public class FileDistributor { /** * Adds the given file to the associated application packages' registry of file and marks the file * for distribution to the given host. - * <b>Note: This class receives ownership of the given collection.</b> * * @return the reference to the file, created by the application package */ |