Add support for configuring actor reminder storage partitions (#574)

* Update GRPC libraries for security updates

* AdConfigurable actor reminder storage patitions

* autoformat code

* Fix test and linter error

* more autoformatting

* competing style checker :(

Co-authored-by: Ubuntu <beverst@beverst-ubuntu.4gvshbv0hrpejbsei5kugsxnoc.xx.internal.cloudapp.net>
Co-authored-by: Artur Souza <artursouza.ms@outlook.com>
This commit is contained in:
Bernd Verst 2021-07-12 16:02:25 -07:00 committed by GitHub
parent fdbd084fd4
commit 48b2d44aa7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 57 additions and 25 deletions

View File

@ -14,7 +14,7 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<grpc.version>1.33.1</grpc.version> <grpc.version>1.39.0</grpc.version>
<protobuf.version>3.13.0</protobuf.version> <protobuf.version>3.13.0</protobuf.version>
<dapr.proto.baseurl>https://raw.githubusercontent.com/dapr/dapr/v1.2.0-rc.3/dapr/proto</dapr.proto.baseurl> <dapr.proto.baseurl>https://raw.githubusercontent.com/dapr/dapr/v1.2.0-rc.3/dapr/proto</dapr.proto.baseurl>
<os-maven-plugin.version>1.6.2</os-maven-plugin.version> <os-maven-plugin.version>1.6.2</os-maven-plugin.version>

View File

@ -74,6 +74,7 @@
<dependency> <dependency>
<groupId>io.grpc</groupId> <groupId>io.grpc</groupId>
<artifactId>grpc-testing</artifactId> <artifactId>grpc-testing</artifactId>
<version>1.39.0</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -53,7 +53,6 @@ public class ActorObjectSerializer extends ObjectSerializer {
return super.serialize(state); return super.serialize(state);
} }
/** /**
* Faster serialization for params of Actor's timer. * Faster serialization for params of Actor's timer.
* *
@ -136,6 +135,9 @@ public class ActorObjectSerializer extends ObjectSerializer {
if (config.getDrainBalancedActors() != null) { if (config.getDrainBalancedActors() != null) {
generator.writeBooleanField("drainBalancedActors", config.getDrainBalancedActors()); generator.writeBooleanField("drainBalancedActors", config.getDrainBalancedActors());
} }
if (config.getRemindersStoragePartitions() != null) {
generator.writeNumberField("remindersStoragePartitions", config.getRemindersStoragePartitions());
}
generator.writeEndObject(); generator.writeEndObject();
generator.close(); generator.close();
writer.flush(); writer.flush();
@ -213,7 +215,7 @@ public class ActorObjectSerializer extends ObjectSerializer {
private static Duration extractDurationOrNull(JsonNode node, String name) { private static Duration extractDurationOrNull(JsonNode node, String name) {
JsonNode valueNode = node.get(name); JsonNode valueNode = node.get(name);
if (valueNode == null) { if (valueNode == null) {
return null; return null;
} }
return DurationUtils.convertDurationFromDaprFormat(valueNode.asText()); return DurationUtils.convertDurationFromDaprFormat(valueNode.asText());

View File

@ -26,6 +26,8 @@ public class ActorRuntimeConfig {
private volatile Boolean drainBalancedActors; private volatile Boolean drainBalancedActors;
private volatile Integer remindersStoragePartitions;
/** /**
* Instantiates a new config for the Actor Runtime. * Instantiates a new config for the Actor Runtime.
*/ */
@ -34,6 +36,7 @@ public class ActorRuntimeConfig {
/** /**
* Adds a registered actor to the list of registered actors. * Adds a registered actor to the list of registered actors.
*
* @param actorTypeName Actor type that was registered. * @param actorTypeName Actor type that was registered.
* @return This instance. * @return This instance.
*/ */
@ -135,4 +138,24 @@ public class ActorRuntimeConfig {
return this; return this;
} }
/**
* Gets the number of storage partitions for Actor reminders.
*
* @return The number of Actor reminder storage partitions.
*/
public Integer getRemindersStoragePartitions() {
return remindersStoragePartitions;
}
/**
* Sets the number of storage partitions for Actor reminders.
*
* @param remindersStoragePartitions The number of storage partitions for Actor reminders.
* @return This instance.
*/
public ActorRuntimeConfig setRemindersStoragePartitions(Integer remindersStoragePartitions) {
this.remindersStoragePartitions = remindersStoragePartitions;
return this;
}
} }

View File

@ -27,6 +27,7 @@ public class ActorRuntimeTest {
public interface MyActor { public interface MyActor {
String say(); String say();
int count(); int count();
} }
@ -93,14 +94,12 @@ public class ActorRuntimeTest {
@BeforeClass @BeforeClass
public static void beforeAll() throws Exception { public static void beforeAll() throws Exception {
constructor = (Constructor<ActorRuntime>) Arrays.stream(ActorRuntime.class.getDeclaredConstructors()) constructor =
.filter(c -> c.getParameters().length == 2) (Constructor<ActorRuntime>) Arrays.stream(ActorRuntime.class.getDeclaredConstructors())
.map(c -> { .filter(c -> c.getParameters().length == 2).map(c -> {
c.setAccessible(true); c.setAccessible(true);
return c; return c;
}) }).findFirst().get();
.findFirst()
.get();
} }
@Before @Before
@ -116,17 +115,20 @@ public class ActorRuntimeTest {
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void registerActorNullFactory() { public void registerActorNullFactory() {
this.runtime.registerActor(MyActorImpl.class, null, new DefaultObjectSerializer(), new DefaultObjectSerializer()); this.runtime.registerActor(MyActorImpl.class, null, new DefaultObjectSerializer(),
new DefaultObjectSerializer());
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void registerActorNullSerializer() { public void registerActorNullSerializer() {
this.runtime.registerActor(MyActorImpl.class, new DefaultActorFactory<>(), null, new DefaultObjectSerializer()); this.runtime.registerActor(MyActorImpl.class, new DefaultActorFactory<>(), null,
new DefaultObjectSerializer());
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void registerActorNullStateSerializer() { public void registerActorNullStateSerializer() {
this.runtime.registerActor(MyActorImpl.class, new DefaultActorFactory<>(), new DefaultObjectSerializer(), null); this.runtime.registerActor(MyActorImpl.class, new DefaultActorFactory<>(),
new DefaultObjectSerializer(), null);
} }
@Test @Test
@ -157,6 +159,13 @@ public class ActorRuntimeTest {
new String(this.runtime.serializeConfig())); new String(this.runtime.serializeConfig()));
} }
@Test
public void setRemindersStoragePartitions() throws Exception {
this.runtime.getConfig().setRemindersStoragePartitions(12);
Assert.assertEquals("{\"entities\":[],\"remindersStoragePartitions\":12}",
new String(this.runtime.serializeConfig()));
}
@Test @Test
public void invokeActor() throws Exception { public void invokeActor() throws Exception {
String actorId = UUID.randomUUID().toString(); String actorId = UUID.randomUUID().toString();
@ -194,10 +203,8 @@ public class ActorRuntimeTest {
deactivateCall.block(); deactivateCall.block();
this.runtime.invoke(ACTOR_NAME, actorId, "say", null) this.runtime.invoke(ACTOR_NAME, actorId, "say", null)
.doOnError(e -> Assert.assertTrue(e.getMessage().contains("Could not find actor"))) .doOnError(e -> Assert.assertTrue(e.getMessage().contains("Could not find actor")))
.doOnSuccess(s -> Assert.fail()) .doOnSuccess(s -> Assert.fail()).onErrorReturn("".getBytes()).block();
.onErrorReturn("".getBytes())
.block();
} }
@Test @Test

View File

@ -32,26 +32,25 @@
<dependency> <dependency>
<groupId>io.grpc</groupId> <groupId>io.grpc</groupId>
<artifactId>grpc-netty-shaded</artifactId> <artifactId>grpc-netty-shaded</artifactId>
<version>1.39.0</version>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>io.grpc</groupId> <groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</artifactId> <artifactId>grpc-protobuf</artifactId>
<version>1.39.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>io.grpc</groupId> <groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId> <artifactId>grpc-stub</artifactId>
<version>1.39.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>io.grpc</groupId> <groupId>io.grpc</groupId>
<artifactId>grpc-testing</artifactId> <artifactId>grpc-testing</artifactId>
<version>1.39.0</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>
<version>1.33.1</version>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -28,7 +28,7 @@
<dapr.sdk.version>1.2.0-SNAPSHOT</dapr.sdk.version> <dapr.sdk.version>1.2.0-SNAPSHOT</dapr.sdk.version>
<protobuf.output.directory>${project.build.directory}/generated-sources</protobuf.output.directory> <protobuf.output.directory>${project.build.directory}/generated-sources</protobuf.output.directory>
<protobuf.input.directory>${project.basedir}/proto</protobuf.input.directory> <protobuf.input.directory>${project.basedir}/proto</protobuf.input.directory>
<grpc.version>1.33.1</grpc.version> <grpc.version>1.39.0</grpc.version>
<protobuf.version>3.13.0</protobuf.version> <protobuf.version>3.13.0</protobuf.version>
<opentelemetry.version>0.14.0</opentelemetry.version> <opentelemetry.version>0.14.0</opentelemetry.version>
</properties> </properties>

View File

@ -107,7 +107,7 @@
<dependency> <dependency>
<groupId>io.grpc</groupId> <groupId>io.grpc</groupId>
<artifactId>grpc-testing</artifactId> <artifactId>grpc-testing</artifactId>
<version>1.33.1</version> <version>1.39.0</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>