diff --git a/sdk-springboot/src/main/java/io/dapr/springboot/DaprSubscriptionBuilder.java b/sdk-springboot/src/main/java/io/dapr/springboot/DaprSubscriptionBuilder.java index 9ed65508e..7a91fef06 100644 --- a/sdk-springboot/src/main/java/io/dapr/springboot/DaprSubscriptionBuilder.java +++ b/sdk-springboot/src/main/java/io/dapr/springboot/DaprSubscriptionBuilder.java @@ -47,10 +47,12 @@ class DaprSubscriptionBuilder { */ DaprSubscriptionBuilder setDefaultPath(String path) { if (defaultPath != null) { - throw new RuntimeException( - String.format( - "a default route is already set for topic %s on pubsub %s", - this.topic, this.pubsubName)); + if (!defaultPath.equals(path)) { + throw new RuntimeException( + String.format( + "a default route is already set for topic %s on pubsub %s (current: '%s', supplied: '%s')", + this.topic, this.pubsubName, this.defaultPath, path)); + } } defaultPath = path; return this; diff --git a/sdk-springboot/src/test/java/io/dapr/springboot/DaprRuntimeTest.java b/sdk-springboot/src/test/java/io/dapr/springboot/DaprRuntimeTest.java new file mode 100644 index 000000000..0488ef299 --- /dev/null +++ b/sdk-springboot/src/test/java/io/dapr/springboot/DaprRuntimeTest.java @@ -0,0 +1,81 @@ +package io.dapr.springboot; + +import io.dapr.Rule; +import org.junit.Assert; +import org.junit.Test; + +import java.lang.annotation.Annotation; +import java.util.HashMap; + +public class DaprRuntimeTest { + + @Test + public void testPubsubDefaultPathDuplicateRegistration() { + String pubSubName = "pubsub"; + String topicName = "topic"; + String match = ""; + String route = String.format("%s/%s", pubSubName, topicName); + HashMap metadata = new HashMap(); + + Rule rule = new Rule(){ + @Override + public Class annotationType() { + return Rule.class; + } + + public String match() { + return match; + } + public int priority() { + return 0; + } + }; + + DaprRuntime runtime = DaprRuntime.getInstance(); + Assert.assertNotNull(runtime); + + // We should be able to register the same route multiple times + runtime.addSubscribedTopic( + pubSubName, topicName, match, rule.priority(), route, metadata); + runtime.addSubscribedTopic( + pubSubName, topicName, match, rule.priority(), route, metadata); + } + + @Test(expected = RuntimeException.class) + public void testPubsubDefaultPathDifferentRegistration() { + String pubSubName = "pubsub"; + String topicName = "topic"; + String match = ""; + String firstRoute = String.format("%s/%s", pubSubName, topicName); + String secondRoute = String.format("%s/%s/subscribe", pubSubName, topicName); + + + HashMap metadata = new HashMap(); + + Rule rule = new Rule(){ + @Override + public Class annotationType() { + return Rule.class; + } + + public String match() { + return match; + } + public int priority() { + return 0; + } + }; + + DaprRuntime runtime = DaprRuntime.getInstance(); + + Assert.assertNotNull(runtime); + runtime.addSubscribedTopic( + pubSubName, topicName, match, rule.priority(), firstRoute, metadata); + + // Supplying the same pubsub bits but a different route should fail + runtime.addSubscribedTopic( + pubSubName, topicName, match, rule.priority(), secondRoute, metadata); + + } + +}