Migrate to Junit5 (#910)

* Migrating to Junit5

Signed-off-by: Emanuel Alves <emanuel.j.b.alves@gmail.com>

* Fix spotbugs errors

Signed-off-by: Emanuel Alves <emanuel.j.b.alves@gmail.com>

* Fix spotbugs errors

Signed-off-by: Emanuel Alves <emanuel.j.b.alves@gmail.com>

* remove unreachable code due to expected exception being thrown

Signed-off-by: Emanuel Alves <emanuel.j.b.alves@gmail.com>

* Increase daprRun timeout

Signed-off-by: Emanuel Alves <emanuel.j.b.alves@gmail.com>

* wait 5 secs before launching toxiproxy

Signed-off-by: Emanuel Alves <emanuel.j.b.alves@gmail.com>

* Rollback spotbugs bump version

Signed-off-by: Emanuel Alves <emanuel.j.b.alves@gmail.com>

* extract junit-bom version to a property

Signed-off-by: Emanuel Alves <emanuel.j.b.alves@gmail.com>

* Change settings in SdkResiliencyIT to reduce flakiness.

Signed-off-by: Artur Souza <asouza.pro@gmail.com>

* Wait for sidecar in SDKResiliencyIT

Signed-off-by: Artur Souza <asouza.pro@gmail.com>

---------

Signed-off-by: Emanuel Alves <emanuel.j.b.alves@gmail.com>
Signed-off-by: Artur Souza <asouza.pro@gmail.com>
Co-authored-by: Artur Souza <artursouza.ms@outlook.com>
Co-authored-by: Artur Souza <asouza.pro@gmail.com>
This commit is contained in:
Emanuel Alves 2023-09-22 18:25:10 +01:00 committed by GitHub
parent 86893a0742
commit 56d9270a0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
108 changed files with 3490 additions and 3509 deletions

View File

@ -96,6 +96,7 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>

69
pom.xml
View File

@ -37,6 +37,9 @@
<spotbugs.exclude.filter.file>../spotbugs-exclude.xml</spotbugs.exclude.filter.file>
<springboot.version>2.7.8</springboot.version>
<argLine>--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED</argLine>
<failsafe.version>3.1.2</failsafe.version>
<surefire.version>3.1.2</surefire.version>
<junit-bom.version>5.7.2</junit-bom.version>
</properties>
<distributionManagement>
@ -70,16 +73,11 @@
<version>${grpc.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.7.2</version>
<scope>test</scope>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>${junit-bom.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
@ -91,6 +89,33 @@
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${failsafe.version}</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<!--suppress UnresolvedMavenProperty -->
<skip>${skipITs}</skip>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
@ -102,13 +127,6 @@
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
@ -165,23 +183,6 @@
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>failsafe-maven-plugin</artifactId>
<version>2.4.3-alpha-1</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<!--suppress UnresolvedMavenProperty -->
<skip>${skipITs}</skip>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>

View File

@ -27,11 +27,6 @@
<artifactId>dapr-sdk</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
@ -45,8 +40,7 @@
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.5.2</version>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>

View File

@ -12,41 +12,44 @@ limitations under the License.
*/
package io.dapr.actors;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* Unit tests for ActorId.
*/
public class ActorIdTest {
@Test(expected = IllegalArgumentException.class)
@Test
public void initializeNewActorIdObjectWithNullId() {
ActorId actorId = new ActorId(null);
assertThrows(IllegalArgumentException.class, () ->{ActorId actorId = new ActorId(null);});
}
@Test
public void getId() {
String id = "123";
ActorId actorId = new ActorId(id);
Assert.assertEquals(id, actorId.toString());
assertEquals(id, actorId.toString());
}
@Test
public void verifyToString() {
String id = "123";
ActorId actorId = new ActorId(id);
Assert.assertEquals(id, actorId.toString());
assertEquals(id, actorId.toString());
}
@Test
public void verifyEqualsByObject() {
List<Wrapper> values = createEqualsTestValues();
for (Wrapper w : values) {
Assert.assertEquals(w.expectedResult, w.item1.equals(w.item2));
assertEquals(w.expectedResult, w.item1.equals(w.item2));
}
}
@ -56,7 +59,7 @@ public class ActorIdTest {
for (Wrapper w : values) {
ActorId a1 = (ActorId) w.item1;
Object a2 = w.item2;
Assert.assertEquals(w.expectedResult, a1.equals(a2));
assertEquals(w.expectedResult, a1.equals(a2));
}
}
@ -66,7 +69,7 @@ public class ActorIdTest {
for (Wrapper w : values) {
ActorId a1 = (ActorId) w.item1;
ActorId a2 = (ActorId) w.item2;
Assert.assertEquals(w.expectedResult, a1.compareTo(a2));
assertEquals(w.expectedResult, a1.compareTo(a2));
}
}

View File

@ -15,51 +15,53 @@ package io.dapr.actors.client;
import io.dapr.actors.ActorId;
import io.dapr.actors.ActorType;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class ActorProxyBuilderTest {
private static ActorClient actorClient;
@BeforeClass
@BeforeAll
public static void initClass() {
actorClient = new ActorClient();
}
@AfterClass
@AfterAll
public static void tearDownClass() {
actorClient.close();
}
@Test(expected = IllegalArgumentException.class)
@Test
public void buildWithNullActorId() {
new ActorProxyBuilder("test", Object.class, actorClient)
.build(null);
assertThrows(IllegalArgumentException.class, () -> new ActorProxyBuilder("test", Object.class, actorClient)
.build(null));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void buildWithEmptyActorType() {
new ActorProxyBuilder("", Object.class, actorClient);
assertThrows(IllegalArgumentException.class, () -> new ActorProxyBuilder("", Object.class, actorClient));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void buildWithNullActorType() {
new ActorProxyBuilder(null, Object.class, actorClient);
assertThrows(IllegalArgumentException.class, () -> new ActorProxyBuilder(null, Object.class, actorClient));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void buildWithNullSerializer() {
new ActorProxyBuilder("MyActor", Object.class, actorClient)
assertThrows(IllegalArgumentException.class, () -> new ActorProxyBuilder("MyActor", Object.class, actorClient)
.withObjectSerializer(null)
.build(new ActorId("100"));
.build(new ActorId("100")));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void buildWithNullClient() {
new ActorProxyBuilder("MyActor", Object.class, null);
assertThrows(IllegalArgumentException.class, () -> new ActorProxyBuilder("MyActor", Object.class, null));
}
@Test()
@ -67,9 +69,9 @@ public class ActorProxyBuilderTest {
ActorProxyBuilder<ActorProxy> builder = new ActorProxyBuilder("test", ActorProxy.class, actorClient);
ActorProxy actorProxy = builder.build(new ActorId("100"));
Assert.assertNotNull(actorProxy);
Assert.assertEquals("test", actorProxy.getActorType());
Assert.assertEquals("100", actorProxy.getActorId().toString());
Assertions.assertNotNull(actorProxy);
Assertions.assertEquals("test", actorProxy.getActorType());
Assertions.assertEquals("100", actorProxy.getActorId().toString());
}
@Test()
@ -77,7 +79,7 @@ public class ActorProxyBuilderTest {
ActorProxyBuilder<MyActor> builder = new ActorProxyBuilder(MyActor.class, actorClient);
MyActor actorProxy = builder.build(new ActorId("100"));
Assert.assertNotNull(actorProxy);
Assertions.assertNotNull(actorProxy);
}
@Test()
@ -85,7 +87,7 @@ public class ActorProxyBuilderTest {
ActorProxyBuilder<ActorWithDefaultName> builder = new ActorProxyBuilder(ActorWithDefaultName.class, actorClient);
ActorWithDefaultName actorProxy = builder.build(new ActorId("100"));
Assert.assertNotNull(actorProxy);
Assertions.assertNotNull(actorProxy);
}
@ActorType(name = "MyActor")

View File

@ -18,11 +18,12 @@ import io.dapr.actors.ActorMethod;
import io.dapr.exceptions.DaprException;
import io.dapr.serializer.DaprObjectSerializer;
import io.dapr.serializer.DefaultObjectSerializer;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import reactor.core.publisher.Mono;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -38,8 +39,8 @@ public class ActorProxyImplTest {
new ActorId("100"),
serializer,
daprClient);
Assert.assertEquals(actorProxy.getActorId().toString(), "100");
Assert.assertEquals(actorProxy.getActorType(), "myActorType");
Assertions.assertEquals(actorProxy.getActorId().toString(), "100");
Assertions.assertEquals(actorProxy.getActorType(), "myActorType");
}
@Test()
@ -59,9 +60,9 @@ public class ActorProxyImplTest {
Mono<MyData> result = actorProxy.invokeMethod("getData", MyData.class);
MyData myData = result.block();
Assert.assertNotNull(myData);
Assert.assertEquals("valueA", myData.getPropertyA());
Assert.assertEquals("valueB", myData.getPropertyB());// propertyB=null
Assertions.assertNotNull(myData);
Assertions.assertEquals("valueA", myData.getPropertyA());
Assertions.assertEquals("valueB", myData.getPropertyB());// propertyB=null
}
@Test()
@ -80,9 +81,9 @@ public class ActorProxyImplTest {
daprClient);
MyData myData = (MyData) actorProxy.invoke(actorProxy, Actor.class.getMethod("getData"), null);
Assert.assertNotNull(myData);
Assert.assertEquals("valueA", myData.getPropertyA());
Assert.assertEquals("valueB", myData.getPropertyB());// propertyB=null
Assertions.assertNotNull(myData);
Assertions.assertEquals("valueA", myData.getPropertyA());
Assertions.assertEquals("valueB", myData.getPropertyB());// propertyB=null
}
@Test()
@ -101,11 +102,11 @@ public class ActorProxyImplTest {
daprClient);
Mono<MyData> res = (Mono<MyData>) actorProxy.invoke(actorProxy, Actor.class.getMethod("getDataMono"), null);
Assert.assertNotNull(res);
Assertions.assertNotNull(res);
MyData myData = res.block();
Assert.assertNotNull(myData);
Assert.assertEquals("valueA", myData.getPropertyA());
Assert.assertEquals("valueB", myData.getPropertyB());// propertyB=null
Assertions.assertNotNull(myData);
Assertions.assertEquals("valueA", myData.getPropertyA());
Assertions.assertEquals("valueB", myData.getPropertyB());// propertyB=null
}
@Test()
@ -128,7 +129,7 @@ public class ActorProxyImplTest {
Actor.class.getMethod("echo", String.class),
new Object[] { "hello world" } );
Assert.assertEquals("OK", res);
Assertions.assertEquals("OK", res);
}
@Test()
@ -151,8 +152,8 @@ public class ActorProxyImplTest {
Actor.class.getMethod("echoMono", String.class),
new Object[] { "hello world" } );
Assert.assertNotNull(res);
Assert.assertEquals("OK", res.block());
Assertions.assertNotNull(res);
Assertions.assertEquals("OK", res.block());
}
@Test()
@ -170,7 +171,7 @@ public class ActorProxyImplTest {
daprClient);
Object myData = actorProxy.invoke(actorProxy, Actor.class.getMethod("doSomething"), null);
Assert.assertNull(myData);
Assertions.assertNull(myData);
}
@Test()
@ -188,8 +189,8 @@ public class ActorProxyImplTest {
daprClient);
Mono<Void> myData = (Mono<Void>)actorProxy.invoke(actorProxy, Actor.class.getMethod("doSomethingMono"), null);
Assert.assertNotNull(myData);
Assert.assertNull(myData.block());
Assertions.assertNotNull(myData);
Assertions.assertNull(myData.block());
}
@Test()
@ -211,11 +212,11 @@ public class ActorProxyImplTest {
Actor.class.getMethod("doSomethingMonoWithArg", String.class),
new Object[] { "hello world" });
Assert.assertNotNull(myData);
Assert.assertNull(myData.block());
Assertions.assertNotNull(myData);
Assertions.assertNull(myData.block());
}
@Test(expected = UnsupportedOperationException.class)
@Test
public void invokeActorMethodWithTooManyArgsViaReflection() throws NoSuchMethodException {
final ActorClient daprClient = mock(ActorClient.class);
@ -225,13 +226,10 @@ public class ActorProxyImplTest {
new DefaultObjectSerializer(),
daprClient);
Mono<Void> myData = (Mono<Void>)actorProxy.invoke(
assertThrows(UnsupportedOperationException.class, () -> actorProxy.invoke(
actorProxy,
Actor.class.getMethod("tooManyArgs", String.class, String.class),
new Object[] { "hello", "world" });
Assert.assertNotNull(myData);
Assert.assertNull(myData.block());
new Object[] { "hello", "world" }));
}
@Test()
@ -253,7 +251,7 @@ public class ActorProxyImplTest {
Actor.class.getMethod("process", String.class),
new Object[] { "hello world" } );
Assert.assertNull(res);
Assertions.assertNull(res);
}
@Test()
@ -270,10 +268,10 @@ public class ActorProxyImplTest {
Mono<MyData> result = actorProxy.invokeMethod("getData", MyData.class);
MyData myData = result.block();
Assert.assertNull(myData);
Assertions.assertNull(myData);
}
@Test(expected = RuntimeException.class)
@Test
public void invokeActorMethodWithIncorrectReturnType() {
final ActorClient daprClient = mock(ActorClient.class);
when(daprClient.invoke(anyString(), anyString(), anyString(), Mockito.isNull()))
@ -287,10 +285,7 @@ public class ActorProxyImplTest {
Mono<MyData> result = actorProxy.invokeMethod("getData", MyData.class);
result.doOnSuccess(x ->
Assert.fail("Not exception was throw"))
.doOnError(Throwable::printStackTrace
).block();
assertThrows(DaprException.class, () ->result.block());
}
@Test()
@ -312,13 +307,13 @@ public class ActorProxyImplTest {
Mono<MyData> result = actorProxy.invokeMethod("getData", saveData, MyData.class);
MyData myData = result.block();
Assert.assertNotNull(myData);
Assert.assertEquals("valueA", myData.getPropertyA());
Assert.assertEquals("valueB", myData.getPropertyB());//propertyB=null
Assertions.assertNotNull(myData);
Assertions.assertEquals("valueA", myData.getPropertyA());
Assertions.assertEquals("valueB", myData.getPropertyB());//propertyB=null
}
@Test(expected = DaprException.class)
@Test
public void invokeActorMethodSavingDataWithIncorrectReturnType() {
final ActorClient daprClient = mock(ActorClient.class);
when(daprClient.invoke(anyString(), anyString(), anyString(), Mockito.isNotNull()))
@ -335,10 +330,7 @@ public class ActorProxyImplTest {
saveData.setPropertyB("valueB");
Mono<MyData> result = actorProxy.invokeMethod("getData", saveData, MyData.class);
result.doOnSuccess(x ->
Assert.fail("Not exception was throw"))
.doOnError(Throwable::printStackTrace
).block();
assertThrows(DaprException.class, () ->result.block());
}
@ -360,11 +352,11 @@ public class ActorProxyImplTest {
Mono<MyData> result = actorProxy.invokeMethod("getData", saveData, MyData.class);
MyData myData = result.block();
Assert.assertNull(myData);
Assertions.assertNull(myData);
}
@Test(expected = DaprException.class)
@Test
public void invokeActorMethodSavingDataWithIncorrectInputType() {
final ActorClient daprClient = mock(ActorClient.class);
when(daprClient.invoke(anyString(), anyString(), anyString(), Mockito.isNotNull()))
@ -381,12 +373,7 @@ public class ActorProxyImplTest {
saveData.setPropertyB("valueB");
saveData.setMyData(saveData);
Mono<MyData> result = actorProxy.invokeMethod("getData", saveData, MyData.class);
result.doOnSuccess(x ->
Assert.fail("Not exception was throw"))
.doOnError(Throwable::printStackTrace
).block();
assertThrows(DaprException.class, () -> actorProxy.invokeMethod("getData", saveData, MyData.class));
}
@Test()
@ -407,11 +394,11 @@ public class ActorProxyImplTest {
Mono<Void> result = actorProxy.invokeMethod("getData", saveData);
Void emptyResponse = result.block();
Assert.assertNull(emptyResponse);
Assertions.assertNull(emptyResponse);
}
@Test(expected = DaprException.class)
@Test
public void invokeActorMethodWithDataWithVoidIncorrectInputType() {
MyData saveData = new MyData();
saveData.setPropertyA("valueA");
@ -428,9 +415,7 @@ public class ActorProxyImplTest {
new DefaultObjectSerializer(),
daprClient);
Mono<Void> result = actorProxy.invokeMethod("getData", saveData);
Void emptyResponse = result.doOnError(Throwable::printStackTrace).block();
Assert.assertNull(emptyResponse);
assertThrows(DaprException.class, () -> actorProxy.invokeMethod("getData", saveData));
}
@Test()
@ -447,7 +432,7 @@ public class ActorProxyImplTest {
Mono<Void> result = actorProxy.invokeMethod("getData");
Void emptyResponse = result.block();
Assert.assertNull(emptyResponse);
Assertions.assertNull(emptyResponse);
}
interface Actor {

View File

@ -23,16 +23,16 @@ import io.grpc.inprocess.InProcessChannelBuilder;
import io.grpc.inprocess.InProcessServerBuilder;
import io.grpc.stub.StreamObserver;
import io.grpc.testing.GrpcCleanupRule;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import static io.dapr.actors.TestUtils.assertThrowsDaprException;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.AdditionalAnswers.delegatesTo;
import static org.mockito.Mockito.*;
@ -91,7 +91,7 @@ public class DaprGrpcClientTest {
private DaprGrpcClient client;
@Before
@BeforeEach
public void setup() throws IOException {
// Generate a unique in-process server name.
String serverName = InProcessServerBuilder.generateName();

View File

@ -21,11 +21,12 @@ import okhttp3.mock.Behavior;
import okhttp3.mock.MediaTypes;
import okhttp3.mock.MockInterceptor;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import static io.dapr.actors.TestUtils.assertThrowsDaprException;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class DaprHttpClientTest {
@ -37,7 +38,7 @@ public class DaprHttpClientTest {
private final String EXPECTED_RESULT = "{\"data\":\"ewoJCSJwcm9wZXJ0eUEiOiAidmFsdWVBIiwKCQkicHJvcGVydHlCIjogInZhbHVlQiIKCX0=\"}";
@Before
@BeforeEach
public void setUp() {
mockInterceptor = new MockInterceptor(Behavior.UNORDERED);
okHttpClient = new OkHttpClient.Builder().addInterceptor(mockInterceptor).build();

View File

@ -19,8 +19,8 @@ import io.dapr.actors.client.ActorProxy;
import io.dapr.actors.client.ActorProxyImplForTests;
import io.dapr.actors.client.DaprClientStub;
import io.dapr.serializer.DaprObjectSerializer;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import java.io.Serializable;
@ -108,8 +108,8 @@ public class ActorCustomSerializerTest {
MyData response = actorProxy.invokeMethod("classInClassOut", d, MyData.class).block();
Assert.assertEquals("hihi", response.getName());
Assert.assertEquals(6, response.getNum());
Assertions.assertEquals("hihi", response.getName());
Assertions.assertEquals(6, response.getNum());
}
@Test
@ -117,7 +117,7 @@ public class ActorCustomSerializerTest {
ActorProxy actorProxy = createActorProxy();
String response = actorProxy.invokeMethod("stringInStringOut", "oi", String.class).block();
Assert.assertEquals("oioi", response);
Assertions.assertEquals("oioi", response);
}
@Test
@ -125,7 +125,7 @@ public class ActorCustomSerializerTest {
ActorProxy actorProxy = createActorProxy();
int response = actorProxy.invokeMethod("intInIntOut", 2, int.class).block();
Assert.assertEquals(4, response);
Assertions.assertEquals(4, response);
}
private static ActorId newActorId() {

View File

@ -17,8 +17,8 @@ import io.dapr.actors.ActorId;
import io.dapr.actors.ActorType;
import io.dapr.serializer.DefaultObjectSerializer;
import io.dapr.utils.TypeRef;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
import reactor.core.publisher.Mono;
@ -26,6 +26,7 @@ import java.io.IOException;
import java.time.Duration;
import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -120,11 +121,13 @@ public class ActorManagerTest {
private ActorManager<MyActorImpl> manager = new ActorManager<>(context);
@Test(expected = IllegalArgumentException.class)
@Test
public void invokeBeforeActivate() throws Exception {
ActorId actorId = newActorId();
String message = "something";
this.manager.invokeMethod(actorId, "say", message.getBytes()).block();
assertThrows(IllegalArgumentException.class, () ->
this.manager.invokeMethod(actorId, "say", message.getBytes()).block());
}
@Test
@ -133,7 +136,7 @@ public class ActorManagerTest {
byte[] message = this.context.getObjectSerializer().serialize("something");
this.manager.activateActor(actorId).block();
byte[] response = this.manager.invokeMethod(actorId, "say", message).block();
Assert.assertEquals(executeSayMethod(
Assertions.assertEquals(executeSayMethod(
this.context.getObjectSerializer().deserialize(message, TypeRef.STRING)),
this.context.getObjectSerializer().deserialize(response, TypeRef.STRING));
}
@ -143,7 +146,7 @@ public class ActorManagerTest {
ActorId actorId = newActorId();
this.manager.activateActor(actorId).block();
Assertions.assertThrows(RuntimeException.class, () -> {
assertThrows(RuntimeException.class, () -> {
this.manager.invokeMethod(actorId, "throwsException", null).block();
});
}
@ -162,7 +165,7 @@ public class ActorManagerTest {
ActorId actorId = newActorId();
this.manager.activateActor(actorId).block();
Assertions.assertThrows(RuntimeException.class, () -> {
assertThrows(RuntimeException.class, () -> {
this.manager.invokeMethod(actorId, "throwsExceptionHotMono", null).block();
});
}
@ -181,7 +184,7 @@ public class ActorManagerTest {
ActorId actorId = newActorId();
this.manager.activateActor(actorId).block();
Assertions.assertThrows(RuntimeException.class, () -> {
assertThrows(RuntimeException.class, () -> {
this.manager.invokeMethod(actorId, "throwsExceptionMono", null).block();
});
}
@ -195,18 +198,19 @@ public class ActorManagerTest {
this.manager.invokeMethod(actorId, "throwsExceptionMono", null);
}
@Test(expected = IllegalArgumentException.class)
@Test
public void activateInvokeDeactivateThenInvoke() throws Exception {
ActorId actorId = newActorId();
byte[] message = this.context.getObjectSerializer().serialize("something");
this.manager.activateActor(actorId).block();
byte[] response = this.manager.invokeMethod(actorId, "say", message).block();
Assert.assertEquals(executeSayMethod(
Assertions.assertEquals(executeSayMethod(
this.context.getObjectSerializer().deserialize(message, TypeRef.STRING)),
this.context.getObjectSerializer().deserialize(response, TypeRef.STRING));
this.manager.deactivateActor(actorId).block();
this.manager.invokeMethod(actorId, "say", message).block();
assertThrows(IllegalArgumentException.class, () ->
this.manager.invokeMethod(actorId, "say", message).block());
}
@Test
@ -217,10 +221,11 @@ public class ActorManagerTest {
manager.invokeReminder(actorId, "myremind", createReminderParams("hello")).block();
}
@Test(expected = IllegalArgumentException.class)
@Test
public void invokeReminderBeforeActivate() throws Exception {
ActorId actorId = newActorId();
this.manager.invokeReminder(actorId, "myremind", createReminderParams("hello")).block();
assertThrows(IllegalArgumentException.class, () ->
this.manager.invokeReminder(actorId, "myremind", createReminderParams("hello")).block());
}
@Test
@ -230,18 +235,21 @@ public class ActorManagerTest {
this.manager.invokeReminder(actorId, "myremind", createReminderParams("hello")).block();
}
@Test(expected = IllegalArgumentException.class)
@Test
public void activateDeactivateThenInvokeReminder() throws Exception {
ActorId actorId = newActorId();
this.manager.activateActor(actorId).block();
this.manager.deactivateActor(actorId).block();;
this.manager.invokeReminder(actorId, "myremind", createReminderParams("hello")).block();
assertThrows(IllegalArgumentException.class, () -> this.manager.invokeReminder(actorId, "myremind", createReminderParams("hello")).block());
}
@Test(expected = IllegalArgumentException.class)
@Test
public void invokeTimerBeforeActivate() throws IOException {
ActorId actorId = newActorId();
this.manager.invokeTimer(actorId, "count", createTimerParams("incrementCount", 2)).block();
assertThrows(IllegalArgumentException.class, () ->
this.manager.invokeTimer(actorId, "count", createTimerParams("incrementCount", 2)).block());
}
@Test
@ -257,19 +265,19 @@ public class ActorManagerTest {
this.manager.activateActor(actorId).block();
this.manager.invokeTimer(actorId, "count", createTimerParams("incrementCount", 2)).block();
byte[] response = this.manager.invokeMethod(actorId, "getCount", null).block();
Assert.assertEquals("2", new String(response));
Assertions.assertEquals("2", new String(response));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void activateInvokeTimerDeactivateThenInvokeTimer() throws IOException {
ActorId actorId = newActorId();
this.manager.activateActor(actorId).block();
this.manager.invokeTimer(actorId, "count", createTimerParams("incrementCount", 2)).block();
byte[] response = this.manager.invokeMethod(actorId, "getCount", null).block();
Assert.assertEquals("2", new String(response));
Assertions.assertEquals("2", new String(response));
this.manager.deactivateActor(actorId).block();
this.manager.invokeTimer(actorId, "count", createTimerParams("incrementCount", 2)).block();
assertThrows(IllegalArgumentException.class, () -> this.manager.invokeTimer(actorId, "count", createTimerParams("incrementCount", 2)).block());
}
private byte[] createReminderParams(String data) throws IOException {

View File

@ -13,13 +13,15 @@ limitations under the License.
package io.dapr.actors.runtime;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.ArrayList;
import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* Unit tests for ActorMethodInfoMap.
*/
@ -33,23 +35,24 @@ public class ActorMethodInfoMapTest {
try {
Method m1 = m.get("getData");
Assert.assertEquals("getData", m1.getName());
Assertions.assertEquals("getData", m1.getName());
Class c = m1.getReturnType();
Assert.assertEquals(c.getClass(), String.class.getClass());
Assertions.assertEquals(c.getClass(), String.class.getClass());
Parameter[] p = m1.getParameters();
Assert.assertEquals(p[0].getType().getClass(), String.class.getClass());
Assertions.assertEquals(p[0].getType().getClass(), String.class.getClass());
} catch (Exception e) {
Assert.fail("Exception not expected.");
Assertions.fail("Exception not expected.");
}
}
@Test(expected = NoSuchMethodException.class)
@Test
public void lookUpNonExistingMethod() throws NoSuchMethodException {
ArrayList<Class<?>> interfaceTypes = new ArrayList<>();
interfaceTypes.add(TestActor.class);
ActorMethodInfoMap m = new ActorMethodInfoMap(interfaceTypes);
m.get("thisMethodDoesNotExist");
assertThrows(NoSuchMethodException.class, () ->
m.get("thisMethodDoesNotExist"));
}
/**

View File

@ -20,14 +20,15 @@ import io.dapr.actors.client.ActorProxy;
import io.dapr.actors.client.ActorProxyImplForTests;
import io.dapr.actors.client.DaprClientStub;
import io.dapr.serializer.DefaultObjectSerializer;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import java.lang.reflect.Proxy;
import java.time.Duration;
import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
@ -153,7 +154,7 @@ public class ActorNoStateTest {
public void actorId() {
ActorProxy proxy = createActorProxy();
Assert.assertEquals(
Assertions.assertEquals(
proxy.getActorId().toString(),
proxy.invokeMethod("getMyId", String.class).block());
}
@ -163,7 +164,7 @@ public class ActorNoStateTest {
ActorProxy proxy = createActorProxy();
// these should only call the actor methods for ActorChild. The implementations in ActorParent will throw.
Assert.assertEquals(
Assertions.assertEquals(
"abcabc",
proxy.invokeMethod("stringInStringOut", "abc", String.class).block());
}
@ -173,21 +174,22 @@ public class ActorNoStateTest {
ActorProxy proxy = createActorProxy();
// these should only call the actor methods for ActorChild. The implementations in ActorParent will throw.
Assert.assertEquals(
Assertions.assertEquals(
false,
proxy.invokeMethod("stringInBooleanOut", "hello world", Boolean.class).block());
Assert.assertEquals(
Assertions.assertEquals(
true,
proxy.invokeMethod("stringInBooleanOut", "true", Boolean.class).block());
}
@Test(expected = IllegalMonitorStateException.class)
@Test
public void stringInVoidOutIntentionallyThrows() {
ActorProxy actorProxy = createActorProxy();
// these should only call the actor methods for ActorChild. The implementations in ActorParent will throw.
actorProxy.invokeMethod("stringInVoidOutIntentionallyThrows", "hello world").block();
assertThrows(IllegalMonitorStateException.class, () ->
actorProxy.invokeMethod("stringInVoidOutIntentionallyThrows", "hello world").block());
}
@Test
@ -204,30 +206,31 @@ public class ActorNoStateTest {
// this should only call the actor methods for ActorChild. The implementations in ActorParent will throw.
MyData response = actorProxy.invokeMethod("classInClassOut", d, MyData.class).block();
Assert.assertEquals(
Assertions.assertEquals(
"hihi",
response.getName());
Assert.assertEquals(
Assertions.assertEquals(
6,
response.getNum());
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testBadTimerCallbackName() {
MyActor actor = createActorProxy(MyActor.class);
actor.registerBadCallbackName().block();
assertThrows(IllegalArgumentException.class, () -> actor.registerBadCallbackName().block());
}
@Test
public void testAutoTimerName() {
MyActor actor = createActorProxy(MyActor.class);
String firstTimer = actor.registerTimerAutoName();
Assert.assertTrue((firstTimer != null) && !firstTimer.isEmpty());
Assertions.assertTrue((firstTimer != null) && !firstTimer.isEmpty());
String secondTimer = actor.registerTimerAutoName();
Assert.assertTrue((secondTimer != null) && !secondTimer.isEmpty());
Assertions.assertTrue((secondTimer != null) && !secondTimer.isEmpty());
Assert.assertNotEquals(firstTimer, secondTimer);
Assertions.assertNotEquals(firstTimer, secondTimer);
}
private static ActorId newActorId() {

View File

@ -13,18 +13,20 @@ limitations under the License.
package io.dapr.actors.runtime;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.time.Duration;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class ActorReminderParamsTest {
private static final ActorObjectSerializer SERIALIZER = new ActorObjectSerializer();
@Test(expected = IllegalArgumentException.class)
@Test
public void outOfRangeDueTime() {
ActorReminderParams info = new ActorReminderParams(null, Duration.ZERO.plusSeconds(-10), Duration.ZERO.plusMinutes(1));
assertThrows(IllegalArgumentException.class, () -> new ActorReminderParams(null, Duration.ZERO.plusSeconds(-10), Duration.ZERO.plusMinutes(1)));
}
@Test
@ -33,9 +35,9 @@ public class ActorReminderParamsTest {
ActorReminderParams info = new ActorReminderParams(null, Duration.ZERO.plusMinutes(1), Duration.ZERO.plusMillis(-1));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void outOfRangePeriod() {
ActorReminderParams info = new ActorReminderParams(null, Duration.ZERO.plusMinutes(1), Duration.ZERO.plusMinutes(-10));
assertThrows(IllegalArgumentException.class, () ->new ActorReminderParams(null, Duration.ZERO.plusMinutes(1), Duration.ZERO.plusMinutes(-10)));
}
@Test
@ -48,12 +50,12 @@ public class ActorReminderParamsTest {
}
catch(Exception e) {
System.out.println("The error is: " + e);
Assert.fail();
Assertions.fail();
}
Assert.assertArrayEquals(original.getData(), recreated.getData());
Assert.assertEquals(original.getDueTime(), recreated.getDueTime());
Assert.assertEquals(original.getPeriod(), recreated.getPeriod());
Assertions.assertArrayEquals(original.getData(), recreated.getData());
Assertions.assertEquals(original.getDueTime(), recreated.getDueTime());
Assertions.assertEquals(original.getPeriod(), recreated.getPeriod());
}
@Test
@ -66,11 +68,11 @@ public class ActorReminderParamsTest {
}
catch(Exception e) {
System.out.println("The error is: " + e);
Assert.fail();
Assertions.fail();
}
Assert.assertArrayEquals(original.getData(), recreated.getData());
Assert.assertEquals(original.getDueTime(), recreated.getDueTime());
Assert.assertEquals(original.getPeriod(), recreated.getPeriod());
Assertions.assertArrayEquals(original.getData(), recreated.getData());
Assertions.assertEquals(original.getDueTime(), recreated.getDueTime());
Assertions.assertEquals(original.getPeriod(), recreated.getPeriod());
}
}

View File

@ -16,10 +16,10 @@ package io.dapr.actors.runtime;
import io.dapr.actors.ActorId;
import io.dapr.actors.ActorType;
import io.dapr.serializer.DefaultObjectSerializer;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import java.lang.reflect.Constructor;
@ -27,6 +27,7 @@ import java.time.Duration;
import java.util.Arrays;
import java.util.UUID;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;
public class ActorRuntimeTest {
@ -100,7 +101,7 @@ public class ActorRuntimeTest {
private ActorRuntime runtime;
@BeforeClass
@BeforeAll
public static void beforeAll() throws Exception {
constructor =
(Constructor<ActorRuntime>) Arrays.stream(ActorRuntime.class.getDeclaredConstructors())
@ -110,67 +111,67 @@ public class ActorRuntimeTest {
}).findFirst().get();
}
@Before
@BeforeEach
public void setup() throws Exception {
this.mockDaprClient = mock(DaprClient.class);
this.runtime = constructor.newInstance(null, this.mockDaprClient);
}
@Test(expected = IllegalArgumentException.class)
@Test
public void registerActorNullClass() {
this.runtime.registerActor(null);
assertThrows(IllegalArgumentException.class, () -> this.runtime.registerActor(null));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void registerActorNullFactory() {
this.runtime.registerActor(MyActorImpl.class, null, new DefaultObjectSerializer(),
new DefaultObjectSerializer());
assertThrows(IllegalArgumentException.class, () -> this.runtime.registerActor(MyActorImpl.class, null, new DefaultObjectSerializer(),
new DefaultObjectSerializer()));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void registerActorNullSerializer() {
this.runtime.registerActor(MyActorImpl.class, new DefaultActorFactory<>(), null,
new DefaultObjectSerializer());
assertThrows(IllegalArgumentException.class, () -> this.runtime.registerActor(MyActorImpl.class, new DefaultActorFactory<>(), null,
new DefaultObjectSerializer()));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void registerActorNullStateSerializer() {
this.runtime.registerActor(MyActorImpl.class, new DefaultActorFactory<>(),
new DefaultObjectSerializer(), null);
assertThrows(IllegalArgumentException.class, () -> this.runtime.registerActor(MyActorImpl.class, new DefaultActorFactory<>(),
new DefaultObjectSerializer(), null));
}
@Test
public void setActorIdleTimeout() throws Exception {
this.runtime.getConfig().setActorIdleTimeout(Duration.ofSeconds(123));
Assert.assertEquals("{\"entities\":[],\"actorIdleTimeout\":\"0h2m3s0ms\"}",
Assertions.assertEquals("{\"entities\":[],\"actorIdleTimeout\":\"0h2m3s0ms\"}",
new String(this.runtime.serializeConfig()));
}
@Test
public void setActorScanInterval() throws Exception {
this.runtime.getConfig().setActorScanInterval(Duration.ofSeconds(123));
Assert.assertEquals("{\"entities\":[],\"actorScanInterval\":\"0h2m3s0ms\"}",
Assertions.assertEquals("{\"entities\":[],\"actorScanInterval\":\"0h2m3s0ms\"}",
new String(this.runtime.serializeConfig()));
}
@Test
public void setDrainBalancedActors() throws Exception {
this.runtime.getConfig().setDrainBalancedActors(true);
Assert.assertEquals("{\"entities\":[],\"drainBalancedActors\":true}",
Assertions.assertEquals("{\"entities\":[],\"drainBalancedActors\":true}",
new String(this.runtime.serializeConfig()));
}
@Test
public void setDrainOngoingCallTimeout() throws Exception {
this.runtime.getConfig().setDrainOngoingCallTimeout(Duration.ofSeconds(123));
Assert.assertEquals("{\"entities\":[],\"drainOngoingCallTimeout\":\"0h2m3s0ms\"}",
Assertions.assertEquals("{\"entities\":[],\"drainOngoingCallTimeout\":\"0h2m3s0ms\"}",
new String(this.runtime.serializeConfig()));
}
@Test
public void setRemindersStoragePartitions() throws Exception {
this.runtime.getConfig().setRemindersStoragePartitions(12);
Assert.assertEquals("{\"entities\":[],\"remindersStoragePartitions\":12}",
Assertions.assertEquals("{\"entities\":[],\"remindersStoragePartitions\":12}",
new String(this.runtime.serializeConfig()));
}
@ -181,15 +182,15 @@ public class ActorRuntimeTest {
byte[] response = this.runtime.invoke(ACTOR_NAME, actorId, "say", null).block();
String message = ACTOR_STATE_SERIALIZER.deserialize(response, String.class);
Assert.assertEquals("Nothing to say.", message);
Assertions.assertEquals("Nothing to say.", message);
}
@Test(expected = IllegalArgumentException.class)
@Test
public void invokeUnknownActor() {
String actorId = UUID.randomUUID().toString();
this.runtime.registerActor(MyActorImpl.class);
this.runtime.invoke("UnknownActor", actorId, "say", null).block();
assertThrows(IllegalArgumentException.class, () -> this.runtime.invoke("UnknownActor", actorId, "say", null).block());
}
@Test
@ -211,8 +212,8 @@ public class ActorRuntimeTest {
deactivateCall.block();
this.runtime.invoke(ACTOR_NAME, actorId, "say", null)
.doOnError(e -> Assert.assertTrue(e.getMessage().contains("Could not find actor")))
.doOnSuccess(s -> Assert.fail()).onErrorReturn("".getBytes()).block();
.doOnError(e -> Assertions.assertTrue(e.getMessage().contains("Could not find actor")))
.doOnSuccess(s -> Assertions.fail()).onErrorReturn("".getBytes()).block();
}
@Test
@ -224,13 +225,13 @@ public class ActorRuntimeTest {
byte[] response = this.runtime.invoke(ACTOR_NAME, actorId, "count", null).block();
int count = ACTOR_STATE_SERIALIZER.deserialize(response, Integer.class);
Assert.assertEquals(0, count);
Assertions.assertEquals(0, count);
invokeCall.block();
response = this.runtime.invoke(ACTOR_NAME, actorId, "count", null).block();
count = ACTOR_STATE_SERIALIZER.deserialize(response, Integer.class);
Assert.assertEquals(1, count);
Assertions.assertEquals(1, count);
}
}

View File

@ -20,8 +20,8 @@ import io.dapr.actors.client.ActorProxyImplForTests;
import io.dapr.actors.client.DaprClientStub;
import io.dapr.serializer.DefaultObjectSerializer;
import io.dapr.utils.TypeRef;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import java.io.IOException;
@ -33,6 +33,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
@ -296,28 +297,28 @@ public class ActorStatefulTest {
@Test
public void happyGetSetDeleteContains() {
ActorProxy proxy = newActorProxy();
Assert.assertEquals(
Assertions.assertEquals(
proxy.getActorId().toString(), proxy.invokeMethod("getIdString", String.class).block());
Assert.assertFalse(proxy.invokeMethod("hasMessage", Boolean.class).block());
Assertions.assertFalse(proxy.invokeMethod("hasMessage", Boolean.class).block());
proxy.invokeMethod("setMessage", "hello world").block();
Assert.assertTrue(proxy.invokeMethod("hasMessage", Boolean.class).block());
Assertions.assertTrue(proxy.invokeMethod("hasMessage", Boolean.class).block());
Assert.assertEquals(
Assertions.assertEquals(
"hello world", proxy.invokeMethod("getMessage", String.class).block());
Assert.assertEquals(
Assertions.assertEquals(
executeSayMethod("hello world"),
proxy.invokeMethod("setMessage", "hello world", String.class).block());
proxy.invokeMethod("deleteMessage").block();
Assert.assertFalse(proxy.invokeMethod("hasMessage", Boolean.class).block());
Assertions.assertFalse(proxy.invokeMethod("hasMessage", Boolean.class).block());
}
@Test(expected = IllegalStateException.class)
@Test
public void lazyGet() {
ActorProxy proxy = newActorProxy();
Assert.assertFalse(proxy.invokeMethod("hasMessage", Boolean.class).block());
Assertions.assertFalse(proxy.invokeMethod("hasMessage", Boolean.class).block());
proxy.invokeMethod("setMessage", "first message").block();
// Creates the mono plan but does not call it yet.
@ -326,30 +327,30 @@ public class ActorStatefulTest {
proxy.invokeMethod("deleteMessage").block();
// Call should fail because the message was deleted.
getMessageCall.block();
assertThrows(IllegalStateException.class, () -> getMessageCall.block());
}
@Test
public void lazySet() {
ActorProxy proxy = newActorProxy();
Assert.assertFalse(proxy.invokeMethod("hasMessage", Boolean.class).block());
Assertions.assertFalse(proxy.invokeMethod("hasMessage", Boolean.class).block());
// Creates the mono plan but does not call it yet.
Mono<Void> setMessageCall = proxy.invokeMethod("setMessage", "first message");
// No call executed yet, so message should not be set.
Assert.assertFalse(proxy.invokeMethod("hasMessage", Boolean.class).block());
Assertions.assertFalse(proxy.invokeMethod("hasMessage", Boolean.class).block());
setMessageCall.block();
// Now the message has been set.
Assert.assertTrue(proxy.invokeMethod("hasMessage", Boolean.class).block());
Assertions.assertTrue(proxy.invokeMethod("hasMessage", Boolean.class).block());
}
@Test
public void lazyContains() {
ActorProxy proxy = newActorProxy();
Assert.assertFalse(proxy.invokeMethod("hasMessage", Boolean.class).block());
Assertions.assertFalse(proxy.invokeMethod("hasMessage", Boolean.class).block());
// Creates the mono plan but does not call it yet.
Mono<Boolean> hasMessageCall = proxy.invokeMethod("hasMessage", Boolean.class);
@ -361,46 +362,46 @@ public class ActorStatefulTest {
hasMessageCall.block();
// Now the message should be set.
Assert.assertTrue(proxy.invokeMethod("hasMessage", Boolean.class).block());
Assertions.assertTrue(proxy.invokeMethod("hasMessage", Boolean.class).block());
}
@Test
public void lazyDelete() {
ActorProxy proxy = newActorProxy();
Assert.assertFalse(proxy.invokeMethod("hasMessage", Boolean.class).block());
Assertions.assertFalse(proxy.invokeMethod("hasMessage", Boolean.class).block());
proxy.invokeMethod("setMessage", "first message").block();
// Message is set.
Assert.assertTrue(proxy.invokeMethod("hasMessage", Boolean.class).block());
Assertions.assertTrue(proxy.invokeMethod("hasMessage", Boolean.class).block());
// Created the mono plan but does not execute it yet.
Mono<Void> deleteMessageCall = proxy.invokeMethod("deleteMessage");
// Message is still set.
Assert.assertTrue(proxy.invokeMethod("hasMessage", Boolean.class).block());
Assertions.assertTrue(proxy.invokeMethod("hasMessage", Boolean.class).block());
deleteMessageCall.block();
// Now message is not set.
Assert.assertFalse(proxy.invokeMethod("hasMessage", Boolean.class).block());
Assertions.assertFalse(proxy.invokeMethod("hasMessage", Boolean.class).block());
}
@Test
public void lazyAdd() {
ActorProxy proxy = newActorProxy();
Assert.assertFalse(proxy.invokeMethod("hasMessage", Boolean.class).block());
Assertions.assertFalse(proxy.invokeMethod("hasMessage", Boolean.class).block());
proxy.invokeMethod("setMessage", "first message").block();
// Message is set.
Assert.assertTrue(proxy.invokeMethod("hasMessage", Boolean.class).block());
Assertions.assertTrue(proxy.invokeMethod("hasMessage", Boolean.class).block());
// Created the mono plan but does not execute it yet.
Mono<Void> addMessageCall = proxy.invokeMethod("addMessage", "second message");
// Message is still set.
Assert.assertEquals("first message",
Assertions.assertEquals("first message",
proxy.invokeMethod("getMessage", String.class).block());
// Delete message
@ -410,7 +411,7 @@ public class ActorStatefulTest {
addMessageCall.block();
// New message is still set.
Assert.assertEquals("second message",
Assertions.assertEquals("second message",
proxy.invokeMethod("getMessage", String.class).block());
}
@ -418,14 +419,14 @@ public class ActorStatefulTest {
public void onActivateAndOnDeactivate() {
ActorProxy proxy = newActorProxy();
Assert.assertTrue(proxy.invokeMethod("isActive", Boolean.class).block());
Assert.assertFalse(DEACTIVATED_ACTOR_IDS.contains(proxy.getActorId().toString()));
Assertions.assertTrue(proxy.invokeMethod("isActive", Boolean.class).block());
Assertions.assertFalse(DEACTIVATED_ACTOR_IDS.contains(proxy.getActorId().toString()));
proxy.invokeMethod("hasMessage", Boolean.class).block();
this.manager.deactivateActor(proxy.getActorId()).block();
Assert.assertTrue(DEACTIVATED_ACTOR_IDS.contains(proxy.getActorId().toString()));
Assertions.assertTrue(DEACTIVATED_ACTOR_IDS.contains(proxy.getActorId().toString()));
}
@Test
@ -436,13 +437,13 @@ public class ActorStatefulTest {
MyMethodContext preContext =
proxy.invokeMethod("getPreCallMethodContext", MyMethodContext.class).block();
Assert.assertEquals("hasMessage", preContext.getName());
Assert.assertEquals(ActorCallType.ACTOR_INTERFACE_METHOD.toString(), preContext.getType());
Assertions.assertEquals("hasMessage", preContext.getName());
Assertions.assertEquals(ActorCallType.ACTOR_INTERFACE_METHOD.toString(), preContext.getType());
MyMethodContext postContext =
proxy.invokeMethod("getPostCallMethodContext", MyMethodContext.class).block();
Assert.assertEquals("hasMessage", postContext.getName());
Assert.assertEquals(ActorCallType.ACTOR_INTERFACE_METHOD.toString(), postContext.getType());
Assertions.assertEquals("hasMessage", postContext.getName());
Assertions.assertEquals(ActorCallType.ACTOR_INTERFACE_METHOD.toString(), postContext.getType());
}
@Test
@ -453,22 +454,23 @@ public class ActorStatefulTest {
MyMethodContext preContext =
proxy.invokeMethod("getPreCallMethodContext", MyMethodContext.class).block();
Assert.assertEquals("mytimer", preContext.getName());
Assert.assertEquals(ActorCallType.TIMER_METHOD.toString(), preContext.getType());
Assertions.assertEquals("mytimer", preContext.getName());
Assertions.assertEquals(ActorCallType.TIMER_METHOD.toString(), preContext.getType());
MyMethodContext postContext =
proxy.invokeMethod("getPostCallMethodContext", MyMethodContext.class).block();
Assert.assertEquals("mytimer", postContext.getName());
Assert.assertEquals(ActorCallType.TIMER_METHOD.toString(), postContext.getType());
Assertions.assertEquals("mytimer", postContext.getName());
Assertions.assertEquals(ActorCallType.TIMER_METHOD.toString(), postContext.getType());
}
@Test(expected = IllegalArgumentException.class)
@Test
public void invokeTimerAfterDeactivate() {
ActorProxy proxy = newActorProxy();
this.manager.deactivateActor(proxy.getActorId()).block();
this.manager.invokeTimer(proxy.getActorId(), "mytimer", "{ \"callback\": \"hasMessage\" }".getBytes()).block();
assertThrows(IllegalArgumentException.class, () ->
this.manager.invokeTimer(proxy.getActorId(), "mytimer", "{ \"callback\": \"hasMessage\" }".getBytes()).block());
}
@Test
@ -499,16 +501,16 @@ public class ActorStatefulTest {
MyMethodContext preContext =
proxy.invokeMethod("getPreCallMethodContext", MyMethodContext.class).block();
Assert.assertEquals("myreminder", preContext.getName());
Assert.assertEquals(ActorCallType.REMINDER_METHOD.toString(), preContext.getType());
Assertions.assertEquals("myreminder", preContext.getName());
Assertions.assertEquals(ActorCallType.REMINDER_METHOD.toString(), preContext.getType());
MyMethodContext postContext =
proxy.invokeMethod("getPostCallMethodContext", MyMethodContext.class).block();
Assert.assertEquals("myreminder", postContext.getName());
Assert.assertEquals(ActorCallType.REMINDER_METHOD.toString(), postContext.getType());
Assertions.assertEquals("myreminder", postContext.getName());
Assertions.assertEquals(ActorCallType.REMINDER_METHOD.toString(), postContext.getType());
}
@Test(expected = IllegalArgumentException.class)
@Test
public void invokeReminderAfterDeactivate() throws Exception {
ActorProxy proxy = newActorProxy();
@ -516,7 +518,7 @@ public class ActorStatefulTest {
byte[] params = createReminderParams("anything");
this.manager.invokeReminder(proxy.getActorId(), "myreminder", params).block();
assertThrows(IllegalArgumentException.class, () -> this.manager.invokeReminder(proxy.getActorId(), "myreminder", params).block());
}
@Test
@ -528,58 +530,60 @@ public class ActorStatefulTest {
proxy.invokeMethod("setMethodContext", expectedContext).block();
MyMethodContext context = proxy.invokeMethod("getMethodContext", MyMethodContext.class).block();
Assert.assertEquals(expectedContext.getName(), context.getName());
Assert.assertEquals(expectedContext.getType(), context.getType());
Assertions.assertEquals(expectedContext.getName(), context.getName());
Assertions.assertEquals(expectedContext.getType(), context.getType());
}
@Test
public void intTypeRequestResponseInStateStore() {
ActorProxy proxy = newActorProxy();
Assert.assertEquals(1, (int)proxy.invokeMethod("incrementAndGetCount", 1, int.class).block());
Assert.assertEquals(6, (int)proxy.invokeMethod("incrementAndGetCount", 5, int.class).block());
Assertions.assertEquals(1, (int)proxy.invokeMethod("incrementAndGetCount", 1, int.class).block());
Assertions.assertEquals(6, (int)proxy.invokeMethod("incrementAndGetCount", 5, int.class).block());
}
@Test(expected = NumberFormatException.class)
@Test
public void intTypeWithMethodException() {
ActorProxy proxy = newActorProxy();
// Zero is a magic input that will make method throw an exception.
proxy.invokeMethod("incrementAndGetCount", 0, int.class).block();
assertThrows(NumberFormatException.class, () -> proxy.invokeMethod("incrementAndGetCount", 0, int.class).block());
}
@Test(expected = IllegalStateException.class)
@Test
public void intTypeWithRuntimeException() {
ActorProxy proxy = newActorProxy();
proxy.invokeMethod("getCountButThrowsException", int.class).block();
assertThrows(RuntimeException.class, () ->
proxy.invokeMethod("getCountButThrowsException", int.class).block());
}
@Test(expected = IllegalStateException.class)
@Test
public void actorRuntimeException() {
ActorProxy proxy = newActorProxy();
Assert.assertFalse(proxy.invokeMethod("hasMessage", Boolean.class).block());
Assertions.assertFalse(proxy.invokeMethod("hasMessage", Boolean.class).block());
proxy.invokeMethod("forceDuplicateException").block();
assertThrows(RuntimeException.class, () ->
proxy.invokeMethod("forceDuplicateException").block());
}
@Test(expected = IllegalCharsetNameException.class)
@Test
public void actorMethodException() {
ActorProxy proxy = newActorProxy();
Assert.assertFalse(proxy.invokeMethod("hasMessage", Boolean.class).block());
Assertions.assertFalse(proxy.invokeMethod("hasMessage", Boolean.class).block());
proxy.invokeMethod("throwsWithoutSaving").block();
assertThrows(IllegalCharsetNameException.class, () -> proxy.invokeMethod("throwsWithoutSaving").block());
Assert.assertFalse(proxy.invokeMethod("hasMessage", Boolean.class).block());
Assertions.assertFalse(proxy.invokeMethod("hasMessage", Boolean.class).block());
}
@Test
public void rollbackChanges() {
ActorProxy proxy = newActorProxy();
Assert.assertFalse(proxy.invokeMethod("hasMessage", Boolean.class).block());
Assertions.assertFalse(proxy.invokeMethod("hasMessage", Boolean.class).block());
// Runs a method that will add one message but fail because tries to add a second one.
proxy.invokeMethod("forceDuplicateException")
@ -587,14 +591,14 @@ public class ActorStatefulTest {
.block();
// No message is set
Assert.assertFalse(proxy.invokeMethod("hasMessage", Boolean.class).block());
Assertions.assertFalse(proxy.invokeMethod("hasMessage", Boolean.class).block());
}
@Test
public void partialChanges() {
ActorProxy proxy = newActorProxy();
Assert.assertFalse(proxy.invokeMethod("hasMessage", Boolean.class).block());
Assertions.assertFalse(proxy.invokeMethod("hasMessage", Boolean.class).block());
// Runs a method that will add one message, commit but fail because tries to add a second one.
proxy.invokeMethod("forcePartialChange")
@ -602,10 +606,10 @@ public class ActorStatefulTest {
.block();
// Message is set.
Assert.assertTrue(proxy.invokeMethod("hasMessage", Boolean.class).block());
Assertions.assertTrue(proxy.invokeMethod("hasMessage", Boolean.class).block());
// It is first message and not the second due to a save() in the middle but an exception in the end.
Assert.assertEquals("first message",
Assertions.assertEquals("first message",
proxy.invokeMethod("getMessage", String.class).block());
}

View File

@ -14,8 +14,8 @@ limitations under the License.
package io.dapr.actors.runtime;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.time.Duration;
@ -43,7 +43,7 @@ public class ActorTimerTest {
String expected = "{\"period\":\"1h0m3s0ms\",\"dueTime\":\"0h7m17s0ms\", \"callback\": \"myfunction\"}";
// Deep comparison via JsonNode.equals method.
Assert.assertEquals(OBJECT_MAPPER.readTree(expected), OBJECT_MAPPER.readTree(s));
Assertions.assertEquals(OBJECT_MAPPER.readTree(expected), OBJECT_MAPPER.readTree(s));
}
@Test
@ -67,6 +67,6 @@ public class ActorTimerTest {
// A negative period will be serialized to an empty string which is interpreted by Dapr to mean fire once only.
String expected = "{\"period\":\"\",\"dueTime\":\"0h7m17s0ms\", \"callback\": \"myfunction\"}";
// Deep comparison via JsonNode.equals method.
Assert.assertEquals(OBJECT_MAPPER.readTree(expected), OBJECT_MAPPER.readTree(s));
Assertions.assertEquals(OBJECT_MAPPER.readTree(expected), OBJECT_MAPPER.readTree(s));
}
}

View File

@ -15,8 +15,8 @@ package io.dapr.actors.runtime;
import io.dapr.actors.ActorType;
import io.dapr.utils.TypeRef;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import java.time.Duration;
@ -52,13 +52,13 @@ public class ActorTypeInformationTest {
}
ActorTypeInformation info = ActorTypeInformation.create(A.class);
Assert.assertNotNull(info);
Assert.assertEquals("A", info.getName());
Assert.assertEquals(A.class, info.getImplementationClass());
Assert.assertFalse(info.isAbstractClass());
Assert.assertFalse(info.isRemindable());
Assert.assertEquals(1, info.getInterfaces().size());
Assert.assertTrue(info.getInterfaces().contains(MyActor.class));
Assertions.assertNotNull(info);
Assertions.assertEquals("A", info.getName());
Assertions.assertEquals(A.class, info.getImplementationClass());
Assertions.assertFalse(info.isAbstractClass());
Assertions.assertFalse(info.isRemindable());
Assertions.assertEquals(1, info.getInterfaces().size());
Assertions.assertTrue(info.getInterfaces().contains(MyActor.class));
}
/**
@ -84,14 +84,14 @@ public class ActorTypeInformationTest {
}
ActorTypeInformation info = ActorTypeInformation.create(A.class);
Assert.assertNotNull(info);
Assert.assertEquals("A", info.getName());
Assert.assertEquals(A.class, info.getImplementationClass());
Assert.assertFalse(info.isAbstractClass());
Assert.assertTrue(info.isRemindable());
Assert.assertEquals(2, info.getInterfaces().size());
Assert.assertTrue(info.getInterfaces().contains(Remindable.class));
Assert.assertTrue(info.getInterfaces().contains(MyActor.class));
Assertions.assertNotNull(info);
Assertions.assertEquals("A", info.getName());
Assertions.assertEquals(A.class, info.getImplementationClass());
Assertions.assertFalse(info.isAbstractClass());
Assertions.assertTrue(info.isRemindable());
Assertions.assertEquals(2, info.getInterfaces().size());
Assertions.assertTrue(info.getInterfaces().contains(Remindable.class));
Assertions.assertTrue(info.getInterfaces().contains(MyActor.class));
}
/**
@ -107,13 +107,13 @@ public class ActorTypeInformationTest {
}
ActorTypeInformation info = ActorTypeInformation.create(A.class);
Assert.assertNotNull(info);
Assert.assertEquals("B", info.getName());
Assert.assertEquals(A.class, info.getImplementationClass());
Assert.assertFalse(info.isAbstractClass());
Assert.assertFalse(info.isRemindable());
Assert.assertEquals(1, info.getInterfaces().size());
Assert.assertTrue(info.getInterfaces().contains(MyActor.class));
Assertions.assertNotNull(info);
Assertions.assertEquals("B", info.getName());
Assertions.assertEquals(A.class, info.getImplementationClass());
Assertions.assertFalse(info.isAbstractClass());
Assertions.assertFalse(info.isRemindable());
Assertions.assertEquals(1, info.getInterfaces().size());
Assertions.assertTrue(info.getInterfaces().contains(MyActor.class));
}
/**
@ -128,13 +128,13 @@ public class ActorTypeInformationTest {
}
ActorTypeInformation info = ActorTypeInformation.create(A.class);
Assert.assertNotNull(info);
Assert.assertEquals("MyActorWithAnnotation", info.getName());
Assert.assertEquals(A.class, info.getImplementationClass());
Assert.assertFalse(info.isAbstractClass());
Assert.assertFalse(info.isRemindable());
Assert.assertEquals(1, info.getInterfaces().size());
Assert.assertTrue(info.getInterfaces().contains(MyActorAnnotated.class));
Assertions.assertNotNull(info);
Assertions.assertEquals("MyActorWithAnnotation", info.getName());
Assertions.assertEquals(A.class, info.getImplementationClass());
Assertions.assertFalse(info.isAbstractClass());
Assertions.assertFalse(info.isRemindable());
Assertions.assertEquals(1, info.getInterfaces().size());
Assertions.assertTrue(info.getInterfaces().contains(MyActorAnnotated.class));
}
/**
@ -149,6 +149,6 @@ public class ActorTypeInformationTest {
}
ActorTypeInformation info = ActorTypeInformation.tryCreate(A.class);
Assert.assertNull(info);
Assertions.assertNull(info);
}
}

View File

@ -14,14 +14,14 @@ package io.dapr.actors.runtime;
import io.dapr.actors.ActorId;
import io.dapr.utils.TypeRef;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import java.io.Closeable;
import java.time.Duration;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class ActorTypeUtilitiesTest {

View File

@ -27,9 +27,9 @@ import io.grpc.inprocess.InProcessChannelBuilder;
import io.grpc.inprocess.InProcessServerBuilder;
import io.grpc.stub.StreamObserver;
import io.grpc.testing.GrpcCleanupRule;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import java.io.IOException;
@ -39,7 +39,7 @@ import java.util.List;
import java.util.concurrent.ExecutionException;
import static io.dapr.actors.TestUtils.assertThrowsDaprException;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class DaprGrpcClientTest {
@ -71,7 +71,7 @@ public class DaprGrpcClientTest {
@Rule
public final GrpcCleanupRule grpcCleanup = new GrpcCleanupRule();
@Before
@BeforeEach
public void setup() throws IOException {
// Generate a unique in-process server name.
String serverName = InProcessServerBuilder.generateName();

View File

@ -24,8 +24,8 @@ import okhttp3.mock.Behavior;
import okhttp3.mock.MockInterceptor;
import okhttp3.mock.RuleAnswer;
import okio.Buffer;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import java.io.IOException;
@ -35,8 +35,8 @@ import java.util.Base64;
import java.util.Collections;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.fail;
public class DaprHttpClientTest {
@ -49,7 +49,7 @@ public class DaprHttpClientTest {
private final String EXPECTED_RESULT = "{\"data\":\"ewoJCSJwcm9wZXJ0eUEiOiAidmFsdWVBIiwKCQkicHJvcGVydHlCIjogInZhbHVlQiIKCX0=\"}";
@Before
@BeforeEach
public void setUp() throws Exception {
mockInterceptor = new MockInterceptor(Behavior.UNORDERED);
okHttpClient = new OkHttpClient.Builder().addInterceptor(mockInterceptor).build();

View File

@ -18,8 +18,8 @@ import io.dapr.actors.ActorId;
import io.dapr.serializer.DaprObjectSerializer;
import io.dapr.serializer.DefaultObjectSerializer;
import io.dapr.utils.TypeRef;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import java.util.Arrays;
@ -180,28 +180,28 @@ public class DaprStateAsyncProviderTest {
DaprStateAsyncProvider provider = new DaprStateAsyncProvider(daprClient, SERIALIZER);
Assert.assertEquals("Jon Doe",
Assertions.assertEquals("Jon Doe",
provider.load("MyActor", new ActorId("123"), "name", TypeRef.STRING).block());
Assert.assertEquals(98021,
Assertions.assertEquals(98021,
(int) provider.load("MyActor", new ActorId("123"), "zipcode", TypeRef.INT).block());
Assert.assertEquals(98,
Assertions.assertEquals(98,
(int) provider.load("MyActor", new ActorId("123"), "goals", TypeRef.INT).block());
Assert.assertEquals(98,
Assertions.assertEquals(98,
(int) provider.load("MyActor", new ActorId("123"), "goals", TypeRef.INT).block());
Assert.assertEquals(46.55,
Assertions.assertEquals(46.55,
(double) provider.load("MyActor", new ActorId("123"), "balance", TypeRef.DOUBLE).block(),
EPSILON);
Assert.assertEquals(true,
Assertions.assertEquals(true,
(boolean) provider.load("MyActor", new ActorId("123"), "active", TypeRef.BOOLEAN).block());
Assert.assertEquals(new Customer().setId(1000).setName("Roxane"),
Assertions.assertEquals(new Customer().setId(1000).setName("Roxane"),
provider.load("MyActor", new ActorId("123"), "customer", TypeRef.get(Customer.class)).block());
Assert.assertNotEquals(new Customer().setId(1000).setName("Roxane"),
Assertions.assertNotEquals(new Customer().setId(1000).setName("Roxane"),
provider.load("MyActor", new ActorId("123"), "anotherCustomer", TypeRef.get(Customer.class)).block());
Assert.assertNull(
Assertions.assertNull(
provider.load("MyActor", new ActorId("123"), "nullCustomer", TypeRef.get(Customer.class)).block());
Assert.assertArrayEquals("A".getBytes(),
Assertions.assertArrayEquals("A".getBytes(),
provider.load("MyActor", new ActorId("123"), "bytes", TypeRef.get(byte[].class)).block());
Assert.assertNull(
Assertions.assertNull(
provider.load("MyActor", new ActorId("123"), "emptyBytes", TypeRef.get(byte[].class)).block());
}
@ -242,15 +242,15 @@ public class DaprStateAsyncProviderTest {
DaprStateAsyncProvider provider = new DaprStateAsyncProvider(daprClient, SERIALIZER);
Assert.assertTrue(provider.contains("MyActor", new ActorId("123"), "name").block());
Assert.assertFalse(provider.contains("MyActor", new ActorId("123"), "NAME").block());
Assert.assertTrue(provider.contains("MyActor", new ActorId("123"), "zipcode").block());
Assert.assertTrue(provider.contains("MyActor", new ActorId("123"), "goals").block());
Assert.assertTrue(provider.contains("MyActor", new ActorId("123"), "balance").block());
Assert.assertTrue(provider.contains("MyActor", new ActorId("123"), "active").block());
Assert.assertTrue(provider.contains("MyActor", new ActorId("123"), "customer").block());
Assert.assertFalse(provider.contains("MyActor", new ActorId("123"), "Does not exist").block());
Assert.assertFalse(provider.contains("MyActor", new ActorId("123"), null).block());
Assertions.assertTrue(provider.contains("MyActor", new ActorId("123"), "name").block());
Assertions.assertFalse(provider.contains("MyActor", new ActorId("123"), "NAME").block());
Assertions.assertTrue(provider.contains("MyActor", new ActorId("123"), "zipcode").block());
Assertions.assertTrue(provider.contains("MyActor", new ActorId("123"), "goals").block());
Assertions.assertTrue(provider.contains("MyActor", new ActorId("123"), "balance").block());
Assertions.assertTrue(provider.contains("MyActor", new ActorId("123"), "active").block());
Assertions.assertTrue(provider.contains("MyActor", new ActorId("123"), "customer").block());
Assertions.assertFalse(provider.contains("MyActor", new ActorId("123"), "Does not exist").block());
Assertions.assertFalse(provider.contains("MyActor", new ActorId("123"), null).block());
}
private final <T> ActorStateChange createInsertChange(String name, T value) {

View File

@ -15,9 +15,10 @@ package io.dapr.actors.runtime;
import io.dapr.actors.ActorId;
import io.dapr.serializer.DaprObjectSerializer;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;
/**
@ -60,20 +61,21 @@ public class DefaultActorFactoryTest {
ActorId actorId = ActorId.createRandom();
MyActor actor = factory.createActor(createActorRuntimeContext(MyActor.class), actorId);
Assert.assertEquals(actorId, actor.actorId);
Assert.assertNotNull(actor.context);
Assertions.assertEquals(actorId, actor.actorId);
Assertions.assertNotNull(actor.context);
}
/**
* Class is not an actor.
*/
@Test(expected = RuntimeException.class)
@Test
public void noValidConstructor() {
DefaultActorFactory<InvalidActor> factory = new DefaultActorFactory<>();
ActorId actorId = ActorId.createRandom();
factory.createActor(createActorRuntimeContext(InvalidActor.class), actorId);
assertThrows(RuntimeException.class, () ->
factory.createActor(createActorRuntimeContext(InvalidActor.class), actorId));
}
private static <T extends AbstractActor> ActorRuntimeContext<T> createActorRuntimeContext(Class<T> clazz) {

View File

@ -19,12 +19,13 @@ import io.dapr.actors.client.ActorProxy;
import io.dapr.actors.client.ActorProxyImplForTests;
import io.dapr.actors.client.DaprClientStub;
import io.dapr.serializer.DefaultObjectSerializer;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
@ -229,7 +230,7 @@ public class DerivedActorTest {
ActorProxy proxy = createActorProxyForActorChild();
// these should only call the actor methods for ActorChild. The implementations in ActorParent will throw.
Assert.assertEquals(
Assertions.assertEquals(
"abcabc",
proxy.invokeMethod("stringInStringOut", "abc", String.class).block());
}
@ -239,11 +240,11 @@ public class DerivedActorTest {
ActorProxy proxy = createActorProxyForActorChild();
// these should only call the actor methods for ActorChild. The implementations in ActorParent will throw.
Assert.assertEquals(
Assertions.assertEquals(
false,
proxy.invokeMethod("stringInBooleanOut", "hello world", Boolean.class).block());
Assert.assertEquals(
Assertions.assertEquals(
true,
proxy.invokeMethod("stringInBooleanOut", "true", Boolean.class).block());
}
@ -253,24 +254,26 @@ public class DerivedActorTest {
ActorProxy actorProxy = createActorProxyForActorChild();
// stringInVoidOut() has not been invoked so this is false
Assert.assertEquals(
Assertions.assertEquals(
false,
actorProxy.invokeMethod("methodReturningVoidInvoked", Boolean.class).block());
// these should only call the actor methods for ActorChild. The implementations in ActorParent will throw.
actorProxy.invokeMethod("stringInVoidOut", "hello world").block();
Assert.assertEquals(
Assertions.assertEquals(
true,
actorProxy.invokeMethod("methodReturningVoidInvoked", Boolean.class).block());
}
@Test(expected = IllegalMonitorStateException.class)
@Test
public void stringInVoidOutIntentionallyThrows() {
ActorProxy actorProxy = createActorProxyForActorChild();
// these should only call the actor methods for ActorChild. The implementations in ActorParent will throw.
actorProxy.invokeMethod("stringInVoidOutIntentionallyThrows", "hello world").block();
assertThrows(IllegalMonitorStateException.class, () ->
actorProxy.invokeMethod("stringInVoidOutIntentionallyThrows", "hello world").block());
}
@Test
@ -281,10 +284,10 @@ public class DerivedActorTest {
// this should only call the actor methods for ActorChild. The implementations in ActorParent will throw.
MyData response = actorProxy.invokeMethod("classInClassOut", d, MyData.class).block();
Assert.assertEquals(
Assertions.assertEquals(
"hihi",
response.getName());
Assert.assertEquals(
Assertions.assertEquals(
6,
response.getNum());
}
@ -294,33 +297,33 @@ public class DerivedActorTest {
public void testInheritedActorMethods() {
ActorProxy actorProxy = createActorProxyForActorChild();
Assert.assertEquals(
Assertions.assertEquals(
"www",
actorProxy.invokeMethod("onlyImplementedInParentStringInStringOut", "w", String.class).block());
Assert.assertEquals(
Assertions.assertEquals(
true,
actorProxy.invokeMethod("onlyImplementedInParentStringInBooleanOut", "icecream", Boolean.class).block());
// onlyImplementedInParentStringInVoidOut() has not been invoked so this is false
Assert.assertEquals(
Assertions.assertEquals(
false,
actorProxy.invokeMethod("methodReturningVoidInvoked", Boolean.class).block());
actorProxy.invokeMethod("onlyImplementedInParentStringInVoidOut", "icecream", Boolean.class).block();
// now it should return true.
Assert.assertEquals(
Assertions.assertEquals(
true,
actorProxy.invokeMethod("methodReturningVoidInvoked", Boolean.class).block());
MyData d = new MyData("hi", 3);
MyData response = actorProxy.invokeMethod("onlyImplementedInParentClassInClassOut", d, MyData.class).block();
Assert.assertEquals(
Assertions.assertEquals(
"hihihi",
response.getName());
Assert.assertEquals(
Assertions.assertEquals(
9,
response.getNum());
}

View File

@ -19,12 +19,13 @@ import io.dapr.actors.client.ActorProxy;
import io.dapr.actors.client.ActorProxyImplForTests;
import io.dapr.actors.client.DaprClientStub;
import io.dapr.serializer.DefaultObjectSerializer;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
@ -122,25 +123,23 @@ public class ThrowFromPreAndPostActorMethodsTest {
// IllegalMonitorStateException should be intentionally thrown. This type was chosen for this test just because
// it is unlikely to collide.
@Test(expected = IllegalMonitorStateException.class)
@Test
public void stringInBooleanOut1() {
ActorProxy proxy = createActorProxyForActorChild();
// these should only call the actor methods for ActorChild. The implementations in ActorParent will throw.
Assert.assertEquals(
false,
assertThrows(IllegalMonitorStateException.class, () ->
proxy.invokeMethod("stringInBooleanOut", "hello world", Boolean.class).block());
}
// IllegalMonitorStateException should be intentionally thrown. This type was chosen for this test just because
// it is unlikely to collide.
@Test(expected = IllegalMonitorStateException.class)
@Test
public void stringInBooleanOut2() {
ActorProxy proxy = createActorProxyForActorChild();
// these should only call the actor methods for ActorChild. The implementations in ActorParent will throw.
Assert.assertEquals(
true,
assertThrows(IllegalMonitorStateException.class, () ->
proxy.invokeMethod("stringInBooleanOut", "true", Boolean.class).block());
}

View File

@ -87,8 +87,13 @@
<optional>true</optional>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

View File

@ -13,8 +13,8 @@
package io.dapr.springboot;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.util.StringValueResolver;
import java.lang.reflect.Constructor;
@ -42,7 +42,7 @@ public class DaprBeanPostProcessorSubscribeTest {
DaprTopicSubscription[] topicSubscriptions = runtime.listSubscribedTopics();
// There should be three subscriptions.
Assert.assertEquals(2, topicSubscriptions.length);
Assertions.assertEquals(2, topicSubscriptions.length);
DaprTopicSubscription[] expectedDaprTopicSubscriptions = getTestDaprTopicSubscriptions();
@ -55,16 +55,16 @@ public class DaprBeanPostProcessorSubscribeTest {
}
private void assertTopicSubscriptionEquality(DaprTopicSubscription s1, DaprTopicSubscription s2) {
Assert.assertEquals(s1.getPubsubName(), s2.getPubsubName());
Assert.assertEquals(s1.getTopic(), s2.getTopic());
Assert.assertEquals(s1.getRoute(), s2.getRoute());
Assert.assertEquals(s1.getMetadata(), s2.getMetadata());
Assertions.assertEquals(s1.getPubsubName(), s2.getPubsubName());
Assertions.assertEquals(s1.getTopic(), s2.getTopic());
Assertions.assertEquals(s1.getRoute(), s2.getRoute());
Assertions.assertEquals(s1.getMetadata(), s2.getMetadata());
if (s1.getBulkSubscribe() == null) {
Assert.assertNull(s2.getBulkSubscribe());
Assertions.assertNull(s2.getBulkSubscribe());
} else {
Assert.assertEquals(s1.getBulkSubscribe().isEnabled(), s2.getBulkSubscribe().isEnabled());
Assert.assertEquals(s1.getBulkSubscribe().getMaxAwaitDurationMs(), s2.getBulkSubscribe().getMaxAwaitDurationMs());
Assert.assertEquals(s1.getBulkSubscribe().getMaxMessagesCount(), s2.getBulkSubscribe().getMaxMessagesCount());
Assertions.assertEquals(s1.getBulkSubscribe().isEnabled(), s2.getBulkSubscribe().isEnabled());
Assertions.assertEquals(s1.getBulkSubscribe().getMaxAwaitDurationMs(), s2.getBulkSubscribe().getMaxAwaitDurationMs());
Assertions.assertEquals(s1.getBulkSubscribe().getMaxMessagesCount(), s2.getBulkSubscribe().getMaxMessagesCount());
}
}

View File

@ -13,54 +13,41 @@
package io.dapr.springboot;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.stream.Stream;
@RunWith(Parameterized.class)
public class DaprBeanPostProcessorTest {
private final Class<?> clazzToBeTested;
private final String methodToBeTested;
private final String[] expected;
private final boolean expectedResult;
private static final String TOPIC_NAME = "topicName1";
public DaprBeanPostProcessorTest(Class<?> clazzToBeTested, String methodToBeTested, String[] expected,
boolean expectedResult) {
this.clazzToBeTested = clazzToBeTested;
this.methodToBeTested = methodToBeTested;
this.expected = expected;
this.expectedResult = expectedResult;
public static Stream<Arguments> routesTester() {
return Stream.of(
Arguments.of(MockController.class, "testMethod1", new String[] {"v1", "v2", "v1/page1", "v2/page1", "v1/page2", "v2/page2"},
true),
Arguments.of(MockController.class, "testMethod2", new String[] {"v1", "v2", "v1/page3", "v2/page3", "v1/page4", "v2/page4"},
true),
Arguments.of(MockController.class, "testMethod3", new String[] {"v1/foo", "v2/foo"}, true),
Arguments.of(MockController.class, "testMethod4", new String[] {"v1/foo1", "v2/foo1", "v1/foo2", "v2/foo2"}, true),
Arguments.of(MockController.class, "testMethod5", new String[] {"v1/" + TOPIC_NAME, "v2/" + TOPIC_NAME}, true),
Arguments.of(MockControllerNoClazzAnnotation.class, "testMethod1", new String[] {"", "page1", "page2"}, true),
Arguments.of(MockControllerNoClazzAnnotation.class, "testMethod2", new String[] {"", "page3", "page4"}, true),
Arguments.of(MockControllerNoClazzAnnotation.class, "testMethod3", new String[] {"foo"}, true),
Arguments.of(MockControllerNoClazzAnnotation.class, "testMethod4", new String[] {"foo1", "foo2"}, true),
Arguments.of(MockControllerNoClazzAnnotation.class, "testMethod5", new String[] {TOPIC_NAME}, true)
);
}
@Parameterized.Parameters
public static Collection<?> routesTester() {
return Arrays.asList(new Object[][] {
{MockController.class, "testMethod1", new String[] {"v1", "v2", "v1/page1", "v2/page1", "v1/page2", "v2/page2"},
true},
{MockController.class, "testMethod2", new String[] {"v1", "v2", "v1/page3", "v2/page3", "v1/page4", "v2/page4"},
true},
{MockController.class, "testMethod3", new String[] {"v1/foo", "v2/foo"}, true},
{MockController.class, "testMethod4", new String[] {"v1/foo1", "v2/foo1", "v1/foo2", "v2/foo2"}, true},
{MockController.class, "testMethod5", new String[] {"v1/" + TOPIC_NAME, "v2/" + TOPIC_NAME}, true},
{MockControllerNoClazzAnnotation.class, "testMethod1", new String[] {"", "page1", "page2"}, true},
{MockControllerNoClazzAnnotation.class, "testMethod2", new String[] {"", "page3", "page4"}, true},
{MockControllerNoClazzAnnotation.class, "testMethod3", new String[] {"foo"}, true},
{MockControllerNoClazzAnnotation.class, "testMethod4", new String[] {"foo1", "foo2"}, true},
{MockControllerNoClazzAnnotation.class, "testMethod5", new String[] {TOPIC_NAME}, true}
});
}
@Test
public void testAllPostRoutesGeneration() throws NoSuchMethodException {
@ParameterizedTest
@MethodSource("routesTester")
public void testAllPostRoutesGeneration(Class<?> clazzToBeTested, String methodToBeTested, String[] expected,
boolean expectedResult) throws NoSuchMethodException {
Method allPostRoutesMethod = DaprBeanPostProcessor.class.
getDeclaredMethod("getAllCompleteRoutesForPost", Class.class, Method.class, String.class);
allPostRoutesMethod.setAccessible(true);
@ -71,7 +58,7 @@ public class DaprBeanPostProcessorTest {
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
Assert.assertEquals(expectedResult,
Assertions.assertEquals(expectedResult,
testingListForOrderAgnosticEquality(Arrays.asList(expected), routesArrayTestMethod1));
}

View File

@ -1,12 +1,14 @@
package io.dapr.springboot;
import io.dapr.Rule;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.lang.annotation.Annotation;
import java.util.HashMap;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class DaprRuntimeTest {
@Test
@ -33,7 +35,7 @@ public class DaprRuntimeTest {
};
DaprRuntime runtime = DaprRuntime.getInstance();
Assert.assertNotNull(runtime);
Assertions.assertNotNull(runtime);
// We should be able to register the same route multiple times
runtime.addSubscribedTopic(
@ -42,7 +44,7 @@ public class DaprRuntimeTest {
pubSubName, topicName, match, rule.priority(), route,deadLetterTopic, metadata);
}
@Test(expected = RuntimeException.class)
@Test
public void testPubsubDefaultPathDifferentRegistration() {
String pubSubName = "pubsub";
String topicName = "topic";
@ -70,14 +72,13 @@ public class DaprRuntimeTest {
DaprRuntime runtime = DaprRuntime.getInstance();
Assert.assertNotNull(runtime);
Assertions.assertNotNull(runtime);
runtime.addSubscribedTopic(
pubSubName, topicName, match, rule.priority(), firstRoute, deadLetterTopic, metadata);
// Supplying the same pubsub bits but a different route should fail
runtime.addSubscribedTopic(
pubSubName, topicName, match, rule.priority(), secondRoute, deadLetterTopic, metadata);
assertThrows(RuntimeException.class, () -> runtime.addSubscribedTopic(
pubSubName, topicName, match, rule.priority(), secondRoute, deadLetterTopic, metadata));
}
}

View File

@ -13,8 +13,8 @@
package io.dapr.springboot;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.Map;
@ -26,12 +26,12 @@ public class DaprTopicBulkSubscribeTest {
bulkSubscribe.setMaxMessagesCount(100);
bulkSubscribe.setMaxAwaitDurationMs(200);
Assert.assertTrue(bulkSubscribe.isEnabled());
Assert.assertEquals(100, bulkSubscribe.getMaxMessagesCount().longValue());
Assert.assertEquals(200, bulkSubscribe.getMaxAwaitDurationMs().longValue());
Assertions.assertTrue(bulkSubscribe.isEnabled());
Assertions.assertEquals(100, bulkSubscribe.getMaxMessagesCount().longValue());
Assertions.assertEquals(200, bulkSubscribe.getMaxAwaitDurationMs().longValue());
bulkSubscribe.setEnabled(false);
Assert.assertFalse(bulkSubscribe.isEnabled());
Assertions.assertFalse(bulkSubscribe.isEnabled());
}
@Test
@ -48,9 +48,9 @@ public class DaprTopicBulkSubscribeTest {
for (Map.Entry<Integer, Boolean> testCase: testCases.entrySet()) {
try {
bulkSubscribe.setMaxMessagesCount(testCase.getKey());
Assert.assertFalse(testCase.getValue());
Assertions.assertFalse(testCase.getValue());
} catch (IllegalArgumentException e) {
Assert.assertTrue(testCase.getValue());
Assertions.assertTrue(testCase.getValue());
}
}
}
@ -69,9 +69,9 @@ public class DaprTopicBulkSubscribeTest {
for (Map.Entry<Integer, Boolean> testCase: testCases.entrySet()) {
try {
bulkSubscribe.setMaxAwaitDurationMs(testCase.getKey());
Assert.assertFalse(testCase.getValue());
Assertions.assertFalse(testCase.getValue());
} catch (IllegalArgumentException e) {
Assert.assertTrue(testCase.getValue());
Assertions.assertTrue(testCase.getValue());
}
}
}

View File

@ -33,6 +33,13 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.7.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
@ -101,15 +108,13 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.5.2</version>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
@ -201,9 +206,9 @@
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>failsafe-maven-plugin</artifactId>
<version>2.4.3-alpha-1</version>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.1.2</version>
<executions>
<execution>
<goals>

View File

@ -17,7 +17,7 @@ import io.dapr.actors.client.ActorClient;
import io.dapr.client.DaprApiProtocol;
import io.dapr.client.resiliency.ResiliencyOptions;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.junit.AfterClass;
import org.junit.jupiter.api.AfterAll;
import java.util.HashMap;
import java.util.LinkedList;
@ -184,7 +184,7 @@ public abstract class BaseIT {
return runs;
}
@AfterClass
@AfterAll
public static void cleanUp() throws Exception {
while (!TO_BE_CLOSED.isEmpty()) {
TO_BE_CLOSED.remove().close();

View File

@ -18,7 +18,7 @@ import io.dapr.actors.client.ActorProxyBuilder;
import io.dapr.it.BaseIT;
import io.dapr.it.actors.services.springboot.DemoActor;
import io.dapr.it.actors.services.springboot.DemoActorService;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -26,9 +26,9 @@ import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import static io.dapr.it.Retry.callWithRetry;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class ActivationDeactivationIT extends BaseIT {
@ -62,14 +62,14 @@ public class ActivationDeactivationIT extends BaseIT {
logger.debug("Retrieving active Actors");
List<String> activeActors = proxy.retrieveActiveActors();
logger.debug("Active actors: [" + activeActors.toString() + "]");
assertTrue("Expecting actorId:[" + actorId1.toString() + "]", activeActors.contains(actorId1.toString()));
assertTrue(activeActors.contains(actorId1.toString()),"Expecting actorId:[" + actorId1.toString() + "]");
ActorId actorId2 = new ActorId(Integer.toString(atomicInteger.getAndIncrement()));
DemoActor proxy2 = proxyBuilder.build(actorId2);
callWithRetry(() -> {
List<String> activeActorsSecondTry = proxy2.retrieveActiveActors();
logger.debug("Active actors: [" + activeActorsSecondTry.toString() + "]");
assertFalse("NOT Expecting actorId:[" + actorId1.toString() + "]", activeActorsSecondTry.contains(actorId1.toString()));
assertFalse(activeActorsSecondTry.contains(actorId1.toString()), "NOT Expecting actorId:[" + actorId1.toString() + "]");
}, 15000);
}
}

View File

@ -14,22 +14,17 @@ limitations under the License.
package io.dapr.it.actors;
import io.dapr.actors.ActorId;
import io.dapr.actors.client.ActorProxy;
import io.dapr.actors.client.ActorProxyBuilder;
import io.dapr.it.BaseIT;
import io.dapr.it.actors.app.MyActor;
import io.dapr.it.actors.app.MyActorService;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.ExecutionException;
import static io.dapr.it.Retry.callWithRetry;
import static io.dapr.it.TestUtils.assertThrowsDaprException;
import static io.dapr.it.TestUtils.assertThrowsDaprExceptionSubstring;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
public class ActorExceptionIT extends BaseIT {
@ -59,8 +54,5 @@ public class ActorExceptionIT extends BaseIT {
"INTERNAL: error invoke actor method: error from actor service",
() -> proxy.throwException());
}, 5000);
}
}

View File

@ -19,12 +19,12 @@ import io.dapr.actors.client.ActorProxyBuilder;
import io.dapr.it.BaseIT;
import io.dapr.it.actors.app.MyActor;
import io.dapr.it.actors.app.MyActorService;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static io.dapr.it.Retry.callWithRetry;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class ActorMethodNameIT extends BaseIT {

View File

@ -19,9 +19,9 @@ import io.dapr.actors.client.ActorProxyBuilder;
import io.dapr.it.BaseIT;
import io.dapr.it.DaprRun;
import io.dapr.it.actors.app.MyActorService;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -31,7 +31,7 @@ import java.util.UUID;
import static io.dapr.it.actors.MyActorTestUtils.countMethodCalls;
import static io.dapr.it.actors.MyActorTestUtils.fetchMethodCallLogs;
import static io.dapr.it.actors.MyActorTestUtils.validateMethodCalls;
import static org.junit.Assert.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
public class ActorReminderFailoverIT extends BaseIT {
@ -47,7 +47,7 @@ public class ActorReminderFailoverIT extends BaseIT {
private DaprRun clientAppRun;
@Before
@BeforeEach
public void init() throws Exception {
firstAppRun = startDaprApp(
ActorReminderFailoverIT.class.getSimpleName() + "One",
@ -78,7 +78,7 @@ public class ActorReminderFailoverIT extends BaseIT {
proxy = proxyBuilder.build(actorId);
}
@After
@AfterEach
public void tearDown() {
// call unregister
logger.debug("Calling actor method 'stopReminder' to unregister reminder");

View File

@ -22,21 +22,23 @@ import io.dapr.it.DaprRun;
import io.dapr.it.actors.app.ActorReminderDataParam;
import io.dapr.it.actors.app.MyActorService;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.runners.Parameterized;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.time.Duration;
import java.util.*;
import java.util.stream.Stream;
import static io.dapr.it.Retry.callWithRetry;
import static io.dapr.it.actors.MyActorTestUtils.*;
@RunWith(Parameterized.class)
public class ActorReminderRecoveryIT extends BaseIT {
private static final Logger logger = LoggerFactory.getLogger(ActorReminderRecoveryIT.class);
@ -49,38 +51,30 @@ public class ActorReminderRecoveryIT extends BaseIT {
*
* @return Collection of parameter tuples.
*/
@Parameterized.Parameters
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] {
{
public static Stream<Arguments> data() {
return Stream.of(Arguments.of(
"MyActorTest",
new ActorReminderDataParam("36", "String"),
"36"
},
{
),
Arguments.of(
"MyActorTest",
new ActorReminderDataParam("\"my_text\"", "String"),
"\"my_text\""
},
{
),
Arguments.of(
"MyActorBinaryTest",
new ActorReminderDataParam(new byte[]{0, 1}, "Binary"),
"AAE="
},
{
),
Arguments.of(
"MyActorObjectTest",
new ActorReminderDataParam("{\"name\":\"abc\",\"age\":30}", "Object"),
"abc,30"
},
});
)
);
}
public String actorType;
public ActorReminderDataParam reminderDataParam;
public String expectedReminderStateText;
public String reminderName = UUID.randomUUID().toString();
private ActorProxy proxy;
@ -89,17 +83,7 @@ public class ActorReminderRecoveryIT extends BaseIT {
private DaprRun clientRun;
public ActorReminderRecoveryIT(
String actorType,
ActorReminderDataParam reminderDataParam,
String expectedReminderStateText) {
this.actorType = actorType;
this.reminderDataParam = reminderDataParam;
this.expectedReminderStateText = expectedReminderStateText;
}
@Before
public void init() throws Exception {
public void setup(String actorType) throws Exception {
runs = startSplitDaprAndApp(
ActorReminderRecoveryIT.class.getSimpleName(),
"Started MyActorService",
@ -118,13 +102,13 @@ public class ActorReminderRecoveryIT extends BaseIT {
logger.debug("Creating proxy builder");
ActorProxyBuilder<ActorProxy> proxyBuilder =
new ActorProxyBuilder(this.actorType, ActorProxy.class, newActorClient());
new ActorProxyBuilder(actorType, ActorProxy.class, newActorClient());
logger.debug("Creating actorId");
logger.debug("Building proxy");
proxy = proxyBuilder.build(actorId);
}
@After
@AfterEach
public void tearDown() {
// call unregister
logger.debug("Calling actor method 'stopReminder' to unregister reminder");
@ -135,12 +119,19 @@ public class ActorReminderRecoveryIT extends BaseIT {
* Create an actor, register a reminder, validates its content, restarts the runtime and confirms reminder continues.
* @throws Exception This test is not expected to throw. Thrown exceptions are bugs.
*/
@Test
public void reminderRecoveryTest() throws Exception {
logger.debug("Invoking actor method 'startReminder' which will register a reminder");
proxy.invokeMethod("setReminderData", this.reminderDataParam).block();
@ParameterizedTest
@MethodSource("data")
public void reminderRecoveryTest(
String actorType,
ActorReminderDataParam reminderDataParam,
String expectedReminderStateText
) throws Exception {
setup(actorType);
proxy.invokeMethod("startReminder", this.reminderName).block();
logger.debug("Invoking actor method 'startReminder' which will register a reminder");
proxy.invokeMethod("setReminderData", reminderDataParam).block();
proxy.invokeMethod("startReminder", reminderName).block();
logger.debug("Pausing 7 seconds to allow reminder to fire");
Thread.sleep(7000);
@ -150,7 +141,7 @@ public class ActorReminderRecoveryIT extends BaseIT {
logs.clear();
logs.addAll(fetchMethodCallLogs(proxy));
validateMethodCalls(logs, METHOD_NAME, 3);
validateMessageContent(logs, METHOD_NAME, this.expectedReminderStateText);
validateMessageContent(logs, METHOD_NAME, expectedReminderStateText);
}, 5000);
// Restarts runtime only.
@ -172,7 +163,7 @@ public class ActorReminderRecoveryIT extends BaseIT {
logger.info("Fetching logs for " + METHOD_NAME);
List<MethodEntryTracker> newLogs = fetchMethodCallLogs(proxy);
validateMethodCalls(newLogs, METHOD_NAME, 1);
validateMessageContent(newLogs, METHOD_NAME, this.expectedReminderStateText);
validateMessageContent(newLogs, METHOD_NAME, expectedReminderStateText);
logger.info("Pausing 10 seconds to allow reminder to fire a few times");
try {

View File

@ -23,17 +23,17 @@ import io.dapr.it.DaprRun;
import io.dapr.it.ToxiProxyRun;
import io.dapr.it.actors.services.springboot.DemoActor;
import io.dapr.it.actors.services.springboot.DemoActorService;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.time.Duration;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Test SDK resiliency.
@ -66,7 +66,7 @@ public class ActorSdkResiliencytIT extends BaseIT {
private static DemoActor oneRetryDemoActor;
@BeforeClass
@BeforeAll
public static void init() throws Exception {
daprRun = startDaprApp(
ActorSdkResiliencytIT.class.getSimpleName(),
@ -98,7 +98,7 @@ public class ActorSdkResiliencytIT extends BaseIT {
return builder.build(ACTOR_ID);
}
@AfterClass
@AfterAll
public static void tearDown() throws Exception {
if (toxiProxyRun != null) {
toxiProxyRun.stop();
@ -106,7 +106,7 @@ public class ActorSdkResiliencytIT extends BaseIT {
}
@Test
@Ignore("Flaky when running on GitHub actions")
@Disabled("Flaky when running on GitHub actions")
public void retryAndTimeout() {
AtomicInteger toxiClientErrorCount = new AtomicInteger();
AtomicInteger retryOneClientErrorCount = new AtomicInteger();

View File

@ -21,21 +21,19 @@ import io.dapr.it.BaseIT;
import io.dapr.it.DaprRun;
import io.dapr.it.actors.services.springboot.StatefulActor;
import io.dapr.it.actors.services.springboot.StatefulActorService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Arrays;
import java.util.Collection;
import java.util.stream.Stream;
import static io.dapr.it.Retry.callWithRetry;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
@RunWith(Parameterized.class)
public class ActorStateIT extends BaseIT {
private static Logger logger = LoggerFactory.getLogger(ActorStateIT.class);
@ -45,24 +43,18 @@ public class ActorStateIT extends BaseIT {
* Param #1: useGrpc.
* @return Collection of parameter tuples.
*/
@Parameterized.Parameters
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] {
{ DaprApiProtocol.HTTP, DaprApiProtocol.HTTP },
{ DaprApiProtocol.HTTP, DaprApiProtocol.GRPC },
{ DaprApiProtocol.GRPC, DaprApiProtocol.HTTP },
{ DaprApiProtocol.GRPC, DaprApiProtocol.GRPC },
});
public static Stream<Arguments> data() {
return Stream.of(
Arguments.of(DaprApiProtocol.HTTP, DaprApiProtocol.HTTP ),
Arguments.of(DaprApiProtocol.HTTP, DaprApiProtocol.GRPC ),
Arguments.of(DaprApiProtocol.GRPC, DaprApiProtocol.HTTP ),
Arguments.of(DaprApiProtocol.GRPC, DaprApiProtocol.GRPC )
);
}
@Parameterized.Parameter(0)
public DaprApiProtocol daprClientProtocol;
@Parameterized.Parameter(1)
public DaprApiProtocol serviceAppProtocol;
@Test
public void writeReadState() throws Exception {
@ParameterizedTest
@MethodSource("data")
public void writeReadState(DaprApiProtocol daprClientProtocol, DaprApiProtocol serviceAppProtocol) throws Exception {
logger.debug("Starting actor runtime ...");
// The call below will fail if service cannot start successfully.
DaprRun runtime = startDaprApp(
@ -73,13 +65,13 @@ public class ActorStateIT extends BaseIT {
60000,
serviceAppProtocol);
runtime.switchToProtocol(this.daprClientProtocol);
runtime.switchToProtocol(daprClientProtocol);
String message = "This is a message to be saved and retrieved.";
String name = "Jon Doe";
byte[] bytes = new byte[] { 0x1 };
ActorId actorId = new ActorId(
String.format("%d-%b-%b", System.currentTimeMillis(), this.daprClientProtocol, this.serviceAppProtocol));
String.format("%d-%b-%b", System.currentTimeMillis(), daprClientProtocol, serviceAppProtocol));
String actorType = "StatefulActorTest";
logger.debug("Building proxy ...");
ActorProxyBuilder<ActorProxy> proxyBuilder =
@ -166,7 +158,7 @@ public class ActorStateIT extends BaseIT {
60000,
serviceAppProtocol);
runtime.switchToProtocol(this.daprClientProtocol);
runtime.switchToProtocol(daprClientProtocol);
// Need new proxy builder because the proxy builder holds the channel.
proxyBuilder = new ActorProxyBuilder(actorType, ActorProxy.class, newActorClient());

View File

@ -21,7 +21,7 @@ import io.dapr.it.BaseIT;
import io.dapr.it.DaprRun;
import io.dapr.it.actors.app.MyActorService;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -34,7 +34,7 @@ import static io.dapr.it.Retry.callWithRetry;
import static io.dapr.it.actors.MyActorTestUtils.fetchMethodCallLogs;
import static io.dapr.it.actors.MyActorTestUtils.validateMethodCalls;
import static io.dapr.it.actors.MyActorTestUtils.validateMessageContent;
import static org.junit.Assert.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
public class ActorTimerRecoveryIT extends BaseIT {

View File

@ -21,9 +21,9 @@ import io.dapr.client.DaprHttp;
import io.dapr.client.DaprHttpBuilder;
import io.dapr.it.BaseIT;
import io.dapr.it.actors.app.MyActorService;
import org.junit.After;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -32,11 +32,10 @@ import java.util.List;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import static io.dapr.it.Retry.callWithRetry;
import static io.dapr.it.actors.MyActorTestUtils.fetchMethodCallLogs;
import static io.dapr.it.actors.MyActorTestUtils.validateMethodCalls;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class ActorTurnBasedConcurrencyIT extends BaseIT {
@ -52,7 +51,7 @@ public class ActorTurnBasedConcurrencyIT extends BaseIT {
private static final String ACTOR_ID = "1";
@After
@AfterEach
public void cleanUpTestCase() {
// Delete the reminder in case the test failed, otherwise it may interfere with future tests since it is persisted.
DaprHttp client = new DaprHttpBuilder().build();
@ -185,7 +184,7 @@ public class ActorTurnBasedConcurrencyIT extends BaseIT {
} else {
String msg = "Error - Enter and Exit should alternate. Incorrect entry: " + s.toString();
System.out.println(msg);
Assert.fail(msg);
Assertions.fail(msg);
}
}
}

View File

@ -20,7 +20,7 @@ import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
/**
* Utility class for tests that use MyActor class.

View File

@ -5,7 +5,9 @@ import io.dapr.client.DaprClientBuilder;
import io.dapr.it.BaseIT;
import io.dapr.it.DaprRun;
import io.dapr.it.actors.ActorReminderRecoveryIT;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.slf4j.Logger;
@ -14,31 +16,17 @@ import org.slf4j.LoggerFactory;
import java.util.Arrays;
import java.util.Collection;
@RunWith(Parameterized.class)
public class ApiIT extends BaseIT {
private static final Logger logger = LoggerFactory.getLogger(ApiIT.class);
private static final int DEFAULT_TIMEOUT = 60000;
/**
* Parameters for this test.
* Param #1: useGrpc.
*
* @return Collection of parameter tuples.
*/
@Parameterized.Parameters
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{{false}, {true}});
}
@Parameterized.Parameter
public boolean useGrpc;
@Test
public void testShutdownAPI() throws Exception {
@ParameterizedTest
@ValueSource(booleans = {true, false})
public void testShutdownAPI(boolean useGrpc) throws Exception {
DaprRun run = startDaprApp(this.getClass().getSimpleName(), DEFAULT_TIMEOUT);
if (this.useGrpc) {
if (useGrpc) {
run.switchToGRPC();
} else {
run.switchToHTTP();

View File

@ -19,24 +19,20 @@ import io.dapr.client.DaprClientBuilder;
import io.dapr.client.domain.HttpExtension;
import io.dapr.it.BaseIT;
import io.dapr.it.DaprRun;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
import static io.dapr.it.Retry.callWithRetry;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
/**
* Service for input and output binding example.
*/
@RunWith(Parameterized.class)
public class BindingIT extends BaseIT {
private static final String BINDING_NAME = "sample123";
@ -50,23 +46,11 @@ public class BindingIT extends BaseIT {
public String message;
}
/**
* Parameters for this test.
* Param #1: useGrpc.
* @return Collection of parameter tuples.
*/
@Parameterized.Parameters
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] { { false }, { true } });
}
@Parameterized.Parameter
public boolean useGrpc;
@Test
public void inputOutputBinding() throws Exception {
@ParameterizedTest
@ValueSource(booleans = {true, false})
public void inputOutputBinding(boolean useGrpc) throws Exception {
System.out.println("Working Directory = " + System.getProperty("user.dir"));
String serviceNameVariant = this.useGrpc ? "-grpc" : "-http";
String serviceNameVariant = useGrpc ? "-grpc" : "-http";
DaprRun daprRun = startDaprApp(
this.getClass().getSimpleName() + serviceNameVariant,
@ -75,7 +59,7 @@ public class BindingIT extends BaseIT {
true,
60000);
// At this point, it is guaranteed that the service above is running and all ports being listened to.
if (this.useGrpc) {
if (useGrpc) {
daprRun.switchToGRPC();
} else {
daprRun.switchToHTTP();

View File

@ -21,7 +21,10 @@ import io.dapr.client.domain.UnsubscribeConfigurationResponse;
import io.dapr.it.BaseIT;
import io.dapr.it.DaprRun;
import org.junit.*;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import reactor.core.Disposable;
import reactor.core.publisher.Flux;
@ -29,7 +32,7 @@ import java.io.IOException;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
public class ConfigurationClientIT extends BaseIT {
@ -59,19 +62,19 @@ public class ConfigurationClientIT extends BaseIT {
"myconfigkey3", "update_myconfigvalue3||2"
};
@BeforeClass
@BeforeAll
public static void init() throws Exception {
daprRun = startDaprApp(ConfigurationClientIT.class.getSimpleName(), 5000);
daprRun.switchToGRPC();
daprClient = new DaprClientBuilder().build();
}
@AfterClass
@AfterAll
public static void tearDown() throws Exception {
daprClient.close();
}
@Before
@BeforeEach
public void setupConfigStore() {
executeDockerCommand(insertCmd);
}

View File

@ -5,16 +5,17 @@ import io.dapr.client.DaprClientBuilder;
import io.dapr.client.domain.ConfigurationItem;
import io.dapr.it.BaseIT;
import io.dapr.it.DaprRun;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.util.*;
import static org.junit.Assert.*;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class ConfigurationIT extends BaseIT {
private static final String CONFIG_STORE_NAME = "redisconfigstore";
@ -35,19 +36,19 @@ public class ConfigurationIT extends BaseIT {
"myconfigkey3", "myconfigvalue3||1"
};
@BeforeClass
@BeforeAll
public static void init() throws Exception {
daprRun = startDaprApp(ConfigurationIT.class.getSimpleName(), 5000);
daprRun.switchToHTTP();
daprClient = new DaprClientBuilder().build();
}
@AfterClass
@AfterAll
public static void tearDown() throws Exception {
daprClient.close();
}
@Before
@BeforeEach
public void setupConfigStore() {
executeDockerCommand(insertCmd);
}

View File

@ -6,17 +6,17 @@ import io.dapr.client.domain.SubscribeConfigurationResponse;
import io.dapr.client.domain.UnsubscribeConfigurationResponse;
import io.dapr.it.BaseIT;
import io.dapr.it.DaprRun;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class ConfigurationSubscribeIT extends BaseIT {
private static final String CONFIG_STORE_NAME = "redisconfigstore";
@ -37,7 +37,7 @@ public class ConfigurationSubscribeIT extends BaseIT {
"myconfigkey3", "myconfigvalue3||1"
};
@BeforeClass
@BeforeAll
public static void init() throws Exception {
daprRun = startDaprApp(
ConfigurationIT.class.getSimpleName(),
@ -49,12 +49,12 @@ public class ConfigurationSubscribeIT extends BaseIT {
daprClient = new DaprClientBuilder().build();
}
@AfterClass
@AfterAll
public static void tearDown() throws Exception {
daprClient.close();
}
@Before
@BeforeEach
public void setupConfigStore() {
executeDockerCommand(insertCmd);
}

View File

@ -7,8 +7,8 @@ import io.dapr.client.domain.HttpExtension;
import io.dapr.exceptions.DaprException;
import io.dapr.it.BaseIT;
import io.dapr.it.DaprRun;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.time.Duration;
import java.util.Map;
@ -18,9 +18,9 @@ import static io.dapr.it.MethodInvokeServiceProtos.GetMessagesRequest;
import static io.dapr.it.MethodInvokeServiceProtos.GetMessagesResponse;
import static io.dapr.it.MethodInvokeServiceProtos.PostMessageRequest;
import static io.dapr.it.MethodInvokeServiceProtos.SleepRequest;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class MethodInvokeIT extends BaseIT {
@ -32,7 +32,7 @@ public class MethodInvokeIT extends BaseIT {
*/
private DaprRun daprRun = null;
@Before
@BeforeEach
public void init() throws Exception {
daprRun = startDaprApp(
MethodInvokeIT.class.getSimpleName(),

View File

@ -7,8 +7,8 @@ import io.dapr.exceptions.DaprException;
import io.dapr.it.BaseIT;
import io.dapr.it.DaprRun;
import io.dapr.it.MethodInvokeServiceProtos;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.time.Duration;
import java.util.Arrays;
@ -17,10 +17,10 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class MethodInvokeIT extends BaseIT {
@ -32,7 +32,7 @@ public class MethodInvokeIT extends BaseIT {
*/
private DaprRun daprRun = null;
@Before
@BeforeEach
public void init() throws Exception {
daprRun = startDaprApp(
MethodInvokeIT.class.getSimpleName(),

View File

@ -33,8 +33,11 @@ import io.dapr.it.DaprRun;
import io.dapr.serializer.DaprObjectSerializer;
import io.dapr.utils.TypeRef;
import org.junit.After;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@ -53,14 +56,13 @@ import java.util.Set;
import static io.dapr.it.Retry.callWithRetry;
import static io.dapr.it.TestUtils.assertThrowsDaprException;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@RunWith(Parameterized.class)
public class PubSubIT extends BaseIT {
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
@ -88,21 +90,6 @@ public class PubSubIT extends BaseIT {
// Topic to test bulk subscribe.
private static final String BULK_SUB_TOPIC_NAME = "topicBulkSub";
/**
* Parameters for this test.
* Param #1: useGrpc.
*
* @return Collection of parameter tuples.
*/
@Parameterized.Parameters
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{{false}, {true}});
}
@Parameterized.Parameter
public boolean useGrpc;
private final List<DaprRun> runs = new ArrayList<>();
private DaprRun closeLater(DaprRun run) {
@ -110,19 +97,20 @@ public class PubSubIT extends BaseIT {
return run;
}
@After
@AfterEach
public void tearDown() throws Exception {
for (DaprRun run : runs) {
run.stop();
}
}
@Test
public void publishPubSubNotFound() throws Exception {
@ParameterizedTest
@ValueSource(booleans = {true, false})
public void publishPubSubNotFound(boolean useGrpc) throws Exception {
DaprRun daprRun = closeLater(startDaprApp(
this.getClass().getSimpleName(),
60000));
if (this.useGrpc) {
if (useGrpc) {
daprRun.switchToGRPC();
} else {
daprRun.switchToHTTP();
@ -130,7 +118,7 @@ public class PubSubIT extends BaseIT {
try (DaprClient client = new DaprClientBuilder().build()) {
if (this.useGrpc) {
if (useGrpc) {
assertThrowsDaprException(
"INVALID_ARGUMENT",
"INVALID_ARGUMENT: pubsub unknown pubsub not found",
@ -144,12 +132,13 @@ public class PubSubIT extends BaseIT {
}
}
@Test
public void testBulkPublishPubSubNotFound() throws Exception {
@ParameterizedTest
@ValueSource(booleans = {true, false})
public void testBulkPublishPubSubNotFound(boolean useGrpc) throws Exception {
DaprRun daprRun = closeLater(startDaprApp(
this.getClass().getSimpleName(),
60000));
if (this.useGrpc) {
if (useGrpc) {
daprRun.switchToGRPC();
} else {
// No HTTP implementation for bulk publish
@ -165,8 +154,9 @@ public class PubSubIT extends BaseIT {
}
}
@Test
public void testBulkPublish() throws Exception {
@ParameterizedTest
@ValueSource(booleans = {true, false})
public void testBulkPublish(boolean useGrpc) throws Exception {
final DaprRun daprRun = closeLater(startDaprApp(
this.getClass().getSimpleName(),
SubscriberService.SUCCESS_MESSAGE,
@ -174,7 +164,7 @@ public class PubSubIT extends BaseIT {
true,
60000));
// At this point, it is guaranteed that the service above is running and all ports being listened to.
if (this.useGrpc) {
if (useGrpc) {
daprRun.switchToGRPC();
} else {
System.out.println("HTTP BulkPublish is not implemented. So skipping tests");
@ -208,8 +198,8 @@ public class PubSubIT extends BaseIT {
BulkPublishResponse response = previewClient.publishEvents(PUBSUB_NAME, TOPIC_BULK, "", messages).block();
System.out.println(String.format("Published %d messages to topic '%s' pubsub_name '%s'",
NUM_MESSAGES, TOPIC_BULK, PUBSUB_NAME));
assertNotNull("expected not null bulk publish response", response);
Assert.assertEquals("expected no failures in the response", 0, response.getFailedEntries().size());
assertNotNull(response, "expected not null bulk publish response");
assertEquals( 0, response.getFailedEntries().size(), "expected no failures in the response");
//Publishing an object.
MyObject object = new MyObject();
@ -217,16 +207,16 @@ public class PubSubIT extends BaseIT {
response = previewClient.publishEvents(PUBSUB_NAME, TOPIC_BULK,
"application/json", Collections.singletonList(object)).block();
System.out.println("Published one object.");
assertNotNull("expected not null bulk publish response", response);
Assert.assertEquals("expected no failures in the response", 0, response.getFailedEntries().size());
assertNotNull(response, "expected not null bulk publish response");
assertEquals(0, response.getFailedEntries().size(), "expected no failures in the response");
//Publishing a single byte: Example of non-string based content published
previewClient.publishEvents(PUBSUB_NAME, TOPIC_BULK, "",
Collections.singletonList(new byte[]{1})).block();
System.out.println("Published one byte.");
assertNotNull("expected not null bulk publish response", response);
Assert.assertEquals("expected no failures in the response", 0, response.getFailedEntries().size());
assertNotNull(response, "expected not null bulk publish response");
assertEquals(0, response.getFailedEntries().size(), "expected no failures in the response");
CloudEvent cloudEvent = new CloudEvent();
cloudEvent.setId("1234");
@ -242,8 +232,8 @@ public class PubSubIT extends BaseIT {
//Publishing a cloud event.
previewClient.publishEvents(req).block();
assertNotNull("expected not null bulk publish response", response);
Assert.assertEquals("expected no failures in the response", 0, response.getFailedEntries().size());
assertNotNull(response, "expected not null bulk publish response");
assertEquals(0, response.getFailedEntries().size(), "expected no failures in the response");
System.out.println("Published one cloud event.");
@ -260,48 +250,49 @@ public class PubSubIT extends BaseIT {
null,
HttpExtension.GET,
CLOUD_EVENT_LIST_TYPE_REF).block();
assertEquals("expected 13 messages to be received on subscribe", 13, cloudEventMessages.size());
assertEquals(13, cloudEventMessages.size(), "expected 13 messages to be received on subscribe");
for (int i = 0; i < NUM_MESSAGES; i++) {
final int messageId = i;
assertTrue("expected data content to match", cloudEventMessages
assertTrue(cloudEventMessages
.stream()
.filter(m -> m.getData() != null)
.map(m -> m.getData())
.filter(m -> m.equals(String.format("This is message #%d on topic %s", messageId, TOPIC_BULK)))
.count() == 1);
.count() == 1, "expected data content to match");
}
// Validate object payload.
assertTrue("expected data content 123 to match", cloudEventMessages
assertTrue(cloudEventMessages
.stream()
.filter(m -> m.getData() != null)
.filter(m -> m.getData() instanceof LinkedHashMap)
.map(m -> (LinkedHashMap) m.getData())
.filter(m -> "123".equals(m.get("id")))
.count() == 1);
.count() == 1, "expected data content 123 to match");
// Validate byte payload.
assertTrue("expected bin data to match", cloudEventMessages
assertTrue(cloudEventMessages
.stream()
.filter(m -> m.getData() != null)
.map(m -> m.getData())
.filter(m -> "AQ==".equals(m))
.count() == 1);
.count() == 1, "expected bin data to match");
// Validate cloudevent payload.
assertTrue("expected data to match",cloudEventMessages
assertTrue( cloudEventMessages
.stream()
.filter(m -> m.getData() != null)
.map(m -> m.getData())
.filter(m -> "message from cloudevent".equals(m))
.count() == 1);
.count() == 1, "expected data to match");
}, 2000);
}
}
@Test
public void testPubSub() throws Exception {
@ParameterizedTest
@ValueSource(booleans = {true, false})
public void testPubSub(boolean useGrpc) throws Exception {
final DaprRun daprRun = closeLater(startDaprApp(
this.getClass().getSimpleName(),
SubscriberService.SUCCESS_MESSAGE,
@ -309,7 +300,7 @@ public class PubSubIT extends BaseIT {
true,
60000));
// At this point, it is guaranteed that the service above is running and all ports being listened to.
if (this.useGrpc) {
if (useGrpc) {
daprRun.switchToGRPC();
} else {
daprRun.switchToHTTP();
@ -520,8 +511,9 @@ public class PubSubIT extends BaseIT {
}
}
@Test
public void testPubSubBinary() throws Exception {
@ParameterizedTest
@ValueSource(booleans = {true, false})
public void testPubSubBinary(boolean useGrpc) throws Exception {
final DaprRun daprRun = closeLater(startDaprApp(
this.getClass().getSimpleName(),
SubscriberService.SUCCESS_MESSAGE,
@ -529,7 +521,7 @@ public class PubSubIT extends BaseIT {
true,
60000));
// At this point, it is guaranteed that the service above is running and all ports being listened to.
if (this.useGrpc) {
if (useGrpc) {
daprRun.switchToGRPC();
} else {
daprRun.switchToHTTP();
@ -576,12 +568,13 @@ public class PubSubIT extends BaseIT {
}
}
@Test
public void testPubSubTTLMetadata() throws Exception {
@ParameterizedTest
@ValueSource(booleans = {true, false})
public void testPubSubTTLMetadata(boolean useGrpc) throws Exception {
DaprRun daprRun = closeLater(startDaprApp(
this.getClass().getSimpleName(),
60000));
if (this.useGrpc) {
if (useGrpc) {
daprRun.switchToGRPC();
} else {
daprRun.switchToHTTP();
@ -612,7 +605,7 @@ public class PubSubIT extends BaseIT {
SubscriberService.class,
true,
60000));
if (this.useGrpc) {
if (useGrpc) {
daprRun.switchToGRPC();
} else {
daprRun.switchToHTTP();
@ -633,15 +626,16 @@ public class PubSubIT extends BaseIT {
daprRun.stop();
}
@Test
public void testPubSubBulkSubscribe() throws Exception {
@ParameterizedTest
@ValueSource(booleans = {true, false})
public void testPubSubBulkSubscribe(boolean useGrpc) throws Exception {
DaprRun daprRun = closeLater(startDaprApp(
this.getClass().getSimpleName(),
SubscriberService.SUCCESS_MESSAGE,
SubscriberService.class,
true,
60000));
if (this.useGrpc) {
if (useGrpc) {
daprRun.switchToGRPC();
} else {
daprRun.switchToHTTP();
@ -695,8 +689,9 @@ public class PubSubIT extends BaseIT {
daprRun.stop();
}
@Test
public void testLongValues() throws Exception {
@ParameterizedTest
@ValueSource(booleans = {true, false})
public void testLongValues(boolean useGrpc) throws Exception {
final DaprRun daprRun = closeLater(startDaprApp(
this.getClass().getSimpleName(),
SubscriberService.SUCCESS_MESSAGE,
@ -704,7 +699,7 @@ public class PubSubIT extends BaseIT {
true,
60000));
// At this point, it is guaranteed that the service above is running and all ports being listened to.
if (this.useGrpc) {
if (useGrpc) {
daprRun.switchToGRPC();
} else {
daprRun.switchToHTTP();
@ -755,7 +750,7 @@ public class PubSubIT extends BaseIT {
for (CloudEvent<ConvertToLong> message : messages) {
actual.add(message.getData());
}
Assert.assertEquals(values, actual);
Assertions.assertEquals(values, actual);
}, 2000);
}
}

View File

@ -20,9 +20,9 @@ import io.dapr.client.resiliency.ResiliencyOptions;
import io.dapr.it.BaseIT;
import io.dapr.it.DaprRun;
import io.dapr.it.ToxiProxyRun;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
@ -30,15 +30,15 @@ import java.util.Base64;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Test SDK resiliency.
*/
public class SdkResiliencytIT extends BaseIT {
private static final int NUM_ITERATIONS = 20;
private static final int NUM_ITERATIONS = 25;
private static final Duration TIMEOUT = Duration.ofMillis(100);
@ -62,16 +62,18 @@ public class SdkResiliencytIT extends BaseIT {
private final String randomStateKeyPrefix = UUID.randomUUID().toString();
@BeforeClass
@BeforeAll
public static void init() throws Exception {
daprRun = startDaprApp(SdkResiliencytIT.class.getSimpleName(), 5000);
// HTTP client is deprecated, so SDK resiliency is for gRPC client only.
daprRun.switchToGRPC();
daprClient = new DaprClientBuilder().build();
daprClient.waitForSidecar(8000).block();
toxiProxyRun = new ToxiProxyRun(daprRun, LATENCY, JITTER);
toxiProxyRun.start();
toxiProxyRun.use();
daprToxiClient = new DaprClientBuilder()
.withResiliencyOptions(
new ResiliencyOptions().setTimeout(TIMEOUT))
@ -91,7 +93,7 @@ public class SdkResiliencytIT extends BaseIT {
assertTrue(daprRetriesOnceClient instanceof DaprClientGrpc);
}
@AfterClass
@AfterAll
public static void tearDown() throws Exception {
if (daprClient != null) {
daprClient.close();

View File

@ -22,7 +22,12 @@ import org.apache.commons.io.IOUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@ -35,15 +40,15 @@ import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Test Secrets Store APIs using local file.
*
* 1. create secret file locally:
*/
@RunWith(Parameterized.class)
public class SecretsClientIT extends BaseIT {
/**
@ -61,24 +66,12 @@ public class SecretsClientIT extends BaseIT {
private static DaprRun daprRun;
/**
* Parameters for this test.
* Param #1: useGrpc.
* @return Collection of parameter tuples.
*/
@Parameterized.Parameters
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] { { false }, { true } });
}
@Parameterized.Parameter
public boolean useGrpc = true;
private DaprClient daprClient;
private static File localSecretFile;
@BeforeClass
@BeforeAll
public static void init() throws Exception {
localSecretFile = new File(LOCAL_SECRET_FILE_PATH);
@ -89,9 +82,8 @@ public class SecretsClientIT extends BaseIT {
daprRun = startDaprApp(SecretsClientIT.class.getSimpleName(), 5000);
}
@Before
public void setup() {
if (this.useGrpc) {
public void setup(boolean useGrpc) {
if (useGrpc) {
daprRun.switchToGRPC();
} else {
daprRun.switchToHTTP();
@ -100,14 +92,16 @@ public class SecretsClientIT extends BaseIT {
this.daprClient = new DaprClientBuilder().build();
}
@After
@AfterEach
public void tearDown() throws Exception {
daprClient.close();
clearSecretFile();
}
@Test
public void getSecret() throws Exception {
@ParameterizedTest
@ValueSource(booleans = {true, false})
public void getSecret(boolean useGrpc) throws Exception {
setup(useGrpc);
Map<String, String> data = daprClient.getSecret(SECRETS_STORE_NAME, KEY1).block();
assertEquals(2, data.size());
@ -115,8 +109,10 @@ public class SecretsClientIT extends BaseIT {
assertEquals("2020", data.get("year"));
}
@Test
public void getBulkSecret() throws Exception {
@ParameterizedTest
@ValueSource(booleans = {true, false})
public void getBulkSecret(boolean useGrpc) throws Exception {
setup(useGrpc);
Map<String, Map<String, String>> data = daprClient.getBulkSecret(SECRETS_STORE_NAME).block();
// There can be other keys from other runs or test cases, so we are good with at least two.
@ -128,14 +124,20 @@ public class SecretsClientIT extends BaseIT {
assertEquals("Jon Doe", data.get(KYE2).get("name"));
}
@Test(expected = RuntimeException.class)
public void getSecretKeyNotFound() {
daprClient.getSecret(SECRETS_STORE_NAME, "unknownKey").block();
@ParameterizedTest
@ValueSource(booleans = {true, false})
public void getSecretKeyNotFound(boolean useGrpc) {
setup(useGrpc);
assertThrows(RuntimeException.class, () -> daprClient.getSecret(SECRETS_STORE_NAME, "unknownKey").block());
}
@Test(expected = RuntimeException.class)
public void getSecretStoreNotFound() throws Exception {
daprClient.getSecret("unknownStore", "unknownKey").block();
@ParameterizedTest
@ValueSource(booleans = {true, false})
public void getSecretStoreNotFound(boolean useGrpc) throws Exception {
setup(useGrpc);
assertThrows(RuntimeException.class, () -> daprClient.getSecret("unknownStore", "unknownKey").block());
}
private static void initSecretFile() throws Exception {

View File

@ -28,7 +28,7 @@ import io.dapr.client.domain.query.Sorting;
import io.dapr.client.domain.query.filters.EqFilter;
import io.dapr.exceptions.DaprException;
import io.dapr.it.BaseIT;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import java.util.Arrays;
@ -39,13 +39,13 @@ import java.util.Map;
import java.util.UUID;
import java.util.logging.Logger;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Common test cases for Dapr client (GRPC and HTTP).
@ -244,7 +244,7 @@ public abstract class AbstractStateClientIT extends BaseIT {
State<MyData> myDataResponse = response.block();
//review that the update was success action
assertNotNull("expected non null response", myDataResponse);
assertNotNull(myDataResponse, "expected non null response");
assertEquals("data in property A", myDataResponse.getValue().getPropertyA());
assertEquals("data in property B2", myDataResponse.getValue().getPropertyB());
}
@ -391,7 +391,7 @@ public abstract class AbstractStateClientIT extends BaseIT {
assertEquals(0, stateNullValue.getMetadata().size());
}
@Test(expected = RuntimeException.class)
@Test
public void saveUpdateAndGetStateWithWrongEtag() {
final String stateKey = "keyToBeUpdatedWithWrongEtag";
@ -402,7 +402,7 @@ public abstract class AbstractStateClientIT extends BaseIT {
data.setPropertyA("data in property A");
data.setPropertyB("data in property B");
//Create deferred action to save the sate
//Create deferred action to save the state
Mono<Void> saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, null, data, null);
//execute the save state action
saveResponse.block();
@ -427,21 +427,9 @@ public abstract class AbstractStateClientIT extends BaseIT {
data.setPropertyB("data in property B2");
//Create deferred action to update the data using the incorrect etag
saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, "99999999999999", data, null);
saveResponse.block();
response = daprClient.getState(STATE_STORE_NAME, new State<>(stateKey, (MyData) null, null), MyData.class);
//retrive the data wihout any etag
myDataResponse = response.block();
//review that state value changes
assertNotNull(myDataResponse.getEtag());
//review that the etag changes after an update
assertNotEquals(firstETag, myDataResponse.getEtag());
assertNotNull(myDataResponse.getKey());
assertNotNull(myDataResponse.getValue());
assertEquals("data in property A2", myDataResponse.getValue().getPropertyA());
assertEquals("data in property B2", myDataResponse.getValue().getPropertyB());
Mono<Void> finalSaveResponse = saveResponse;
assertThrows(RuntimeException.class, finalSaveResponse::block);
}
@Test
@ -484,7 +472,7 @@ public abstract class AbstractStateClientIT extends BaseIT {
}
@Test(expected = RuntimeException.class)
@Test
public void saveAndDeleteStateWithWrongEtag() {
final String stateKey = "myeKeyToBeDeletedWithWrongEtag";
@ -513,18 +501,11 @@ public abstract class AbstractStateClientIT extends BaseIT {
//Create deferred action to delete an state sending the incorrect etag
Mono<Void> deleteResponse = daprClient.deleteState(STATE_STORE_NAME, stateKey, "99999999999", null);
//execute the delete of the state, this should trhow an exception
deleteResponse.block();
//Create deferred action to get the sate without an etag
response = daprClient.getState(STATE_STORE_NAME, new State(stateKey), MyData.class);
myDataResponse = response.block();
//Review that the response is null, because the state was deleted
assertNull(myDataResponse.getValue());
//execute the delete of the state, this should throw an exception
assertThrows(RuntimeException.class, deleteResponse::block);
}
@Test(expected = RuntimeException.class)
@Test
public void saveUpdateAndGetStateWithEtagAndStateOptionsFirstWrite() {
final String stateKey = "keyToBeUpdatedWithEtagAndOptions";
@ -545,7 +526,7 @@ public abstract class AbstractStateClientIT extends BaseIT {
saveResponse.block();
//crate deferred action to retrieve the state
//create deferred action to retrieve the state
Mono<State<MyData>> response = daprClient.getState(STATE_STORE_NAME, new State(stateKey, null, stateOptions),
MyData.class);
//execute the retrieve of the state using options
@ -557,7 +538,7 @@ public abstract class AbstractStateClientIT extends BaseIT {
assertEquals("data in property A", myDataResponse.getValue().getPropertyA());
assertEquals("data in property B", myDataResponse.getValue().getPropertyB());
//change data to be udpated
//change data to be updated
data.setPropertyA("data in property A2");
data.setPropertyB("data in property B2");
//create deferred action to update the action with options
@ -570,8 +551,10 @@ public abstract class AbstractStateClientIT extends BaseIT {
data.setPropertyB("data in property B2");
//create deferred action to update the action with the same etag
saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, myDataResponse.getEtag(), data, stateOptions);
//throws an exception, the state was already udpated
saveResponse.block();
//throws an exception, the state was already updated
Mono<Void> finalSaveResponse2 = saveResponse;
assertThrows(RuntimeException.class, () -> finalSaveResponse2.block());
response = daprClient.getState(STATE_STORE_NAME, new State(stateKey, null, stateOptions), MyData.class);
State<MyData> myLastDataResponse = response.block();

View File

@ -17,9 +17,9 @@ import io.dapr.client.DaprClient;
import io.dapr.client.DaprClientBuilder;
import io.dapr.client.domain.State;
import io.dapr.it.DaprRun;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.util.Collections;
@ -34,14 +34,14 @@ public class GRPCStateClientIT extends AbstractStateClientIT {
private static DaprClient daprClient;
@BeforeClass
@BeforeAll
public static void init() throws Exception {
daprRun = startDaprApp(GRPCStateClientIT.class.getSimpleName(), 5000);
daprRun.switchToGRPC();
daprClient = new DaprClientBuilder().build();
}
@AfterClass
@AfterAll
public static void tearDown() throws Exception {
daprClient.close();
}

View File

@ -19,8 +19,8 @@ import io.dapr.v1.DaprGrpc;
import io.dapr.v1.DaprProtos;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class HelloWorldClientIT extends BaseIT {
@ -47,7 +47,7 @@ public class HelloWorldClientIT extends BaseIT {
DaprProtos.GetStateResponse response = client.getState(req);
String value = response.getData().toStringUtf8();
System.out.println("Got: " + value);
Assert.assertEquals("Hello World", value);
Assertions.assertEquals("Hello World", value);
}
// Then, delete it.
@ -70,7 +70,7 @@ public class HelloWorldClientIT extends BaseIT {
DaprProtos.GetStateResponse response = client.getState(req);
String value = response.getData().toStringUtf8();
System.out.println("Got: " + value);
Assert.assertEquals("", value);
Assertions.assertEquals("", value);
}
channel.shutdown();
}

View File

@ -18,14 +18,14 @@ import io.dapr.client.DaprClientBuilder;
import io.dapr.client.DaprClientHttp;
import io.dapr.client.domain.State;
import io.dapr.it.DaprRun;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.util.Collections;
import static io.dapr.it.TestUtils.assertThrowsDaprException;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Test State HTTP DAPR capabilities using a DAPR instance with an empty service running
@ -36,7 +36,7 @@ public class HttpStateClientIT extends AbstractStateClientIT {
private static DaprClient daprClient;
@BeforeClass
@BeforeAll
public static void init() throws Exception {
daprRun = startDaprApp(HttpStateClientIT.class.getSimpleName(), 5000);
daprRun.switchToHTTP();
@ -44,7 +44,7 @@ public class HttpStateClientIT extends AbstractStateClientIT {
assertTrue(daprClient instanceof DaprClientHttp);
}
@AfterClass
@AfterAll
public static void tearDown() throws Exception {
daprClient.close();
}

View File

@ -21,8 +21,8 @@ import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Class used to verify that traces are present as expected.

View File

@ -13,7 +13,11 @@ import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.context.Scope;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@ -27,29 +31,14 @@ import static io.dapr.it.tracing.OpenTelemetry.getReactorContext;
import static org.junit.runners.Parameterized.Parameter;
import static org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class TracingIT extends BaseIT {
/**
* Parameters for this test.
* Param #1: useGrpc.
* @return Collection of parameter tuples.
*/
@Parameters
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] { { false }, { true } });
}
/**
* Run of a Dapr application.
*/
private DaprRun daprRun = null;
@Parameter
public boolean useGrpc;
@Before
public void init() throws Exception {
public void setup(boolean useGrpc) throws Exception {
daprRun = startDaprApp(
TracingIT.class.getSimpleName(),
Service.SUCCESS_MESSAGE,
@ -57,7 +46,7 @@ public class TracingIT extends BaseIT {
DaprApiProtocol.GRPC, // appProtocol
60000);
if (this.useGrpc) {
if (useGrpc) {
daprRun.switchToGRPC();
} else {
daprRun.switchToHTTP();
@ -67,8 +56,11 @@ public class TracingIT extends BaseIT {
Thread.sleep(2000);
}
@Test
public void testInvoke() throws Exception {
@ParameterizedTest
@ValueSource(booleans = {true, false})
public void testInvoke(boolean useGrpc) throws Exception {
setup(useGrpc);
final OpenTelemetry openTelemetry = createOpenTelemetry("service over grpc");
final Tracer tracer = openTelemetry.getTracer("grpc integration test tracer");

View File

@ -12,7 +12,9 @@ import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.context.Scope;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@ -25,29 +27,14 @@ import static io.dapr.it.tracing.OpenTelemetry.getReactorContext;
import static org.junit.runners.Parameterized.Parameter;
import static org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class TracingIT extends BaseIT {
/**
* Parameters for this test.
* Param #1: useGrpc.
* @return Collection of parameter tuples.
*/
@Parameters
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] { { false }, { true } });
}
/**
* Run of a Dapr application.
*/
private DaprRun daprRun = null;
@Parameter
public boolean useGrpc;
@Before
public void init() throws Exception {
public void setup(boolean useGrpc) throws Exception {
daprRun = startDaprApp(
TracingIT.class.getSimpleName(),
Service.SUCCESS_MESSAGE,
@ -55,7 +42,7 @@ public class TracingIT extends BaseIT {
true,
30000);
if (this.useGrpc) {
if (useGrpc) {
daprRun.switchToGRPC();
} else {
daprRun.switchToHTTP();
@ -65,8 +52,11 @@ public class TracingIT extends BaseIT {
Thread.sleep(2000);
}
@Test
public void testInvoke() throws Exception {
@ParameterizedTest
@ValueSource(booleans = {true, false})
public void testInvoke(boolean useGrpc) throws Exception {
setup(useGrpc);
final OpenTelemetry openTelemetry = createOpenTelemetry(OpenTelemetryConfig.SERVICE_NAME);
final Tracer tracer = openTelemetry.getTracer(OpenTelemetryConfig.TRACER_NAME);

View File

@ -26,11 +26,6 @@
<artifactId>dapr-sdk</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>

View File

@ -17,8 +17,9 @@ import com.microsoft.durabletask.RetryPolicy;
import com.microsoft.durabletask.Task;
import com.microsoft.durabletask.TaskOptions;
import com.microsoft.durabletask.TaskOrchestrationContext;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import java.time.Duration;
@ -31,12 +32,13 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class DaprWorkflowContextImplTest {
private DaprWorkflowContextImpl context;
private TaskOrchestrationContext mockInnerContext;
@Before
@BeforeEach
public void setUp() {
mockInnerContext = mock(TaskOrchestrationContext.class);
context = new DaprWorkflowContextImpl(mockInnerContext);
@ -87,15 +89,17 @@ public class DaprWorkflowContextImplTest {
verify(mockInnerContext, times(1)).callActivity(expectedName, expectedInput, null, String.class);
}
@Test(expected = IllegalArgumentException.class)
@Test
public void DaprWorkflowContextWithEmptyInnerContext() {
assertThrows(IllegalArgumentException.class, () -> {
context = new DaprWorkflowContextImpl(mockInnerContext, null);
}
}); }
@Test(expected = IllegalArgumentException.class)
@Test
public void DaprWorkflowContextWithEmptyLogger() {
assertThrows(IllegalArgumentException.class, () -> {
context = new DaprWorkflowContextImpl(null, null);
});
}
@Test
@ -170,9 +174,9 @@ public class DaprWorkflowContextImplTest {
verify(mockInnerContext, times(1)).createTimer(Duration.ofSeconds(10));
}
@Test(expected = UnsupportedOperationException.class)
@Test
public void createTimerWithZonedDateTimeThrowsTest() {
context.createTimer(ZonedDateTime.now());
assertThrows(UnsupportedOperationException.class, () -> context.createTimer(ZonedDateTime.now()));
}
@Test

View File

@ -20,17 +20,17 @@ import io.dapr.workflows.Workflow;
import io.dapr.workflows.WorkflowContext;
import io.dapr.workflows.WorkflowStub;
import io.grpc.ManagedChannel;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.lang.reflect.Constructor;
import java.time.Duration;
import java.util.Arrays;
import java.util.concurrent.TimeoutException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
@ -50,7 +50,7 @@ public class DaprWorkflowClientTest {
}
}
@BeforeClass
@BeforeAll
public static void beforeAll() {
constructor =
Constructor.class.cast(Arrays.stream(DaprWorkflowClient.class.getDeclaredConstructors())
@ -60,7 +60,7 @@ public class DaprWorkflowClientTest {
}).findFirst().get());
}
@Before
@BeforeEach
public void setUp() throws Exception {
mockInnerClient = mock(DurableTaskClient.class);
mockGrpcChannel = mock(ManagedChannel.class);

View File

@ -18,8 +18,8 @@ import com.microsoft.durabletask.TaskOrchestrationContext;
import io.dapr.workflows.Workflow;
import io.dapr.workflows.WorkflowContext;
import io.dapr.workflows.WorkflowStub;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
@ -37,7 +37,7 @@ public class OrchestratorWrapperTest {
@Test
public void getName() {
OrchestratorWrapper<TestWorkflow> wrapper = new OrchestratorWrapper<>(TestWorkflow.class);
Assert.assertEquals(
Assertions.assertEquals(
"io.dapr.workflows.runtime.OrchestratorWrapperTest.TestWorkflow",
wrapper.getName()
);

View File

@ -3,7 +3,7 @@ package io.dapr.workflows.runtime;
import io.dapr.workflows.Workflow;
import io.dapr.workflows.WorkflowStub;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;

View File

@ -18,7 +18,7 @@ import com.microsoft.durabletask.DurableTaskGrpcWorker;
import com.microsoft.durabletask.DurableTaskGrpcWorkerBuilder;
import io.dapr.workflows.Workflow;
import io.dapr.workflows.WorkflowStub;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;

View File

@ -46,16 +46,16 @@
<artifactId>reactor-core</artifactId>
<version>3.5.0</version>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<version>3.5.0</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.9.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
@ -87,8 +87,12 @@
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.7.0</version>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
@ -109,6 +113,17 @@
<version>${grpc.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>uk.org.webcompere</groupId>
<artifactId>system-stubs-jupiter</artifactId>
<version>2.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-migrationsupport</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@ -102,7 +102,7 @@ public class DaprHttp implements AutoCloseable {
*/
public Response(byte[] body, Map<String, String> headers, int statusCode) {
this.body = body == null ? EMPTY_BYTES : Arrays.copyOf(body, body.length);
this.headers = headers;
this.headers = headers == null ? null : Collections.unmodifiableMap(headers);
this.statusCode = statusCode;
}

View File

@ -17,6 +17,7 @@ import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
@ -32,8 +33,7 @@ public final class BulkSubscribeAppResponse {
@JsonCreator
public BulkSubscribeAppResponse(
@JsonProperty("statuses") List<BulkSubscribeAppResponseEntry> statuses) {
this.statuses = new ArrayList<>();
this.statuses.addAll(statuses);
this.statuses = Collections.unmodifiableList(statuses);
}
public List<BulkSubscribeAppResponseEntry> getStatuses() {

View File

@ -27,7 +27,7 @@ public class GetBulkStateRequest {
private final List<String> keys;
private Map<String, String> metadata;
private Map<String, String> metadata = Collections.emptyMap();
private int parallelism = 1;

View File

@ -33,7 +33,7 @@ public class GetConfigurationRequest {
*/
public GetConfigurationRequest(String storeName, List<String> keys) {
this.storeName = storeName;
this.keys = keys == null ? Collections.EMPTY_LIST : Collections.unmodifiableList(keys);
this.keys = keys == null ? Collections.emptyList() : Collections.unmodifiableList(keys);
}
public GetConfigurationRequest setMetadata(Map<String, String> metadata) {

View File

@ -30,7 +30,7 @@ public class PublishEventRequest {
private String contentType;
private Map<String, String> metadata = new HashMap<>();
private Map<String, String> metadata = Collections.emptyMap();
/**
* Constructor for PublishEventRequest.

View File

@ -13,6 +13,7 @@ limitations under the License.
package io.dapr.client.domain;
import java.util.Collections;
import java.util.Map;
/**
@ -116,7 +117,7 @@ public class State<T> {
this.value = value;
this.key = key;
this.etag = etag;
this.metadata = metadata;
this.metadata = metadata == null ? null : Collections.unmodifiableMap(metadata);
this.options = options;
this.error = null;
}

View File

@ -33,7 +33,7 @@ public class SubscribeConfigurationRequest {
*/
public SubscribeConfigurationRequest(String storeName, List<String> keys) {
this.storeName = storeName;
this.keys = keys == null ? Collections.EMPTY_LIST : Collections.unmodifiableList(keys);
this.keys = keys == null ? Collections.emptyList() : Collections.unmodifiableList(keys);
}
public SubscribeConfigurationRequest setMetadata(Map<String, String> metadata) {

View File

@ -39,12 +39,12 @@ public class TransactionalStateRequest<T> {
* @param metadata Metadata used for transactional operations.
*/
public TransactionalStateRequest(List<TransactionalStateOperation<T>> operations, Map<String, String> metadata) {
this.operations = operations;
this.metadata = metadata;
this.operations = operations == null ? null : Collections.unmodifiableList(operations);
this.metadata = metadata == null ? null : Collections.unmodifiableMap(metadata);
}
public List<TransactionalStateOperation<T>> getOperations() {
return Collections.unmodifiableList(operations);
return operations;
}
public Map<String, String> getMetadata() {

View File

@ -13,11 +13,11 @@ limitations under the License.
package io.dapr.client;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import io.dapr.serializer.DaprObjectSerializer;
import io.dapr.serializer.DefaultObjectSerializer;

View File

@ -15,11 +15,11 @@ package io.dapr.client;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.dapr.client.domain.CloudEvent;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
public class CloudEventTest {

View File

@ -14,9 +14,11 @@ limitations under the License.
package io.dapr.client;
import io.dapr.serializer.DaprObjectSerializer;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -34,19 +36,19 @@ public class DaprClientBuilderTest {
assertNotNull(daprClient);
}
@Test(expected = IllegalArgumentException.class)
@Test
public void noObjectSerializer() {
new DaprClientBuilder().withObjectSerializer(null);
assertThrows(IllegalArgumentException.class, () -> { new DaprClientBuilder().withObjectSerializer(null);});
}
@Test(expected = IllegalArgumentException.class)
@Test
public void blankContentTypeInObjectSerializer() {
new DaprClientBuilder().withObjectSerializer(mock(DaprObjectSerializer.class));
assertThrows(IllegalArgumentException.class, () -> { new DaprClientBuilder().withObjectSerializer(mock(DaprObjectSerializer.class));});
}
@Test(expected = IllegalArgumentException.class)
@Test
public void noStateSerializer() {
new DaprClientBuilder().withStateSerializer(null);
assertThrows(IllegalArgumentException.class, () -> { new DaprClientBuilder().withStateSerializer(null);});
}
}

View File

@ -29,26 +29,26 @@ import io.grpc.ServerServiceDefinition;
import io.grpc.inprocess.InProcessChannelBuilder;
import io.grpc.inprocess.InProcessServerBuilder;
import io.grpc.testing.GrpcCleanupRule;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import reactor.core.publisher.Mono;
import reactor.util.context.Context;
import java.io.Closeable;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.stream.Stream;
import reactor.util.context.ContextView;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@RunWith(Parameterized.class)
@EnableRuleMigrationSupport
public class DaprClientGrpcTelemetryTest {
private static final Metadata.Key<byte[]> GRPC_TRACE_BIN_KEY = Metadata.Key.of(Headers.GRPC_TRACE_BIN,
@ -69,62 +69,42 @@ public class DaprClientGrpcTelemetryTest {
private DaprClient client;
@Parameterized.Parameter
public Scenario scenario;
@Parameterized.Parameters
public static Collection<Scenario[]> data() {
return Arrays.asList(new Scenario[][]{
{
new Scenario() {{
traceparent = "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01";
tracestate = "congo=ucfJifl5GOE,rojo=00f067aa0ba902b7";
expectGrpcTraceBin = true;
}}
},
{
new Scenario() {{
traceparent = null;
tracestate = null;
expectGrpcTraceBin = false;
}}
},
{
new Scenario() {{
traceparent = null;
tracestate = "congo=ucfJifl5GOE,rojo=00f067aa0ba902b7";
expectGrpcTraceBin = false;
}}
},
{
new Scenario() {{
traceparent = "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01";
tracestate = null;
expectGrpcTraceBin = true;
}},
},
{
new Scenario() {{
traceparent = "BAD FORMAT";
tracestate = null;
expectGrpcTraceBin = false;
}},
},
{
new Scenario() {{
traceparent = "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01";
tracestate = "INVALID";
expectGrpcTraceBin = false;
}},
},
{
null
}
});
public static Stream<Arguments> data() {
return Stream.of(
Arguments.of(
"00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01",
"congo=ucfJifl5GOE,rojo=00f067aa0ba902b7",
true
),
Arguments.of(
null,
null,
false
),
Arguments.of(
null,
"congo=ucfJifl5GOE,rojo=00f067aa0ba902b7",
false
),
Arguments.of(
"00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01",
null,
true
),
Arguments.of(
"BAD FORMAT",
null,
false
),
Arguments.of(
"00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01",
"INVALID",
false
)
);
}
@Before
public void setup() throws IOException {
public void setup(String traceparent, String tracestate, boolean expectGrpcTraceBin) throws IOException {
DaprGrpc.DaprImplBase daprImplBase = new DaprGrpc.DaprImplBase() {
public void invokeService(io.dapr.v1.DaprProtos.InvokeServiceRequest request,
@ -140,16 +120,10 @@ public class DaprClientGrpcTelemetryTest {
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> serverCall,
Metadata metadata,
ServerCallHandler<ReqT, RespT> serverCallHandler) {
if (scenario == null) {
assertNull(metadata.get(TRACEPARENT_KEY));
assertNull(metadata.get(TRACESTATE_KEY));
assertNull(metadata.get(GRPC_TRACE_BIN_KEY));
return serverCallHandler.startCall(serverCall, metadata);
}
assertEquals(scenario.traceparent, metadata.get(TRACEPARENT_KEY));
assertEquals(scenario.tracestate, metadata.get(TRACESTATE_KEY));
assertTrue((metadata.get(GRPC_TRACE_BIN_KEY) != null) == scenario.expectGrpcTraceBin);
assertEquals(traceparent, metadata.get(TRACEPARENT_KEY));
assertEquals(tracestate, metadata.get(TRACESTATE_KEY));
assertEquals((metadata.get(GRPC_TRACE_BIN_KEY) != null), expectGrpcTraceBin);
return serverCallHandler.startCall(serverCall, metadata);
}
});
@ -168,18 +142,75 @@ public class DaprClientGrpcTelemetryTest {
new GrpcChannelFacade(channel), asyncStub, new DefaultObjectSerializer(), new DefaultObjectSerializer());
}
public void setup() throws IOException {
DaprGrpc.DaprImplBase daprImplBase = new DaprGrpc.DaprImplBase() {
public void invokeService(io.dapr.v1.DaprProtos.InvokeServiceRequest request,
io.grpc.stub.StreamObserver<io.dapr.v1.CommonProtos.InvokeResponse> responseObserver) {
responseObserver.onNext(CommonProtos.InvokeResponse.getDefaultInstance());
responseObserver.onCompleted();
}
};
ServerServiceDefinition service = ServerInterceptors.intercept(daprImplBase, new ServerInterceptor() {
@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> serverCall,
Metadata metadata,
ServerCallHandler<ReqT, RespT> serverCallHandler) {
assertNull(metadata.get(TRACEPARENT_KEY));
assertNull(metadata.get(TRACESTATE_KEY));
assertNull(metadata.get(GRPC_TRACE_BIN_KEY));
return serverCallHandler.startCall(serverCall, metadata);
}
});
// Generate a unique in-process server name.
String serverName = InProcessServerBuilder.generateName();
// Create a server, add service, start, and register for automatic graceful shutdown.
grpcCleanup.register(InProcessServerBuilder.forName(serverName).directExecutor()
.addService(service)
.build().start());
// Create a client channel and register for automatic graceful shutdown.
ManagedChannel channel = InProcessChannelBuilder.forName(serverName).directExecutor().build();
DaprGrpc.DaprStub asyncStub = DaprGrpc.newStub(channel);
client = new DaprClientGrpc(
new GrpcChannelFacade(channel), asyncStub, new DefaultObjectSerializer(), new DefaultObjectSerializer());
}
@ParameterizedTest
@MethodSource("data")
public void invokeServiceVoidWithTracingTest(String traceparent, String tracestate, boolean expectGrpcTraceBin) throws IOException {
// setup server
setup(traceparent, tracestate, expectGrpcTraceBin);
Context context = Context.empty();
if (traceparent != null) {
context = context.put("traceparent", traceparent);
}
if (tracestate != null) {
context = context.put("tracestate", tracestate);
}
final Context contextCopy = context;
InvokeMethodRequest req = new InvokeMethodRequest("appId", "method")
.setBody("request")
.setHttpExtension(HttpExtension.NONE);
Mono<Void> result = this.client.invokeMethod(req, TypeRef.get(Void.class))
.contextWrite(it -> it.putAll(contextCopy));
result.block();
}
@Test
public void invokeServiceVoidWithTracingTest() {
public void invokeServiceVoidWithTracingTestAndEmptyContext() throws IOException {
// setup server
setup();
Context context = null;
if (scenario != null) {
context = Context.empty();
if (scenario.traceparent != null) {
context = context.put("traceparent", scenario.traceparent);
}
if (scenario.tracestate != null) {
context = context.put("tracestate", scenario.tracestate);
}
}
final Context contextCopy = context;
InvokeMethodRequest req = new InvokeMethodRequest("appId", "method")
.setBody("request")
@ -188,15 +219,4 @@ public class DaprClientGrpcTelemetryTest {
.contextWrite(it -> it.putAll(contextCopy == null ? (ContextView) Context.empty() : contextCopy));
result.block();
}
@After
public void tearDown() throws Exception {
client.close();
}
public static class Scenario {
public String traceparent;
public String tracestate;
public boolean expectGrpcTraceBin;
}
}

View File

@ -38,9 +38,9 @@ import io.dapr.v1.DaprProtos;
import io.grpc.Status;
import io.grpc.StatusRuntimeException;
import io.grpc.stub.StreamObserver;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.ArgumentMatcher;
import org.mockito.ArgumentMatchers;
@ -62,8 +62,14 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
import static io.dapr.utils.TestUtils.assertThrowsDaprException;
import static org.junit.Assert.*;
import static io.dapr.utils.TestUtils.findFreePort;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
@ -80,7 +86,7 @@ public class DaprClientGrpcTest {
private DaprClient client;
private ObjectSerializer serializer;
@Before
@BeforeEach
public void setup() throws IOException {
channel = mock(GrpcChannelFacade.class);
daprStub = mock(DaprGrpc.DaprStub.class);
@ -92,7 +98,7 @@ public class DaprClientGrpcTest {
doNothing().when(channel).close();
}
@After
@AfterEach
public void tearDown() throws Exception {
client.close();
verify(channel).close();
@ -583,7 +589,7 @@ public class DaprClientGrpcTest {
.build();
String expected = "Value";
doAnswer((Answer<Void>) invocation -> {
doAnswer(invocation -> {
StreamObserver<CommonProtos.InvokeResponse> observer = (StreamObserver<CommonProtos.InvokeResponse>) invocation.getArguments()[1];
observer.onNext(CommonProtos.InvokeResponse.newBuilder().setData(getAny(expected)).build());
observer.onCompleted();
@ -909,7 +915,7 @@ public class DaprClientGrpcTest {
String expectedValue = "Expected state";
State<String> expectedState = buildStateKey(expectedValue, key, etag, new HashMap<>(), null);
DaprProtos.GetStateResponse responseEnvelope = buildGetStateResponse(expectedValue, etag);
doAnswer((Answer<Void>) invocation -> {
doAnswer(invocation -> {
StreamObserver<DaprProtos.GetStateResponse> observer = (StreamObserver<DaprProtos.GetStateResponse>) invocation.getArguments()[1];
observer.onNext(responseEnvelope);
observer.onCompleted();
@ -2127,10 +2133,10 @@ public class DaprClientGrpcTest {
Map<String, ConfigurationItem> cis = client.getConfiguration(CONFIG_STORE_NAME, "configkey1","configkey2").block();
assertEquals(2, cis.size());
assertTrue("configkey1", cis.containsKey("configkey1"));
assertTrue(cis.containsKey("configkey1"), "configkey1");
assertEquals("configvalue1", cis.get("configkey1").getValue());
assertEquals("1", cis.get("configkey1").getVersion());
assertTrue("configkey2", cis.containsKey("configkey2"));
assertTrue(cis.containsKey("configkey2"), "configkey2");
assertEquals("configvalue2", cis.get("configkey2").getValue());
assertEquals("1", cis.get("configkey2").getVersion());
}
@ -2150,7 +2156,7 @@ public class DaprClientGrpcTest {
List<String> keys = Arrays.asList("configkey1","configkey2");
Map<String, ConfigurationItem> cis = client.getConfiguration(CONFIG_STORE_NAME, keys, reqMetadata).block();
assertEquals(2, cis.size());
assertTrue("configkey1", cis.containsKey("configkey1"));
assertTrue(cis.containsKey("configkey1"), "configkey1");
assertEquals("configvalue1", cis.get("configkey1").getValue());
}

View File

@ -41,8 +41,8 @@ import okhttp3.mock.MockInterceptor;
import okhttp3.mock.matchers.Matcher;
import okio.Buffer;
import okio.BufferedSink;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import reactor.core.publisher.Mono;
import reactor.util.context.Context;
@ -62,11 +62,11 @@ import reactor.util.context.ContextView;
import static io.dapr.utils.TestUtils.assertThrowsDaprException;
import static io.dapr.utils.TestUtils.findFreePort;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;
@ -91,7 +91,7 @@ public class DaprClientHttpTest {
private MockInterceptor mockInterceptor;
@Before
@BeforeEach
public void setUp() {
mockInterceptor = new MockInterceptor(Behavior.UNORDERED);
okHttpClient = new OkHttpClient.Builder().addInterceptor(mockInterceptor).build();

View File

@ -13,7 +13,7 @@ limitations under the License.
package io.dapr.client;
import io.dapr.client.domain.HttpExtension;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import reactor.core.publisher.Mono;

View File

@ -14,12 +14,12 @@ limitations under the License.
package io.dapr.client;
import okhttp3.OkHttpClient;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.lang.reflect.Field;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertSame;
public class DaprHttpBuilderTest {

View File

@ -14,17 +14,20 @@ package io.dapr.client;
import io.dapr.config.Properties;
import io.dapr.exceptions.DaprException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
import reactor.test.StepVerifier;
import reactor.util.context.Context;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.ResponseBody;
import okhttp3.mock.Behavior;
import okhttp3.mock.MockInterceptor;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.EnvironmentVariables;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import uk.org.webcompere.systemstubs.environment.EnvironmentVariables;
import uk.org.webcompere.systemstubs.jupiter.SystemStub;
import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension;
import java.io.IOException;
import java.util.Collections;
@ -32,14 +35,15 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;
@ExtendWith(SystemStubsExtension.class)
public class DaprHttpTest {
@Rule
@SystemStub
public final EnvironmentVariables environmentVariables = new EnvironmentVariables();
private static final String STATE_PATH = DaprHttp.API_VERSION + "/state";
@ -53,7 +57,7 @@ public class DaprHttpTest {
private ObjectSerializer serializer = new ObjectSerializer();
@Before
@BeforeEach
public void setUp() {
mockInterceptor = new MockInterceptor(Behavior.UNORDERED);
okHttpClient = new OkHttpClient.Builder().addInterceptor(mockInterceptor).build();
@ -164,7 +168,7 @@ public class DaprHttpTest {
assertEquals(EXPECTED_RESULT, body);
}
@Test(expected = RuntimeException.class)
@Test
public void invokePostMethodRuntime() throws IOException {
mockInterceptor.addRule()
.post("http://127.0.0.1:3500/v1.0/state")
@ -172,26 +176,21 @@ public class DaprHttpTest {
DaprHttp daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3500, okHttpClient);
Mono<DaprHttp.Response> mono =
daprHttp.invokeApi("POST", "v1.0/state".split("/"), null, null, Context.empty());
DaprHttp.Response response = mono.block();
String body = serializer.deserialize(response.getBody(), String.class);
assertEquals(EXPECTED_RESULT, body);
StepVerifier.create(mono).expectError(RuntimeException.class);
}
@Test(expected = RuntimeException.class)
@Test
public void invokePostDaprError() throws IOException {
mockInterceptor.addRule()
.post("http://127.0.0.1:3500/v1.0/state")
.respond(500, ResponseBody.create(MediaType.parse("text"),
"{\"errorCode\":null,\"message\":null}"));
DaprHttp daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3500, okHttpClient);
Mono<DaprHttp.Response> mono = daprHttp.invokeApi("POST", "v1.0/state".split("/"), null, null, Context.empty());
DaprHttp.Response response = mono.block();
String body = serializer.deserialize(response.getBody(), String.class);
assertEquals(EXPECTED_RESULT, body);
StepVerifier.create(mono).expectError(RuntimeException.class);
}
@Test(expected = RuntimeException.class)
@Test
public void invokePostMethodUnknownError() throws IOException {
mockInterceptor.addRule()
.post("http://127.0.0.1:3500/v1.0/state")
@ -199,9 +198,7 @@ public class DaprHttpTest {
"{\"errorCode\":\"null\",\"message\":\"null\"}"));
DaprHttp daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3500, okHttpClient);
Mono<DaprHttp.Response> mono = daprHttp.invokeApi("POST", "v1.0/state".split("/"), null, null, Context.empty());
DaprHttp.Response response = mono.block();
String body = serializer.deserialize(response.getBody(), String.class);
assertEquals(EXPECTED_RESULT, body);
StepVerifier.create(mono).expectError(RuntimeException.class);
}
/**

View File

@ -32,15 +32,14 @@ import io.dapr.v1.DaprProtos;
import io.grpc.Status;
import io.grpc.StatusRuntimeException;
import io.grpc.stub.StreamObserver;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers;
import org.mockito.stubbing.Answer;
import reactor.core.publisher.Mono;
import java.io.Closeable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
@ -50,8 +49,8 @@ import java.util.Map;
import java.util.concurrent.ExecutionException;
import static io.dapr.utils.TestUtils.assertThrowsDaprException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
@ -64,16 +63,20 @@ import static org.mockito.Mockito.when;
public class DaprPreviewClientGrpcTest {
private static final ObjectMapper MAPPER = new ObjectMapper();
private static final String QUERY_STORE_NAME = "testQueryStore";
private static final String PUBSUB_NAME = "testPubsub";
private static final String TOPIC_NAME = "testTopic";
private static final String LOCK_STORE_NAME = "MyLockStore";
private GrpcChannelFacade channel;
private DaprGrpc.DaprStub daprStub;
private DaprPreviewClient previewClient;
@Before
@BeforeEach
public void setup() throws IOException {
channel = mock(GrpcChannelFacade.class);
daprStub = mock(DaprGrpc.DaprStub.class);
@ -83,7 +86,7 @@ public class DaprPreviewClientGrpcTest {
doNothing().when(channel).close();
}
@After
@AfterEach
public void tearDown() throws Exception {
previewClient.close();
verify(channel).close();
@ -121,7 +124,7 @@ public class DaprPreviewClientGrpcTest {
Collections.EMPTY_LIST)).block());
}
@Test(expected = IllegalArgumentException.class)
@Test
public void publishEventsContentTypeMismatchException() throws IOException {
DaprObjectSerializer mockSerializer = mock(DaprObjectSerializer.class);
doAnswer((Answer<Void>) invocation -> {
@ -137,7 +140,8 @@ public class DaprPreviewClientGrpcTest {
, "application/octet-stream", null);
BulkPublishRequest<String> wrongReq = new BulkPublishRequest<>(PUBSUB_NAME, TOPIC_NAME,
Collections.singletonList(entry));
previewClient.publishEvents(wrongReq).block();
assertThrows(IllegalArgumentException.class, () -> previewClient.publishEvents(wrongReq).block());
}
@Test
@ -182,8 +186,8 @@ public class DaprPreviewClientGrpcTest {
Collections.singletonList(entry));
Mono<BulkPublishResponse<String>> result = previewClient.publishEvents(req);
BulkPublishResponse res = result.block();
Assert.assertNotNull(res);
assertEquals("expected no entry in failed entries list", 0, res.getFailedEntries().size());
Assertions.assertNotNull(res);
assertEquals( 0, res.getFailedEntries().size(), "expected no entry in failed entries list");
}
@Test
@ -200,8 +204,8 @@ public class DaprPreviewClientGrpcTest {
Mono<BulkPublishResponse<String>> result = previewClient.publishEvents(PUBSUB_NAME, TOPIC_NAME,
"text/plain", Collections.singletonList("test"));
BulkPublishResponse<String> res = result.block();
Assert.assertNotNull(res);
assertEquals("expected no entries in failed entries list", 0, res.getFailedEntries().size());
Assertions.assertNotNull(res);
assertEquals( 0, res.getFailedEntries().size(), "expected no entries in failed entries list");
}
@Test
@ -220,8 +224,8 @@ public class DaprPreviewClientGrpcTest {
put("ttlInSeconds", "123");
}}, Collections.singletonList("test"));
BulkPublishResponse<String> res = result.block();
Assert.assertNotNull(res);
assertEquals("expected no entry in failed entries list", 0, res.getFailedEntries().size());
Assertions.assertNotNull(res);
assertEquals( 0, res.getFailedEntries().size(), "expected no entry in failed entries list");
}
@Test
@ -252,8 +256,8 @@ public class DaprPreviewClientGrpcTest {
BulkPublishRequest<DaprClientGrpcTest.MyObject> req = new BulkPublishRequest<>(PUBSUB_NAME, TOPIC_NAME,
Collections.singletonList(entry));
BulkPublishResponse<DaprClientGrpcTest.MyObject> result = previewClient.publishEvents(req).block();
Assert.assertNotNull(result);
Assert.assertEquals("expected no entries to be failed", 0, result.getFailedEntries().size());
Assertions.assertNotNull(result);
Assertions.assertEquals(0, result.getFailedEntries().size(), "expected no entries to be failed");
}
@Test
@ -281,8 +285,8 @@ public class DaprPreviewClientGrpcTest {
BulkPublishRequest<String> req = new BulkPublishRequest<>(PUBSUB_NAME, TOPIC_NAME,
Collections.singletonList(entry));
BulkPublishResponse<String> result = previewClient.publishEvents(req).block();
Assert.assertNotNull(result);
Assert.assertEquals("expected no entries to be failed", 0, result.getFailedEntries().size());
Assertions.assertNotNull(result);
Assertions.assertEquals( 0, result.getFailedEntries().size(), "expected no entries to be failed");
}
@Test
@ -312,8 +316,8 @@ public class DaprPreviewClientGrpcTest {
List<QueryStateItem<?>> resp = new ArrayList<>();
resp.add(new QueryStateItem<Object>("1", (Object)"testData", "6f54ad94-dfb9-46f0-a371-e42d550adb7d"));
DaprProtos.QueryStateResponse responseEnvelope = buildQueryStateResponse(resp, "");
doAnswer((Answer<Void>) invocation -> {
DaprProtos.QueryStateRequest req = invocation.getArgument(0);
doAnswer(invocation -> {
DaprProtos.QueryStateRequest req = (DaprProtos.QueryStateRequest) invocation.getArgument(0);
assertEquals(QUERY_STORE_NAME, req.getStoreName());
assertEquals("query", req.getQuery());
assertEquals(0, req.getMetadataCount());
@ -327,10 +331,10 @@ public class DaprPreviewClientGrpcTest {
QueryStateResponse<String> response = previewClient.queryState(QUERY_STORE_NAME, "query", String.class).block();
assertNotNull(response);
assertEquals("result size must be 1", 1, response.getResults().size());
assertEquals("result must be same", "1", response.getResults().get(0).getKey());
assertEquals("result must be same", "testData", response.getResults().get(0).getValue());
assertEquals("result must be same", "6f54ad94-dfb9-46f0-a371-e42d550adb7d", response.getResults().get(0).getEtag());
assertEquals(1, response.getResults().size(), "result size must be 1");
assertEquals("1", response.getResults().get(0).getKey(), "result must be same");
assertEquals("testData", response.getResults().get(0).getValue(), "result must be same");
assertEquals("6f54ad94-dfb9-46f0-a371-e42d550adb7d", response.getResults().get(0).getEtag(), "result must be same");
}
@Test
@ -338,8 +342,8 @@ public class DaprPreviewClientGrpcTest {
List<QueryStateItem<?>> resp = new ArrayList<>();
resp.add(new QueryStateItem<Object>("1", null, "error data"));
DaprProtos.QueryStateResponse responseEnvelope = buildQueryStateResponse(resp, "");
doAnswer((Answer<Void>) invocation -> {
DaprProtos.QueryStateRequest req = invocation.getArgument(0);
doAnswer(invocation -> {
DaprProtos.QueryStateRequest req = (DaprProtos.QueryStateRequest) invocation.getArgument(0);
assertEquals(QUERY_STORE_NAME, req.getStoreName());
assertEquals("query", req.getQuery());
assertEquals(1, req.getMetadataCount());
@ -355,9 +359,9 @@ public class DaprPreviewClientGrpcTest {
QueryStateResponse<String> response = previewClient.queryState(QUERY_STORE_NAME, "query",
new HashMap<String, String>(){{ put("key", "error"); }}, String.class).block();
assertNotNull(response);
assertEquals("result size must be 1", 1, response.getResults().size());
assertEquals("result must be same", "1", response.getResults().get(0).getKey());
assertEquals("result must be same", "error data", response.getResults().get(0).getError());
assertEquals(1, response.getResults().size(), "result size must be 1");
assertEquals( "1", response.getResults().get(0).getKey(), "result must be same");
assertEquals( "error data", response.getResults().get(0).getError(), "result must be same");
}
@Test

View File

@ -24,13 +24,13 @@ import io.dapr.utils.TypeRef;
import okhttp3.OkHttpClient;
import okhttp3.mock.Behavior;
import okhttp3.mock.MockInterceptor;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class DaprPreviewClientHttpTest {
@ -45,7 +45,7 @@ public class DaprPreviewClientHttpTest {
private MockInterceptor mockInterceptor;
@Before
@BeforeEach
public void setUp() {
mockInterceptor = new MockInterceptor(Behavior.UNORDERED);
okHttpClient = new OkHttpClient.Builder().addInterceptor(mockInterceptor).build();
@ -99,10 +99,10 @@ public class DaprPreviewClientHttpTest {
+ "\"etag\": \"6f54ad94-dfb9-46f0-a371-e42d550adb7d\"}]}");
QueryStateResponse<String> response = daprPreviewClientHttp.queryState("testStore", "query", String.class).block();
assertNotNull(response);
assertEquals("result size must be 1", 1, response.getResults().size());
assertEquals("result must be same", "1", response.getResults().get(0).getKey());
assertEquals("result must be same", "testData", response.getResults().get(0).getValue());
assertEquals("result must be same", "6f54ad94-dfb9-46f0-a371-e42d550adb7d", response.getResults().get(0).getEtag());
assertEquals(1, response.getResults().size(), "result size must be 1");
assertEquals( "1", response.getResults().get(0).getKey(), "result must be same");
assertEquals("testData", response.getResults().get(0).getValue(), "result must be same");
assertEquals( "6f54ad94-dfb9-46f0-a371-e42d550adb7d", response.getResults().get(0).getEtag(), "result must be same");
}
@Test

View File

@ -13,8 +13,8 @@ limitations under the License.
package io.dapr.client.domain;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Collections;
@ -22,7 +22,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertNull;
public class BulkPublishRequestTest {
@ -38,6 +38,6 @@ public class BulkPublishRequestTest {
request.setMetadata(metadata);
Map<String, String> initial = request.getMetadata();
request.setMetadata(metadata);
Assert.assertNotSame("Should not be same map", request.getMetadata(), initial);
Assertions.assertNotSame( request.getMetadata(), initial, "Should not be same map");
}
}

View File

@ -1,13 +1,13 @@
package io.dapr.client.domain;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertNull;
public class DeleteStateRequestTest {
@ -26,6 +26,6 @@ public class DeleteStateRequestTest {
request.setMetadata(metadata);
Map<String, String> initial = request.getMetadata();
request.setMetadata(metadata);
Assert.assertNotSame("Should not be same map", request.getMetadata(), initial);
Assertions.assertNotSame(request.getMetadata(), initial, "Should not be same map");
}
}

View File

@ -1,14 +1,14 @@
package io.dapr.client.domain;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertNull;
public class ExecuteStateTransactionRequestTest {
@ -26,7 +26,7 @@ public class ExecuteStateTransactionRequestTest {
request.setMetadata(metadata);
Map<String, String> initial = request.getMetadata();
request.setMetadata(metadata);
assertNotSame("Should not be same map", request.getMetadata(), initial);
assertNotSame(request.getMetadata(), initial, "Should not be same map");
}
@Test
@ -41,6 +41,6 @@ public class ExecuteStateTransactionRequestTest {
request.setOperations(operations);
List<TransactionalStateOperation<?>> initial = request.getOperations();
request.setOperations(operations);
assertNotSame("Should not be same list", request.getOperations(), initial);
assertNotSame(request.getOperations(), initial, "Should not be same list");
}
}

View File

@ -1,12 +1,12 @@
package io.dapr.client.domain;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertNull;
public class GetBulkSecretRequestTest {
@ -24,6 +24,6 @@ public class GetBulkSecretRequestTest {
request.setMetadata(metadata);
Map<String, String> initial = request.getMetadata();
request.setMetadata(metadata);
assertNotSame("Should not be same map", request.getMetadata(), initial);
assertNotSame(request.getMetadata(), initial, "Should not be same map");
}
}

View File

@ -1,14 +1,17 @@
package io.dapr.client.domain;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class GetBulkStateRequestTest {
@ -32,7 +35,7 @@ public class GetBulkStateRequestTest {
request.setMetadata(metadata);
Map<String, String> initial = request.getMetadata();
request.setMetadata(metadata);
assertNotSame("Should not be same map", request.getMetadata(), initial);
assertNotSame(request.getMetadata(), initial, "Should not be same map");
// Var args constructor
request = new GetBulkStateRequest(STORE_NAME, "test var key");
@ -53,6 +56,6 @@ public class GetBulkStateRequestTest {
request.setMetadata(metadata);
initial = request.getMetadata();
request.setMetadata(metadata);
assertNotSame("Should not be same map", request.getMetadata(), initial);
assertNotSame( request.getMetadata(), initial, "Should not be same map");
}
}

View File

@ -1,15 +1,15 @@
package io.dapr.client.domain;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
public class GetSecretRequestTest {
@ -27,6 +27,6 @@ public class GetSecretRequestTest {
request.setMetadata(metadata);
Map<String, String> initial = request.getMetadata();
request.setMetadata(metadata);
assertNotSame("Should not be same map", request.getMetadata(), initial);
assertNotSame(request.getMetadata(), initial, "Should not be same map");
}
}

View File

@ -1,12 +1,12 @@
package io.dapr.client.domain;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertNull;
public class GetStateRequestTest {
@ -24,6 +24,6 @@ public class GetStateRequestTest {
request.setMetadata(metadata);
Map<String, String> initial = request.getMetadata();
request.setMetadata(metadata);
assertNotSame("Should not be same map", request.getMetadata(), initial);
assertNotSame(request.getMetadata(), initial, "Should not be same map");
}
}

View File

@ -1,12 +1,12 @@
package io.dapr.client.domain;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertNull;
public class InvokeBindingRequestTest {
@ -24,6 +24,6 @@ public class InvokeBindingRequestTest {
request.setMetadata(metadata);
Map<String, String> initial = request.getMetadata();
request.setMetadata(metadata);
assertNotSame("Should not be same map", request.getMetadata(), initial);
assertNotSame(request.getMetadata(), initial, "Should not be same map");
}
}

View File

@ -1,13 +1,13 @@
package io.dapr.client.domain;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertNull;
public class PublishEventRequestTest {
@ -27,6 +27,6 @@ public class PublishEventRequestTest {
request.setMetadata(metadata);
Map<String, String> initial = request.getMetadata();
request.setMetadata(metadata);
assertNotSame("Should not be same map", request.getMetadata(), initial);
assertNotSame(request.getMetadata(), initial, "Should not be same map");
}
}

View File

@ -2,13 +2,14 @@ package io.dapr.client.domain;
import io.dapr.client.domain.query.Query;
import io.dapr.client.domain.query.filters.EqFilter;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class QueryStateRequestTest {
@ -27,20 +28,20 @@ public class QueryStateRequestTest {
request.setMetadata(metadata);
Map<String, String> initial = request.getMetadata();
request.setMetadata(metadata);
Assert.assertNotSame("Should not be same map", request.getMetadata(), initial);
Assertions.assertNotSame(request.getMetadata(), initial, "Should not be same map");
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testSetNullQuery() {
QueryStateRequest request = new QueryStateRequest(STORE_NAME);
request.setQuery(null);
assertThrows(IllegalArgumentException.class, () -> request.setQuery(null));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testSetNullFilterQuery() {
QueryStateRequest request = new QueryStateRequest(STORE_NAME);
Query query = new Query();
request.setQuery(query);
assertThrows(IllegalArgumentException.class, () -> request.setQuery(query));
}
@Test
@ -49,6 +50,6 @@ public class QueryStateRequestTest {
Query query = new Query();
query.setFilter(new EqFilter<>("key", "value"));
request.setQuery(query);
Assert.assertEquals(query, request.getQuery());
Assertions.assertEquals(query, request.getQuery());
}
}

View File

@ -1,13 +1,13 @@
package io.dapr.client.domain;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertNull;
public class SaveStateRequestTest {
@ -24,11 +24,11 @@ public class SaveStateRequestTest {
request.setStates(states);
List<State<?>> initial = request.getStates();
request.setStates(states);
assertNotSame("Should not be same list", request.getStates(), initial);
assertNotSame( request.getStates(), initial, "Should not be same list");
// With var args method
request.setStates(new State<>("test var args 1"), new State<>("test var args 2"));
assertEquals("Value incorrectly set", "test var args 1", request.getStates().get(0).getKey());
assertEquals("Value incorrectly set", "test var args 2", request.getStates().get(1).getKey());
assertEquals("test var args 1", request.getStates().get(0).getKey(), "Value incorrectly set");
assertEquals("test var args 2", request.getStates().get(1).getKey(), "Value incorrectly set");
}
}

View File

@ -1,14 +1,14 @@
package io.dapr.client.domain;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
public class StateTest {

View File

@ -3,11 +3,13 @@ package io.dapr.client.domain.query;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.dapr.client.domain.query.filters.*;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class QueryTest {
ObjectMapper mapper = new ObjectMapper();
@ -35,7 +37,7 @@ public class QueryTest {
q.setPagination(new Pagination(10, "test-token"));
q.setSort(Arrays.asList(new Sorting("value.person.org", Sorting.Order.ASC),
new Sorting("value.state", Sorting.Order.DESC)));
Assert.assertEquals(json, mapper.writeValueAsString(q));
Assertions.assertEquals(json, mapper.writeValueAsString(q));
}
@ -44,61 +46,61 @@ public class QueryTest {
Query query = mapper.readValue(json, Query.class);
Assert.assertNotNull(query.getPagination());
Assert.assertNotNull(query.getFilter());
Assert.assertNotNull(query.getSort());
Assertions.assertNotNull(query.getPagination());
Assertions.assertNotNull(query.getFilter());
Assertions.assertNotNull(query.getSort());
// Assert Pagination
Assert.assertEquals(10, query.getPagination().getLimit());
Assert.assertEquals("test-token", query.getPagination().getToken());
Assertions.assertEquals(10, query.getPagination().getLimit());
Assertions.assertEquals("test-token", query.getPagination().getToken());
// Assert Sort
Assert.assertEquals(2, query.getSort().size());
Assert.assertEquals("value.person.org", query.getSort().get(0).getKey());
Assert.assertEquals(Sorting.Order.ASC, query.getSort().get(0).getOrder());
Assert.assertEquals("value.state", query.getSort().get(1).getKey());
Assert.assertEquals(Sorting.Order.DESC, query.getSort().get(1).getOrder());
Assertions.assertEquals(2, query.getSort().size());
Assertions.assertEquals("value.person.org", query.getSort().get(0).getKey());
Assertions.assertEquals(Sorting.Order.ASC, query.getSort().get(0).getOrder());
Assertions.assertEquals("value.state", query.getSort().get(1).getKey());
Assertions.assertEquals(Sorting.Order.DESC, query.getSort().get(1).getOrder());
// Assert Filter
// Top level AND filter
Assert.assertEquals("AND", query.getFilter().getName());
Assertions.assertEquals("AND", query.getFilter().getName());
// Type cast to AND filter
AndFilter filter = (AndFilter) query.getFilter();
// Assert 3 AND clauses
Assert.assertEquals(3, filter.getClauses().length);
Assertions.assertEquals(3, filter.getClauses().length);
Filter<?>[] andClauses = filter.getClauses();
// First EQ
Assert.assertEquals("EQ", andClauses[0].getName());
Assert.assertSame(EqFilter.class, andClauses[0].getClass());
Assertions.assertEquals("EQ", andClauses[0].getName());
Assertions.assertSame(EqFilter.class, andClauses[0].getClass());
EqFilter<?> eq = (EqFilter<?>) andClauses[0];
Assert.assertEquals("key", eq.getKey());
Assert.assertEquals("value", eq.getValue());
Assertions.assertEquals("key", eq.getKey());
Assertions.assertEquals("value", eq.getValue());
// Second IN
Assert.assertEquals("IN", andClauses[1].getName());
Assert.assertSame(InFilter.class, andClauses[1].getClass());
Assertions.assertEquals("IN", andClauses[1].getName());
Assertions.assertSame(InFilter.class, andClauses[1].getClass());
InFilter<?> in = (InFilter<?>) andClauses[1];
Assert.assertEquals("key2", in.getKey());
Assert.assertArrayEquals(new String[]{ "v1", "v2" }, in.getValues().toArray());
Assertions.assertEquals("key2", in.getKey());
Assertions.assertArrayEquals(new String[]{ "v1", "v2" }, in.getValues().toArray());
// Third OR
Assert.assertEquals("OR", andClauses[2].getName());
Assert.assertSame(OrFilter.class, andClauses[2].getClass());
Assertions.assertEquals("OR", andClauses[2].getName());
Assertions.assertSame(OrFilter.class, andClauses[2].getClass());
OrFilter orFilter = (OrFilter) andClauses[2];
Filter<?>[] orClauses = orFilter.getClauses();
// First EQ in OR
Assert.assertEquals("EQ", orClauses[0].getName());
Assert.assertSame(EqFilter.class, orClauses[0].getClass());
Assertions.assertEquals("EQ", orClauses[0].getName());
Assertions.assertSame(EqFilter.class, orClauses[0].getClass());
eq = (EqFilter<?>) orClauses[0];
Assert.assertEquals("v2", eq.getKey());
Assert.assertEquals(true, eq.getValue());
Assertions.assertEquals("v2", eq.getKey());
Assertions.assertEquals(true, eq.getValue());
// Second IN in OR
Assert.assertEquals("IN", orClauses[1].getName());
Assert.assertSame(InFilter.class, orClauses[1].getClass());
Assertions.assertEquals("IN", orClauses[1].getName());
Assertions.assertSame(InFilter.class, orClauses[1].getClass());
in = (InFilter<?>) orClauses[1];
Assert.assertEquals("v3", in.getKey());
Assert.assertArrayEquals(new Double[]{ 1.3, 1.5 }, in.getValues().toArray());
Assertions.assertEquals("v3", in.getKey());
Assertions.assertArrayEquals(new Double[]{ 1.3, 1.5 }, in.getValues().toArray());
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testQueryInValidFilter() throws JsonProcessingException {
Query q = new Query();
@ -113,6 +115,6 @@ public class QueryTest {
filter.addClause((Filter<?>) orFilter);
// Add Filter
q.setFilter(filter);
assertThrows(IllegalArgumentException.class, () -> q.setFilter(filter));
}
}

View File

@ -2,8 +2,8 @@ package io.dapr.client.domain.query.filters;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class AndFilterTest {
@ -18,7 +18,7 @@ public class AndFilterTest {
filter.addClause(new EqFilter<>("key", "value"));
filter.addClause(new InFilter<>("key2", "v1", "v2"));
Assert.assertEquals(json, MAPPER.writeValueAsString((Filter) filter));
Assertions.assertEquals(json, MAPPER.writeValueAsString((Filter) filter));
}
@Test
@ -26,34 +26,34 @@ public class AndFilterTest {
Filter<?> res = MAPPER.readValue(json, Filter.class);
// Check for AndFilter
Assert.assertEquals("AND", res.getName());
Assert.assertSame(AndFilter.class, res.getClass());
Assertions.assertEquals("AND", res.getName());
Assertions.assertSame(AndFilter.class, res.getClass());
AndFilter filter = (AndFilter) res;
// Check 2 clauses
Assert.assertEquals(2, filter.getClauses().length);
Assertions.assertEquals(2, filter.getClauses().length);
// First EQ
Assert.assertSame(EqFilter.class, filter.getClauses()[0].getClass());
Assertions.assertSame(EqFilter.class, filter.getClauses()[0].getClass());
EqFilter<?> eq = (EqFilter<?>) filter.getClauses()[0];
Assert.assertEquals("key", eq.getKey());
Assert.assertEquals("value", eq.getValue());
Assertions.assertEquals("key", eq.getKey());
Assertions.assertEquals("value", eq.getValue());
// Second IN
Assert.assertSame(InFilter.class, filter.getClauses()[1].getClass());
Assertions.assertSame(InFilter.class, filter.getClauses()[1].getClass());
InFilter<?> in = (InFilter<?>) filter.getClauses()[1];
Assert.assertEquals("key2", in.getKey());
Assert.assertArrayEquals(new String[]{ "v1", "v2" }, in.getValues().toArray());
Assertions.assertEquals("key2", in.getKey());
Assertions.assertArrayEquals(new String[]{ "v1", "v2" }, in.getValues().toArray());
}
@Test
public void testValidation() {
AndFilter filter = new AndFilter();
Assert.assertFalse(filter.isValid());
Assertions.assertFalse(filter.isValid());
filter.addClause(new EqFilter<>("key1", "v2"));
Assert.assertFalse(filter.isValid());
Assertions.assertFalse(filter.isValid());
filter.addClause(new EqFilter<>("key2", "v3"));
Assert.assertTrue(filter.isValid());
Assertions.assertTrue(filter.isValid());
}
}

View File

@ -2,8 +2,8 @@ package io.dapr.client.domain.query.filters;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class EqFilterTest {
private static final ObjectMapper MAPPER = new ObjectMapper();
@ -14,32 +14,32 @@ public class EqFilterTest {
public void testSerialization() throws JsonProcessingException {
EqFilter<?> filter = new EqFilter<>("key", 1.5);
Assert.assertEquals(json, MAPPER.writeValueAsString(filter));
Assertions.assertEquals(json, MAPPER.writeValueAsString(filter));
}
@Test
public void testDeserialization() throws JsonProcessingException {
EqFilter<?> filter = MAPPER.readValue(json, EqFilter.class);
Assert.assertEquals("key", filter.getKey());
Assert.assertEquals(1.5, filter.getValue());
Assertions.assertEquals("key", filter.getKey());
Assertions.assertEquals(1.5, filter.getValue());
}
@Test
public void testValidation() {
EqFilter<?> filter = new EqFilter<>(null, "val");
Assert.assertFalse(filter.isValid());
Assertions.assertFalse(filter.isValid());
filter = new EqFilter<>("", "");
Assert.assertFalse(filter.isValid());
Assertions.assertFalse(filter.isValid());
filter = new EqFilter<>("", true);
Assert.assertFalse(filter.isValid());
Assertions.assertFalse(filter.isValid());
filter = new EqFilter<>(" ", "valid");
Assert.assertFalse(filter.isValid());
Assertions.assertFalse(filter.isValid());
filter = new EqFilter<>("valid", "");
Assert.assertTrue(filter.isValid());
Assertions.assertTrue(filter.isValid());
}
}

View File

@ -2,8 +2,8 @@ package io.dapr.client.domain.query.filters;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class InFilterTest {
private static final ObjectMapper MAPPER = new ObjectMapper();
@ -14,35 +14,35 @@ public class InFilterTest {
public void testSerialization() throws JsonProcessingException {
InFilter<?> filter = new InFilter<>("key", 1.5, 44.0);
Assert.assertEquals(json, MAPPER.writeValueAsString(filter));
Assertions.assertEquals(json, MAPPER.writeValueAsString(filter));
}
@Test
public void testDeserialization() throws JsonProcessingException {
InFilter<?> filter = MAPPER.readValue(json, InFilter.class);
Assert.assertEquals("key", filter.getKey());
Assert.assertArrayEquals(new Double[]{ 1.5, 44.0 }, filter.getValues().toArray());
Assertions.assertEquals("key", filter.getKey());
Assertions.assertArrayEquals(new Double[]{ 1.5, 44.0 }, filter.getValues().toArray());
}
@Test
public void testValidation() {
InFilter<?> filter = new InFilter<>(null, "val");
Assert.assertFalse(filter.isValid());
Assertions.assertFalse(filter.isValid());
filter = new InFilter<>("", "");
Assert.assertFalse(filter.isValid());
Assertions.assertFalse(filter.isValid());
filter = new InFilter<>("", true);
Assert.assertFalse(filter.isValid());
Assertions.assertFalse(filter.isValid());
filter = new InFilter<>(" ", "valid");
Assert.assertFalse(filter.isValid());
Assertions.assertFalse(filter.isValid());
filter = new InFilter<>("valid", "");
Assert.assertTrue(filter.isValid());
Assertions.assertTrue(filter.isValid());
filter = new InFilter<>("valid", "1.5", "2.5");
Assert.assertTrue(filter.isValid());
Assertions.assertTrue(filter.isValid());
}
}

Some files were not shown because too many files have changed in this diff Show More