2121import io .a2a .server .events .EventQueueClosedException ;
2222import io .a2a .server .events .EventQueueItem ;
2323import io .a2a .server .events .EventQueueTestHelper ;
24+ import io .a2a .server .events .EventQueueUtil ;
25+ import io .a2a .server .events .MainEventBus ;
26+ import io .a2a .server .events .MainEventBusProcessor ;
2427import io .a2a .server .events .QueueClosedEvent ;
28+ import io .a2a .server .tasks .InMemoryTaskStore ;
29+ import io .a2a .server .tasks .PushNotificationSender ;
2530import io .a2a .spec .Event ;
2631import io .a2a .spec .StreamingEventKind ;
2732import io .a2a .spec .TaskState ;
@@ -35,10 +40,24 @@ class ReplicatedQueueManagerTest {
3540
3641 private ReplicatedQueueManager queueManager ;
3742 private StreamingEventKind testEvent ;
43+ private MainEventBus mainEventBus ;
44+ private MainEventBusProcessor mainEventBusProcessor ;
45+ private static final PushNotificationSender NOOP_PUSHNOTIFICATION_SENDER = task -> {};
3846
3947 @ BeforeEach
4048 void setUp () {
41- queueManager = new ReplicatedQueueManager (new NoOpReplicationStrategy (), new MockTaskStateProvider (true ));
49+ // Create MainEventBus and MainEventBusProcessor for tests
50+ InMemoryTaskStore taskStore = new InMemoryTaskStore ();
51+ mainEventBus = new MainEventBus ();
52+ mainEventBusProcessor = new MainEventBusProcessor (mainEventBus , taskStore , NOOP_PUSHNOTIFICATION_SENDER );
53+ EventQueueUtil .start (mainEventBusProcessor );
54+
55+ queueManager = new ReplicatedQueueManager (
56+ new NoOpReplicationStrategy (),
57+ new MockTaskStateProvider (true ),
58+ mainEventBus
59+ );
60+
4261 testEvent = new TaskStatusUpdateEvent .Builder ()
4362 .taskId ("test-task" )
4463 .contextId ("test-context" )
@@ -50,7 +69,7 @@ void setUp() {
5069 @ Test
5170 void testReplicationStrategyTriggeredOnNormalEnqueue () throws InterruptedException {
5271 CountingReplicationStrategy strategy = new CountingReplicationStrategy ();
53- queueManager = new ReplicatedQueueManager (strategy , new MockTaskStateProvider (true ));
72+ queueManager = new ReplicatedQueueManager (strategy , new MockTaskStateProvider (true ), mainEventBus );
5473
5574 String taskId = "test-task-1" ;
5675 EventQueue queue = queueManager .createOrTap (taskId );
@@ -65,7 +84,7 @@ void testReplicationStrategyTriggeredOnNormalEnqueue() throws InterruptedExcepti
6584 @ Test
6685 void testReplicationStrategyNotTriggeredOnReplicatedEvent () throws InterruptedException {
6786 CountingReplicationStrategy strategy = new CountingReplicationStrategy ();
68- queueManager = new ReplicatedQueueManager (strategy , new MockTaskStateProvider (true ));
87+ queueManager = new ReplicatedQueueManager (strategy , new MockTaskStateProvider (true ), mainEventBus );
6988
7089 String taskId = "test-task-2" ;
7190 EventQueue queue = queueManager .createOrTap (taskId );
@@ -79,7 +98,7 @@ void testReplicationStrategyNotTriggeredOnReplicatedEvent() throws InterruptedEx
7998 @ Test
8099 void testReplicationStrategyWithCountingImplementation () throws InterruptedException {
81100 CountingReplicationStrategy countingStrategy = new CountingReplicationStrategy ();
82- queueManager = new ReplicatedQueueManager (countingStrategy , new MockTaskStateProvider (true ));
101+ queueManager = new ReplicatedQueueManager (countingStrategy , new MockTaskStateProvider (true ), mainEventBus );
83102
84103 String taskId = "test-task-3" ;
85104 EventQueue queue = queueManager .createOrTap (taskId );
@@ -170,7 +189,7 @@ void testBasicQueueManagerFunctionality() throws InterruptedException {
170189 void testQueueToTaskIdMappingMaintained () throws InterruptedException {
171190 String taskId = "test-task-6" ;
172191 CountingReplicationStrategy countingStrategy = new CountingReplicationStrategy ();
173- queueManager = new ReplicatedQueueManager (countingStrategy , new MockTaskStateProvider (true ));
192+ queueManager = new ReplicatedQueueManager (countingStrategy , new MockTaskStateProvider (true ), mainEventBus );
174193
175194 EventQueue queue = queueManager .createOrTap (taskId );
176195 queue .enqueueEvent (testEvent );
@@ -217,7 +236,7 @@ void testReplicatedEventJsonSerialization() throws Exception {
217236 @ Test
218237 void testParallelReplicationBehavior () throws InterruptedException {
219238 CountingReplicationStrategy strategy = new CountingReplicationStrategy ();
220- queueManager = new ReplicatedQueueManager (strategy , new MockTaskStateProvider (true ));
239+ queueManager = new ReplicatedQueueManager (strategy , new MockTaskStateProvider (true ), mainEventBus );
221240
222241 String taskId = "parallel-test-task" ;
223242 EventQueue queue = queueManager .createOrTap (taskId );
@@ -297,7 +316,7 @@ void testParallelReplicationBehavior() throws InterruptedException {
297316 void testReplicatedEventSkippedWhenTaskInactive () throws InterruptedException {
298317 // Create a task state provider that returns false (task is inactive)
299318 MockTaskStateProvider stateProvider = new MockTaskStateProvider (false );
300- queueManager = new ReplicatedQueueManager (new CountingReplicationStrategy (), stateProvider );
319+ queueManager = new ReplicatedQueueManager (new CountingReplicationStrategy (), stateProvider , mainEventBus );
301320
302321 String taskId = "inactive-task" ;
303322
@@ -316,7 +335,7 @@ void testReplicatedEventSkippedWhenTaskInactive() throws InterruptedException {
316335 void testReplicatedEventProcessedWhenTaskActive () throws InterruptedException {
317336 // Create a task state provider that returns true (task is active)
318337 MockTaskStateProvider stateProvider = new MockTaskStateProvider (true );
319- queueManager = new ReplicatedQueueManager (new CountingReplicationStrategy (), stateProvider );
338+ queueManager = new ReplicatedQueueManager (new CountingReplicationStrategy (), stateProvider , mainEventBus );
320339
321340 String taskId = "active-task" ;
322341
@@ -347,7 +366,7 @@ void testReplicatedEventProcessedWhenTaskActive() throws InterruptedException {
347366 void testReplicatedEventToExistingQueueWhenTaskBecomesInactive () throws InterruptedException {
348367 // Create a task state provider that returns true initially
349368 MockTaskStateProvider stateProvider = new MockTaskStateProvider (true );
350- queueManager = new ReplicatedQueueManager (new CountingReplicationStrategy (), stateProvider );
369+ queueManager = new ReplicatedQueueManager (new CountingReplicationStrategy (), stateProvider , mainEventBus );
351370
352371 String taskId = "task-becomes-inactive" ;
353372
@@ -387,7 +406,7 @@ void testReplicatedEventToExistingQueueWhenTaskBecomesInactive() throws Interrup
387406 @ Test
388407 void testPoisonPillSentViaTransactionAwareEvent () throws InterruptedException {
389408 CountingReplicationStrategy strategy = new CountingReplicationStrategy ();
390- queueManager = new ReplicatedQueueManager (strategy , new MockTaskStateProvider (true ));
409+ queueManager = new ReplicatedQueueManager (strategy , new MockTaskStateProvider (true ), mainEventBus );
391410
392411 String taskId = "poison-pill-test" ;
393412 EventQueue queue = queueManager .createOrTap (taskId );
0 commit comments