aboutsummaryrefslogtreecommitdiffstats
path: root/clustercontroller-apps/src/test/java/com
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
commit72231250ed81e10d66bfe70701e64fa5fe50f712 (patch)
tree2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /clustercontroller-apps/src/test/java/com
Publish
Diffstat (limited to 'clustercontroller-apps/src/test/java/com')
-rw-r--r--clustercontroller-apps/src/test/java/com/yahoo/vespa/clustercontroller/apps/clustercontroller/ClusterControllerClusterConfigurerTest.java77
-rw-r--r--clustercontroller-apps/src/test/java/com/yahoo/vespa/clustercontroller/apps/clustercontroller/ClusterControllerTest.java57
-rw-r--r--clustercontroller-apps/src/test/java/com/yahoo/vespa/clustercontroller/apps/clustercontroller/StateRestApiV2HandlerTest.java51
-rw-r--r--clustercontroller-apps/src/test/java/com/yahoo/vespa/clustercontroller/apps/clustercontroller/StatusHandlerTest.java19
4 files changed, 204 insertions, 0 deletions
diff --git a/clustercontroller-apps/src/test/java/com/yahoo/vespa/clustercontroller/apps/clustercontroller/ClusterControllerClusterConfigurerTest.java b/clustercontroller-apps/src/test/java/com/yahoo/vespa/clustercontroller/apps/clustercontroller/ClusterControllerClusterConfigurerTest.java
new file mode 100644
index 00000000000..6cf4f962c9f
--- /dev/null
+++ b/clustercontroller-apps/src/test/java/com/yahoo/vespa/clustercontroller/apps/clustercontroller/ClusterControllerClusterConfigurerTest.java
@@ -0,0 +1,77 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.clustercontroller.apps.clustercontroller;
+
+import com.yahoo.cloud.config.SlobroksConfig;
+import com.yahoo.cloud.config.ZookeepersConfig;
+import com.yahoo.jdisc.Metric;
+import com.yahoo.vespa.config.content.FleetcontrollerConfig;
+import com.yahoo.vespa.config.content.StorDistributionConfig;
+import junit.framework.TestCase;
+
+import java.util.Map;
+
+public class ClusterControllerClusterConfigurerTest extends TestCase {
+
+ public void testSimple() throws Exception {
+ ClusterController controller = new ClusterController();
+ StorDistributionConfig.Builder distributionConfig = new StorDistributionConfig.Builder();
+ StorDistributionConfig.Group.Builder group = new StorDistributionConfig.Group.Builder();
+ group.index("0").name("foo");
+ StorDistributionConfig.Group.Nodes.Builder node = new StorDistributionConfig.Group.Nodes.Builder();
+ node.index(0);
+ group.nodes.add(node);
+ distributionConfig.group.add(group);
+ FleetcontrollerConfig.Builder fleetcontrollerConfig = new FleetcontrollerConfig.Builder();
+ fleetcontrollerConfig.cluster_name("storage").index(0).zookeeper_server("zoo");
+ SlobroksConfig.Builder slobroksConfig = new SlobroksConfig.Builder();
+ SlobroksConfig.Slobrok.Builder slobrok = new SlobroksConfig.Slobrok.Builder();
+ slobrok.connectionspec("foo");
+ slobroksConfig.slobrok.add(slobrok);
+ ZookeepersConfig.Builder zookeepersConfig = new ZookeepersConfig.Builder();
+ zookeepersConfig.zookeeperserverlist("foo");
+ Metric metric = new Metric() {
+ @Override
+ public void set(String s, Number number, Context context) {}
+ @Override
+ public void add(String s, Number number, Context context) {}
+ @Override
+ public Context createContext(Map<String, ?> stringMap) { return null; }
+ };
+ // Used in standalone modus to get config without a cluster controller instance
+ ClusterControllerClusterConfigurer configurer = new ClusterControllerClusterConfigurer(
+ null,
+ new StorDistributionConfig(distributionConfig),
+ new FleetcontrollerConfig(fleetcontrollerConfig),
+ new SlobroksConfig(slobroksConfig),
+ new ZookeepersConfig(zookeepersConfig),
+ metric
+ );
+ assertTrue(configurer.getOptions() != null);
+
+ // Oki with no zookeeper if one node
+ zookeepersConfig.zookeeperserverlist("");
+ new ClusterControllerClusterConfigurer(
+ controller,
+ new StorDistributionConfig(distributionConfig),
+ new FleetcontrollerConfig(fleetcontrollerConfig),
+ new SlobroksConfig(slobroksConfig),
+ new ZookeepersConfig(zookeepersConfig),
+ metric
+ );
+
+ try{
+ fleetcontrollerConfig.fleet_controller_count(5);
+ new ClusterControllerClusterConfigurer(
+ controller,
+ new StorDistributionConfig(distributionConfig),
+ new FleetcontrollerConfig(fleetcontrollerConfig),
+ new SlobroksConfig(slobroksConfig),
+ new ZookeepersConfig(zookeepersConfig),
+ metric
+ );
+ fail("Should not get here");
+ } catch (Exception e) {
+ assertEquals("Must set zookeeper server with multiple fleetcontrollers", e.getMessage());
+ }
+ }
+}
diff --git a/clustercontroller-apps/src/test/java/com/yahoo/vespa/clustercontroller/apps/clustercontroller/ClusterControllerTest.java b/clustercontroller-apps/src/test/java/com/yahoo/vespa/clustercontroller/apps/clustercontroller/ClusterControllerTest.java
new file mode 100644
index 00000000000..be5c7bf026e
--- /dev/null
+++ b/clustercontroller-apps/src/test/java/com/yahoo/vespa/clustercontroller/apps/clustercontroller/ClusterControllerTest.java
@@ -0,0 +1,57 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+/**
+ * Doesn't really test cluster controller, but runs some lines of code.
+ * System tests verifies that container can load it..
+ */
+package com.yahoo.vespa.clustercontroller.apps.clustercontroller;
+
+import com.yahoo.jdisc.Metric;
+import com.yahoo.vespa.clustercontroller.core.FleetController;
+import com.yahoo.vespa.clustercontroller.core.FleetControllerOptions;
+import junit.framework.TestCase;
+
+import java.util.Map;
+
+public class ClusterControllerTest extends TestCase {
+ private FleetControllerOptions options = new FleetControllerOptions("storage");
+ private Metric metric = new Metric() {
+ @Override
+ public void set(String s, Number number, Context context) {}
+ @Override
+ public void add(String s, Number number, Context context) {}
+ @Override
+ public Context createContext(Map<String, ?> stringMap) { return null; }
+ };
+
+ public void setUp() {
+ options = new FleetControllerOptions("storage");
+ options.zooKeeperServerAddress = null;
+ options.slobrokConfigId = "raw:";
+ options.slobrokConnectionSpecs = null;
+ }
+
+ public void testSimple() throws Exception {
+ // Cluster controller object keeps state and should never be remade, so should
+ // inject nothing
+ ClusterController cc = new ClusterController();
+ cc.setOptions("storage", options, metric);
+ cc.setOptions("storage", options, metric);
+ cc.getFleetControllers();
+ cc.getAll();
+
+ assertTrue(cc.get("storage") != null);
+ assertFalse(cc.get("music") != null);
+ cc.deconstruct();
+ }
+
+ public void testShutdownException() throws Exception {
+ ClusterController cc = new ClusterController() {
+ void shutdownController(FleetController controller) throws Exception {
+ throw new Exception("Foo");
+ }
+ };
+ cc.setOptions("storage", options, metric);
+ cc.deconstruct();
+ }
+
+}
diff --git a/clustercontroller-apps/src/test/java/com/yahoo/vespa/clustercontroller/apps/clustercontroller/StateRestApiV2HandlerTest.java b/clustercontroller-apps/src/test/java/com/yahoo/vespa/clustercontroller/apps/clustercontroller/StateRestApiV2HandlerTest.java
new file mode 100644
index 00000000000..9230c08f735
--- /dev/null
+++ b/clustercontroller-apps/src/test/java/com/yahoo/vespa/clustercontroller/apps/clustercontroller/StateRestApiV2HandlerTest.java
@@ -0,0 +1,51 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.clustercontroller.apps.clustercontroller;
+
+import com.yahoo.cloud.config.ClusterInfoConfig;
+import com.yahoo.container.logging.AccessLog;
+import com.yahoo.vespa.clustercontroller.core.restapiv2.ClusterControllerStateRestAPI;
+import junit.framework.TestCase;
+
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+public class StateRestApiV2HandlerTest extends TestCase {
+
+ public void testNoMatchingSockets() {
+ ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 100, 100, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(1000));
+ ClusterController controller = new ClusterController();
+ ClusterInfoConfig config = new ClusterInfoConfig(
+ new ClusterInfoConfig.Builder().clusterId("cluster-id").nodeCount(1));
+ ClusterInfoConfig.Builder clusterConfig = new ClusterInfoConfig.Builder();
+ new StateRestApiV2Handler(executor, controller, config, AccessLog.voidAccessLog());
+ executor.shutdown();
+ }
+
+ public void testMappingOfIndexToClusterControllers() {
+ ClusterInfoConfig.Builder builder = new ClusterInfoConfig.Builder()
+ .clusterId("cluster-id")
+ .nodeCount(1)
+ .services(new ClusterInfoConfig.Services.Builder()
+ .index(1)
+ .hostname("host-1")
+ .ports(new ClusterInfoConfig.Services.Ports.Builder().number(80).tags("state http"))
+ .ports(new ClusterInfoConfig.Services.Ports.Builder().number(81).tags("ignored port http")))
+ .services(new ClusterInfoConfig.Services.Builder()
+ .index(3)
+ .hostname("host-3")
+ .ports(new ClusterInfoConfig.Services.Ports.Builder().number(85).tags("state http"))
+ .ports(new ClusterInfoConfig.Services.Ports.Builder().number(86).tags("foo http bar state")));
+
+ ClusterInfoConfig config = new ClusterInfoConfig(builder);
+ Map<Integer, ClusterControllerStateRestAPI.Socket> mapping = StateRestApiV2Handler.getClusterControllerSockets(config);
+ Map<Integer, ClusterControllerStateRestAPI.Socket> expected = new TreeMap<>();
+
+ expected.put(1, new ClusterControllerStateRestAPI.Socket("host-1", 80));
+ expected.put(3, new ClusterControllerStateRestAPI.Socket("host-3", 85));
+
+ assertEquals(expected, mapping);
+ }
+}
diff --git a/clustercontroller-apps/src/test/java/com/yahoo/vespa/clustercontroller/apps/clustercontroller/StatusHandlerTest.java b/clustercontroller-apps/src/test/java/com/yahoo/vespa/clustercontroller/apps/clustercontroller/StatusHandlerTest.java
new file mode 100644
index 00000000000..e066e0b367e
--- /dev/null
+++ b/clustercontroller-apps/src/test/java/com/yahoo/vespa/clustercontroller/apps/clustercontroller/StatusHandlerTest.java
@@ -0,0 +1,19 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.clustercontroller.apps.clustercontroller;
+
+import com.yahoo.container.logging.AccessLog;
+import junit.framework.TestCase;
+
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+public class StatusHandlerTest extends TestCase {
+
+ public void testSimple() {
+ ClusterController controller = new ClusterController();
+ ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 100, 100, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(1000));
+ StatusHandler handler = new StatusHandler(controller, executor, AccessLog.voidAccessLog());
+ executor.shutdown();
+ }
+}