@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public EventHandler<Event> getEventHandler() { class EventArgMatcher extends ArgumentMatcher<AbstractEvent> { @Override public boolean matches(Object argument) { if (argument instanceof RMAppNodeUpdateEvent) { ApplicationId appid = ((RMAppNodeUpdateEvent) argument).getApplicationId(); applist.add(appid); } return false; } } EventHandler handler = spy(super.getEventHandler()); doNothing().when(handler).handle(argThat(new EventArgMatcher())); return handler; } };
@Override public EventHandler<Event> getEventHandler() { class EventArgMatcher extends ArgumentMatcher<AbstractEvent> { @Override public boolean matches(Object argument) { if (argument instanceof RMAppAttemptEvent) { if (((RMAppAttemptEvent) argument).getType().equals( RMAppAttemptEventType.KILL)) { return true; } } return false; } } EventHandler handler = spy(super.getEventHandler()); doNothing().when(handler).handle(argThat(new EventArgMatcher())); return handler; } };
@Override public EventHandler<Event> getEventHandler() { class EventArgMatcher extends ArgumentMatcher<AbstractEvent> { @Override public boolean matches(Object argument) { if (argument instanceof RMAppAttemptEvent) { if (((RMAppAttemptEvent) argument).getType().equals( RMAppAttemptEventType.KILL)) { return true; } } return false; } } EventHandler handler = spy(super.getEventHandler()); doNothing().when(handler).handle(argThat(new EventArgMatcher())); return handler; } };
@Override public EventHandler<Event> getEventHandler() { class EventArgMatcher extends ArgumentMatcher<AbstractEvent> { @Override public boolean matches(Object argument) { if (argument instanceof RMAppAttemptEvent) { if (((RMAppAttemptEvent) argument).getType().equals( RMAppAttemptEventType.KILL)) { return true; } } return false; } } EventHandler handler = spy(super.getEventHandler()); doNothing().when(handler).handle(argThat(new EventArgMatcher())); return handler; } };
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test(timeout=10000) public void testDispatcherOnCloseIfQueueEmpty() throws Exception { BlockingQueue<Event> eventQueue = spy(new LinkedBlockingQueue<Event>()); Event event = mock(Event.class); doThrow(new InterruptedException()).when(eventQueue).put(event); DrainDispatcher disp = new DrainDispatcher(eventQueue); disp.init(new Configuration()); disp.setDrainEventsOnStop(); disp.start(); // Wait for event handler thread to start and begin waiting for events. disp.waitForEventThreadToWait(); try { disp.getEventHandler().handle(event); Assert.fail("Expected YarnRuntimeException"); } catch (YarnRuntimeException e) { Assert.assertTrue(e.getCause() instanceof InterruptedException); } // Queue should be empty and dispatcher should not hang on close Assert.assertTrue("Event Queue should have been empty", eventQueue.isEmpty()); disp.close(); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test(timeout=10000) public void testDispatcherOnCloseIfQueueEmpty() throws Exception { BlockingQueue<Event> eventQueue = spy(new LinkedBlockingQueue<Event>()); Event event = mock(Event.class); doThrow(new InterruptedException()).when(eventQueue).put(event); DrainDispatcher disp = new DrainDispatcher(eventQueue); disp.init(new Configuration()); disp.setDrainEventsOnStop(); disp.start(); // Wait for event handler thread to start and begin waiting for events. disp.waitForEventThreadToWait(); try { disp.getEventHandler().handle(event); Assert.fail("Expected YarnRuntimeException"); } catch (YarnRuntimeException e) { Assert.assertTrue(e.getCause() instanceof InterruptedException); } // Queue should be empty and dispatcher should not hang on close Assert.assertTrue("Event Queue should have been empty", eventQueue.isEmpty()); disp.close(); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test(timeout=10000) public void testDispatcherOnCloseIfQueueEmpty() throws Exception { BlockingQueue<Event> eventQueue = spy(new LinkedBlockingQueue<Event>()); Event event = mock(Event.class); doThrow(new InterruptedException()).when(eventQueue).put(event); DrainDispatcher disp = new DrainDispatcher(eventQueue); disp.init(new Configuration()); disp.setDrainEventsOnStop(); disp.start(); // Wait for event handler thread to start and begin waiting for events. disp.waitForEventThreadToWait(); try { disp.getEventHandler().handle(event); Assert.fail("Expected YarnRuntimeException"); } catch (YarnRuntimeException e) { Assert.assertTrue(e.getCause() instanceof InterruptedException); } // Queue should be empty and dispatcher should not hang on close Assert.assertTrue("Event Queue should have been empty", eventQueue.isEmpty()); disp.close(); }