-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
1 parent
d425377
commit 576d89a
Showing
2 changed files
with
87 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
sdk-springboot/src/test/java/io/dapr/springboot/DaprRuntimeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
|
||
} | ||
|
||
} |