Skip to content

Commit 14e12f9

Browse files
committed
fix: Constants to the confg properties
This came up in a Gemini review on the backport to 0.3.x
1 parent bfdee13 commit 14e12f9

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

extras/task-store-database-jpa/src/main/java/io/a2a/extras/taskstore/database/jpa/JpaDatabaseTaskStore.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
public class JpaDatabaseTaskStore implements TaskStore, TaskStateProvider {
3838

3939
private static final Logger LOGGER = LoggerFactory.getLogger(JpaDatabaseTaskStore.class);
40+
private static final String A2A_REPLICATION_GRACE_PERIOD_SECONDS = "a2a.replication.grace-period-seconds";
4041

4142
@PersistenceContext(unitName = "a2a-java")
4243
EntityManager em;
@@ -60,7 +61,7 @@ public class JpaDatabaseTaskStore implements TaskStore, TaskStateProvider {
6061

6162
@PostConstruct
6263
void initConfig() {
63-
gracePeriodSeconds = Long.parseLong(configProvider.getValue("a2a.replication.grace-period-seconds"));
64+
gracePeriodSeconds = Long.parseLong(configProvider.getValue(A2A_REPLICATION_GRACE_PERIOD_SECONDS));
6465
}
6566

6667
@Transactional

integrations/microprofile-config/src/test/java/io/a2a/integrations/microprofile/MicroProfileConfigProviderTest.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.a2a.integrations.microprofile;
22

33
import io.a2a.server.config.A2AConfigProvider;
4+
import io.a2a.server.util.async.AsyncExecutorProducer;
45
import io.quarkus.test.junit.QuarkusTest;
56
import jakarta.inject.Inject;
67
import org.junit.jupiter.api.Test;
@@ -16,6 +17,10 @@
1617
@QuarkusTest
1718
public class MicroProfileConfigProviderTest {
1819

20+
private static final String A2A_EXECUTOR_CORE_POOL_SIZE = "a2a.executor.core-pool-size";
21+
private static final String A2A_EXECUTOR_MAX_POOL_SIZE = "a2a.executor.max-pool-size";
22+
private static final String A2A_EXECUTOR_KEEP_ALIVE_SECONDS = "a2a.executor.keep-alive-seconds";
23+
1924
@Inject
2025
A2AConfigProvider configProvider;
2126

@@ -31,37 +36,37 @@ public void testIsMicroProfileConfigProvider() {
3136
public void testGetValueFromMicroProfileConfig() {
3237
// Test that values from application.properties override defaults
3338
// The test application.properties sets a2a.executor.core-pool-size=15
34-
String value = configProvider.getValue("a2a.executor.core-pool-size");
39+
String value = configProvider.getValue(A2A_EXECUTOR_CORE_POOL_SIZE);
3540
assertEquals("15", value, "Should get value from MicroProfile Config (application.properties)");
3641
}
3742

3843
@Test
3944
public void testGetValueFallbackToDefaults() {
4045
// Test that values not in application.properties fall back to META-INF/a2a-defaults.properties
4146
// a2a.executor.max-pool-size is not in test application.properties, so should use default
42-
String value = configProvider.getValue("a2a.executor.max-pool-size");
47+
String value = configProvider.getValue(A2A_EXECUTOR_MAX_POOL_SIZE);
4348
assertEquals("50", value, "Should fall back to default value from META-INF/a2a-defaults.properties");
4449
}
4550

4651
@Test
4752
public void testGetValueAnotherDefault() {
4853
// Test another default property to ensure fallback works
49-
String value = configProvider.getValue("a2a.executor.keep-alive-seconds");
54+
String value = configProvider.getValue(A2A_EXECUTOR_KEEP_ALIVE_SECONDS);
5055
assertEquals("60", value, "Should fall back to default value");
5156
}
5257

5358
@Test
5459
public void testGetOptionalValueFromMicroProfileConfig() {
5560
// Test optional value that exists in application.properties
56-
Optional<String> value = configProvider.getOptionalValue("a2a.executor.core-pool-size");
61+
Optional<String> value = configProvider.getOptionalValue(A2A_EXECUTOR_CORE_POOL_SIZE);
5762
assertTrue(value.isPresent(), "Optional value should be present");
5863
assertEquals("15", value.get(), "Should get overridden value from MicroProfile Config");
5964
}
6065

6166
@Test
6267
public void testGetOptionalValueFallbackToDefaults() {
6368
// Test optional value that falls back to defaults
64-
Optional<String> value = configProvider.getOptionalValue("a2a.executor.max-pool-size");
69+
Optional<String> value = configProvider.getOptionalValue(A2A_EXECUTOR_MAX_POOL_SIZE);
6570
assertTrue(value.isPresent(), "Optional value should be present from defaults");
6671
assertEquals("50", value.get(), "Should get default value");
6772
}

server-common/src/main/java/io/a2a/server/requesthandlers/DefaultRequestHandler.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ public class DefaultRequestHandler implements RequestHandler {
7373

7474
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultRequestHandler.class);
7575

76+
private static final String A2A_BLOCKING_AGENT_TIMEOUT_SECONDS = "a2a.blocking.agent.timeout.seconds";
77+
private static final String A2A_BLOCKING_CONSUMPTION_TIMEOUT_SECONDS = "a2a.blocking.consumption.timeout.seconds";
78+
7679
@Inject
7780
A2AConfigProvider configProvider;
7881

@@ -130,9 +133,9 @@ public DefaultRequestHandler(AgentExecutor agentExecutor, TaskStore taskStore,
130133
@PostConstruct
131134
void initConfig() {
132135
agentCompletionTimeoutSeconds = Integer.parseInt(
133-
configProvider.getValue("a2a.blocking.agent.timeout.seconds"));
136+
configProvider.getValue(A2A_BLOCKING_AGENT_TIMEOUT_SECONDS));
134137
consumptionCompletionTimeoutSeconds = Integer.parseInt(
135-
configProvider.getValue("a2a.blocking.consumption.timeout.seconds"));
138+
configProvider.getValue(A2A_BLOCKING_CONSUMPTION_TIMEOUT_SECONDS));
136139
}
137140

138141
/**

server-common/src/main/java/io/a2a/server/util/async/AsyncExecutorProducer.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
public class AsyncExecutorProducer {
2323

2424
private static final Logger LOGGER = LoggerFactory.getLogger(AsyncExecutorProducer.class);
25+
private static final String A2A_EXECUTOR_CORE_POOL_SIZE = "a2a.executor.core-pool-size";
26+
private static final String A2A_EXECUTOR_MAX_POOL_SIZE = "a2a.executor.max-pool-size";
27+
private static final String A2A_EXECUTOR_KEEP_ALIVE_SECONDS = "a2a.executor.keep-alive-seconds";
2528

2629
@Inject
2730
A2AConfigProvider configProvider;
@@ -57,9 +60,9 @@ public class AsyncExecutorProducer {
5760

5861
@PostConstruct
5962
public void init() {
60-
corePoolSize = Integer.parseInt(configProvider.getValue("a2a.executor.core-pool-size"));
61-
maxPoolSize = Integer.parseInt(configProvider.getValue("a2a.executor.max-pool-size"));
62-
keepAliveSeconds = Long.parseLong(configProvider.getValue("a2a.executor.keep-alive-seconds"));
63+
corePoolSize = Integer.parseInt(configProvider.getValue(A2A_EXECUTOR_CORE_POOL_SIZE));
64+
maxPoolSize = Integer.parseInt(configProvider.getValue(A2A_EXECUTOR_MAX_POOL_SIZE));
65+
keepAliveSeconds = Long.parseLong(configProvider.getValue(A2A_EXECUTOR_KEEP_ALIVE_SECONDS));
6366

6467
LOGGER.info("Initializing async executor: corePoolSize={}, maxPoolSize={}, keepAliveSeconds={}",
6568
corePoolSize, maxPoolSize, keepAliveSeconds);

0 commit comments

Comments
 (0)