diff options
73 files changed, 711 insertions, 765 deletions
diff --git a/config-application-package/src/test/java/com/yahoo/config/application/ConfigDefinitionDirTest.java b/config-application-package/src/test/java/com/yahoo/config/application/ConfigDefinitionDirTest.java index b6b5936eda7..65e06a71583 100644 --- a/config-application-package/src/test/java/com/yahoo/config/application/ConfigDefinitionDirTest.java +++ b/config-application-package/src/test/java/com/yahoo/config/application/ConfigDefinitionDirTest.java @@ -12,8 +12,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.jar.JarFile; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; /** @@ -32,9 +31,9 @@ public class ConfigDefinitionDirTest { File defDir = temporaryFolder.newFolder(); ConfigDefinitionDir dir = new ConfigDefinitionDir(defDir); Bundle bundle = new Bundle(new JarFile(bundleFile), bundleFile); - assertThat(defDir.listFiles().length, is(0)); - dir.addConfigDefinitionsFromBundle(bundle, new ArrayList<Bundle>()); - assertThat(defDir.listFiles().length, is(1)); + assertEquals(0, defDir.listFiles().length); + dir.addConfigDefinitionsFromBundle(bundle, new ArrayList<>()); + assertEquals(1, defDir.listFiles().length); } @@ -62,10 +61,10 @@ public class ConfigDefinitionDirTest { try { dir.addConfigDefinitionsFromBundle(bundle2, bundlesAdded); } catch (IllegalArgumentException e) { - assertThat(e.getMessage(), - is("The config definition with name 'bar.foo' contained in the bundle '" + - bundleFileName + - "' conflicts with the same config definition in the bundle 'com.yahoo.searcher1.jar'. Please choose a different name.")); + assertEquals("The config definition with name 'bar.foo' contained in the bundle '" + + bundleFileName + + "' conflicts with the same config definition in the bundle 'com.yahoo.searcher1.jar'. Please choose a different name.", + e.getMessage()); } } } diff --git a/config-application-package/src/test/java/com/yahoo/config/application/PropertiesProcessorTest.java b/config-application-package/src/test/java/com/yahoo/config/application/PropertiesProcessorTest.java index fe9ca4a7951..41e08e00040 100644 --- a/config-application-package/src/test/java/com/yahoo/config/application/PropertiesProcessorTest.java +++ b/config-application-package/src/test/java/com/yahoo/config/application/PropertiesProcessorTest.java @@ -4,17 +4,12 @@ package com.yahoo.config.application; import org.custommonkey.xmlunit.XMLUnit; import org.junit.Test; import org.w3c.dom.Document; -import org.xml.sax.SAXException; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.stream.XMLStreamException; import javax.xml.transform.TransformerException; -import java.io.IOException; import java.io.StringReader; import java.util.Map; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertEquals; /** * @author hmusum @@ -44,9 +39,9 @@ public class PropertiesProcessorTest { PropertiesProcessor p = new PropertiesProcessor(); p.process(Xml.getDocument(new StringReader(input))); Map<String, String> properties = p.getProperties(); - assertThat(properties.size(), is(2)); - assertThat(properties.get("slobrok.port"), is("4099")); - assertThat(properties.get("redundancy"), is("2")); + assertEquals(2, properties.size()); + assertEquals("4099", properties.get("slobrok.port")); + assertEquals("2", properties.get("redundancy")); } @Test diff --git a/config-application-package/src/test/java/com/yahoo/config/model/application/provider/FilesApplicationPackageTest.java b/config-application-package/src/test/java/com/yahoo/config/model/application/provider/FilesApplicationPackageTest.java index 44656f8f534..be4d8fdab25 100644 --- a/config-application-package/src/test/java/com/yahoo/config/model/application/provider/FilesApplicationPackageTest.java +++ b/config-application-package/src/test/java/com/yahoo/config/model/application/provider/FilesApplicationPackageTest.java @@ -15,14 +15,11 @@ import org.xml.sax.SAXException; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.TransformerException; import java.io.File; -import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; -import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; /** @@ -92,7 +89,7 @@ public class FilesApplicationPackageTest { FilesApplicationPackage app = FilesApplicationPackage.fromFile(appDir); assertTrue(app.getDeployment().isPresent()); assertFalse(app.getMajorVersion().isPresent()); - assertThat(IOUtils.readAll(new FileReader(deployment)), is(IOUtils.readAll(app.getDeployment().get()))); + assertEquals(IOUtils.readAll(app.getDeployment().get()), IOUtils.readAll(new FileReader(deployment))); } @Test @@ -104,7 +101,7 @@ public class FilesApplicationPackageTest { assertTrue(app.getDeployment().isPresent()); assertTrue(app.getMajorVersion().isPresent()); assertEquals(6, (int)app.getMajorVersion().get()); - assertThat(IOUtils.readAll(new FileReader(deployment)), is(IOUtils.readAll(app.getDeployment().get()))); + assertEquals(IOUtils.readAll(app.getDeployment().get()), IOUtils.readAll(new FileReader(deployment))); } } diff --git a/config-application-package/src/test/java/com/yahoo/config/model/application/provider/StaticConfigDefinitionRepoTest.java b/config-application-package/src/test/java/com/yahoo/config/model/application/provider/StaticConfigDefinitionRepoTest.java index 0f32ff46b9f..1cfd737a857 100644 --- a/config-application-package/src/test/java/com/yahoo/config/model/application/provider/StaticConfigDefinitionRepoTest.java +++ b/config-application-package/src/test/java/com/yahoo/config/model/application/provider/StaticConfigDefinitionRepoTest.java @@ -1,7 +1,6 @@ // 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.model.application.provider.StaticConfigDefinitionRepo; import com.yahoo.config.model.api.ConfigDefinitionRepo; import com.yahoo.io.IOUtils; import com.yahoo.vespa.config.ConfigDefinitionKey; @@ -12,8 +11,7 @@ import org.junit.rules.TemporaryFolder; import java.io.File; import java.io.IOException; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertEquals; /** * @author Ulf Lilleengen @@ -31,7 +29,7 @@ public class StaticConfigDefinitionRepoTest { addFile(defDir, new ConfigDefinitionKey("foo", "foons"), "namespace=foons\nval int\n"); addFile(defDir, new ConfigDefinitionKey("bar", "barns"), "namespace=barns\nval string\n"); ConfigDefinitionRepo repo = new StaticConfigDefinitionRepo(defDir); - assertThat(repo.getConfigDefinitions().size(), is(2)); + assertEquals(2, repo.getConfigDefinitions().size()); } private void addFile(File defDir, ConfigDefinitionKey key, String content) throws IOException { diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/http/FilterBindingsTest.java b/config-model/src/test/java/com/yahoo/vespa/model/container/http/FilterBindingsTest.java index f776db6f942..0f9de516a4b 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/container/http/FilterBindingsTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/container/http/FilterBindingsTest.java @@ -13,8 +13,7 @@ import org.junit.Test; import org.w3c.dom.Element; import static com.yahoo.collections.CollectionUtil.first; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; /** @@ -24,7 +23,7 @@ public class FilterBindingsTest extends DomBuilderTest { private static final String MY_CHAIN_BINDING = "http://*/my-chain-binding"; - private Http buildHttp(Element xml) throws Exception { + private Http buildHttp(Element xml) { Http http = new HttpBuilder().build(root.getDeployState(), root, xml); root.freezeModelTopology(); http.validate(); @@ -50,8 +49,8 @@ public class FilterBindingsTest extends DomBuilderTest { Http http = buildHttp(xml); Binding binding = first(http.getBindings()); - assertThat(binding.filterId().getName(), is("my-request-chain")); - assertThat(binding.binding(), is(MY_CHAIN_BINDING)); + assertEquals("my-request-chain", binding.filterId().getName()); + assertEquals(MY_CHAIN_BINDING, binding.binding()); Chain<Filter> myChain = http.getFilterChains().allChains().getComponent("my-request-chain"); assertNotNull("Missing chain", myChain); @@ -70,15 +69,15 @@ public class FilterBindingsTest extends DomBuilderTest { Http http = buildHttp(xml); Binding binding = first(http.getBindings()); - assertThat(binding.filterId().getName(), is("my-response-chain")); - assertThat(binding.binding(), is(MY_CHAIN_BINDING)); + assertEquals("my-response-chain", binding.filterId().getName()); + assertEquals(MY_CHAIN_BINDING, binding.binding()); Chain<Filter> myChain = http.getFilterChains().allChains().getComponent("my-response-chain"); assertNotNull("Missing chain", myChain); } @Test - public void bindings_are_added_to_config_for_all_http_servers_with_jetty() throws Exception { + public void bindings_are_added_to_config_for_all_http_servers_with_jetty() { final Element xml = parse( "<container version='1.0'>", " <http>", @@ -95,15 +94,15 @@ public class FilterBindingsTest extends DomBuilderTest { { final ServerConfig config = root.getConfig(ServerConfig.class, "container/http/jdisc-jetty/server1"); - assertThat(config.filter().size(), is(1)); - assertThat(config.filter(0).id(), is("my-request-chain")); - assertThat(config.filter(0).binding(), is(MY_CHAIN_BINDING)); + assertEquals(1, config.filter().size()); + assertEquals("my-request-chain", config.filter(0).id()); + assertEquals(MY_CHAIN_BINDING, config.filter(0).binding()); } { final ServerConfig config = root.getConfig(ServerConfig.class, "container/http/jdisc-jetty/server2"); - assertThat(config.filter().size(), is(1)); - assertThat(config.filter(0).id(), is("my-request-chain")); - assertThat(config.filter(0).binding(), is(MY_CHAIN_BINDING)); + assertEquals(1, config.filter().size()); + assertEquals("my-request-chain", config.filter(0).id()); + assertEquals(MY_CHAIN_BINDING, config.filter(0).binding()); } } diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/SearchBuilderTest.java b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/SearchBuilderTest.java index a2d13439f4e..b2f9c805be1 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/SearchBuilderTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/SearchBuilderTest.java @@ -20,11 +20,13 @@ import static com.yahoo.test.Matchers.hasItemWithMethod; import static com.yahoo.vespa.model.container.search.ContainerSearch.QUERY_PROFILE_REGISTRY_CLASS; import static com.yahoo.vespa.model.container.xml.ContainerModelBuilder.SEARCH_HANDLER_BINDING; import static com.yahoo.vespa.model.container.xml.ContainerModelBuilder.SEARCH_HANDLER_CLASS; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; /** * @author gjoranv @@ -46,7 +48,7 @@ public class SearchBuilderTest extends ContainerModelBuilderTestBase { createModel(root, clusterElem); String discBindingsConfig = root.getConfig(JdiscBindingsConfig.class, "default").toString(); - assertThat(discBindingsConfig, containsString(GUIHandler.BINDING)); + assertTrue(discBindingsConfig.contains(GUIHandler.BINDING)); ApplicationContainerCluster cluster = (ApplicationContainerCluster)root.getChildren().get("default"); @@ -56,7 +58,7 @@ public class SearchBuilderTest extends ContainerModelBuilderTestBase { guiHandler = (GUIHandler) handler; } } - if (guiHandler == null) fail(); + assertNotNull(guiHandler); } @Test @@ -73,9 +75,9 @@ public class SearchBuilderTest extends ContainerModelBuilderTestBase { createModel(root, clusterElem); String discBindingsConfig = root.getConfig(JdiscBindingsConfig.class, "default").toString(); - assertThat(discBindingsConfig, containsString(".serverBindings[0] \"binding0\"")); - assertThat(discBindingsConfig, containsString(".serverBindings[1] \"binding1\"")); - assertThat(discBindingsConfig, not(containsString("/search/*"))); + assertTrue(discBindingsConfig.contains(".serverBindings[0] \"binding0\"")); + assertTrue(discBindingsConfig.contains(".serverBindings[1] \"binding1\"")); + assertFalse(discBindingsConfig.contains("/search/*")); } @Test @@ -91,7 +93,7 @@ public class SearchBuilderTest extends ContainerModelBuilderTestBase { createModel(root, clusterElem); String discBindingsConfig = root.getConfig(JdiscBindingsConfig.class, "default").toString(); - assertThat(discBindingsConfig, not(containsString("/search/*"))); + assertFalse(discBindingsConfig.contains("/search/*")); } @Test @@ -109,8 +111,8 @@ public class SearchBuilderTest extends ContainerModelBuilderTestBase { createModel(root, clusterElem); var discBindingsConfig = root.getConfig(JdiscBindingsConfig.class, "default"); - assertThat(discBindingsConfig.handlers(myHandler).serverBindings(0), is(SEARCH_HANDLER_BINDING)); - assertThat(discBindingsConfig.handlers(SEARCH_HANDLER_CLASS), is(nullValue())); + assertEquals(SEARCH_HANDLER_BINDING, discBindingsConfig.handlers(myHandler).serverBindings(0)); + assertNull(discBindingsConfig.handlers(SEARCH_HANDLER_CLASS)); } // TODO: remove test when all containers are named 'container' @@ -118,7 +120,7 @@ public class SearchBuilderTest extends ContainerModelBuilderTestBase { public void cluster_with_only_search_gets_qrserver_as_service_name() { createClusterWithOnlyDefaultChains(); ApplicationContainerCluster cluster = (ApplicationContainerCluster)root.getChildren().get("default"); - assertThat(cluster.getContainers().get(0).getServiceName(), is(QRSERVER.serviceName)); + assertEquals(QRSERVER.serviceName, cluster.getContainers().get(0).getServiceName()); } @Test @@ -162,7 +164,7 @@ public class SearchBuilderTest extends ContainerModelBuilderTestBase { createModel(root, clusterElem); fail("Expected exception"); } catch (Exception e) { - assertThat(e.getMessage(), containsString("Setting up com.yahoo.search.handler.SearchHandler manually is not supported")); + assertTrue(e.getMessage().contains("Setting up com.yahoo.search.handler.SearchHandler manually is not supported")); } } diff --git a/config-model/src/test/java/com/yahoo/vespa/model/content/ContentClusterTest.java b/config-model/src/test/java/com/yahoo/vespa/model/content/ContentClusterTest.java index 0a97bcc700f..27c88ad2d1f 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/content/ContentClusterTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/content/ContentClusterTest.java @@ -40,12 +40,10 @@ import java.util.Collections; import java.util.List; import java.util.Optional; -import static com.yahoo.test.PatternMatcher.matchesPattern; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -796,7 +794,7 @@ public class ContentClusterTest extends ContentBaseTest { private static void assertPrepareRestartCommand(ContentCluster cluster) { Optional<String> command = cluster.getSearch().getSearchNodes().get(0).getPreShutdownCommand(); assertTrue(command.isPresent()); - assertThat(command.get(), matchesPattern(".*vespa-proton-cmd [0-9]+ prepareRestart")); + assertTrue(command.get().matches(".*vespa-proton-cmd [0-9]+ prepareRestart")); } private static void assertNoPreShutdownCommand(ContentCluster cluster) { diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/ConfigServerBootstrap.java b/configserver/src/main/java/com/yahoo/vespa/config/server/ConfigServerBootstrap.java index 2d296b0a691..0aab83d5a6a 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/ConfigServerBootstrap.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/ConfigServerBootstrap.java @@ -11,6 +11,8 @@ import com.yahoo.config.provision.TransientException; import com.yahoo.container.handler.VipStatus; import com.yahoo.container.jdisc.state.StateMonitor; import java.util.logging.Level; + +import com.yahoo.vespa.config.server.maintenance.ConfigServerMaintenance; import com.yahoo.vespa.config.server.rpc.RpcServer; import com.yahoo.vespa.config.server.version.VersionState; import com.yahoo.yolean.Exceptions; @@ -70,23 +72,25 @@ public class ConfigServerBootstrap extends AbstractComponent implements Runnable @SuppressWarnings("unused") @Inject public ConfigServerBootstrap(ApplicationRepository applicationRepository, RpcServer server, - VersionState versionState, StateMonitor stateMonitor, VipStatus vipStatus) { + VersionState versionState, StateMonitor stateMonitor, VipStatus vipStatus, + ConfigServerMaintenance configServerMaintenance) { this(applicationRepository, server, versionState, stateMonitor, vipStatus, BOOTSTRAP_IN_CONSTRUCTOR, EXIT_JVM, applicationRepository.configserverConfig().hostedVespa() ? VipStatusMode.VIP_STATUS_FILE - : VipStatusMode.VIP_STATUS_PROGRAMMATICALLY); + : VipStatusMode.VIP_STATUS_PROGRAMMATICALLY, + Optional.of(configServerMaintenance)); } // For testing only ConfigServerBootstrap(ApplicationRepository applicationRepository, RpcServer server, VersionState versionState, StateMonitor stateMonitor, VipStatus vipStatus, Mode mode, VipStatusMode vipStatusMode) { - this(applicationRepository, server, versionState, stateMonitor, vipStatus, mode, CONTINUE, vipStatusMode); + this(applicationRepository, server, versionState, stateMonitor, vipStatus, mode, CONTINUE, vipStatusMode, Optional.empty()); } private ConfigServerBootstrap(ApplicationRepository applicationRepository, RpcServer server, VersionState versionState, StateMonitor stateMonitor, VipStatus vipStatus, Mode mode, RedeployingApplicationsFails exitIfRedeployingApplicationsFails, - VipStatusMode vipStatusMode) { + VipStatusMode vipStatusMode, Optional<ConfigServerMaintenance> configServerMaintenance) { this.applicationRepository = applicationRepository; this.server = server; this.versionState = versionState; @@ -99,6 +103,10 @@ public class ConfigServerBootstrap extends AbstractComponent implements Runnable rpcServerExecutor = Executors.newSingleThreadExecutor(new DaemonThreadFactory("config server RPC server")); log.log(Level.FINE, "Bootstrap mode: " + mode + ", VIP status mode: " + vipStatusMode); initializing(vipStatusMode); + + // Run maintainers that cleans up zookeeper and disk usage before bootstrapping + configServerMaintenance.ifPresent(ConfigServerMaintenance::runBeforeBootstrap); + switch (mode) { case BOOTSTRAP_IN_SEPARATE_THREAD: this.serverThread = Optional.of(new Thread(this, "config server bootstrap thread")); diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/maintenance/ConfigServerMaintenance.java b/configserver/src/main/java/com/yahoo/vespa/config/server/maintenance/ConfigServerMaintenance.java index ecdca39dc72..fe72fda6f25 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/maintenance/ConfigServerMaintenance.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/maintenance/ConfigServerMaintenance.java @@ -59,4 +59,9 @@ public class ConfigServerMaintenance extends AbstractComponent { } } + public void runBeforeBootstrap() { + fileDistributionMaintainer.maintain(); + sessionsMaintainer.maintain(); + } + } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/PrepareParams.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/PrepareParams.java index fa1d90e0fb1..34974c00a84 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/PrepareParams.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/PrepareParams.java @@ -19,6 +19,7 @@ import com.yahoo.vespa.config.server.tenant.EndpointCertificateMetadataSerialize import java.time.Clock; import java.time.Duration; import java.util.List; +import java.util.Objects; import java.util.Optional; /** @@ -63,7 +64,7 @@ public final class PrepareParams { Optional<DockerImage> dockerImageRepository, Optional<AthenzDomain> athenzDomain, Optional<ApplicationRoles> applicationRoles) { this.timeoutBudget = timeoutBudget; - this.applicationId = applicationId; + this.applicationId = Objects.requireNonNull(applicationId); this.ignoreValidationErrors = ignoreValidationErrors; this.dryRun = dryRun; this.verbose = verbose; @@ -83,7 +84,7 @@ public final class PrepareParams { private boolean dryRun = false; private boolean verbose = false; private boolean isBootstrap = false; - private ApplicationId applicationId = ApplicationId.defaultId(); + private ApplicationId applicationId = null; private TimeoutBudget timeoutBudget = new TimeoutBudget(Clock.systemUTC(), Duration.ofSeconds(60)); private Optional<Version> vespaVersion = Optional.empty(); private List<ContainerEndpoint> containerEndpoints = null; diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionPreparerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionPreparerTest.java index 7d1554c3e19..e53f9270983 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionPreparerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionPreparerTest.java @@ -145,18 +145,18 @@ public class SessionPreparerTest { @Test public void require_that_application_validation_exception_is_ignored_if_forced() throws IOException { - prepare(invalidTestApp, new PrepareParams.Builder().ignoreValidationErrors(true).timeoutBudget(TimeoutBudgetTest.day()).build()); + prepare(invalidTestApp, new PrepareParams.Builder().applicationId(applicationId()).ignoreValidationErrors(true).timeoutBudget(TimeoutBudgetTest.day()).build()); } @Test public void require_that_zookeeper_is_not_written_to_if_dryrun() throws IOException { - prepare(testApp, new PrepareParams.Builder().dryRun(true).timeoutBudget(TimeoutBudgetTest.day()).build()); + prepare(testApp, new PrepareParams.Builder().applicationId(applicationId()).dryRun(true).timeoutBudget(TimeoutBudgetTest.day()).build()); assertFalse(configCurator.exists(sessionsPath.append(ConfigCurator.USERAPP_ZK_SUBPATH).append("services.xml").getAbsolute())); } @Test public void require_that_filedistribution_is_ignored_on_dryrun() throws IOException { - PrepareResult result = prepare(testApp, new PrepareParams.Builder().dryRun(true).build()); + PrepareResult result = prepare(testApp, new PrepareParams.Builder().applicationId(applicationId()).dryRun(true).build()); assertTrue(result.getFileRegistries().get(version321).export().isEmpty()); } @@ -171,7 +171,7 @@ public class SessionPreparerTest { FilesApplicationPackage app = getApplicationPackage(testApp); HostRegistry<ApplicationId> hostValidator = new HostRegistry<>(); hostValidator.update(applicationId("foo"), Collections.singletonList("mytesthost")); - preparer.prepare(hostValidator, new BaseDeployLogger(), new PrepareParams.Builder().build(), + preparer.prepare(hostValidator, new BaseDeployLogger(), new PrepareParams.Builder().applicationId(applicationId("default")).build(), Optional.empty(), tenantPath, Instant.now(), app.getAppDir(), app, new SessionZooKeeperClient(curator, sessionsPath)); } @@ -183,9 +183,11 @@ public class SessionPreparerTest { }; FilesApplicationPackage app = getApplicationPackage(testApp); HostRegistry<ApplicationId> hostValidator = new HostRegistry<>(); - hostValidator.update(applicationId("default"), Collections.singletonList("mytesthost")); - preparer.prepare(hostValidator, logger, new PrepareParams.Builder().build(), - Optional.empty(), tenantPath, Instant.now(), app.getAppDir(), app, new SessionZooKeeperClient(curator, sessionsPath)); + ApplicationId applicationId = applicationId(); + hostValidator.update(applicationId, Collections.singletonList("mytesthost")); + preparer.prepare(hostValidator, logger, new PrepareParams.Builder().applicationId(applicationId).build(), + Optional.empty(), tenantPath, Instant.now(), app.getAppDir(), app, + new SessionZooKeeperClient(curator, sessionsPath)); assertEquals(logged.toString(), ""); } @@ -327,7 +329,7 @@ public class SessionPreparerTest { } private void prepare(File app) throws IOException { - prepare(app, new PrepareParams.Builder().build()); + prepare(app, new PrepareParams.Builder().applicationId(applicationId()).build()); } private PrepareResult prepare(File app, PrepareParams params) throws IOException { @@ -348,6 +350,11 @@ public class SessionPreparerTest { new ApplicationId.Builder().tenant("testtenant").applicationName("testapp").build()); } + + private ApplicationId applicationId() { + return ApplicationId.from(TenantName.defaultName(), ApplicationName.from("default"), InstanceName.defaultName()); + } + private ApplicationId applicationId(String applicationName) { return ApplicationId.from(TenantName.defaultName(), ApplicationName.from(applicationName), InstanceName.defaultName()); diff --git a/container-disc/src/test/java/com/yahoo/container/jdisc/FilterBindingsProviderTest.java b/container-disc/src/test/java/com/yahoo/container/jdisc/FilterBindingsProviderTest.java index f9662dc9f98..e3039e88525 100644 --- a/container-disc/src/test/java/com/yahoo/container/jdisc/FilterBindingsProviderTest.java +++ b/container-disc/src/test/java/com/yahoo/container/jdisc/FilterBindingsProviderTest.java @@ -10,8 +10,6 @@ import com.yahoo.jdisc.application.UriPattern; import com.yahoo.jdisc.http.ServerConfig; import com.yahoo.jdisc.http.filter.RequestFilter; import com.yahoo.jdisc.http.filter.ResponseFilter; -import com.yahoo.jdisc.http.filter.SecurityRequestFilter; -import com.yahoo.jdisc.http.filter.SecurityResponseFilter; import com.yahoo.jdisc.http.server.FilterBindings; import org.hamcrest.Description; import org.hamcrest.Matcher; @@ -23,11 +21,11 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.CoreMatchers.nullValue; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; @@ -54,9 +52,9 @@ public class FilterBindingsProviderTest { final FilterBindings filterBindings = provider.get(); - assertThat(filterBindings, is(not(nullValue()))); - assertThat(filterBindings.getRequestFilters().iterator().hasNext(), is(false)); - assertThat(filterBindings.getResponseFilters().iterator().hasNext(), is(false)); + assertNotNull(filterBindings); + assertFalse(filterBindings.getRequestFilters().iterator().hasNext()); + assertFalse(filterBindings.getResponseFilters().iterator().hasNext()); } @Test @@ -93,21 +91,21 @@ public class FilterBindingsProviderTest { new ChainsConfig(new ChainsConfig.Builder()), availableRequestFilters, availableResponseFilters, - new ComponentRegistry<SecurityRequestFilter>(), - new ComponentRegistry<SecurityResponseFilter>()); + new ComponentRegistry<>(), + new ComponentRegistry<>()); // Set up the provider that we aim to test. final FilterBindingsProvider provider = new FilterBindingsProvider( new ComponentId("foo"), new ServerConfig(configBuilder), filterChainRepository, - new ComponentRegistry<SecurityRequestFilter>()); + new ComponentRegistry<>()); // Execute. final FilterBindings filterBindings = provider.get(); // Verify. - assertThat(filterBindings, is(not(nullValue()))); + assertNotNull(filterBindings); assertThat( filterBindings.getRequestFilters(), containsFilters(requestFilter1Instance, requestFilter2Instance)); @@ -150,7 +148,7 @@ public class FilterBindingsProviderTest { new ComponentRegistry<>()); fail("Dual-role filter should not be accepted"); } catch (RuntimeException e) { - assertThat(e.getMessage(), containsString("Invalid config")); + assertTrue(e.getMessage().contains("Invalid config")); } } @@ -175,7 +173,7 @@ public class FilterBindingsProviderTest { new ComponentRegistry<>()); fail("Config with unknown filter reference should not be accepted"); } catch (RuntimeException e) { - assertThat(e.getMessage(), containsString("Invalid config")); + assertTrue(e.getMessage().contains("Invalid config")); } } @@ -183,7 +181,7 @@ public class FilterBindingsProviderTest { @SuppressWarnings("varargs") private static <T> Matcher<? super BindingRepository<T>> containsFilters( final T... requiredInstances) { - return new TypeSafeMatcher<BindingRepository<T>>() { + return new TypeSafeMatcher<>() { private final Set<T> requiredFilterSet = new HashSet<>(Arrays.asList(requiredInstances)); @Override diff --git a/container-disc/src/test/java/com/yahoo/container/jdisc/metric/GarbageCollectionMetricsTest.java b/container-disc/src/test/java/com/yahoo/container/jdisc/metric/GarbageCollectionMetricsTest.java index 6a669d9f7f9..33dd1dade2f 100644 --- a/container-disc/src/test/java/com/yahoo/container/jdisc/metric/GarbageCollectionMetricsTest.java +++ b/container-disc/src/test/java/com/yahoo/container/jdisc/metric/GarbageCollectionMetricsTest.java @@ -9,8 +9,7 @@ import java.lang.management.ManagementFactory; import java.time.Duration; import java.util.LinkedList; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; @@ -29,7 +28,7 @@ public class GarbageCollectionMetricsTest { Duration interval = GarbageCollectionMetrics.REPORTING_INTERVAL; GarbageCollectionMetrics garbageCollectionMetrics = new GarbageCollectionMetrics(clock); - assertThat(garbageCollectionMetrics.getGcStatistics().keySet().size(), is(garbageCollectors)); + assertEquals(garbageCollectors, garbageCollectionMetrics.getGcStatistics().keySet().size()); clock.advance(interval.minus(Duration.ofMillis(10))); garbageCollectionMetrics.emitMetrics(metric); @@ -52,7 +51,7 @@ public class GarbageCollectionMetricsTest { private static void assertWindowLengths(GarbageCollectionMetrics gcm, int count) { for(LinkedList<GarbageCollectionMetrics.GcStats> window: gcm.getGcStatistics().values()) { - assertThat(window.size(), is(count)); + assertEquals(count, window.size()); } } } diff --git a/docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/DockerImplTest.java b/docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/DockerImplTest.java index 2f84f84249b..1ca6cd5662e 100644 --- a/docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/DockerImplTest.java +++ b/docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/DockerImplTest.java @@ -21,9 +21,8 @@ import org.mockito.ArgumentMatchers; import java.util.OptionalLong; -import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; @@ -70,7 +69,7 @@ public class DockerImplTest { final ProcessResult result = docker.executeInContainerAsUser( new ContainerName(containerId), "root", OptionalLong.empty(), command); - assertThat(result.getExitStatus(), is(exitCode)); + assertEquals(exitCode, result.getExitStatus()); } @Test diff --git a/docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/ProcessResultTest.java b/docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/ProcessResultTest.java index 0f1ad8a3466..590833151f2 100644 --- a/docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/ProcessResultTest.java +++ b/docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/ProcessResultTest.java @@ -3,21 +3,22 @@ package com.yahoo.vespa.hosted.dockerapi; import org.junit.Test; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; public class ProcessResultTest { @Test public void testBasicProperties() { ProcessResult processResult = new ProcessResult(0, "foo", "bar"); - assertThat(processResult.getExitStatus(), is(0)); - assertThat(processResult.getOutput(), is("foo")); - assertThat(processResult.isSuccess(), is(true)); + assertEquals(0, processResult.getExitStatus()); + assertEquals("foo", processResult.getOutput()); + assertTrue(processResult.isSuccess()); } @Test public void testSuccessFails() { ProcessResult processResult = new ProcessResult(1, "foo", "bar"); - assertThat(processResult.isSuccess(), is(false)); + assertFalse(processResult.isSuccess()); } } diff --git a/document/src/tests/annotation/annotation_test.cpp b/document/src/tests/annotation/annotation_test.cpp index 846504fda94..5e7fc325ecd 100644 --- a/document/src/tests/annotation/annotation_test.cpp +++ b/document/src/tests/annotation/annotation_test.cpp @@ -140,8 +140,8 @@ TEST("requireThatSpanTreeCanHaveMultipleLevels") { TEST("requireThatAnnotationsCanHaveValues") { PrimitiveDataType double_type(DataType::T_DOUBLE); StructDataType city_data_type; - city_data_type.addField(Field("latitude", 0, double_type, false)); - city_data_type.addField(Field("longitude", 1, double_type, false)); + city_data_type.addField(Field("latitude", 0, double_type)); + city_data_type.addField(Field("longitude", 1, double_type)); StructFieldValue::UP position(new StructFieldValue(city_data_type)); position->setValue("latitude", DoubleFieldValue(37.774929)); @@ -162,14 +162,12 @@ TEST("requireThatAnnotationsCanReferenceAnnotations") { AnnotationReferenceDataType annotation_ref_type(text_type, 101); ArrayDataType array_type(annotation_ref_type); StructDataType city_data_type("name", 42); - city_data_type.addField(Field("references", 0, array_type, false)); + city_data_type.addField(Field("references", 0, array_type)); StructFieldValue::UP city_data(new StructFieldValue(city_data_type)); ArrayFieldValue ref_list(array_type); - ref_list.add(AnnotationReferenceFieldValue(annotation_ref_type, - san_index)); - ref_list.add(AnnotationReferenceFieldValue(annotation_ref_type, - fran_index)); + ref_list.add(AnnotationReferenceFieldValue(annotation_ref_type, san_index)); + ref_list.add(AnnotationReferenceFieldValue(annotation_ref_type, fran_index)); city_data->setValue("references", ref_list); StructFieldValue original(*city_data); diff --git a/document/src/tests/datatype/datatype_test.cpp b/document/src/tests/datatype/datatype_test.cpp index fff913a0f91..1e9b9ad64fa 100644 --- a/document/src/tests/datatype/datatype_test.cpp +++ b/document/src/tests/datatype/datatype_test.cpp @@ -51,8 +51,8 @@ TEST("require that assignment operator works for LongFieldValue") { TEST("require that StructDataType can redeclare identical fields.") { StructDataType s("foo"); - Field field1("field1", 42, *DataType::STRING, true); - Field field2("field2", 42, *DataType::STRING, true); + Field field1("field1", 42, *DataType::STRING); + Field field2("field2", 42, *DataType::STRING); s.addField(field1); s.addField(field1); // ok diff --git a/document/src/tests/documentselectparsertest.cpp b/document/src/tests/documentselectparsertest.cpp index b75d094459b..6fd9ab80faa 100644 --- a/document/src/tests/documentselectparsertest.cpp +++ b/document/src/tests/documentselectparsertest.cpp @@ -1002,7 +1002,7 @@ TEST_F(DocumentSelectParserTest, testBodyFieldDetection) select::BodyFieldDetector detector(*_repo); root->visit(detector); - EXPECT_TRUE(!detector.foundBodyField); + EXPECT_FALSE(detector.foundBodyField); EXPECT_TRUE(detector.foundHeaderField); } @@ -1011,7 +1011,7 @@ TEST_F(DocumentSelectParserTest, testBodyFieldDetection) select::BodyFieldDetector detector(*_repo); root->visit(detector); - EXPECT_TRUE(!detector.foundBodyField); + EXPECT_FALSE(detector.foundBodyField); EXPECT_TRUE(detector.foundHeaderField); } @@ -1020,7 +1020,7 @@ TEST_F(DocumentSelectParserTest, testBodyFieldDetection) select::BodyFieldDetector detector(*_repo); root->visit(detector); - EXPECT_TRUE(!detector.foundBodyField); + EXPECT_FALSE(detector.foundBodyField); EXPECT_TRUE(detector.foundHeaderField); } @@ -1029,7 +1029,7 @@ TEST_F(DocumentSelectParserTest, testBodyFieldDetection) select::BodyFieldDetector detector(*_repo); root->visit(detector); - EXPECT_TRUE(detector.foundBodyField); + EXPECT_FALSE(detector.foundBodyField); } { @@ -1040,7 +1040,7 @@ TEST_F(DocumentSelectParserTest, testBodyFieldDetection) select::BodyFieldDetector detector(*_repo); root->visit(detector); - EXPECT_TRUE(!detector.foundBodyField); + EXPECT_FALSE(detector.foundBodyField); } } diff --git a/document/src/tests/documenttestcase.cpp b/document/src/tests/documenttestcase.cpp index 968470e9693..e917e33f9ef 100644 --- a/document/src/tests/documenttestcase.cpp +++ b/document/src/tests/documenttestcase.cpp @@ -92,29 +92,29 @@ Handler::~Handler() = default; TEST(DocumentTest, testTraversing) { - Field primitive1("primitive1", 1, *DataType::INT, true); - Field primitive2("primitive2", 2, *DataType::INT, true); + Field primitive1("primitive1", 1, *DataType::INT); + Field primitive2("primitive2", 2, *DataType::INT); StructDataType struct1("struct1"); struct1.addField(primitive1); struct1.addField(primitive2); ArrayDataType iarr(*DataType::INT); ArrayDataType sarr(struct1); - Field iarrF("iarray", 21, iarr, true); - Field sarrF("sarray", 22, sarr, true); + Field iarrF("iarray", 21, iarr); + Field sarrF("sarray", 22, sarr); StructDataType struct2("struct2"); struct2.addField(primitive1); struct2.addField(primitive2); struct2.addField(iarrF); struct2.addField(sarrF); - Field s2("ss", 12, struct2, true); + Field s2("ss", 12, struct2); StructDataType struct3("struct3"); struct3.addField(primitive1); struct3.addField(s2); - Field structl1s1("l1s1", 11, struct3, true); + Field structl1s1("l1s1", 11, struct3); DocumentType type("test"); type.addField(primitive1); @@ -175,7 +175,7 @@ TEST(DocumentTest, testVariables) ArrayDataType iiarr(static_cast<DataType &>(iarr)); ArrayDataType iiiarr(static_cast<DataType &>(iiarr)); - Field iiiarrF("iiiarray", 1, iiiarr, true); + Field iiiarrF("iiiarray", 1, iiiarr); DocumentType type("test"); type.addField(iiiarrF); @@ -255,19 +255,19 @@ public: TEST(DocumentTest, testModifyDocument) { // Create test document type and content - Field primitive1("primitive1", 1, *DataType::INT, true); - Field primitive2("primitive2", 2, *DataType::INT, true); + Field primitive1("primitive1", 1, *DataType::INT); + Field primitive2("primitive2", 2, *DataType::INT); StructDataType struct1("struct1"); struct1.addField(primitive1); struct1.addField(primitive2); ArrayDataType iarr(*DataType::INT); ArrayDataType sarr(struct1); - Field iarrF("iarray", 21, iarr, true); - Field sarrF("sarray", 22, sarr, true); + Field iarrF("iarray", 21, iarr); + Field sarrF("sarray", 22, sarr); MapDataType smap(*DataType::STRING, *DataType::STRING); - Field smapF("smap", 23, smap, true); + Field smapF("smap", 23, smap); StructDataType struct2("struct2"); struct2.addField(primitive1); @@ -275,16 +275,16 @@ TEST(DocumentTest, testModifyDocument) struct2.addField(iarrF); struct2.addField(sarrF); struct2.addField(smapF); - Field s2("ss", 12, struct2, true); + Field s2("ss", 12, struct2); MapDataType structmap(*DataType::STRING, struct2); - Field structmapF("structmap", 24, structmap, true); + Field structmapF("structmap", 24, structmap); WeightedSetDataType wset(*DataType::STRING, false, false); - Field wsetF("wset", 25, wset, true); + Field wsetF("wset", 25, wset); WeightedSetDataType structwset(struct2, false, false); - Field structwsetF("structwset", 26, structwset, true); + Field structwsetF("structwset", 26, structwset); StructDataType struct3("struct3"); struct3.addField(primitive1); @@ -293,7 +293,7 @@ TEST(DocumentTest, testModifyDocument) struct3.addField(wsetF); struct3.addField(structwsetF); - Field structl1s1("l1s1", 11, struct3, true); + Field structl1s1("l1s1", 11, struct3); DocumentType type("test"); type.addField(primitive1); @@ -363,9 +363,9 @@ TEST(DocumentTest, testModifyDocument) TEST(DocumentTest, testSimpleUsage) { DocumentType::SP type(new DocumentType("test")); - Field intF("int", 1, *DataType::INT, true); - Field longF("long", 2, *DataType::LONG, true); - Field strF("content", 4, *DataType::STRING, false); + Field intF("int", 1, *DataType::INT); + Field longF("long", 2, *DataType::LONG); + Field strF("content", 4, *DataType::STRING); type->addField(intF); type->addField(longF); @@ -462,9 +462,9 @@ TEST(DocumentTest, testSimpleUsage) " DocumentType(test, id -877171244)\n" " : DocumentType(document) {\n" " StructDataType(test.header, id 306916075) {\n" -" Field(content, id 4, PrimitiveDataType(String, id 2), body)\n" -" Field(int, id 1, NumericDataType(Int, id 0), header)\n" -" Field(long, id 2, NumericDataType(Long, id 4), header)\n" +" Field(content, id 4, PrimitiveDataType(String, id 2))\n" +" Field(int, id 1, NumericDataType(Int, id 0))\n" +" Field(long, id 2, NumericDataType(Long, id 4))\n" " }\n" " }\n" " int: 1\n" @@ -484,7 +484,7 @@ TEST(DocumentTest, testSimpleUsage) // Fetch a field not existing in type // (Would be nice if this failed, but whole idea to fetch by field // objects is to improve performance.) - Field anotherIntF("int", 17, *DataType::INT, true); + Field anotherIntF("int", 17, *DataType::INT); EXPECT_TRUE(!value.hasValue(anotherIntF)); EXPECT_TRUE(!value.getValue(anotherIntF)); @@ -1096,10 +1096,10 @@ TEST(DocumentTest, testUnknownEntries) // We should be able to deserialize a document with unknown values in it. DocumentType type1("test", 0); DocumentType type2("test", 0); - Field field1("int1", *DataType::INT, true); - Field field2("int2", *DataType::INT, true); - Field field3("int3", *DataType::INT, false); - Field field4("int4", *DataType::INT, false); + Field field1("int1", *DataType::INT); + Field field2("int2", *DataType::INT); + Field field3("int3", *DataType::INT); + Field field4("int4", *DataType::INT); type1.addField(field1); type1.addField(field2); diff --git a/document/src/tests/documenttypetestcase.cpp b/document/src/tests/documenttypetestcase.cpp index caddfbc70fc..901f02652fb 100644 --- a/document/src/tests/documenttypetestcase.cpp +++ b/document/src/tests/documenttypetestcase.cpp @@ -5,7 +5,6 @@ #include <vespa/document/repo/configbuilder.h> #include <vespa/document/repo/documenttyperepo.h> #include <vespa/vespalib/testkit/test_kit.h> -#include <vespa/vespalib/util/exceptions.h> #include <gtest/gtest.h> #include <gmock/gmock.h> @@ -22,8 +21,8 @@ TEST(DocumentTypeTest, testSetGet) { DocumentType docType("doctypetestdoc", 0); - docType.addField(Field("stringattr", 3, *DataType::STRING, true)); - docType.addField(Field("nalle", 0, *DataType::INT, false)); + docType.addField(Field("stringattr", 3, *DataType::STRING)); + docType.addField(Field("nalle", 0, *DataType::INT)); const Field& fetch1 = docType.getField("stringattr"); const Field& fetch2 = docType.getField("stringattr"); @@ -42,17 +41,11 @@ TEST(DocumentTypeTest, testSetGet) void categorizeFields(const Field::Set& fields, - std::vector<const Field*>& headers, - std::vector<const Field*>& bodies) + std::vector<const Field*>& headers) { - for (Field::Set::const_iterator it(fields.begin()), e(fields.end()); - it != e; ++it) + for (const Field * field : fields) { - if ((*it)->isHeaderField()) { - headers.push_back(*it); - } else { - bodies.push_back(*it); - } + headers.push_back(field); } } @@ -81,18 +74,15 @@ TEST(DocumentTypeTest, testHeaderContent) Field::Set fields = type->getFieldsType().getFieldSet(); std::vector<const Field*> headers; - std::vector<const Field*> bodies; - categorizeFields(fields, headers, bodies); + categorizeFields(fields, headers); - EXPECT_TRUE(headers.size() == 4); + EXPECT_TRUE(headers.size() == 6); EXPECT_TRUE(headers[0]->getName() == "field1"); EXPECT_TRUE(headers[1]->getName() == "field2"); - EXPECT_TRUE(headers[2]->getName() == "field4"); - EXPECT_TRUE(headers[3]->getName() == "fieldarray1"); - - EXPECT_TRUE(bodies.size() == 2); - EXPECT_TRUE(bodies[0]->getName() == "field3"); - EXPECT_TRUE(bodies[1]->getName() == "field5"); + EXPECT_TRUE(headers[2]->getName() == "field3"); + EXPECT_TRUE(headers[3]->getName() == "field4"); + EXPECT_TRUE(headers[4]->getName() == "field5"); + EXPECT_TRUE(headers[5]->getName() == "fieldarray1"); } TEST(DocumentTypeTest, testMultipleInheritance) @@ -142,8 +132,8 @@ bool containsField(const DocumentType::FieldSet &fieldSet, const vespalib::strin TEST(DocumentTypeTest, testFieldSetCanContainFieldsNotInDocType) { DocumentType docType("test1"); - docType.addField(Field("stringattr", 3, *DataType::STRING, false)); - docType.addField(Field("nalle", 0, *DataType::INT, false)); + docType.addField(Field("stringattr", 3, *DataType::STRING)); + docType.addField(Field("nalle", 0, *DataType::INT)); { DocumentType::FieldSet::Fields tmp; tmp.insert("nalle"); @@ -160,13 +150,13 @@ TEST(DocumentTypeTest, testInheritance) { // Inheritance of conflicting but equal datatype ok DocumentType docType("test1"); - docType.addField(Field("stringattr", 3, *DataType::STRING, false)); - docType.addField(Field("nalle", 0, *DataType::INT, false)); + docType.addField(Field("stringattr", 3, *DataType::STRING)); + docType.addField(Field("nalle", 0, *DataType::INT)); DocumentType docType2("test2"); - docType2.addField(Field("stringattr", 3, *DataType::STRING, false)); - docType2.addField(Field("tmp", 5, *DataType::STRING, false)); - docType2.addField(Field("tall", 10, *DataType::INT, false)); + docType2.addField(Field("stringattr", 3, *DataType::STRING)); + docType2.addField(Field("tmp", 5, *DataType::STRING)); + docType2.addField(Field("tall", 10, *DataType::INT)); docType.inherit(docType2); EXPECT_TRUE(docType.hasField("stringattr")); @@ -175,8 +165,8 @@ TEST(DocumentTypeTest, testInheritance) EXPECT_TRUE(docType.hasField("tall")); DocumentType docType3("test3"); - docType3.addField(Field("stringattr", 3, *DataType::RAW, false)); - docType3.addField(Field("tall", 10, *DataType::INT, false)); + docType3.addField(Field("stringattr", 3, *DataType::RAW)); + docType3.addField(Field("tall", 10, *DataType::INT)); try{ docType2.inherit(docType3); @@ -206,7 +196,7 @@ TEST(DocumentTypeTest, testInheritance) } DocumentType docType5("test5"); - docType5.addField(Field("stringattr", 20, *DataType::RAW, false)); + docType5.addField(Field("stringattr", 20, *DataType::RAW)); try{ docType4.inherit(docType5); diff --git a/document/src/tests/fieldsettest.cpp b/document/src/tests/fieldsettest.cpp index 37c55385c0f..29581ff4549 100644 --- a/document/src/tests/fieldsettest.cpp +++ b/document/src/tests/fieldsettest.cpp @@ -14,18 +14,12 @@ namespace document { class FieldSetTest : public ::testing::Test { protected: - std::string stringifyFields(const Document& doc) const; - std::string doCopyFields(const Document& src, - const DocumentTypeRepo& docRepo, - const std::string& fieldSetStr, - Document* dest = 0) const; - std::string doCopyDocument(const Document& src, - const DocumentTypeRepo& docRepo, - const std::string& fieldSetStr); - std::string doStripFields(const Document& doc, - const DocumentTypeRepo& docRepo, - const std::string& fieldSetStr); - Document::UP createTestDocument(const TestDocMan& testDocMan) const; + static std::string stringifyFields(const Document& doc); + static std::string doCopyFields(const Document& src, const DocumentTypeRepo& docRepo, + const std::string& fieldSetStr,Document* dest = nullptr); + static std::string doCopyDocument(const Document& src, const DocumentTypeRepo& docRepo, const std::string& fieldSetStr); + static std::string doStripFields(const Document& doc, const DocumentTypeRepo& docRepo, const std::string& fieldSetStr); + static Document::UP createTestDocument(const TestDocMan& testDocMan); }; TEST_F(FieldSetTest, testParsing) @@ -33,20 +27,16 @@ TEST_F(FieldSetTest, testParsing) TestDocMan testDocMan; const DocumentTypeRepo& docRepo = testDocMan.getTypeRepo(); - FieldSetRepo repo; - - (void) dynamic_cast<AllFields&>(*repo.parse(docRepo, AllFields::NAME)); - (void) dynamic_cast<NoFields&>(*repo.parse(docRepo, NoFields::NAME)); - (void) dynamic_cast<DocIdOnly&>(*repo.parse(docRepo, DocIdOnly::NAME)); + (void) dynamic_cast<AllFields&>(*FieldSetRepo::parse(docRepo, AllFields::NAME)); + (void) dynamic_cast<NoFields&>(*FieldSetRepo::parse(docRepo, NoFields::NAME)); + (void) dynamic_cast<DocIdOnly&>(*FieldSetRepo::parse(docRepo, DocIdOnly::NAME)); - FieldSet::UP set = repo.parse(docRepo, "testdoctype1:headerval,content"); - FieldCollection& coll = dynamic_cast<FieldCollection&>(*set); + FieldSet::UP set = FieldSetRepo::parse(docRepo, "testdoctype1:headerval,content"); + auto & coll = dynamic_cast<FieldCollection&>(*set); std::ostringstream ost; - for (Field::Set::const_iterator iter = coll.getFields().begin(); - iter != coll.getFields().end(); - ++iter) { - ost << (*iter)->getName() << " "; + for (const Field * field : coll.getFields()) { + ost << field->getName() << " "; } EXPECT_EQ(std::string("content headerval "), ost.str()); @@ -54,18 +44,17 @@ TEST_F(FieldSetTest, testParsing) namespace { -bool checkContains(FieldSetRepo& r, const DocumentTypeRepo& repo, - const std::string& str1, const std::string str2) { - FieldSet::UP set1 = r.parse(repo, str1); - FieldSet::UP set2 = r.parse(repo, str2); +bool checkContains(const DocumentTypeRepo& repo, + const std::string& str1, const std::string & str2) { + FieldSet::UP set1 = FieldSetRepo::parse(repo, str1); + FieldSet::UP set2 = FieldSetRepo::parse(repo, str2); return set1->contains(*set2); } -bool checkError(FieldSetRepo& r, const DocumentTypeRepo& repo, - const std::string& str) { +bool checkError(const DocumentTypeRepo& repo, const std::string& str) { try { - r.parse(repo, str); + FieldSetRepo::parse(repo, str); return false; } catch (...) { return true; @@ -99,25 +88,24 @@ TEST_F(FieldSetTest, testContains) EXPECT_EQ(false, none.contains(id)); EXPECT_EQ(true, id.contains(none)); - FieldSetRepo r; - EXPECT_EQ(true, checkContains(r, repo, + EXPECT_EQ(true, checkContains(repo, "testdoctype1:content,headerval", "testdoctype1:content")); - EXPECT_EQ(false, checkContains(r, repo, + EXPECT_EQ(false, checkContains(repo, "testdoctype1:content", "testdoctype1:content,headerval")); - EXPECT_EQ(true, checkContains(r, repo, + EXPECT_EQ(true, checkContains(repo, "testdoctype1:headerval,content", "testdoctype1:content,headerval")); - EXPECT_TRUE(checkError(r, repo, "nodoctype")); - EXPECT_TRUE(checkError(r, repo, "unknowndoctype:foo")); - EXPECT_TRUE(checkError(r, repo, "testdoctype1:unknownfield")); - EXPECT_TRUE(checkError(r, repo, "[badid]")); + EXPECT_TRUE(checkError(repo, "nodoctype")); + EXPECT_TRUE(checkError(repo, "unknowndoctype:foo")); + EXPECT_TRUE(checkError(repo, "testdoctype1:unknownfield")); + EXPECT_TRUE(checkError(repo, "[badid]")); } std::string -FieldSetTest::stringifyFields(const Document& doc) const +FieldSetTest::stringifyFields(const Document& doc) { std::vector<std::string> output; const StructFieldValue& fields(doc.getFields()); @@ -147,14 +135,13 @@ std::string FieldSetTest::doCopyFields(const Document& src, const DocumentTypeRepo& docRepo, const std::string& fieldSetStr, - Document* dest) const + Document* dest) { Document destDoc(src.getType(), DocumentId("id:ns:" + src.getType().getName() + "::fieldset")); if (!dest) { dest = &destDoc; } - FieldSetRepo repo; - FieldSet::UP fset = repo.parse(docRepo, fieldSetStr); + FieldSet::UP fset = FieldSetRepo::parse(docRepo, fieldSetStr); FieldSet::copyFields(*dest, src, *fset); return stringifyFields(*dest); } @@ -165,14 +152,13 @@ FieldSetTest::doStripFields(const Document& doc, const std::string& fieldSetStr) { Document::UP copy(doc.clone()); - FieldSetRepo repo; - FieldSet::UP fset = repo.parse(docRepo, fieldSetStr); + FieldSet::UP fset = FieldSetRepo::parse(docRepo, fieldSetStr); FieldSet::stripFields(*copy, *fset); return stringifyFields(*copy); } Document::UP -FieldSetTest::createTestDocument(const TestDocMan& testDocMan) const +FieldSetTest::createTestDocument(const TestDocMan& testDocMan) { Document::UP doc(testDocMan.createDocument("megafoo megabar", "id:ns:testdoctype1::1", @@ -212,8 +198,7 @@ FieldSetTest::doCopyDocument(const Document& src, const DocumentTypeRepo& docRepo, const std::string& fieldSetStr) { - FieldSetRepo repo; - FieldSet::UP fset = repo.parse(docRepo, fieldSetStr); + FieldSet::UP fset = FieldSetRepo::parse(docRepo, fieldSetStr); Document::UP doc(FieldSet::createDocumentSubsetCopy(src, *fset)); return stringifyFields(*doc); } @@ -240,9 +225,9 @@ TEST_F(FieldSetTest, testDocumentSubsetCopy) NoFields::NAME, "testdoctype1:hstringval,content" }; - for (size_t i = 0; i < sizeof(fieldSets) / sizeof(fieldSets[0]); ++i) { - EXPECT_EQ(doCopyFields(*src, repo, fieldSets[i]), - doCopyDocument(*src, repo, fieldSets[i])); + for (const char * fieldSet : fieldSets) { + EXPECT_EQ(doCopyFields(*src, repo, fieldSet), + doCopyDocument(*src, repo, fieldSet)); } } @@ -260,9 +245,9 @@ TEST_F(FieldSetTest, testSerialize) }; FieldSetRepo repo; - for (size_t i = 0; i < sizeof(fieldSets) / sizeof(fieldSets[0]); ++i) { - FieldSet::UP fs = repo.parse(docRepo, fieldSets[i]); - EXPECT_EQ(vespalib::string(fieldSets[i]), repo.serialize(*fs)); + for (const char * fieldSet : fieldSets) { + FieldSet::UP fs = FieldSetRepo::parse(docRepo, fieldSet); + EXPECT_EQ(vespalib::string(fieldSet), repo.serialize(*fs)); } } @@ -289,14 +274,11 @@ TEST(FieldCollectionTest, testHash ) { TestDocMan testDocMan; const DocumentTypeRepo& repo = testDocMan.getTypeRepo(); const DocumentType & type = *repo.getDocumentType("testdoctype1"); - Field::Set set; - EXPECT_EQ(0ul, FieldCollection(type, set).hash()); - set.insert(&type.getField("headerval")); - EXPECT_EQ(0x548599858c77ef83ul, FieldCollection(type, set).hash()); - set.insert(&type.getField("hstringval")); - EXPECT_EQ(0x4a7ff2406d36a9b0ul, FieldCollection(type, set).hash()); - set.erase(&type.getField("headerval")); - EXPECT_EQ(0x1e0918531b19734ul, FieldCollection(type, set).hash()); + EXPECT_EQ(0ul, FieldCollection(type, Field::Set::Builder().build()).hash()); + EXPECT_EQ(0x548599858c77ef83ul, FieldCollection(type, Field::Set::Builder().add(&type.getField("headerval")).build()).hash()); + EXPECT_EQ(0x4a7ff2406d36a9b0ul, FieldCollection(type, Field::Set::Builder().add(&type.getField("headerval")).add( + &type.getField("hstringval")).build()).hash()); + EXPECT_EQ(0x1e0918531b19734ul, FieldCollection(type, Field::Set::Builder().add(&type.getField("hstringval")).build()).hash()); } } // document diff --git a/document/src/tests/serialization/vespadocumentserializer_test.cpp b/document/src/tests/serialization/vespadocumentserializer_test.cpp index 2ad06dc93de..c0ebdad6373 100644 --- a/document/src/tests/serialization/vespadocumentserializer_test.cpp +++ b/document/src/tests/serialization/vespadocumentserializer_test.cpp @@ -422,8 +422,8 @@ TEST("requireThatWeightedSetFieldValueCanBeSerialized") { EXPECT_EQUAL(3u, weight); } -const Field field1("field1", *DataType::INT, false); -const Field field2("field2", *DataType::STRING, false); +const Field field1("field1", *DataType::INT); +const Field field2("field2", *DataType::STRING); StructDataType getStructDataType() { StructDataType struct_type("struct"); @@ -638,7 +638,7 @@ TEST("requireThatDocumentWithDocumentCanBeSerialized") { setSpanTree(str, *tree); - const Field str_field("str", *DataType::STRING, false); + const Field str_field("str", *DataType::STRING); Document inner(*inner_type, DocumentId("id:ns:" + inner_type->getName() + "::")); inner.setValue(str_field, str); @@ -646,7 +646,7 @@ TEST("requireThatDocumentWithDocumentCanBeSerialized") { ASSERT_TRUE(type); DocumentId doc_id("id:ns:" + type->getName() + "::"); Document value(*type, doc_id); - const Field doc_field(inner_name, *inner_type, false); + const Field doc_field(inner_name, *inner_type); value.setValue(doc_field, inner); nbostream stream; diff --git a/document/src/vespa/document/base/field.cpp b/document/src/vespa/document/base/field.cpp index 316394c289f..fb814fc5f17 100644 --- a/document/src/vespa/document/base/field.cpp +++ b/document/src/vespa/document/base/field.cpp @@ -7,25 +7,43 @@ #include <vespa/vespalib/util/exceptions.h> #include <vespa/vespalib/stllike/asciistream.h> #include <vespa/vespalib/util/bobhash.h> +#include <algorithm> namespace document { -Field::Field() : Field("", 0, *DataType::INT, false) { } +Field::Set::Set(std::vector<CPtr> fields) + : _fields(std::move(fields)) +{ + std::sort(_fields.begin(), _fields.end(), Field::FieldPtrLess()); + _fields.erase(std::unique(_fields.begin(), _fields.end(), Field::FieldPtrEqual()), _fields.end()); +} + +bool +Field::Set::contains(const Field & field) const { + return std::binary_search(_fields.begin(), _fields.end(), &field, Field::FieldPtrLess()); +} + +bool +Field::Set::contains(const Set & fields) const { + return std::includes(_fields.begin(), _fields.end(), + fields._fields.begin(), fields._fields.end(), + Field::FieldPtrLess()); +} + +Field::Field() + : Field("", 0, *DataType::INT) +{ } -Field::Field(vespalib::stringref name, int fieldId, - const DataType& dataType, bool headerField) +Field::Field(vespalib::stringref name, int fieldId, const DataType& dataType) : FieldBase(name), _dataType(&dataType), - _fieldId(fieldId), - _isHeaderField(headerField) + _fieldId(fieldId) { } -Field::Field(vespalib::stringref name, - const DataType& dataType, bool headerField) +Field::Field(vespalib::stringref name, const DataType& dataType) : FieldBase(name), _dataType(&dataType), - _fieldId(calculateIdV7()), - _isHeaderField(headerField) + _fieldId(calculateIdV7()) { } FieldValue::UP @@ -42,9 +60,6 @@ Field::toString(bool verbose) const out << ", id " << _fieldId; } out << ", " << _dataType->toString(); - if (verbose) { - out << ", " << (_isHeaderField ? "header" : "body"); - } out << ")"; return out.str(); } diff --git a/document/src/vespa/document/base/field.h b/document/src/vespa/document/base/field.h index a77034932cf..7580b2b692f 100644 --- a/document/src/vespa/document/base/field.h +++ b/document/src/vespa/document/base/field.h @@ -26,19 +26,45 @@ class Field final : public vespalib::FieldBase, public FieldSet { const DataType *_dataType; - int _fieldId; - bool _isHeaderField; + int _fieldId; public: - typedef std::shared_ptr<const Field> CSP; - typedef std::shared_ptr<Field> SP; + using CSP = std::shared_ptr<const Field>; + using SP = std::shared_ptr<Field>; + using CPtr = const Field *; - struct FieldPtrComparator { - bool operator()(const Field* f1, const Field* f2) const { + struct FieldPtrLess { + bool operator()(CPtr f1, CPtr f2) const { return (*f1 < *f2); } }; - using Set = std::set<const Field*, FieldPtrComparator>; + struct FieldPtrEqual { + bool operator()(CPtr f1, CPtr f2) const { + return (*f1 == *f2); + } + }; + + class Set { + public: + class Builder { + public: + Builder & reserve(size_t sz) { _vector.reserve(sz); return *this; } + Builder & add(CPtr field) { _vector.push_back(field); return *this; } + Set build() { return Set(std::move(_vector)); } + private: + std::vector<CPtr> _vector; + }; + bool contains(const Field & field) const; + bool contains(const Set & field) const; + size_t size() const { return _fields.size(); } + bool empty() const { return _fields.empty(); } + const CPtr * begin() const { return &_fields[0]; } + const CPtr * end() const { return begin() + _fields.size(); } + static Set emptySet() { return Builder().build(); } + private: + explicit Set(std::vector<CPtr> fields); + std::vector<CPtr> _fields; + }; /** * Creates a completely specified field instance. @@ -48,8 +74,7 @@ public: * @param type The datatype of the field. * @param headerField Whether or not this is a "header" field. */ - Field(vespalib::stringref name, int fieldId, - const DataType &type, bool headerField); + Field(vespalib::stringref name, int fieldId, const DataType &type); Field(); @@ -61,7 +86,7 @@ public: * @param dataType The datatype of the field. * @param headerField Whether or not this is a "header" field. */ - Field(vespalib::stringref name, const DataType &dataType, bool headerField); + Field(vespalib::stringref name, const DataType &dataType); Field* clone() const override { return new Field(*this); } std::unique_ptr<FieldValue> createValue() const; @@ -74,7 +99,6 @@ public: const DataType &getDataType() const { return *_dataType; } int getId() const { return _fieldId; } - bool isHeaderField() const { return _isHeaderField; } vespalib::string toString(bool verbose=false) const; bool contains(const FieldSet& fields) const override; diff --git a/document/src/vespa/document/datatype/positiondatatype.cpp b/document/src/vespa/document/datatype/positiondatatype.cpp index 24fbcc76be3..a8e9c81c895 100644 --- a/document/src/vespa/document/datatype/positiondatatype.cpp +++ b/document/src/vespa/document/datatype/positiondatatype.cpp @@ -21,17 +21,17 @@ StructDataType::UP PositionDataType::createInstance() { StructDataType::UP type(new StructDataType(PositionDataType::STRUCT_NAME)); - type->addField(Field(PositionDataType::FIELD_X, *DataType::INT, true)); - type->addField(Field(PositionDataType::FIELD_Y, *DataType::INT, true)); + type->addField(Field(PositionDataType::FIELD_X, *DataType::INT)); + type->addField(Field(PositionDataType::FIELD_Y, *DataType::INT)); return type; } const StructDataType & PositionDataType::getInstance() { - if (_instance.get() == NULL) { + if ( ! _instance) { vespalib::LockGuard guard(_lock); - if (_instance.get() == NULL) { + if ( ! _instance) { _instance = createInstance(); } } diff --git a/document/src/vespa/document/datatype/structdatatype.cpp b/document/src/vespa/document/datatype/structdatatype.cpp index ed17d22da59..c0c63ddb37f 100644 --- a/document/src/vespa/document/datatype/structdatatype.cpp +++ b/document/src/vespa/document/datatype/structdatatype.cpp @@ -164,11 +164,12 @@ bool StructDataType::hasField(int32_t fieldId) const { Field::Set StructDataType::getFieldSet() const { - Field::Set fields; + Field::Set::Builder builder; + builder.reserve(_idFieldMap.size()); for (const auto & entry : _idFieldMap) { - fields.insert(entry.second.get()); + builder.add(entry.second.get()); } - return fields; + return builder.build(); } namespace { diff --git a/document/src/vespa/document/datatype/urldatatype.cpp b/document/src/vespa/document/datatype/urldatatype.cpp index 95f8af2a881..00ea31408af 100644 --- a/document/src/vespa/document/datatype/urldatatype.cpp +++ b/document/src/vespa/document/datatype/urldatatype.cpp @@ -20,22 +20,22 @@ StructDataType::UP UrlDataType::createInstance() { StructDataType::UP type(new StructDataType(UrlDataType::STRUCT_NAME)); - type->addField(Field(UrlDataType::FIELD_ALL, *DataType::STRING, true)); - type->addField(Field(UrlDataType::FIELD_SCHEME, *DataType::STRING, true)); - type->addField(Field(UrlDataType::FIELD_HOST, *DataType::STRING, true)); - type->addField(Field(UrlDataType::FIELD_PORT, *DataType::STRING, true)); - type->addField(Field(UrlDataType::FIELD_PATH, *DataType::STRING, true)); - type->addField(Field(UrlDataType::FIELD_QUERY, *DataType::STRING, true)); - type->addField(Field(UrlDataType::FIELD_FRAGMENT,*DataType::STRING, true)); + type->addField(Field(UrlDataType::FIELD_ALL, *DataType::STRING)); + type->addField(Field(UrlDataType::FIELD_SCHEME, *DataType::STRING)); + type->addField(Field(UrlDataType::FIELD_HOST, *DataType::STRING)); + type->addField(Field(UrlDataType::FIELD_PORT, *DataType::STRING)); + type->addField(Field(UrlDataType::FIELD_PATH, *DataType::STRING)); + type->addField(Field(UrlDataType::FIELD_QUERY, *DataType::STRING)); + type->addField(Field(UrlDataType::FIELD_FRAGMENT,*DataType::STRING)); return type; } const StructDataType & UrlDataType::getInstance() { - if (_instance.get() == NULL) { + if ( ! _instance ) { vespalib::LockGuard guard(_lock); - if (_instance.get() == NULL) { + if ( ! _instance ) { _instance = createInstance(); } } diff --git a/document/src/vespa/document/fieldset/fieldsetrepo.cpp b/document/src/vespa/document/fieldset/fieldsetrepo.cpp index c576624b026..33cbf6185c4 100644 --- a/document/src/vespa/document/fieldset/fieldsetrepo.cpp +++ b/document/src/vespa/document/fieldset/fieldsetrepo.cpp @@ -44,18 +44,18 @@ parseFieldCollection(const DocumentTypeRepo& repo, const DocumentType& type(*typePtr); StringTokenizer tokenizer(fieldNames, ","); - Field::Set fields; + Field::Set::Builder builder; for (const auto & token : tokenizer) { const DocumentType::FieldSet * fs = type.getFieldSet(token); if (fs) { for (const auto & fieldName : fs->getFields()) { - fields.insert(&type.getField(fieldName)); + builder.add(&type.getField(fieldName)); } } else { - fields.insert(&type.getField(token)); + builder.add(&type.getField(token)); } } - return std::make_unique<FieldCollection>(type, std::move(fields)); + return std::make_unique<FieldCollection>(type, builder.build()); } } diff --git a/document/src/vespa/document/fieldset/fieldsets.cpp b/document/src/vespa/document/fieldset/fieldsets.cpp index 586cef0e5f4..317c1743bb5 100644 --- a/document/src/vespa/document/fieldset/fieldsets.cpp +++ b/document/src/vespa/document/fieldset/fieldsets.cpp @@ -4,6 +4,7 @@ #include <vespa/document/fieldvalue/document.h> #include <vespa/document/datatype/documenttype.h> #include <vespa/vespalib/stllike/asciistream.h> +#include <algorithm> #include <xxhash.h> namespace document { @@ -38,25 +39,10 @@ FieldCollection::contains(const FieldSet& fields) const { switch (fields.getType()) { case Type::FIELD: - return _set.find(static_cast<const Field*>(&fields)) != _set.end(); + return _set.contains(static_cast<const Field &>(fields)); case Type::SET: { const auto & coll = static_cast<const FieldCollection&>(fields); - - if (_set.size() < coll._set.size()) { - return false; - } - - auto iter = coll.getFields().begin(); - - while (iter != coll.getFields().end()) { - if (_set.find(*iter) == _set.end()) { - return false; - } - - ++iter; - } - - return true; + return _set.contains(coll.getFields()); } case Type::NONE: case Type::DOCID: diff --git a/document/src/vespa/document/fieldset/fieldsets.h b/document/src/vespa/document/fieldset/fieldsets.h index d37d72d6109..9537a5bdf61 100644 --- a/document/src/vespa/document/fieldset/fieldsets.h +++ b/document/src/vespa/document/fieldset/fieldsets.h @@ -65,8 +65,8 @@ public: uint64_t hash() const { return _hash; } private: - Field::Set _set; - uint64_t _hash; + Field::Set _set; + uint64_t _hash; const DocumentType& _docType; }; diff --git a/document/src/vespa/document/repo/configbuilder.cpp b/document/src/vespa/document/repo/configbuilder.cpp index 7d9b607facd..2f507a43204 100644 --- a/document/src/vespa/document/repo/configbuilder.cpp +++ b/document/src/vespa/document/repo/configbuilder.cpp @@ -6,7 +6,7 @@ namespace document::config_builder { int32_t createFieldId(const vespalib::string &name, int32_t type) { StructDataType dummy("dummy", type); - Field f(name, dummy, true); + Field f(name, dummy); return f.getId(); } diff --git a/document/src/vespa/document/repo/documenttyperepo.cpp b/document/src/vespa/document/repo/documenttyperepo.cpp index 58dbd16beb6..bcd4edb3ab8 100644 --- a/document/src/vespa/document/repo/documenttyperepo.cpp +++ b/document/src/vespa/document/repo/documenttyperepo.cpp @@ -232,7 +232,7 @@ struct DataTypeRepo { namespace { void addAnnotationType(const DocumenttypesConfig::Documenttype::Annotationtype &type, AnnotationTypeRepo &annotations) { - AnnotationType::UP a(new AnnotationType(type.id, type.name)); + auto a = std::make_unique<AnnotationType>(type.id, type.name); annotations.addAnnotationType(std::move(a)); } @@ -257,17 +257,12 @@ void setAnnotationDataTypes(const vector<DocumenttypesConfig::Documenttype::Anno typedef DocumenttypesConfig::Documenttype::Datatype Datatype; -void addField(const Datatype::Sstruct::Field &field, Repo &repo, StructDataType &struct_type, bool isHeaderField) +void addField(const Datatype::Sstruct::Field &field, Repo &repo, StructDataType &struct_type) { - LOG(spam, "Adding field %s to %s (header: %s)", - field.name.c_str(), struct_type.getName().c_str(), isHeaderField ? "yes" : "no"); + LOG(spam, "Adding field %s to %s", + field.name.c_str(), struct_type.getName().c_str()); const DataType &field_type = repo.findOrThrowOrCreate(field.datatype, field.detailedtype); - struct_type.addField(Field(field.name, field.id, field_type, isHeaderField)); -} - -bool hasSuffix(const string &s, const string &suffix) { - string::size_type pos = s.rfind(suffix.c_str()); - return pos != string::npos && pos == s.size() - suffix.size(); + struct_type.addField(Field(field.name, field.id, field_type)); } void addStruct(int32_t id, const Datatype::Sstruct &s, Repo &repo) { @@ -318,7 +313,7 @@ void addStruct(int32_t id, const Datatype::Sstruct &s, Repo &repo) { CompressionConfig(type, s.compression.level, s.compression.threshold, s.compression.minsize)); for (size_t i = 0; i < s.field.size(); ++i) { - addField(s.field[i], repo, *struct_type, hasSuffix(s.name, ".header")); + addField(s.field[i], repo, *struct_type); } } diff --git a/document/src/vespa/document/select/bodyfielddetector.cpp b/document/src/vespa/document/select/bodyfielddetector.cpp index 228fec26277..3d32813621d 100644 --- a/document/src/vespa/document/select/bodyfielddetector.cpp +++ b/document/src/vespa/document/select/bodyfielddetector.cpp @@ -18,11 +18,7 @@ BodyFieldDetector::detectFieldType(const FieldValueNode *expr, const DocumentTyp FieldPath path; type.buildFieldPath(path, expr->getFieldName()); if ( ! path.empty() ) { - if (path[0].getFieldRef().isHeaderField()) { - foundHeaderField = true; - } else { - foundBodyField = true; - } + foundHeaderField = true; } } catch (FieldNotFoundException &) { } diff --git a/document/src/vespa/document/select/bodyfielddetector.h b/document/src/vespa/document/select/bodyfielddetector.h index 028519c8101..99cf9f7c6ea 100644 --- a/document/src/vespa/document/select/bodyfielddetector.h +++ b/document/src/vespa/document/select/bodyfielddetector.h @@ -33,19 +33,4 @@ public: void visitFieldValueNode(const FieldValueNode& expr) override; }; -class NeedDocumentDetector : public TraversingVisitor -{ -private: - bool _needDocument; - void visitDocumentType(const DocType &) override { - _needDocument = true; - } - void visitFieldValueNode(const FieldValueNode &) override { - _needDocument = true; - } -public: - NeedDocumentDetector() : _needDocument(false) { } - bool needDocument() const { return _needDocument; } -}; - } diff --git a/jaxrs_client_utils/src/test/java/com/yahoo/vespa/jaxrs/client/HttpPatchTest.java b/jaxrs_client_utils/src/test/java/com/yahoo/vespa/jaxrs/client/HttpPatchTest.java index 8161602cdac..3270ac0141e 100644 --- a/jaxrs_client_utils/src/test/java/com/yahoo/vespa/jaxrs/client/HttpPatchTest.java +++ b/jaxrs_client_utils/src/test/java/com/yahoo/vespa/jaxrs/client/HttpPatchTest.java @@ -21,8 +21,7 @@ import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertEquals; /** * @author bakksjo @@ -57,8 +56,8 @@ public class HttpPatchTest extends JerseyTest { final Response response = target(TestResourceApi.PATH) .request() .method("PATCH", Entity.text(REQUEST_BODY)); - assertThat(testResourceSingleton.invocation.get(60, TimeUnit.SECONDS), is(REQUEST_BODY)); - assertThat(response.readEntity(String.class), is(REQUEST_BODY)); + assertEquals(REQUEST_BODY, testResourceSingleton.invocation.get(60, TimeUnit.SECONDS)); + assertEquals(REQUEST_BODY, response.readEntity(String.class)); } @Test @@ -76,8 +75,8 @@ public class HttpPatchTest extends JerseyTest { final String responseBody; responseBody = client.apply(api -> api.doPatch(REQUEST_BODY)); - assertThat(testResourceSingleton.invocation.get(60, TimeUnit.SECONDS), is(REQUEST_BODY)); - assertThat(responseBody, is(REQUEST_BODY)); + assertEquals(REQUEST_BODY, testResourceSingleton.invocation.get(60, TimeUnit.SECONDS)); + assertEquals(REQUEST_BODY, responseBody); } public interface TestResourceApi { diff --git a/jaxrs_client_utils/src/test/java/com/yahoo/vespa/jaxrs/client/RetryingJaxRsStrategyTest.java b/jaxrs_client_utils/src/test/java/com/yahoo/vespa/jaxrs/client/RetryingJaxRsStrategyTest.java index 4a78452c956..bc48ab1c5a6 100644 --- a/jaxrs_client_utils/src/test/java/com/yahoo/vespa/jaxrs/client/RetryingJaxRsStrategyTest.java +++ b/jaxrs_client_utils/src/test/java/com/yahoo/vespa/jaxrs/client/RetryingJaxRsStrategyTest.java @@ -20,9 +20,8 @@ import java.util.HashSet; import java.util.Set; import java.util.stream.Collectors; -import static org.hamcrest.CoreMatchers.hasItem; -import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.atLeast; @@ -72,7 +71,7 @@ public class RetryingJaxRsStrategyTest { assertEquals(REST_PORT, params.uri().getPort()); assertEquals(API_PATH, params.uri().getPath()); assertEquals("http", params.uri().getScheme()); - assertThat(SERVER_HOSTS, hasItem(new HostName(params.uri().getHost()))); + assertTrue(SERVER_HOSTS.contains(new HostName(params.uri().getHost()))); } @Test diff --git a/linguistics/pom.xml b/linguistics/pom.xml index e341258c75f..3cc430dacc6 100644 --- a/linguistics/pom.xml +++ b/linguistics/pom.xml @@ -15,11 +15,6 @@ <version>7-SNAPSHOT</version> <dependencies> <dependency> - <groupId>org.hamcrest</groupId> - <artifactId>hamcrest-library</artifactId> - <scope>test</scope> - </dependency> - <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> diff --git a/linguistics/src/test/java/com/yahoo/language/opennlp/OpenNlpTokenizationTestCase.java b/linguistics/src/test/java/com/yahoo/language/opennlp/OpenNlpTokenizationTestCase.java index 914e3817568..fb313e2d281 100644 --- a/linguistics/src/test/java/com/yahoo/language/opennlp/OpenNlpTokenizationTestCase.java +++ b/linguistics/src/test/java/com/yahoo/language/opennlp/OpenNlpTokenizationTestCase.java @@ -7,11 +7,19 @@ import com.yahoo.language.process.Token; import com.yahoo.language.process.Tokenizer; import org.junit.Test; -import java.util.*; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.NoSuchElementException; import static com.yahoo.language.LinguisticsCase.toLowerCase; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; /** * Test of tokenization, with stemming and accent removal @@ -136,8 +144,8 @@ public class OpenNlpTokenizationTestCase { int idx = 0; for (Token token : tokenizer.tokenize(input, Language.GERMAN, StemMode.SHORTEST, false)) { - assertThat("Token offset for token #" + idx, token.getOffset(), is(expOffset[idx])); - assertThat("Token len for token #" + idx, token.getOrig().length(), is(len[idx])); + assertEquals("Token offset for token #" + idx, expOffset[idx], token.getOffset()); + assertEquals("Token len for token #" + idx, len[idx], token.getOrig().length()); idx++; } } @@ -216,21 +224,21 @@ public class OpenNlpTokenizationTestCase { for (int comp = 0; comp < token.getNumComponents(); comp++) { Token t = token.getComponent(comp); if (t.getType().isIndexable()) { - assertThat("comp index: " + i, toLowerCase(t.getTokenString()), is(indexed.get(i++))); + assertEquals("comp index: " + i, indexed.get(i++), toLowerCase(t.getTokenString())); } } } else { if (token.getType().isIndexable()) { - assertThat("exp index: " + i, toLowerCase(token.getTokenString()), is(indexed.get(i++))); + assertEquals("exp index: " + i, indexed.get(i++), toLowerCase(token.getTokenString())); } } if (orig != null) { - assertThat("orig index: " + j, token.getOrig(), is(orig.get(j++))); + assertEquals("orig index: " + j, token.getOrig(), orig.get(j++)); } } - assertThat("indexed length", i, is(indexed.size())); + assertEquals("indexed length", indexed.size(), i); if (orig != null) { - assertThat("orig length", j, is(orig.size())); + assertEquals("orig length", orig.size(), j); } } diff --git a/linguistics/src/test/java/com/yahoo/language/process/TokenizationTestCase.java b/linguistics/src/test/java/com/yahoo/language/process/TokenizationTestCase.java index 72dd6f8ce58..041a27fb1fc 100644 --- a/linguistics/src/test/java/com/yahoo/language/process/TokenizationTestCase.java +++ b/linguistics/src/test/java/com/yahoo/language/process/TokenizationTestCase.java @@ -5,11 +5,19 @@ import com.yahoo.language.Language; import com.yahoo.language.simple.SimpleTokenizer; import org.junit.Test; -import java.util.*; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.NoSuchElementException; import static com.yahoo.language.LinguisticsCase.toLowerCase; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; /** * Test of tokenization, with stemming and accent removal @@ -134,8 +142,8 @@ public class TokenizationTestCase { int idx = 0; for (Token token : tokenizer.tokenize(input, Language.GERMAN, StemMode.SHORTEST, false)) { - assertThat("Token offset for token #" + idx, token.getOffset(), is(expOffset[idx])); - assertThat("Token len for token #" + idx, token.getOrig().length(), is(len[idx])); + assertEquals("Token offset for token #" + idx, expOffset[idx], token.getOffset()); + assertEquals("Token len for token #" + idx, len[idx], token.getOrig().length()); idx++; } } @@ -214,21 +222,21 @@ public class TokenizationTestCase { for (int comp = 0; comp < token.getNumComponents(); comp++) { Token t = token.getComponent(comp); if (t.getType().isIndexable()) { - assertThat("comp index: " + i, toLowerCase(t.getTokenString()), is(indexed.get(i++))); + assertEquals("comp index: " + i, indexed.get(i++), toLowerCase(t.getTokenString())); } } } else { if (token.getType().isIndexable()) { - assertThat("exp index: " + i, toLowerCase(token.getTokenString()), is(indexed.get(i++))); + assertEquals("exp index: " + i, indexed.get(i++), toLowerCase(token.getTokenString())); } } if (orig != null) { - assertThat("orig index: " + j, token.getOrig(), is(orig.get(j++))); + assertEquals("orig index: " + j, orig.get(j++), token.getOrig()); } } - assertThat("indexed length", i, is(indexed.size())); + assertEquals("indexed length", indexed.size(), i); if (orig != null) { - assertThat("orig length", j, is(orig.size())); + assertEquals("orig length", orig.size(), j); } } diff --git a/searchcore/src/tests/proton/attribute/attribute_test.cpp b/searchcore/src/tests/proton/attribute/attribute_test.cpp index 258ee5f32d8..41de6827244 100644 --- a/searchcore/src/tests/proton/attribute/attribute_test.cpp +++ b/searchcore/src/tests/proton/attribute/attribute_test.cpp @@ -984,7 +984,7 @@ public: StructWriterTestBase() : AttributeWriterTest(), _type("test"), - _valueField("value", 2, *DataType::INT, true), + _valueField("value", 2, *DataType::INT), _structFieldType("struct") { addAttribute({"value", AVConfig(AVBasicType::INT32, AVCollectionType::SINGLE)}); @@ -1019,7 +1019,7 @@ public: StructArrayWriterTest() : StructWriterTestBase(), _structArrayFieldType(_structFieldType), - _structArrayField("array", _structArrayFieldType, true) + _structArrayField("array", _structArrayFieldType) { addAttribute({"array.value", AVConfig(AVBasicType::INT32, AVCollectionType::ARRAY)}); _type.addField(_structArrayField); @@ -1070,7 +1070,7 @@ public: StructMapWriterTest() : StructWriterTestBase(), _structMapFieldType(*DataType::INT, _structFieldType), - _structMapField("map", _structMapFieldType, true) + _structMapField("map", _structMapFieldType) { addAttribute({"map.value.value", AVConfig(AVBasicType::INT32, AVCollectionType::ARRAY)}); addAttribute({"map.key", AVConfig(AVBasicType::INT32, AVCollectionType::ARRAY)}); diff --git a/searchcore/src/tests/proton/attribute/document_field_extractor/document_field_extractor_test.cpp b/searchcore/src/tests/proton/attribute/document_field_extractor/document_field_extractor_test.cpp index 33a3de0c5b6..89dbf20eb61 100644 --- a/searchcore/src/tests/proton/attribute/document_field_extractor/document_field_extractor_test.cpp +++ b/searchcore/src/tests/proton/attribute/document_field_extractor/document_field_extractor_test.cpp @@ -97,8 +97,8 @@ struct FixtureBase FixtureBase(bool byteWeight) : type("test"), - weightField("weight", 1, byteWeight ? *DataType::BYTE : *DataType::INT, true), - nameField("name", 2, *DataType::STRING, true), + weightField("weight", 1, byteWeight ? *DataType::BYTE : *DataType::INT), + nameField("name", 2, *DataType::STRING), doc(), extractor() { @@ -174,9 +174,9 @@ struct ArrayFixture : public FixtureBase ArrayFixture(bool byteWeight = false) : FixtureBase(byteWeight), weightArrayFieldType(weightField.getDataType()), - weightArrayField("weight", weightArrayFieldType, true), + weightArrayField("weight", weightArrayFieldType), valueArrayFieldType(nameField.getDataType()), - valueArrayField("val", valueArrayFieldType, true) + valueArrayField("val", valueArrayFieldType) { type.addField(weightArrayField); type.addField(valueArrayField); @@ -206,9 +206,9 @@ struct WeightedSetFixture : public FixtureBase WeightedSetFixture(bool byteWeight = false) : FixtureBase(byteWeight), weightWeightedSetFieldType(weightField.getDataType(), false, false), - weightWeightedSetField("weight", weightWeightedSetFieldType, true), + weightWeightedSetField("weight", weightWeightedSetFieldType), valueWeightedSetFieldType(*DataType::STRING, false, false), - valueWeightedSetField("val", valueWeightedSetFieldType, true) + valueWeightedSetField("val", valueWeightedSetFieldType) { type.addField(weightWeightedSetField); type.addField(valueWeightedSetField); @@ -280,7 +280,7 @@ struct StructArrayFixture : public StructFixtureBase StructArrayFixture(bool byteWeight = false) : StructFixtureBase(byteWeight), structArrayFieldType(structFieldType), - structArrayField("s", 11, structArrayFieldType, true) + structArrayField("s", 11, structArrayFieldType) { type.addField(structArrayField); } @@ -310,7 +310,7 @@ struct StructMapFixture : public StructFixtureBase StructMapFixture(bool byteWeight = false, bool byteKey = false) : StructFixtureBase(byteWeight), structMapFieldType(byteKey ? *DataType::BYTE : *DataType::STRING, structFieldType), - structMapField("s", 12, structMapFieldType, true) + structMapField("s", 12, structMapFieldType) { type.addField(structMapField); } @@ -343,7 +343,7 @@ struct PrimitiveMapFixture : public FixtureBase PrimitiveMapFixture() : FixtureBase(false), mapFieldType(nameField.getDataType(), weightField.getDataType()), - mapField("map", mapFieldType, true) + mapField("map", mapFieldType) { type.addField(mapField); } diff --git a/searchcore/src/tests/proton/common/document_type_inspector/document_type_inspector_test.cpp b/searchcore/src/tests/proton/common/document_type_inspector/document_type_inspector_test.cpp index 167865b5c68..5e8f320d86a 100644 --- a/searchcore/src/tests/proton/common/document_type_inspector/document_type_inspector_test.cpp +++ b/searchcore/src/tests/proton/common/document_type_inspector/document_type_inspector_test.cpp @@ -11,14 +11,14 @@ template <class Type> void addFields(Type &type, bool fieldF3IsString, bool hasFieldF4, bool hasFieldF5) { - type.addField(Field("f1", 1, *DataType::STRING, true)); - type.addField(Field("f2", 2, *DataType::STRING, true)); - type.addField(Field("f3", 3, fieldF3IsString ? *DataType::STRING : *DataType::INT, true)); + type.addField(Field("f1", 1, *DataType::STRING)); + type.addField(Field("f2", 2, *DataType::STRING)); + type.addField(Field("f3", 3, fieldF3IsString ? *DataType::STRING : *DataType::INT)); if (hasFieldF4) { - type.addField(Field("f4", 4, *DataType::STRING, true)); + type.addField(Field("f4", 4, *DataType::STRING)); } if (hasFieldF5) { - type.addField(Field("f5", 5, *DataType::STRING, true)); + type.addField(Field("f5", 5, *DataType::STRING)); } } @@ -44,9 +44,9 @@ DocumentTypeFixture::DocumentTypeFixture(bool fieldF3IsString, bool hasFieldF4, addFields(_documentType, fieldF3IsString, hasFieldF4, hasFieldF5); if (hasStruct) { addFields(_structFieldType, fieldF3IsString, hasFieldF4, hasFieldF5); - _documentType.addField(Field("sarray", 11, _structArrayFieldType, true)); - _documentType.addField(Field("smap", 12, _structMapFieldType, true)); - _documentType.addField(Field("map", 13, _mapFieldType, true)); + _documentType.addField(Field("sarray", 11, _structArrayFieldType)); + _documentType.addField(Field("smap", 12, _structMapFieldType)); + _documentType.addField(Field("map", 13, _mapFieldType)); } } @@ -57,7 +57,7 @@ struct Fixture DocumentTypeFixture _oldDocType; DocumentTypeFixture _newDocType; DocumentTypeInspector _inspector; - Fixture(bool hasStruct = true, bool mapKeyIsByte = false) + explicit Fixture(bool hasStruct = true, bool mapKeyIsByte = false) : _oldDocType(true, true, false, hasStruct, mapKeyIsByte), _newDocType(false, false, true, true, false), _inspector(_oldDocType._documentType, _newDocType._documentType) diff --git a/searchcore/src/tests/proton/document_iterator/document_iterator_test.cpp b/searchcore/src/tests/proton/document_iterator/document_iterator_test.cpp index abe326425c3..147bd9afb84 100644 --- a/searchcore/src/tests/proton/document_iterator/document_iterator_test.cpp +++ b/searchcore/src/tests/proton/document_iterator/document_iterator_test.cpp @@ -326,8 +326,8 @@ const DocumentType &getDocType() { static DocumentType::UP doc_type; if (!doc_type) { doc_type = std::make_unique<DocumentType>("foo", 42); - doc_type->addField(Field("header", 43, *DataType::STRING, true)); - doc_type->addField(Field("body", 44, *DataType::STRING, false)); + doc_type->addField(Field("header", 43, *DataType::STRING)); + doc_type->addField(Field("body", 44, *DataType::STRING)); } return *doc_type; } @@ -336,12 +336,12 @@ const DocumentType &getAttrDocType() { static DocumentType::UP doc_type; if (!doc_type) { doc_type = std::make_unique<DocumentType>("foo", 42); - doc_type->addField(Field("header", 43, *DataType::STRING, true)); - doc_type->addField(Field("body", 44, *DataType::STRING, false)); - doc_type->addField(Field("aa", 45, *DataType::INT, false)); - doc_type->addField(Field("ab", 46, *DataType::INT, false)); - doc_type->addField(Field("dd", 47, *DataType::DOUBLE, false)); - doc_type->addField(Field("ss", 48, *DataType::STRING, false)); + doc_type->addField(Field("header", 43, *DataType::STRING)); + doc_type->addField(Field("body", 44, *DataType::STRING)); + doc_type->addField(Field("aa", 45, *DataType::INT)); + doc_type->addField(Field("ab", 46, *DataType::INT)); + doc_type->addField(Field("dd", 47, *DataType::DOUBLE)); + doc_type->addField(Field("ss", 48, *DataType::STRING)); } return *doc_type; } @@ -757,9 +757,8 @@ TEST("require that document selection and timestamp range works together") { } TEST("require that fieldset limits fields returned") { - document::Field::Set fields; - fields.insert(&getDocType().getField("header")); - document::FieldCollection limited(getDocType(), std::move(fields)); + document::FieldCollection limited(getDocType(), + document::Field::Set::Builder().add(&getDocType().getField("header")).build()); DocumentIterator itr(bucket(5), limited, selectAll(), newestV(), -1, false); itr.add(doc_with_fields("id:ns:foo::xxx1", Timestamp(1), bucket(5))); IterateResult res = itr.iterate(largeNum); diff --git a/searchcore/src/tests/proton/reference/document_db_reference_resolver/document_db_reference_resolver_test.cpp b/searchcore/src/tests/proton/reference/document_db_reference_resolver/document_db_reference_resolver_test.cpp index f57c2118363..48b2a269f6b 100644 --- a/searchcore/src/tests/proton/reference/document_db_reference_resolver/document_db_reference_resolver_test.cpp +++ b/searchcore/src/tests/proton/reference/document_db_reference_resolver/document_db_reference_resolver_test.cpp @@ -150,10 +150,10 @@ struct DocumentModel { } ~DocumentModel(); void initChildDocType() { - childDocType.addField(Field("ref", refDataType, true)); - childDocType.addField(Field("other_ref", refDataType, true)); - childDocType.addField(Field("parent2_ref", refDataType2, true)); - childDocType.addField(Field("parent3_ref", refDataType3, true)); + childDocType.addField(Field("ref", refDataType)); + childDocType.addField(Field("other_ref", refDataType)); + childDocType.addField(Field("parent2_ref", refDataType2)); + childDocType.addField(Field("parent3_ref", refDataType3)); } }; diff --git a/searchcore/src/tests/proton/server/documentretriever_test.cpp b/searchcore/src/tests/proton/server/documentretriever_test.cpp index 8385bf89780..a934254aca3 100644 --- a/searchcore/src/tests/proton/server/documentretriever_test.cpp +++ b/searchcore/src/tests/proton/server/documentretriever_test.cpp @@ -17,6 +17,7 @@ #include <vespa/document/fieldvalue/structfieldvalue.h> #include <vespa/document/fieldvalue/tensorfieldvalue.h> #include <vespa/document/fieldvalue/weightedsetfieldvalue.h> +#include <vespa/document/fieldset/fieldsets.h> #include <vespa/document/repo/configbuilder.h> #include <vespa/document/repo/documenttyperepo.h> #include <vespa/eval/tensor/tensor.h> @@ -464,6 +465,16 @@ TEST_F("require that attributes are patched into stored document", Fixture) { EXPECT_FALSE(doc->getValue(dyn_wset_field_n)); } +TEST_F("require that we can look up NONE and DOCIDONLY field sets", Fixture) { + DocumentMetaData meta_data = f._retriever->getDocumentMetaData(doc_id); + Document::UP doc = f._retriever->getPartialDocument(meta_data.lid, doc_id, document::NoFields()); + ASSERT_TRUE(doc); + EXPECT_TRUE(doc->getFields().empty()); + doc = f._retriever->getPartialDocument(meta_data.lid, doc_id, document::DocIdOnly()); + ASSERT_TRUE(doc); + EXPECT_TRUE(doc->getFields().empty()); +} + TEST_F("require that attributes are patched into stored document unless also index field", Fixture) { f.addIndexField(Schema::IndexField(dyn_field_s, DataType::STRING)).build(); DocumentMetaData meta_data = f._retriever->getDocumentMetaData(doc_id); @@ -572,38 +583,36 @@ struct Lookup : public IFieldInfo Lookup() : _count(0) {} bool isFieldAttribute(const document::Field & field) const override { _count++; - return (field.getName()[0] == 'a'); + return ((field.getName()[0] % 2) == 1); // a, c, e... are attributes } mutable unsigned _count; }; -TEST("require ") { +TEST("require that fieldset can figure out their attributeness and rember it") { Lookup lookup; FieldSetAttributeDB fsDB(lookup); - document::Field attr1("attr1", 1, *document::DataType::LONG, true); - document::Field attr2("attr2", 2, *document::DataType::LONG, true); - document::Field not_attr1("not_attr1", 3, *document::DataType::LONG, true); - document::Field::Set allAttr; - allAttr.insert(&attr1); + document::Field attr1("attr1", 1, *document::DataType::LONG); + document::Field attr2("cttr2", 2, *document::DataType::LONG); + document::Field not_attr1("b_not_attr1", 3, *document::DataType::LONG); + document::Field::Set allAttr = document::Field::Set::Builder().add(&attr1).build(); EXPECT_TRUE(fsDB.areAllFieldsAttributes(13, allAttr)); EXPECT_EQUAL(1u, lookup._count); EXPECT_TRUE(fsDB.areAllFieldsAttributes(13, allAttr)); EXPECT_EQUAL(1u, lookup._count); - allAttr.insert(&attr2); + allAttr = document::Field::Set::Builder().add(&attr1).add(&attr2).build(); EXPECT_TRUE(fsDB.areAllFieldsAttributes(17, allAttr)); EXPECT_EQUAL(3u, lookup._count); EXPECT_TRUE(fsDB.areAllFieldsAttributes(17, allAttr)); EXPECT_EQUAL(3u, lookup._count); - document::Field::Set notAllAttr; - notAllAttr.insert(¬_attr1); + document::Field::Set notAllAttr = document::Field::Set::Builder().add(¬_attr1).build(); EXPECT_FALSE(fsDB.areAllFieldsAttributes(33, notAllAttr)); EXPECT_EQUAL(4u, lookup._count); EXPECT_FALSE(fsDB.areAllFieldsAttributes(33, notAllAttr)); EXPECT_EQUAL(4u, lookup._count); - notAllAttr.insert(&attr1); + notAllAttr = document::Field::Set::Builder().add(&attr1).add(¬_attr1).add(&attr2).build(); EXPECT_FALSE(fsDB.areAllFieldsAttributes(39, notAllAttr)); EXPECT_EQUAL(6u, lookup._count); EXPECT_FALSE(fsDB.areAllFieldsAttributes(39, notAllAttr)); diff --git a/searchcore/src/vespa/searchcore/proton/server/documentretriever.cpp b/searchcore/src/vespa/searchcore/proton/server/documentretriever.cpp index 9a219df3f52..031dd4f35e7 100644 --- a/searchcore/src/vespa/searchcore/proton/server/documentretriever.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/documentretriever.cpp @@ -17,6 +17,8 @@ LOG_SETUP(".proton.server.documentretriever"); using document::Document; +using document::Field; +using document::FieldSet; using document::DocumentType; using document::DocumentTypeRepo; using document::PositionDataType; @@ -57,16 +59,16 @@ bool FieldSetAttributeDB::areAllFieldsAttributes(uint64_t key, const document::Field::Set & set) const { std::lock_guard guard(_lock); auto found = _isFieldSetAttributeOnly.find(key); - if (found != _isFieldSetAttributeOnly.end()) { - return found->second; - } - bool isAttributeOnly = true; - for (const document::Field * field : set) { - isAttributeOnly = _fieldInfo.isFieldAttribute(*field); - if (!isAttributeOnly) break; + if (found == _isFieldSetAttributeOnly.end()) { + for (const Field *field : set) { + isAttributeOnly = _fieldInfo.isFieldAttribute(*field); + if (!isAttributeOnly) break; + } + _isFieldSetAttributeOnly[key] = isAttributeOnly; + } else { + isAttributeOnly = found->second; } - _isFieldSetAttributeOnly[key] = isAttributeOnly; return isAttributeOnly; } @@ -82,15 +84,16 @@ DocumentRetriever _attr_manager(attr_manager), _doc_store(doc_store), _possiblePositionFields(), - _attributeFields(), + _attributeFields(Field::Set::emptySet()), _areAllFieldsAttributes(true), _fieldSetAttributeInfo(*this) { const DocumentType * documentType = repo.getDocumentType(docTypeName.getName()); - document::Field::Set fields = documentType->getFieldSet(); + Field::Set fields = documentType->getFieldSet(); int32_t positionDataTypeId = PositionDataType::getInstance().getId(); LOG(debug, "checking document type '%s' for position fields", docTypeName.getName().c_str()); - for (const document::Field * field : fields) { + Field::Set::Builder attrBuilder; + for (const Field* field : fields) { if ((field->getDataType().getId() == positionDataTypeId) || is_array_of_position_type(field->getDataType())) { LOG(debug, "Field '%s' is a position field", field->getName().data()); const vespalib::string & zcurve_name = PositionDataType::getZCurveFieldName(field->getName()); @@ -109,38 +112,38 @@ DocumentRetriever && ((*attr)->getBasicType() != BasicType::PREDICATE) && ((*attr)->getBasicType() != BasicType::REFERENCE)) { - _attributeFields.insert(field); + attrBuilder.add(field); } else { _areAllFieldsAttributes = false; } } } + _attributeFields = attrBuilder.build(); } bool -DocumentRetriever::needFetchFromDocStore(const document::FieldSet & fieldSet) const { +DocumentRetriever::needFetchFromDocStore(const FieldSet & fieldSet) const { switch (fieldSet.getType()) { - case document::FieldSet::Type::NONE: - case document::FieldSet::Type::DOCID: + case FieldSet::Type::NONE: + case FieldSet::Type::DOCID: return false; - case document::FieldSet::Type::ALL: + case FieldSet::Type::ALL: return ! _areAllFieldsAttributes; - case document::FieldSet::Type::FIELD: { - const auto & field = static_cast<const document::Field &>(fieldSet); + case FieldSet::Type::FIELD: { + const auto & field = static_cast<const Field&>(fieldSet); return ! isFieldAttribute(field); } - case document::FieldSet::Type::SET: { + case FieldSet::Type::SET: { const auto &set = static_cast<const document::FieldCollection &>(fieldSet); return ! _fieldSetAttributeInfo.areAllFieldsAttributes(set.hash(), set.getFields()); } - default: - abort(); } + abort(); } bool -DocumentRetriever::isFieldAttribute(const document::Field & field) const { - return _attributeFields.find(&field) != _attributeFields.end(); +DocumentRetriever::isFieldAttribute(const Field& field) const { + return _attributeFields.contains(field); } DocumentRetriever::~DocumentRetriever() = default; @@ -230,34 +233,33 @@ DocumentRetriever::getFullDocument(DocumentIdT lid) const } Document::UP -DocumentRetriever::getPartialDocument(search::DocumentIdT lid, const document::DocumentId & docId, const document::FieldSet & fieldSet) const { +DocumentRetriever::getPartialDocument(search::DocumentIdT lid, const document::DocumentId & docId, const FieldSet & fieldSet) const { Document::UP doc; if (needFetchFromDocStore(fieldSet)) { doc = _doc_store.read(lid, getDocumentTypeRepo()); if (doc) { populate(lid, *doc); } - document::FieldSet::stripFields(*doc, fieldSet); + FieldSet::stripFields(*doc, fieldSet); } else { doc = std::make_unique<Document>(getDocumentType(), docId); switch (fieldSet.getType()) { - case document::FieldSet::Type::ALL: + case FieldSet::Type::ALL: populate(lid, *doc); break; - case document::FieldSet::Type::FIELD: { - const auto & field = static_cast<const document::Field &>(fieldSet); - document::Field::Set attributes; - attributes.insert(&field); - populate(lid, *doc, attributes); + case FieldSet::Type::FIELD: { + const auto & field = static_cast<const Field&>(fieldSet); + populate(lid, *doc, Field::Set::Builder().add(&field).build()); break; } - case document::FieldSet::Type::SET: { + case FieldSet::Type::SET: { const auto &set = static_cast<const document::FieldCollection &>(fieldSet); populate(lid, *doc, set.getFields()); break; } - default: - abort(); + case FieldSet::Type::NONE: + case FieldSet::Type::DOCID: + break; } } return doc; @@ -276,9 +278,9 @@ DocumentRetriever::populate(DocumentIdT lid, Document & doc) const { } void -DocumentRetriever::populate(DocumentIdT lid, Document & doc, const document::Field::Set & attributeFields) const +DocumentRetriever::populate(DocumentIdT lid, Document & doc, const Field::Set & attributeFields) const { - for (const document::Field * field : attributeFields) { + for (const Field* field : attributeFields) { AttributeGuard::UP attr = _attr_manager.getAttribute(field->getName()); if (lid < (*attr)->getCommittedDocIdLimit()) { DocumentFieldRetriever::populate(lid, doc, *field, **attr); diff --git a/searchlib/src/vespa/searchlib/index/doctypebuilder.cpp b/searchlib/src/vespa/searchlib/index/doctypebuilder.cpp index 4656a5e9edd..d82b5e0f4a5 100644 --- a/searchlib/src/vespa/searchlib/index/doctypebuilder.cpp +++ b/searchlib/src/vespa/searchlib/index/doctypebuilder.cpp @@ -43,21 +43,18 @@ DataType::Type convert(Schema::DataType type) { } void -insertStructType(document::DocumenttypesConfig::Documenttype & cfg, - const StructDataType & structType) +insertStructType(document::DocumenttypesConfig::Documenttype & cfg, const StructDataType & structType) { typedef document::DocumenttypesConfig DTC; DTC::Documenttype::Datatype::Sstruct cfgStruct; cfgStruct.name = structType.getName(); Field::Set fieldSet = structType.getFieldSet(); - for (Field::Set::const_iterator itr = fieldSet.begin(); - itr != fieldSet.end(); ++itr) - { - DTC::Documenttype::Datatype::Sstruct::Field field; - field.name = (*itr)->getName(); - field.datatype = (*itr)->getDataType().getId(); - field.id = (*itr)->getId(); - cfgStruct.field.push_back(field); + for (const Field * field : fieldSet) { + DTC::Documenttype::Datatype::Sstruct::Field sField; + sField.name = field->getName(); + sField.datatype = field->getDataType().getId(); + sField.id = field->getId(); + cfgStruct.field.push_back(sField); } cfg.datatype.push_back(DTC::Documenttype::Datatype()); cfg.datatype.back().sstruct = cfgStruct; @@ -66,8 +63,7 @@ insertStructType(document::DocumenttypesConfig::Documenttype & cfg, using namespace document::config_builder; -TypeOrId makeCollection(TypeOrId datatype, - Schema::CollectionType collection_type) { +TypeOrId makeCollection(TypeOrId datatype, Schema::CollectionType collection_type) { switch (collection_type) { case schema::CollectionType::ARRAY: return Array(datatype); diff --git a/searchsummary/src/tests/docsummary/matched_elements_filter/matched_elements_filter_test.cpp b/searchsummary/src/tests/docsummary/matched_elements_filter/matched_elements_filter_test.cpp index 55c363a12c1..d3712d8a90f 100644 --- a/searchsummary/src/tests/docsummary/matched_elements_filter/matched_elements_filter_test.cpp +++ b/searchsummary/src/tests/docsummary/matched_elements_filter/matched_elements_filter_test.cpp @@ -45,8 +45,8 @@ StructDataType::UP make_struct_elem_type() { auto result = std::make_unique<StructDataType>("elem"); - result->addField(Field("name", *DataType::STRING, true)); - result->addField(Field("weight", *DataType::INT, true)); + result->addField(Field("name", *DataType::STRING)); + result->addField(Field("weight", *DataType::INT)); return result; } @@ -87,8 +87,8 @@ public: _array_type(*_elem_type), _map_type(*DataType::STRING, *_elem_type) { - _doc_type.addField(Field("array_in_doc", _array_type, true)); - _doc_type.addField(Field("map_in_doc", _map_type, true)); + _doc_type.addField(Field("array_in_doc", _array_type)); + _doc_type.addField(Field("map_in_doc", _map_type)); auto* result_class = _config.AddResultClass("test", class_id); EXPECT_TRUE(result_class->AddConfigEntry("array", ResType::RES_JSONSTRING)); @@ -96,7 +96,7 @@ public: EXPECT_TRUE(result_class->AddConfigEntry("map2", ResType::RES_JSONSTRING)); _config.CreateEnumMaps(); } - ~DocsumStore() {} + ~DocsumStore(); const ResultConfig& get_config() const { return _config; } const ResultClass* get_class() const { return _config.LookupResultClass(class_id); } search::docsummary::DocsumStoreValue getMappedDocsum() { @@ -130,6 +130,8 @@ public: } }; +DocsumStore::~DocsumStore() = default; + class AttributeContext : public IAttributeContext { private: AttributeVector::SP _map_value_name; @@ -141,7 +143,7 @@ public: _map2_key(AttributeFactory::createAttribute("map2.key", Config(BasicType::STRING, CollectionType::ARRAY))), _array_weight(AttributeFactory::createAttribute("array.weight", Config(BasicType::INT32, CollectionType::ARRAY))) {} - ~AttributeContext() {} + ~AttributeContext() override; const IAttributeVector* getAttribute(const string&) const override { abort(); } const IAttributeVector* getAttributeStableEnum(const string&) const override { abort(); } void getAttributeList(std::vector<const IAttributeVector*>& list) const override { @@ -153,6 +155,8 @@ public: void asyncForAttribute(const vespalib::string&, std::unique_ptr<search::attribute::IAttributeFunctor>) const override { abort(); } }; +AttributeContext::~AttributeContext() = default; + class StateCallback : public GetDocsumsStateCallback { private: std::string _field_name; @@ -164,7 +168,7 @@ public: _matching_elements(matching_elements) { } - ~StateCallback() {} + ~StateCallback() override; void FillSummaryFeatures(GetDocsumsState*, IDocsumEnvironment*) override {} void FillRankFeatures(GetDocsumsState*, IDocsumEnvironment*) override {} std::unique_ptr<MatchingElements> fill_matching_elements(const MatchingElementsFields&) override { @@ -174,6 +178,8 @@ public: } }; +StateCallback::~StateCallback() = default; + class MatchedElementsFilterTest : public ::testing::Test { private: DocsumStore _doc_store; @@ -201,7 +207,7 @@ public: _fields(std::make_shared<MatchingElementsFields>()) { } - ~MatchedElementsFilterTest() {} + ~MatchedElementsFilterTest(); std::unique_ptr<IDocsumFieldWriter> make_field_writer(const std::string& input_field_name) { int input_field_enum = _doc_store.get_config().GetFieldNameEnum().Lookup(input_field_name.c_str()); return MatchedElementsFilterDFW::create(input_field_name, input_field_enum, @@ -215,6 +221,8 @@ public: const MatchingElementsFields& fields() const { return *_fields; } }; +MatchedElementsFilterTest::~MatchedElementsFilterTest() = default; + TEST_F(MatchedElementsFilterTest, filters_elements_in_array_field_value) { expect_filtered("array", {}, "[]"); diff --git a/searchsummary/src/vespa/searchsummary/docsummary/searchdatatype.cpp b/searchsummary/src/vespa/searchsummary/docsummary/searchdatatype.cpp index 7d8bd2a7c22..f0518f378d1 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/searchdatatype.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/searchdatatype.cpp @@ -17,13 +17,13 @@ PrimitiveDataType STRING_OBJ(DataType::T_STRING); StructDataType URI_OBJ("url"); const StructDataType *setUpUriType() { - URI_OBJ.addField(Field("all", STRING_OBJ, true)); - URI_OBJ.addField(Field("scheme", STRING_OBJ, true)); - URI_OBJ.addField(Field("host", STRING_OBJ, true)); - URI_OBJ.addField(Field("port", STRING_OBJ, true)); - URI_OBJ.addField(Field("path", STRING_OBJ, true)); - URI_OBJ.addField(Field("query", STRING_OBJ, true)); - URI_OBJ.addField(Field("fragment", STRING_OBJ, true)); + URI_OBJ.addField(Field("all", STRING_OBJ)); + URI_OBJ.addField(Field("scheme", STRING_OBJ)); + URI_OBJ.addField(Field("host", STRING_OBJ)); + URI_OBJ.addField(Field("port", STRING_OBJ)); + URI_OBJ.addField(Field("path", STRING_OBJ)); + URI_OBJ.addField(Field("query", STRING_OBJ)); + URI_OBJ.addField(Field("fragment", STRING_OBJ)); return &URI_OBJ; } } // namespace diff --git a/standalone-container/pom.xml b/standalone-container/pom.xml index 479a76e2fc6..0a756d5913f 100644 --- a/standalone-container/pom.xml +++ b/standalone-container/pom.xml @@ -62,11 +62,6 @@ <scope>provided</scope> </dependency> <dependency> - <groupId>org.hamcrest</groupId> - <artifactId>hamcrest-all</artifactId> - <scope>test</scope> - </dependency> - <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> diff --git a/standalone-container/src/test/java/com/yahoo/container/standalone/CloudConfigInstallVariablesTest.java b/standalone-container/src/test/java/com/yahoo/container/standalone/CloudConfigInstallVariablesTest.java index 1cd110d8106..9e5d2b694df 100644 --- a/standalone-container/src/test/java/com/yahoo/container/standalone/CloudConfigInstallVariablesTest.java +++ b/standalone-container/src/test/java/com/yahoo/container/standalone/CloudConfigInstallVariablesTest.java @@ -11,9 +11,8 @@ import java.util.stream.Collectors; import static com.yahoo.container.standalone.CloudConfigInstallVariables.toConfigModelsPluginDir; import static com.yahoo.container.standalone.CloudConfigInstallVariables.toConfigServer; import static com.yahoo.container.standalone.CloudConfigInstallVariables.toConfigServers; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.Matchers.contains; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; /** * @author Ulf Lilleengen @@ -24,23 +23,23 @@ public class CloudConfigInstallVariablesTest { @Test public void test_configserver_parsing() { CloudConfigOptions.ConfigServer[] parsed = toConfigServers("myhost.mydomain.com"); - assertThat(parsed.length, is(1)); + assertEquals(1, parsed.length); } @Test public void port_can_be_configured() { CloudConfigOptions.ConfigServer[] parsed = toConfigServers("myhost:123"); int port = parsed[0].port.get(); - assertThat(port, is(123)); + assertEquals(123, port); } @Test public void multiple_spaces_are_supported() { CloudConfigOptions.ConfigServer[] parsed = toConfigServers("test1 test2"); - assertThat(parsed.length, is(2)); + assertEquals(2, parsed.length); List<String> hostNames = Arrays.stream(parsed).map(cs -> cs.hostName).collect(Collectors.toList()); - assertThat(hostNames, contains("test1", "test2")); + assertTrue(hostNames.containsAll(Arrays.asList("test1", "test2"))); } @Test(expected = IllegalArgumentException.class) @@ -56,12 +55,12 @@ public class CloudConfigInstallVariablesTest { @Test public void string_arrays_are_split_on_spaces() { String[] parsed = toConfigModelsPluginDir("/home/vespa/foo /home/vespa/bar "); - assertThat(parsed.length, is(2)); + assertEquals(2, parsed.length); } @Test public void string_arrays_are_split_on_comma() { String[] parsed = toConfigModelsPluginDir("/home/vespa/foo,/home/vespa/bar,"); - assertThat(parsed.length, is(2)); + assertEquals(2, parsed.length); } } diff --git a/standalone-container/src/test/java/com/yahoo/container/standalone/StandaloneSubscriberTest.java b/standalone-container/src/test/java/com/yahoo/container/standalone/StandaloneSubscriberTest.java index 8ca20fdf7cd..3025a641ec9 100644 --- a/standalone-container/src/test/java/com/yahoo/container/standalone/StandaloneSubscriberTest.java +++ b/standalone-container/src/test/java/com/yahoo/container/standalone/StandaloneSubscriberTest.java @@ -15,9 +15,8 @@ import java.util.Map; import java.util.Set; import static com.yahoo.container.standalone.StandaloneContainer.withContainerModel; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.number.OrderingComparison.greaterThan; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; /** * @author Tony Vaagenes @@ -42,15 +41,15 @@ public class StandaloneSubscriberTest { keys.add(componentsKey); Subscriber subscriber = new StandaloneSubscriberFactory(root).getSubscriber(keys); Map<ConfigKey<ConfigInstance>, ConfigInstance> config = subscriber.config(); - assertThat(config.size(), is(2)); + assertEquals(2, config.size()); PlatformBundlesConfig platformBundlesConfig = (PlatformBundlesConfig) config.get(platformBundlesKey); ApplicationBundlesConfig applicationBundlesConfig = (ApplicationBundlesConfig) config.get(applicationBundlesKey); ComponentsConfig componentsConfig = (ComponentsConfig) config.get(componentsKey); - assertThat(platformBundlesConfig.bundlePaths().size(), is(0)); - assertThat(applicationBundlesConfig.bundles().size(), is(0)); - assertThat(componentsConfig.components().size(), greaterThan(10)); + assertEquals(0, platformBundlesConfig.bundlePaths().size()); + assertEquals(0, applicationBundlesConfig.bundles().size()); + assertTrue(componentsConfig.components().size() > 10); return null; }); } diff --git a/storage/src/vespa/storage/persistence/fieldvisitor.cpp b/storage/src/vespa/storage/persistence/fieldvisitor.cpp index 0071d7a010f..ace99dec276 100644 --- a/storage/src/vespa/storage/persistence/fieldvisitor.cpp +++ b/storage/src/vespa/storage/persistence/fieldvisitor.cpp @@ -9,7 +9,7 @@ namespace storage { FieldVisitor::~FieldVisitor() = default; void FieldVisitor::visitFieldValueNode(const document::select::FieldValueNode & node) { - _fields.insert(&_docType.getField(node.getRealFieldName())); + _fields.add(&_docType.getField(node.getRealFieldName())); } void FieldVisitor::visitComparison(const document::select::Compare & node) { diff --git a/storage/src/vespa/storage/persistence/fieldvisitor.h b/storage/src/vespa/storage/persistence/fieldvisitor.h index f2b07e193d6..99558fe6e9c 100644 --- a/storage/src/vespa/storage/persistence/fieldvisitor.h +++ b/storage/src/vespa/storage/persistence/fieldvisitor.h @@ -16,7 +16,7 @@ namespace storage { class FieldVisitor : public document::select::Visitor { private: document::DocumentType _docType; - document::Field::Set _fields; + document::Field::Set::Builder _fields; public: explicit FieldVisitor(const document::DocumentType & docType) @@ -26,7 +26,7 @@ public: ~FieldVisitor() override; document::FieldCollection getFieldSet() { - return document::FieldCollection(_docType, std::move(_fields)); + return document::FieldCollection(_docType, _fields.build()); } void visitFieldValueNode(const document::select::FieldValueNode &) override; diff --git a/streamingvisitors/src/tests/matching_elements_filler/matching_elements_filler_test.cpp b/streamingvisitors/src/tests/matching_elements_filler/matching_elements_filler_test.cpp index b40e045f8b0..d14a792a8d1 100644 --- a/streamingvisitors/src/tests/matching_elements_filler/matching_elements_filler_test.cpp +++ b/streamingvisitors/src/tests/matching_elements_filler/matching_elements_filler_test.cpp @@ -143,15 +143,15 @@ struct MyDocType { }; MyDocType::MyDocType() - : _name_field("name", 1, *DataType::STRING, true), - _weight_field("weight", 2, *DataType::INT, true), + : _name_field("name", 1, *DataType::STRING), + _weight_field("weight", 2, *DataType::INT), _elem_type(make_elem_type(_name_field, _weight_field)), _elem_array_type(_elem_type), _elem_map_type(*DataType::STRING, _elem_type), _str_int_map_type(*DataType::STRING, *DataType::INT), - _elem_array_field("elem_array", 3, _elem_array_type, true), - _elem_map_field("elem_map", 4, _elem_map_type, true), - _str_int_map_field("str_int_map", _str_int_map_type, true), + _elem_array_field("elem_array", 3, _elem_array_type), + _elem_map_field("elem_map", 4, _elem_map_type), + _str_int_map_field("str_int_map", _str_int_map_type), _document_type("test") { _document_type.addField(_elem_array_field); diff --git a/testutil/src/main/java/com/yahoo/test/CollectionPatternMatcher.java b/testutil/src/main/java/com/yahoo/test/CollectionPatternMatcher.java deleted file mode 100644 index 609a5558027..00000000000 --- a/testutil/src/main/java/com/yahoo/test/CollectionPatternMatcher.java +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.test; - -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; -import org.hamcrest.Factory; -import org.hamcrest.Matcher; - -import java.util.Collection; - -/** - * Checks if a collection of strings contains at least one string with the expected regex pattern. - * - * @author gjoranv - * @since 5.1.8 - */ -public class CollectionPatternMatcher extends BaseMatcher<Collection<String>> { - - private final String pattern; - - public CollectionPatternMatcher(String pattern) { - this.pattern = pattern; - } - - @Override - public void describeTo(Description description) { - description.appendText("contains a string that matches expression '" + pattern + "'"); - } - - @Override - public boolean matches(Object o) { - @SuppressWarnings("unchecked") - Collection<String> strings = (Collection<String>) o; - for (String s : strings) - if (s.matches(pattern)) - return true; - return false; - } - - @Factory - public static <T> Matcher<Collection<String>> containsStringWithPattern(String pattern) { - return new CollectionPatternMatcher(pattern); - } - -} diff --git a/testutil/src/main/java/com/yahoo/test/PartialOrderTester.java b/testutil/src/main/java/com/yahoo/test/PartialOrderTester.java index c5fa71ddc62..6152cbf5b25 100644 --- a/testutil/src/main/java/com/yahoo/test/PartialOrderTester.java +++ b/testutil/src/main/java/com/yahoo/test/PartialOrderTester.java @@ -1,10 +1,8 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.test; -import static org.junit.Assert.assertThat; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.Matchers.lessThanOrEqualTo; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; /** * PartialOrderTester implements a partial order test for OrderTester @@ -16,14 +14,14 @@ import static org.hamcrest.Matchers.greaterThanOrEqualTo; public class PartialOrderTester<T extends Comparable<T>> extends OrderTester<T> { protected void lessTest(T a, T b) throws AssertionError { - assertThat(a + " must be less than or equal to " + b, a.compareTo(b), lessThanOrEqualTo(0)); + assertTrue(a + " must be less than or equal to " + b, a.compareTo(b) <= 0); } protected void greaterTest(T a, T b) throws AssertionError { - assertThat(a + " must be greater than or equal to " + b, a.compareTo(b), greaterThanOrEqualTo(0)); + assertTrue(a + " must be greater than or equal to " + b, a.compareTo(b) >= 0); } protected void equalTest(T a, T b) throws AssertionError { - assertThat(a + " must be compared equal to " + b, a.compareTo(b), is(0)); + assertEquals(a + " must be compared equal to " + b, 0, a.compareTo(b)); } } diff --git a/testutil/src/main/java/com/yahoo/test/PatternMatcher.java b/testutil/src/main/java/com/yahoo/test/PatternMatcher.java deleted file mode 100644 index 0aafcf2f1be..00000000000 --- a/testutil/src/main/java/com/yahoo/test/PatternMatcher.java +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.test; - -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; -import org.hamcrest.Factory; -import org.hamcrest.Matcher; - -/** - * Matches a string against an expected regex pattern. - * - * @author gjoranv - * @since 5.1.7 - */ -public class PatternMatcher extends BaseMatcher<String> { - - private final String pattern; - - public PatternMatcher(String pattern) { - this.pattern = pattern; - } - - @Override - public void describeTo(Description description) { - description.appendText("matches expression '" + pattern + "'"); - } - - @Override - public boolean matches(Object o) { - return ((String)o).matches(pattern); - } - - @Factory - public static <T> Matcher<String> matchesPattern(String pattern) { - return new PatternMatcher(pattern); - } - -} diff --git a/testutil/src/main/java/com/yahoo/test/TotalOrderTester.java b/testutil/src/main/java/com/yahoo/test/TotalOrderTester.java index d9acd845428..05a8545d606 100644 --- a/testutil/src/main/java/com/yahoo/test/TotalOrderTester.java +++ b/testutil/src/main/java/com/yahoo/test/TotalOrderTester.java @@ -1,10 +1,8 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.test; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.hamcrest.Matchers.lessThanOrEqualTo; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; /** * TotalOrderTester implements a total order test for OrderTester @@ -24,14 +22,14 @@ import static org.hamcrest.Matchers.greaterThanOrEqualTo; public class TotalOrderTester<T extends Comparable<T>> extends OrderTester<T> { protected void lessTest(T a, T b) throws AssertionError { - assertThat(a + " must be less than " + b, a.compareTo(b), lessThanOrEqualTo(-1)); + assertTrue(a + " must be less than " + b, a.compareTo(b) <= -1); } protected void greaterTest(T a, T b) throws AssertionError { - assertThat(a + " must be greater than " + b, a.compareTo(b), greaterThanOrEqualTo(1)); + assertTrue(a + " must be greater than " + b, a.compareTo(b) >= 1); } protected void equalTest(T a, T b) throws AssertionError { - assertThat(a + " must be compared equal to " + b, a.compareTo(b), is(0)); + assertEquals(a + " must be compared equal to " + b, 0, a.compareTo(b)); } } diff --git a/testutil/src/test/java/com/yahoo/test/PatternMatchersTestCase.java b/testutil/src/test/java/com/yahoo/test/PatternMatchersTestCase.java deleted file mode 100644 index b17d5b36252..00000000000 --- a/testutil/src/test/java/com/yahoo/test/PatternMatchersTestCase.java +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.test; - -import static org.junit.Assert.*; - -import java.util.Arrays; - -import org.junit.Test; - -/** - * Check CollectionPatternMatcher, LinePatternMatcher and PatternMatcher. - * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> - */ -public class PatternMatchersTestCase { - - @Test - public final void testCollections() { - CollectionPatternMatcher cm = new CollectionPatternMatcher("a.*"); - String[] coll = new String[] {}; - assertEquals(false, cm.matches(Arrays.asList(coll))); - coll = new String[] { "ba", "ab" }; - assertEquals(true, cm.matches(Arrays.asList(coll))); - } - - @Test - public final void testLines() { - LinePatternMatcher lp = new LinePatternMatcher("a"); - assertEquals(true, lp.matches("a\nab")); - assertEquals(false, lp.matches("ab\nb")); - } - - @Test - public final void testPatterns() { - PatternMatcher m = new PatternMatcher(".*a.*"); - assertEquals(true, m.matches("ab")); - assertEquals(false, m.matches("b")); - } - -} diff --git a/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/api/AthenzDomainTest.java b/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/api/AthenzDomainTest.java index 2a35fe63d5c..3ce9a8b3431 100644 --- a/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/api/AthenzDomainTest.java +++ b/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/api/AthenzDomainTest.java @@ -5,10 +5,8 @@ import org.junit.Test; import java.util.function.Supplier; -import static org.hamcrest.CoreMatchers.startsWith; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -49,7 +47,7 @@ public class AthenzDomainTest { AthenzDomain domain = domainCreator.get(); fail("Expected IllegalArgumentException for domain: " + domain.getName()); } catch (IllegalArgumentException e) { - assertThat(e.getMessage(), startsWith("Not a valid domain name")); + assertTrue(e.getMessage().startsWith("Not a valid domain name")); } } diff --git a/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/utils/SiaUtilsTest.java b/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/utils/SiaUtilsTest.java index 0e6aff1eeca..85ce3641226 100644 --- a/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/utils/SiaUtilsTest.java +++ b/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/utils/SiaUtilsTest.java @@ -12,11 +12,8 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.List; -import static java.util.Collections.emptyList; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.hasItem; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; /** * @author bjorncs @@ -29,7 +26,7 @@ public class SiaUtilsTest { @Test public void it_finds_all_identity_names_from_files_in_sia_keys_directory() throws IOException { Path siaRoot = tempDirectory.getRoot().toPath(); - assertThat(SiaUtils.findSiaServices(siaRoot), is(emptyList())); + assertTrue(SiaUtils.findSiaServices(siaRoot).isEmpty()); Files.createDirectory(siaRoot.resolve("keys")); AthenzService fooService = new AthenzService("my.domain.foo"); Files.createFile(SiaUtils.getPrivateKeyFile(siaRoot, fooService)); @@ -37,9 +34,9 @@ public class SiaUtilsTest { Files.createFile(SiaUtils.getPrivateKeyFile(siaRoot, barService)); List<AthenzIdentity> siaIdentities = SiaUtils.findSiaServices(siaRoot); - assertThat(siaIdentities.size(), equalTo(2)); - assertThat(siaIdentities, hasItem(fooService)); - assertThat(siaIdentities, hasItem(barService)); + assertEquals(2, siaIdentities.size()); + assertTrue(siaIdentities.contains(fooService)); + assertTrue(siaIdentities.contains(barService)); } } diff --git a/vsm/src/tests/docsum/docsum.cpp b/vsm/src/tests/docsum/docsum.cpp index 3333b8d7718..fa75e6eefed 100644 --- a/vsm/src/tests/docsum/docsum.cpp +++ b/vsm/src/tests/docsum/docsum.cpp @@ -177,8 +177,8 @@ DocsumTest::testSlimeFieldWriter() } { // struct field value StructDataType subType("substruct"); - Field fd("d", 0, *DataType::STRING, true); - Field fe("e", 1, *DataType::STRING, true); + Field fd("d", 0, *DataType::STRING); + Field fe("e", 1, *DataType::STRING); subType.addField(fd); subType.addField(fe); StructFieldValue subValue(subType); @@ -186,9 +186,9 @@ DocsumTest::testSlimeFieldWriter() subValue.setValue(fe, StringFieldValue("qux")); StructDataType type("struct"); - Field fa("a", 0, *DataType::STRING, true); - Field fb("b", 1, *DataType::STRING, true); - Field fc("c", 2, subType, true); + Field fa("a", 0, *DataType::STRING); + Field fb("b", 1, *DataType::STRING); + Field fc("c", 2, subType); type.addField(fa); type.addField(fb); type.addField(fc); @@ -241,8 +241,8 @@ DocsumTest::requireThatSlimeFieldWriterHandlesMap() } { // map<string, struct> StructDataType structType("struct"); - Field fa("a", 0, *DataType::STRING, true); - Field fb("b", 1, *DataType::STRING, true); + Field fa("a", 0, *DataType::STRING); + Field fb("b", 1, *DataType::STRING); structType.addField(fa); structType.addField(fb); StructFieldValue structValue(structType); diff --git a/vsm/src/tests/document/document.cpp b/vsm/src/tests/document/document.cpp index b8175a01547..bb18c4b0a91 100644 --- a/vsm/src/tests/document/document.cpp +++ b/vsm/src/tests/document/document.cpp @@ -24,8 +24,8 @@ DocumentTest::testStorageDocument() { DocumentType dt("testdoc", 0); - Field fa("a", 0, *DataType::STRING, true); - Field fb("b", 1, *DataType::STRING, true); + Field fa("a", 0, *DataType::STRING); + Field fb("b", 1, *DataType::STRING); dt.addField(fa); dt.addField(fb); diff --git a/yolean/pom.xml b/yolean/pom.xml index 742142fe167..f994d401c60 100644 --- a/yolean/pom.xml +++ b/yolean/pom.xml @@ -19,16 +19,6 @@ <scope>provided</scope> </dependency> <dependency> - <groupId>org.hamcrest</groupId> - <artifactId>hamcrest-library</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.hamcrest</groupId> - <artifactId>hamcrest-core</artifactId> - <scope>test</scope> - </dependency> - <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> diff --git a/yolean/src/test/java/com/yahoo/yolean/chain/ChainBuilderTest.java b/yolean/src/test/java/com/yahoo/yolean/chain/ChainBuilderTest.java index 70bb0ab1397..84467283398 100644 --- a/yolean/src/test/java/com/yahoo/yolean/chain/ChainBuilderTest.java +++ b/yolean/src/test/java/com/yahoo/yolean/chain/ChainBuilderTest.java @@ -4,13 +4,13 @@ package com.yahoo.yolean.chain; import org.junit.Test; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import static com.yahoo.yolean.chain.Dependencies.after; import static com.yahoo.yolean.chain.Dependencies.before; import static com.yahoo.yolean.chain.Dependencies.provides; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.collection.IsIterableContainingInOrder.contains; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -103,6 +103,13 @@ public class ChainBuilderTest { assertEquals("myChain", chain.id()); } + boolean equalOrder(Iterator<Filter> a, Iterator<Filter> b) { + while (a.hasNext() && b.hasNext()) { + if ( ! a.next().equals(b.next())) return false; + } + return a.hasNext() == b.hasNext(); + } + @Test public void filters_without_dependencies_are_not_reordered() { List<Filter> filters = new ArrayList<>(); @@ -114,7 +121,7 @@ public class ChainBuilderTest { chain.add(filter); } - assertThat(chain.build(), contains(filters.toArray())); + assertTrue(equalOrder(chain.build().iterator(), filters.iterator())); } @Test(expected = ChainCycleException.class) diff --git a/yolean/src/test/java/com/yahoo/yolean/chain/ContainsSameElements.java b/yolean/src/test/java/com/yahoo/yolean/chain/ContainsSameElements.java deleted file mode 100644 index d3fddeafbb3..00000000000 --- a/yolean/src/test/java/com/yahoo/yolean/chain/ContainsSameElements.java +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.yolean.chain; - -import org.hamcrest.Description; -import org.hamcrest.Matcher; -import org.hamcrest.TypeSafeMatcher; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.IdentityHashMap; -import java.util.List; -import java.util.Set; - -import static java.util.Collections.sort; - -/** - * @author Tony Vaagenes - */ -class ContainsSameElements<T> extends TypeSafeMatcher<Collection<? super T>> { - - private final Set<T> identitySet; - - public static <T> Matcher<Collection<? super T>> containsSameElements(Collection<T> collection) { - return new ContainsSameElements<>(collection); - } - - public ContainsSameElements(Collection<T> collection) { - identitySet = toIdentitySet(collection); - } - - @SuppressWarnings("SuspiciousMethodCalls") - @Override - protected boolean matchesSafely(Collection<? super T> collection2) { - for (Object elem : collection2) { - if (!identitySet.contains(elem)) { - return false; - } - } - - return collection2.size() == identitySet.size(); - } - - @Override - public void describeTo(Description description) { - description.appendText("containsSameElements "); - appendCollection(description, identitySet); - } - - private void appendCollection(Description description, Collection<?> collection) { - description.appendValueList("{", ", ", "}", elementsToStringSorted(collection)); - } - - private List<String> elementsToStringSorted(Collection<?> collection) { - List<String> result = new ArrayList<>(); - for (Object o : collection) { - result.add(o.toString()); - } - sort(result); - return result; - } - - @Override - protected void describeMismatchSafely(Collection<? super T> collection, Description description) { - description.appendText("was "); - appendCollection(description, collection); - } - - public static <T> Set<T> toIdentitySet(Collection<? extends T> collection) { - Set<T> identitySet = Collections.newSetFromMap(new IdentityHashMap<T, Boolean>()); - identitySet.addAll(collection); - return identitySet; - } -} diff --git a/yolean/src/test/java/com/yahoo/yolean/chain/EnumeratedIdentitySetTest.java b/yolean/src/test/java/com/yahoo/yolean/chain/EnumeratedIdentitySetTest.java index 5f0692e186f..30951f88162 100644 --- a/yolean/src/test/java/com/yahoo/yolean/chain/EnumeratedIdentitySetTest.java +++ b/yolean/src/test/java/com/yahoo/yolean/chain/EnumeratedIdentitySetTest.java @@ -5,17 +5,14 @@ import org.junit.Test; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; import java.util.IdentityHashMap; import java.util.Iterator; import java.util.List; import java.util.Set; -import static com.yahoo.yolean.chain.ContainsSameElements.containsSameElements; -import static com.yahoo.yolean.chain.ContainsSameElements.toIdentitySet; import static java.util.Collections.singleton; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.collection.IsEmptyCollection.empty; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertSame; @@ -81,6 +78,28 @@ public class EnumeratedIdentitySetTest { assertTrue(collectedElements.containsKey(element)); } } + private static boolean containsSame(Object a, Collection<?> coll) { + for (Object b : coll) { + if (a == b) return true; + } + return false; + } + private static boolean containsSubsetSame(Collection<?> subSet, Collection<?> superSet) { + for (Object a : subSet) { + if ( ! containsSame(a, superSet)) return false; + } + return true; + } + + private static boolean containsAllSame(Collection<?> a, Collection<?> b) { + return containsSubsetSame(a, b) && containsSubsetSame(b, a); + } + + private static <T> Set<T> toIdentitySet(Collection<? extends T> collection) { + Set<T> identitySet = Collections.newSetFromMap(new IdentityHashMap<>()); + identitySet.addAll(collection); + return identitySet; + } @Test public void toArray() { @@ -89,8 +108,9 @@ public class EnumeratedIdentitySetTest { Object[] array = set.toArray(); Element[] array2 = set.toArray(new Element[0]); - assertThat(Arrays.asList(array), containsSameElements(set)); - assertThat(Arrays.asList(array2), containsSameElements(set)); + assertTrue(set.containsAll(Arrays.asList(array))); + assertTrue(containsAllSame(Arrays.asList(array), set)); + assertTrue(containsAllSame(Arrays.asList(array2), set)); } @Test @@ -123,7 +143,7 @@ public class EnumeratedIdentitySetTest { EnumeratedIdentitySet<Element> set = new EnumeratedIdentitySet<>(); set.addAll(elements); - assertThat(set, containsSameElements(elements)); + assertTrue(containsAllSame(set, elements)); } @Test @@ -134,7 +154,7 @@ public class EnumeratedIdentitySetTest { boolean changed = set.retainAll(toIdentitySet(elements.subList(3, 10))); assertTrue(changed); - assertThat(set, containsSameElements(elements.subList(3, 5))); + assertTrue(containsAllSame(set, elements.subList(3, 5))); changed = set.retainAll(toIdentitySet(elements)); assertFalse(changed); @@ -144,7 +164,7 @@ public class EnumeratedIdentitySetTest { public void removeAll() { EnumeratedIdentitySet<Element> set = new EnumeratedIdentitySet<>(elements); set.removeAll(elements.subList(0, 5)); - assertThat(set, containsSameElements(elements.subList(5, 10))); + assertTrue(containsAllSame(set, elements.subList(5, 10))); } @Test @@ -157,8 +177,8 @@ public class EnumeratedIdentitySetTest { @Test public void removeNulls() { Element[] singletonArray = { null, elements.get(0), null }; - assertThat(EnumeratedIdentitySet.removeNulls(singletonArray), - containsSameElements(Arrays.asList(elements.get(0)))); + assertTrue(containsAllSame(EnumeratedIdentitySet.removeNulls(singletonArray), + Arrays.asList(elements.get(0)))); Element[] elementsWithNull = new Element[20]; @@ -168,7 +188,7 @@ public class EnumeratedIdentitySetTest { copyElementsTo(iterator, elementsWithNull, 4, 8); copyElementsTo(iterator, elementsWithNull, 19, 1); - assertThat(EnumeratedIdentitySet.removeNulls(elementsWithNull), containsSameElements(elements)); + assertTrue(containsAllSame(EnumeratedIdentitySet.removeNulls(elementsWithNull), elements)); } private void copyElementsTo(Iterator<Element> iterator, Element[] array, int startIndex, int numItems) { @@ -203,7 +223,7 @@ public class EnumeratedIdentitySetTest { } set.add(new Element()); - assertThat(set.numbers(), containsSameElements(range(0, 10))); + assertTrue(containsAllSame(set.numbers(), range(0, 10))); } @Test @@ -218,7 +238,7 @@ public class EnumeratedIdentitySetTest { assertTrue(set.numbers().isEmpty()); set.add(new Element()); - assertThat(set.numbers(), containsSameElements(singleton(0))); + assertTrue(containsAllSame(set.numbers(), singleton(0))); } private List<Integer> range(int start, int endInclusive) { diff --git a/zookeeper-server/CMakeLists.txt b/zookeeper-server/CMakeLists.txt index b146390046c..e61cf8ba4d5 100644 --- a/zookeeper-server/CMakeLists.txt +++ b/zookeeper-server/CMakeLists.txt @@ -1,4 +1,5 @@ # Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. add_subdirectory(zookeeper-server-common) add_subdirectory(zookeeper-server-3.5.6) +add_subdirectory(zookeeper-server-3.5.7) add_subdirectory(zookeeper-server-3.5.8) diff --git a/zookeeper-server/pom.xml b/zookeeper-server/pom.xml index 28f18000c2d..0499c989b07 100644 --- a/zookeeper-server/pom.xml +++ b/zookeeper-server/pom.xml @@ -14,6 +14,7 @@ <modules> <module>zookeeper-server-common</module> <module>zookeeper-server-3.5.6</module> + <module>zookeeper-server-3.5.7</module> <module>zookeeper-server-3.5.8</module> </modules> <dependencies> diff --git a/zookeeper-server/zookeeper-server-3.5.7/CMakeLists.txt b/zookeeper-server/zookeeper-server-3.5.7/CMakeLists.txt new file mode 100644 index 00000000000..50d803460f1 --- /dev/null +++ b/zookeeper-server/zookeeper-server-3.5.7/CMakeLists.txt @@ -0,0 +1,5 @@ +# Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +install_fat_java_artifact(zookeeper-server-3.5.7) +# TODO: Needs to be included when this is the wanted default version (and other symlinks need to be removed) +#install_symlink(lib/jars/zookeeper-server-3.5.7-jar-with-dependencies.jar lib/jars/zookeeper-server-jar-with-dependencies.jar) + diff --git a/zookeeper-server/zookeeper-server-3.5.7/pom.xml b/zookeeper-server/zookeeper-server-3.5.7/pom.xml new file mode 100644 index 00000000000..db0a2b77e37 --- /dev/null +++ b/zookeeper-server/zookeeper-server-3.5.7/pom.xml @@ -0,0 +1,78 @@ +<?xml version="1.0"?> +<!-- Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>com.yahoo.vespa</groupId> + <artifactId>zookeeper-server</artifactId> + <version>7-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + <artifactId>zookeeper-server-3.5.7</artifactId> + <packaging>container-plugin</packaging> + <version>7-SNAPSHOT</version> + <dependencies> + <dependency> + <groupId>com.yahoo.vespa</groupId> + <artifactId>zookeeper-server-common</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.zookeeper</groupId> + <artifactId>zookeeper</artifactId> + <version>3.5.7</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-jdk14</artifactId> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.7.5</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <compilerArgs> + <arg>-Xlint:all</arg> + <arg>-Werror</arg> + </compilerArgs> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <redirectTestOutputToFile>${test.hide}</redirectTestOutputToFile> + <forkMode>once</forkMode> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-install-plugin</artifactId> + <configuration> + <updateReleaseInfo>true</updateReleaseInfo> + </configuration> + </plugin> + <plugin> + <groupId>com.yahoo.vespa</groupId> + <artifactId>bundle-plugin</artifactId> + <extensions>true</extensions> + <configuration> + <importPackage>com.sun.management</importPackage> + <bundleSymbolicName>zookeeper-server</bundleSymbolicName> + </configuration> + </plugin> + </plugins> + </build> +</project> diff --git a/zookeeper-server/zookeeper-server-3.5.7/src/main/java/com/yahoo/vespa/zookeeper/VespaZooKeeperServerImpl.java b/zookeeper-server/zookeeper-server-3.5.7/src/main/java/com/yahoo/vespa/zookeeper/VespaZooKeeperServerImpl.java new file mode 100644 index 00000000000..ee3695b02f8 --- /dev/null +++ b/zookeeper-server/zookeeper-server-3.5.7/src/main/java/com/yahoo/vespa/zookeeper/VespaZooKeeperServerImpl.java @@ -0,0 +1,56 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.zookeeper; + +import com.google.inject.Inject; +import com.yahoo.cloud.config.ZookeeperServerConfig; +import com.yahoo.component.AbstractComponent; +import com.yahoo.security.tls.TransportSecurityUtils; + +import java.util.logging.Level; + +import static com.yahoo.vespa.defaults.Defaults.getDefaults; +import static com.yahoo.vespa.zookeeper.Configurator.zookeeperServerHostnames; + +/** + * Writes zookeeper config and starts zookeeper server. + * + * @author Ulf Lilleengen + * @author Harald Musum + */ +public class VespaZooKeeperServerImpl extends AbstractComponent implements Runnable, VespaZooKeeperServer { + private static final java.util.logging.Logger log = java.util.logging.Logger.getLogger(VespaZooKeeperServerImpl.class.getName()); + private final Thread zkServerThread; + private final ZookeeperServerConfig zookeeperServerConfig; + + @Inject + public VespaZooKeeperServerImpl(ZookeeperServerConfig zookeeperServerConfig) { + this.zookeeperServerConfig = zookeeperServerConfig; + new Configurator(zookeeperServerConfig).writeConfigToDisk(TransportSecurityUtils.getOptions()); + zkServerThread = new Thread(this, "zookeeper server"); + zkServerThread.start(); + } + + private void shutdown() { + zkServerThread.interrupt(); + try { + zkServerThread.join(); + } catch (InterruptedException e) { + log.log(Level.WARNING, "Error joining server thread on shutdown", e); + } + } + + @Override + public void run() { + String[] args = new String[]{getDefaults().underVespaHome(zookeeperServerConfig.zooKeeperConfigFile())}; + log.log(Level.INFO, "Starting ZooKeeper server with config file " + args[0] + + ". Trying to establish ZooKeeper quorum (members: " + zookeeperServerHostnames(zookeeperServerConfig) + ")"); + org.apache.zookeeper.server.quorum.QuorumPeerMain.main(args); + } + + @Override + public void deconstruct() { + shutdown(); + super.deconstruct(); + } + +} |