summaryrefslogtreecommitdiffstats
path: root/documentapi
diff options
context:
space:
mode:
authorTor Brede Vekterli <vekterli@yahoo-inc.com>2017-05-18 15:06:49 +0200
committerTor Brede Vekterli <vekterli@yahoo-inc.com>2017-05-18 15:06:49 +0200
commit832ee21d59d3ae4415b845aa39020313567f5d22 (patch)
tree772d9bfe6919abeae2e3be00f5498ad72df6142f /documentapi
parent480270b558640b0bc5f4d63f64cb0b36a85a85fc (diff)
Don't swallow document policy creation exceptions
Prevents an ErrorPolicy from being cached for the policy when a policy (likely transiently) cannot be created. Caching an ErrorPolicy will fail all ops towards the policy until the process has been restarted.
Diffstat (limited to 'documentapi')
-rw-r--r--documentapi/pom.xml5
-rwxr-xr-xdocumentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/RoutingPolicyRepository.java16
-rw-r--r--documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/RoutingPolicyRepositoryTest.java33
3 files changed, 44 insertions, 10 deletions
diff --git a/documentapi/pom.xml b/documentapi/pom.xml
index 17fd0cc5505..41552fb33e1 100644
--- a/documentapi/pom.xml
+++ b/documentapi/pom.xml
@@ -43,6 +43,11 @@
<version>${project.version}</version>
</dependency>
<dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>com.yahoo.vespa</groupId>
<artifactId>config</artifactId>
<version>${project.version}</version>
diff --git a/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/RoutingPolicyRepository.java b/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/RoutingPolicyRepository.java
index 26b0eec8cf4..1a3a23eb8e4 100755
--- a/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/RoutingPolicyRepository.java
+++ b/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/RoutingPolicyRepository.java
@@ -55,22 +55,18 @@ class RoutingPolicyRepository {
log.log(LogLevel.ERROR, "No routing policy factory found for name '" + name + "'.");
return null;
}
- DocumentProtocolRoutingPolicy ret;
- try {
- ret = factory.createPolicy(param);
- } catch (Exception e) {
- ret = new ErrorPolicy(e.getMessage());
+ final DocumentProtocolRoutingPolicy ret = factory.createPolicy(param);
+
+ if (ret == null) {
+ log.log(LogLevel.ERROR, "Routing policy factory " + factory.getClass().getName() + " failed to create a " +
+ "routing policy for parameter '" + name + "'.");
+ return null;
}
if (ret.getMetrics() != null) {
metrics.routingPolicyMetrics.addMetric(ret.getMetrics());
}
- if (ret == null) {
- log.log(LogLevel.ERROR, "Routing policy factory " + factory.getClass().getName() + " failed to create a " +
- "routing policy for parameter '" + name + "'.");
- return null;
- }
return ret;
}
}
diff --git a/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/RoutingPolicyRepositoryTest.java b/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/RoutingPolicyRepositoryTest.java
new file mode 100644
index 00000000000..609e83683b1
--- /dev/null
+++ b/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/RoutingPolicyRepositoryTest.java
@@ -0,0 +1,33 @@
+// Copyright 2017 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.documentapi.messagebus.protocol;
+
+import com.yahoo.documentapi.metrics.DocumentProtocolMetricSet;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class RoutingPolicyRepositoryTest {
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ @Test
+ public void policy_creation_does_not_swallow_exception() {
+ final DocumentProtocolMetricSet metrics = new DocumentProtocolMetricSet();
+ final RoutingPolicyRepository repo = new RoutingPolicyRepository(metrics);
+ final RoutingPolicyFactory factory = mock(RoutingPolicyFactory.class);
+
+ when(factory.createPolicy(anyString())).thenThrow(new IllegalArgumentException("oh no!"));
+ repo.putFactory("foo", factory);
+
+ expectedException.expectMessage("oh no!");
+ expectedException.expect(IllegalArgumentException.class);
+
+ repo.createPolicy("foo", "bar");
+ }
+
+}