Search in sources :

Example 1 with TaskEventHandler

use of org.apache.flink.runtime.io.network.api.TaskEventHandler in project flink by apache.

the class TaskEventHandlerTest method testEventNotificationManager.

/**
	 * Tests the publish/subscribe mechanisms implemented in the {@link TaskEventHandler}.
	 */
@Test
public void testEventNotificationManager() {
    final TaskEventHandler evm = new TaskEventHandler();
    final TestEventListener listener = new TestEventListener();
    evm.subscribe(listener, StringTaskEvent.class);
    final StringTaskEvent stringTaskEvent1 = new StringTaskEvent("Test 1");
    final StringTaskEvent stringTaskEvent2 = new StringTaskEvent("Test 2");
    evm.publish(stringTaskEvent1);
    evm.publish(new IntegerTaskEvent(5));
    assertNotNull(listener.getLastReceivedEvent());
    StringTaskEvent receivedStringEvent = (StringTaskEvent) listener.getLastReceivedEvent();
    assertEquals(stringTaskEvent1, receivedStringEvent);
    evm.unsubscribe(listener, StringTaskEvent.class);
    evm.publish(stringTaskEvent2);
    assertNotNull(listener.getLastReceivedEvent());
    receivedStringEvent = (StringTaskEvent) listener.getLastReceivedEvent();
    assertEquals(stringTaskEvent1, receivedStringEvent);
}
Also used : IntegerTaskEvent(org.apache.flink.runtime.event.task.IntegerTaskEvent) StringTaskEvent(org.apache.flink.runtime.event.task.StringTaskEvent) TaskEventHandler(org.apache.flink.runtime.io.network.api.TaskEventHandler) Test(org.junit.Test)

Aggregations

IntegerTaskEvent (org.apache.flink.runtime.event.task.IntegerTaskEvent)1 StringTaskEvent (org.apache.flink.runtime.event.task.StringTaskEvent)1 TaskEventHandler (org.apache.flink.runtime.io.network.api.TaskEventHandler)1 Test (org.junit.Test)1