Skip to content

Commit 48b2d44

Browse files
berndverstUbuntuartursouza
authored
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 <[email protected]>
1 parent fdbd084 commit 48b2d44

File tree

8 files changed

+57
-25
lines changed

8 files changed

+57
-25
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
<properties>
1616
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17-
<grpc.version>1.33.1</grpc.version>
17+
<grpc.version>1.39.0</grpc.version>
1818
<protobuf.version>3.13.0</protobuf.version>
1919
<dapr.proto.baseurl>https://raw.githubusercontent.com/dapr/dapr/v1.2.0-rc.3/dapr/proto</dapr.proto.baseurl>
2020
<os-maven-plugin.version>1.6.2</os-maven-plugin.version>

sdk-actors/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
<dependency>
7575
<groupId>io.grpc</groupId>
7676
<artifactId>grpc-testing</artifactId>
77+
<version>1.39.0</version>
7778
<scope>test</scope>
7879
</dependency>
7980
</dependencies>

sdk-actors/src/main/java/io/dapr/actors/runtime/ActorObjectSerializer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ public byte[] serialize(Object state) throws IOException {
5353
return super.serialize(state);
5454
}
5555

56-
5756
/**
5857
* Faster serialization for params of Actor's timer.
5958
*
@@ -136,6 +135,9 @@ private byte[] serialize(ActorRuntimeConfig config) throws IOException {
136135
if (config.getDrainBalancedActors() != null) {
137136
generator.writeBooleanField("drainBalancedActors", config.getDrainBalancedActors());
138137
}
138+
if (config.getRemindersStoragePartitions() != null) {
139+
generator.writeNumberField("remindersStoragePartitions", config.getRemindersStoragePartitions());
140+
}
139141
generator.writeEndObject();
140142
generator.close();
141143
writer.flush();
@@ -213,7 +215,7 @@ private ActorReminderParams deserializeActorReminder(byte[] value) throws IOExce
213215
private static Duration extractDurationOrNull(JsonNode node, String name) {
214216
JsonNode valueNode = node.get(name);
215217
if (valueNode == null) {
216-
return null;
218+
return null;
217219
}
218220

219221
return DurationUtils.convertDurationFromDaprFormat(valueNode.asText());

sdk-actors/src/main/java/io/dapr/actors/runtime/ActorRuntimeConfig.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public class ActorRuntimeConfig {
2626

2727
private volatile Boolean drainBalancedActors;
2828

29+
private volatile Integer remindersStoragePartitions;
30+
2931
/**
3032
* Instantiates a new config for the Actor Runtime.
3133
*/
@@ -34,6 +36,7 @@ public class ActorRuntimeConfig {
3436

3537
/**
3638
* Adds a registered actor to the list of registered actors.
39+
*
3740
* @param actorTypeName Actor type that was registered.
3841
* @return This instance.
3942
*/
@@ -135,4 +138,24 @@ public ActorRuntimeConfig setDrainBalancedActors(Boolean drainBalancedActors) {
135138
return this;
136139
}
137140

141+
/**
142+
* Gets the number of storage partitions for Actor reminders.
143+
*
144+
* @return The number of Actor reminder storage partitions.
145+
*/
146+
public Integer getRemindersStoragePartitions() {
147+
return remindersStoragePartitions;
148+
}
149+
150+
/**
151+
* Sets the number of storage partitions for Actor reminders.
152+
*
153+
* @param remindersStoragePartitions The number of storage partitions for Actor reminders.
154+
* @return This instance.
155+
*/
156+
public ActorRuntimeConfig setRemindersStoragePartitions(Integer remindersStoragePartitions) {
157+
this.remindersStoragePartitions = remindersStoragePartitions;
158+
return this;
159+
}
160+
138161
}

sdk-actors/src/test/java/io/dapr/actors/runtime/ActorRuntimeTest.java

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class ActorRuntimeTest {
2727

2828
public interface MyActor {
2929
String say();
30+
3031
int count();
3132
}
3233

@@ -93,14 +94,12 @@ public int count() {
9394

9495
@BeforeClass
9596
public static void beforeAll() throws Exception {
96-
constructor = (Constructor<ActorRuntime>) Arrays.stream(ActorRuntime.class.getDeclaredConstructors())
97-
.filter(c -> c.getParameters().length == 2)
98-
.map(c -> {
99-
c.setAccessible(true);
100-
return c;
101-
})
102-
.findFirst()
103-
.get();
97+
constructor =
98+
(Constructor<ActorRuntime>) Arrays.stream(ActorRuntime.class.getDeclaredConstructors())
99+
.filter(c -> c.getParameters().length == 2).map(c -> {
100+
c.setAccessible(true);
101+
return c;
102+
}).findFirst().get();
104103
}
105104

106105
@Before
@@ -116,17 +115,20 @@ public void registerActorNullClass() {
116115

117116
@Test(expected = IllegalArgumentException.class)
118117
public void registerActorNullFactory() {
119-
this.runtime.registerActor(MyActorImpl.class, null, new DefaultObjectSerializer(), new DefaultObjectSerializer());
118+
this.runtime.registerActor(MyActorImpl.class, null, new DefaultObjectSerializer(),
119+
new DefaultObjectSerializer());
120120
}
121121

122122
@Test(expected = IllegalArgumentException.class)
123123
public void registerActorNullSerializer() {
124-
this.runtime.registerActor(MyActorImpl.class, new DefaultActorFactory<>(), null, new DefaultObjectSerializer());
124+
this.runtime.registerActor(MyActorImpl.class, new DefaultActorFactory<>(), null,
125+
new DefaultObjectSerializer());
125126
}
126127

127128
@Test(expected = IllegalArgumentException.class)
128129
public void registerActorNullStateSerializer() {
129-
this.runtime.registerActor(MyActorImpl.class, new DefaultActorFactory<>(), new DefaultObjectSerializer(), null);
130+
this.runtime.registerActor(MyActorImpl.class, new DefaultActorFactory<>(),
131+
new DefaultObjectSerializer(), null);
130132
}
131133

132134
@Test
@@ -157,6 +159,13 @@ public void setDrainOngoingCallTimeout() throws Exception {
157159
new String(this.runtime.serializeConfig()));
158160
}
159161

162+
@Test
163+
public void setRemindersStoragePartitions() throws Exception {
164+
this.runtime.getConfig().setRemindersStoragePartitions(12);
165+
Assert.assertEquals("{\"entities\":[],\"remindersStoragePartitions\":12}",
166+
new String(this.runtime.serializeConfig()));
167+
}
168+
160169
@Test
161170
public void invokeActor() throws Exception {
162171
String actorId = UUID.randomUUID().toString();
@@ -194,10 +203,8 @@ public void lazyDeactivate() throws Exception {
194203
deactivateCall.block();
195204

196205
this.runtime.invoke(ACTOR_NAME, actorId, "say", null)
197-
.doOnError(e -> Assert.assertTrue(e.getMessage().contains("Could not find actor")))
198-
.doOnSuccess(s -> Assert.fail())
199-
.onErrorReturn("".getBytes())
200-
.block();
206+
.doOnError(e -> Assert.assertTrue(e.getMessage().contains("Could not find actor")))
207+
.doOnSuccess(s -> Assert.fail()).onErrorReturn("".getBytes()).block();
201208
}
202209

203210
@Test

sdk-autogen/pom.xml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,25 @@
3232
<dependency>
3333
<groupId>io.grpc</groupId>
3434
<artifactId>grpc-netty-shaded</artifactId>
35+
<version>1.39.0</version>
3536
<scope>runtime</scope>
3637
</dependency>
3738
<dependency>
3839
<groupId>io.grpc</groupId>
3940
<artifactId>grpc-protobuf</artifactId>
41+
<version>1.39.0</version>
4042
</dependency>
4143
<dependency>
4244
<groupId>io.grpc</groupId>
4345
<artifactId>grpc-stub</artifactId>
46+
<version>1.39.0</version>
4447
</dependency>
4548
<dependency>
4649
<groupId>io.grpc</groupId>
4750
<artifactId>grpc-testing</artifactId>
51+
<version>1.39.0</version>
4852
<scope>test</scope>
4953
</dependency>
50-
<dependency>
51-
<groupId>io.grpc</groupId>
52-
<artifactId>grpc-stub</artifactId>
53-
<version>1.33.1</version>
54-
</dependency>
5554
</dependencies>
5655

5756
<build>

sdk-tests/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<dapr.sdk.version>1.2.0-SNAPSHOT</dapr.sdk.version>
2929
<protobuf.output.directory>${project.build.directory}/generated-sources</protobuf.output.directory>
3030
<protobuf.input.directory>${project.basedir}/proto</protobuf.input.directory>
31-
<grpc.version>1.33.1</grpc.version>
31+
<grpc.version>1.39.0</grpc.version>
3232
<protobuf.version>3.13.0</protobuf.version>
3333
<opentelemetry.version>0.14.0</opentelemetry.version>
3434
</properties>

sdk/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
<dependency>
108108
<groupId>io.grpc</groupId>
109109
<artifactId>grpc-testing</artifactId>
110-
<version>1.33.1</version>
110+
<version>1.39.0</version>
111111
<scope>test</scope>
112112
</dependency>
113113
</dependencies>

0 commit comments

Comments
 (0)