Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public ListTaskPushNotificationConfigsResult getInfo(ListTaskPushNotificationCon
return new ListTaskPushNotificationConfigsResult(Collections.emptyList());
}
if (params.pageSize() <= 0) {
return new ListTaskPushNotificationConfigsResult(new ArrayList<>(configs), null);
return new ListTaskPushNotificationConfigsResult(configs, null);
}
if (params.pageToken() != null && !params.pageToken().isBlank()) {
int index = findFirstIndex(configs, params.pageToken());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import static org.mockito.Mockito.when;

import java.util.List;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.atomic.AtomicInteger;

import org.a2aproject.sdk.client.http.A2AHttpClient;
import org.a2aproject.sdk.client.http.A2AHttpResponse;
Expand Down Expand Up @@ -692,6 +695,52 @@ public void testSetInfoRejectsExceedingPerTaskLimit() {
assertTrue(result.configs().stream().noneMatch(c -> "cfg-overflow".equals(c.id())));
}

@Test
public void testConcurrentSetInfoAtLimitOnlyOneSucceeds() throws InterruptedException {
String taskId = "task_concurrent_limit";
int limit = InMemoryPushNotificationConfigStore.MAX_PUSH_CONFIGS_PER_TASK;

// Fill to limit - 1, leaving exactly one slot open
for (int i = 0; i < limit - 1; i++) {
configStore.setInfo(createSamplePushConfig(taskId,
"http://url" + i + ".com/callback", "cfg" + i, null));
}

CyclicBarrier barrier = new CyclicBarrier(2);
AtomicInteger successCount = new AtomicInteger(0);
AtomicInteger errorCount = new AtomicInteger(0);

Runnable contestant = () -> {
try {
barrier.await();
} catch (InterruptedException | BrokenBarrierException e) {
Thread.currentThread().interrupt();
return;
}
try {
configStore.setInfo(createSamplePushConfig(taskId,
"http://concurrent.com/callback",
"cfg-concurrent-" + Thread.currentThread().getId(), null));
successCount.incrementAndGet();
} catch (InvalidParamsError e) {
errorCount.incrementAndGet();
}
};

Thread t1 = new Thread(contestant);
Thread t2 = new Thread(contestant);
t1.start();
t2.start();
t1.join();
t2.join();

assertEquals(1, successCount.get(), "Exactly one thread should succeed");
assertEquals(1, errorCount.get(), "Exactly one thread should be rejected");

ListTaskPushNotificationConfigsResult result = configStore.getInfo(new ListTaskPushNotificationConfigsParams(taskId));
assertEquals(limit, result.configs().size(), "Store must be at exactly the limit after the race");
}

@Test
public void testSetInfoUpdateExistingConfigAtLimitAllowed() {
String taskId = "task_limit_update";
Expand Down
Loading