summaryrefslogtreecommitdiffstats
path: root/config-provisioning/src/test/java/com/yahoo/config/provision/HostFilterTest.java
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 /config-provisioning/src/test/java/com/yahoo/config/provision/HostFilterTest.java
Publish
Diffstat (limited to 'config-provisioning/src/test/java/com/yahoo/config/provision/HostFilterTest.java')
-rw-r--r--config-provisioning/src/test/java/com/yahoo/config/provision/HostFilterTest.java76
1 files changed, 76 insertions, 0 deletions
diff --git a/config-provisioning/src/test/java/com/yahoo/config/provision/HostFilterTest.java b/config-provisioning/src/test/java/com/yahoo/config/provision/HostFilterTest.java
new file mode 100644
index 00000000000..b16e2d76ca8
--- /dev/null
+++ b/config-provisioning/src/test/java/com/yahoo/config/provision/HostFilterTest.java
@@ -0,0 +1,76 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.config.provision;
+
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Optional;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author bratseth
+ */
+public class HostFilterTest {
+
+ @Test
+ public void testSingleConditionFilter() {
+ HostFilter all = HostFilter.all();
+ HostFilter hostname = HostFilter.hostname("host1");
+ HostFilter type = HostFilter.clusterType(ClusterSpec.Type.content);
+ HostFilter id = HostFilter.clusterId(ClusterSpec.Id.from("type1"));
+
+ assertTrue( all.matches("anyhost", "flavor", membership("container/anytype/0")));
+ assertFalse(hostname.matches("anyhost", "flavor", membership("container/anytype/0")));
+ assertFalse(type.matches("anyhost", "flavor", membership("container/anytype/0")));
+ assertFalse(id.matches("anyhost", "flavor", membership("container/anytype/0")));
+
+ assertTrue( all.matches("anyhost", "flavor", membership("content/anytype/0")));
+ assertFalse(hostname.matches("anyhost", "flavor", membership("content/anytype/0")));
+ assertTrue( type.matches("anyhost", "flavor", membership("content/anytype/0")));
+ assertFalse( id.matches("anyhost", "flavor", membership("content/anytype/0")));
+
+ assertTrue( all.matches("host1", "flavor", membership("content/anytype/0")));
+ assertTrue( hostname.matches("host1", "flavor", membership("content/anytype/0")));
+ assertTrue( type.matches("host1", "flavor", membership("content/anytype/0")));
+ assertFalse( id.matches("host1", "flavor", membership("content/anytype/0")));
+
+ assertTrue( all.matches("host1", "flavor", membership("content/type1/0")));
+ assertTrue( hostname.matches("host1", "flavor", membership("content/type1/0")));
+ assertTrue( type.matches("host1", "flavor", membership("content/type1/0")));
+ assertTrue( id.matches("host1", "flavor", membership("content/type1/0")));
+ }
+
+ @Test
+ public void testMultiConditionFilter() {
+ HostFilter typeAndId = HostFilter.from(Collections.emptyList(),
+ Collections.emptyList(),
+ Collections.singletonList(ClusterSpec.Type.content),
+ Collections.singletonList(ClusterSpec.Id.from("type1")));
+
+ assertFalse(typeAndId.matches("anyhost", "flavor", membership("content/anyType/0")));
+ assertFalse(typeAndId.matches("anyhost", "flavor", membership("container/type1/0")));
+ assertTrue(typeAndId.matches("anyhost", "flavor", membership("content/type1/0")));
+ }
+
+ @Test
+ public void testMultiConditionFilterFromStrings() {
+ HostFilter typeAndId = HostFilter.from("host1 host2, host3,host4", " , ,flavor", null, "type1 ");
+
+ assertFalse(typeAndId.matches("anotherhost", "flavor", membership("content/type1/0")));
+ assertTrue(typeAndId.matches("host1", "flavor", membership("content/type1/0")));
+ assertTrue(typeAndId.matches("host2", "flavor", membership("content/type1/0")));
+ assertTrue(typeAndId.matches("host3", "flavor", membership("content/type1/0")));
+ assertTrue(typeAndId.matches("host4", "flavor", membership("content/type1/0")));
+ assertFalse(typeAndId.matches("host1", "flavor", membership("content/type2/0")));
+ assertFalse(typeAndId.matches("host4", "differentflavor", membership("content/type1/0")));
+ }
+
+ private Optional<ClusterMembership> membership(String membershipString) {
+ return Optional.of(ClusterMembership.from(membershipString, Optional.empty()));
+ }
+
+}