mirror of https://github.com/dapr/java-sdk.git
Allow subscription builder to be called with the same route (#805)
If the route being provided for a topic is the same as it was previously, do not raise an exception. Fixes parallel test execution without `forkMode=always` (#766) Signed-off-by: John Ewart <johnewart@microsoft.com> Signed-off-by: John Ewart <johnewart@microsoft.com>
This commit is contained in:
parent
5dd45adcf2
commit
aeb42d833f
|
@ -47,10 +47,12 @@ class DaprSubscriptionBuilder {
|
||||||
*/
|
*/
|
||||||
DaprSubscriptionBuilder setDefaultPath(String path) {
|
DaprSubscriptionBuilder setDefaultPath(String path) {
|
||||||
if (defaultPath != null) {
|
if (defaultPath != null) {
|
||||||
|
if (!defaultPath.equals(path)) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
String.format(
|
String.format(
|
||||||
"a default route is already set for topic %s on pubsub %s",
|
"a default route is already set for topic %s on pubsub %s (current: '%s', supplied: '%s')",
|
||||||
this.topic, this.pubsubName));
|
this.topic, this.pubsubName, this.defaultPath, path));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
defaultPath = path;
|
defaultPath = path;
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -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<String, String> metadata = new HashMap<String, String>();
|
||||||
|
|
||||||
|
Rule rule = new Rule(){
|
||||||
|
@Override
|
||||||
|
public Class<? extends Annotation> 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<String, String> metadata = new HashMap<String, String>();
|
||||||
|
|
||||||
|
Rule rule = new Rule(){
|
||||||
|
@Override
|
||||||
|
public Class<? extends Annotation> 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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue