summaryrefslogtreecommitdiffstats
path: root/standalone-container/src/test/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'standalone-container/src/test/java/com')
-rw-r--r--standalone-container/src/test/java/com/yahoo/container/standalone/CloudConfigInstallVariablesTest.java67
-rw-r--r--standalone-container/src/test/java/com/yahoo/container/standalone/StandaloneContainer.java61
-rw-r--r--standalone-container/src/test/java/com/yahoo/container/standalone/StandaloneContainerActivatorTest.java5
-rw-r--r--standalone-container/src/test/java/com/yahoo/container/standalone/StandaloneContainerTest.java74
-rw-r--r--standalone-container/src/test/java/com/yahoo/container/standalone/StandaloneSubscriberTest.java52
5 files changed, 256 insertions, 3 deletions
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
new file mode 100644
index 00000000000..1cd110d8106
--- /dev/null
+++ b/standalone-container/src/test/java/com/yahoo/container/standalone/CloudConfigInstallVariablesTest.java
@@ -0,0 +1,67 @@
+// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.container.standalone;
+
+import com.yahoo.vespa.model.container.configserver.option.CloudConfigOptions;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.List;
+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;
+
+/**
+ * @author Ulf Lilleengen
+ * @author Tony Vaagenes
+ */
+public class CloudConfigInstallVariablesTest {
+
+ @Test
+ public void test_configserver_parsing() {
+ CloudConfigOptions.ConfigServer[] parsed = toConfigServers("myhost.mydomain.com");
+ assertThat(parsed.length, is(1));
+ }
+
+ @Test
+ public void port_can_be_configured() {
+ CloudConfigOptions.ConfigServer[] parsed = toConfigServers("myhost:123");
+ int port = parsed[0].port.get();
+ assertThat(port, is(123));
+ }
+
+ @Test
+ public void multiple_spaces_are_supported() {
+ CloudConfigOptions.ConfigServer[] parsed = toConfigServers("test1 test2");
+ assertThat(parsed.length, is(2));
+
+ List<String> hostNames = Arrays.stream(parsed).map(cs -> cs.hostName).collect(Collectors.toList());
+ assertThat(hostNames, contains("test1", "test2"));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void missing_port_gives_exception() {
+ toConfigServer("myhost:");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void non_numeric_port_gives_exception() {
+ toConfigServer("myhost:non-numeric");
+ }
+
+ @Test
+ public void string_arrays_are_split_on_spaces() {
+ String[] parsed = toConfigModelsPluginDir("/home/vespa/foo /home/vespa/bar ");
+ assertThat(parsed.length, is(2));
+ }
+
+ @Test
+ public void string_arrays_are_split_on_comma() {
+ String[] parsed = toConfigModelsPluginDir("/home/vespa/foo,/home/vespa/bar,");
+ assertThat(parsed.length, is(2));
+ }
+}
diff --git a/standalone-container/src/test/java/com/yahoo/container/standalone/StandaloneContainer.java b/standalone-container/src/test/java/com/yahoo/container/standalone/StandaloneContainer.java
new file mode 100644
index 00000000000..a00ffd8b985
--- /dev/null
+++ b/standalone-container/src/test/java/com/yahoo/container/standalone/StandaloneContainer.java
@@ -0,0 +1,61 @@
+// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.container.standalone;
+
+import com.yahoo.collections.Pair;
+import com.yahoo.config.model.ConfigModelRepo;
+import com.yahoo.config.model.producer.AbstractConfigProducerRoot;
+import com.yahoo.io.IOUtils;
+import com.yahoo.vespa.model.VespaModel;
+import com.yahoo.vespa.model.container.xml.ContainerModelBuilder.Networking;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Creates a local application from vespa-services fragments.
+ *
+ * @author Tony Vaagenes
+ * @author ollivir
+ */
+public class StandaloneContainer {
+ public static String firstContainerId(AbstractConfigProducerRoot root) {
+ return root.getConfigProducer("container").get().getConfigId();
+ }
+
+ interface ThrowingFunction<T, U> {
+ U apply(T input) throws Exception;
+ }
+
+ static <T> T withContainerModel(String servicesXml, ThrowingFunction<VespaModel, T> f) throws Exception {
+ return withTempDirectory(applicationPath -> {
+ writeServicesXml(applicationPath, servicesXml);
+
+ LocalFileDb distributedFiles = new LocalFileDb(applicationPath);
+ VespaModel root;
+ Pair<VespaModel, com.yahoo.vespa.model.container.Container> rc = StandaloneContainerApplication.createContainerModel(
+ applicationPath, distributedFiles, applicationPath.resolve("preprocesedApp").toFile(), Networking.enable,
+ new ConfigModelRepo());
+ root = rc.getFirst();
+ return f.apply(root);
+ });
+ }
+
+ private static <T> T withTempDirectory(ThrowingFunction<Path, T> f) throws Exception {
+ Path directory = Files.createTempDirectory("application");
+ try {
+ return f.apply(directory);
+ } finally {
+ IOUtils.recursiveDeleteDir(directory.toFile());
+ }
+ }
+
+ private static void writeServicesXml(Path applicationPath, String servicesXml) throws IOException {
+ Path path = applicationPath.resolve("services.xml");
+ List<String> output = Arrays.asList("<?xml version=\"1.0\" encoding=\"utf-8\"?>", servicesXml);
+ Files.write(path, output, StandardCharsets.UTF_8);
+ }
+}
diff --git a/standalone-container/src/test/java/com/yahoo/container/standalone/StandaloneContainerActivatorTest.java b/standalone-container/src/test/java/com/yahoo/container/standalone/StandaloneContainerActivatorTest.java
index 8d413ade0f0..71668b595a0 100644
--- a/standalone-container/src/test/java/com/yahoo/container/standalone/StandaloneContainerActivatorTest.java
+++ b/standalone-container/src/test/java/com/yahoo/container/standalone/StandaloneContainerActivatorTest.java
@@ -1,4 +1,4 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.standalone;
import com.google.inject.Module;
@@ -25,7 +25,6 @@ import static org.junit.Assert.assertThat;
/**
* @author Einar M R Rosenvinge
- * @since 5.22.0
*/
public class StandaloneContainerActivatorTest {
@@ -100,7 +99,7 @@ public class StandaloneContainerActivatorTest {
private static Module newAppDirBinding(final Path applicationDir) {
return binder -> binder.bind(Path.class)
- .annotatedWith(StandaloneContainerApplication.applicationPathName())
+ .annotatedWith(StandaloneContainerApplication.APPLICATION_PATH_NAME)
.toInstance(applicationDir);
}
diff --git a/standalone-container/src/test/java/com/yahoo/container/standalone/StandaloneContainerTest.java b/standalone-container/src/test/java/com/yahoo/container/standalone/StandaloneContainerTest.java
new file mode 100644
index 00000000000..6d4abc84dbc
--- /dev/null
+++ b/standalone-container/src/test/java/com/yahoo/container/standalone/StandaloneContainerTest.java
@@ -0,0 +1,74 @@
+// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.container.standalone;
+
+import com.yahoo.vespa.model.AbstractService;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author Tony Vaagenes
+ * @author gjoranv
+ * @author ollivir
+ */
+
+public class StandaloneContainerTest {
+ private static final String PLAIN_XML = "<container version=\"1.0\" />";
+
+ @Test
+ public void container_is_allowed_root_element() throws Exception {
+ StandaloneContainer.withContainerModel(PLAIN_XML, root -> null);
+ }
+
+ @Test
+ public void services_is_allowed_root_element() throws Exception {
+ String servicesXml = "<services>" + //
+ "<container version=\"1.0\" />" + //
+ "</services>";
+
+ StandaloneContainer.withContainerModel(servicesXml, root -> null);
+ }
+
+ @Test(expected = Exception.class)
+ public void multiple_container_elements_cannot_be_deployed() throws Exception {
+ String twoContainersXml = "<services>" + //
+ "<container id=\"container-1\" version=\"1.0\" />" + //
+ "<container id=\"container-2\" version=\"1.0\" />" + //
+ "</services>";
+
+ StandaloneContainer.withContainerModel(twoContainersXml, root -> null);
+ }
+
+ @Test
+ public void application_preprocessor_is_run() throws Exception {
+ String servicesXml = "<services xmlns:preprocess=\"properties\">" + //
+ "<preprocess:properties>" + //
+ "<container_id>container-1</container_id>" + //
+ "</preprocess:properties>" + //
+ "<container id=\"${container_id}\" version=\"1.0\" />" + //
+ "</services>";
+
+ StandaloneContainer.withContainerModel(servicesXml, root -> {
+ assertTrue(root.getConfigProducer("container-1/standalone").isPresent());
+ return null;
+ });
+ }
+
+ @Test
+ public void no_default_ports_are_enabled_when_using_http() throws Exception {
+ String xml = "<jdisc version=\"1.0\">" + //
+ "<http>" + //
+ "<server port=\"4000\" id=\"server1\" />" + //
+ "</http>" + //
+ "</jdisc>";
+
+ StandaloneContainer.withContainerModel(xml, root -> {
+ AbstractService container = (AbstractService) root.getConfigProducer("jdisc/standalone").get();
+ System.out.println("portCnt: " + container.getPortCount());
+ System.out.println("numPorts: " + container.getNumPortsAllocated());
+ assertEquals(1, container.getNumPortsAllocated());
+ return null;
+ });
+ }
+}
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
new file mode 100644
index 00000000000..dd755e8e6dd
--- /dev/null
+++ b/standalone-container/src/test/java/com/yahoo/container/standalone/StandaloneSubscriberTest.java
@@ -0,0 +1,52 @@
+// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.container.standalone;
+
+import com.yahoo.config.ConfigInstance;
+import com.yahoo.container.BundlesConfig;
+import com.yahoo.container.ComponentsConfig;
+import com.yahoo.container.di.config.Subscriber;
+import com.yahoo.vespa.config.ConfigKey;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import java.util.HashSet;
+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;
+
+/**
+ * @author Tony Vaagenes
+ * @author ollivir
+ */
+public class StandaloneSubscriberTest {
+ private static ConfigKey<ConfigInstance> bundlesKey = key("bundles");
+ private static ConfigKey<ConfigInstance> componentsKey = key("components");
+
+ private static ConfigKey<ConfigInstance> key(String name) {
+ return new ConfigKey<>(name, "container", "container");
+ }
+
+ @Test
+ @Ignore
+ public void standalone_subscriber() throws Exception {
+ withContainerModel("<container version=\"1.0\"></container>", root -> {
+ Set<ConfigKey<ConfigInstance>> keys = new HashSet<>();
+ keys.add(bundlesKey);
+ keys.add(componentsKey);
+ Subscriber subscriber = new StandaloneSubscriberFactory(root).getSubscriber(keys);
+ Map<ConfigKey<ConfigInstance>, ConfigInstance> config = subscriber.config();
+ assertThat(config.size(), is(2));
+
+ BundlesConfig bundlesConfig = (BundlesConfig) config.get(bundlesKey);
+ ComponentsConfig componentsConfig = (ComponentsConfig) config.get(componentsKey);
+
+ assertThat(bundlesConfig.bundle().size(), is(0));
+ assertThat(componentsConfig.components().size(), greaterThan(10));
+ return null;
+ });
+ }
+}