List of usage examples for org.apache.hadoop.yarn.event AsyncDispatcher register
@SuppressWarnings("unchecked") @Override public void register(Class<? extends Enum> eventType, EventHandler handler)
From source file:org.apache.tez.common.TestAsyncDispatcher.java
License:Apache License
@SuppressWarnings("unchecked") @Test(timeout = 5000)/* w ww . ja va 2 s .c o m*/ public void testBasic() throws Exception { CountDownLatch latch = new CountDownLatch(4); CountDownEventHandler.latch = latch; AsyncDispatcher central = new AsyncDispatcher("Type1"); central.register(TestEventType1.class, new TestEventHandler1()); central.registerAndCreateDispatcher(TestEventType2.class, new TestEventHandler2(), "Type2"); central.registerAndCreateDispatcher(TestEventType3.class, new TestEventHandler3(), "Type3"); central.init(new Configuration()); central.start(); central.getEventHandler().handle(new TestEvent1(TestEventType1.TYPE1)); central.getEventHandler().handle(new TestEvent2(TestEventType2.TYPE2)); central.getEventHandler().handle(new TestEvent3(TestEventType3.TYPE3)); latch.countDown(); latch.await(); central.close(); }
From source file:org.apache.tez.common.TestAsyncDispatcher.java
License:Apache License
@Test(timeout = 5000) public void testMultipleRegisterFail() throws Exception { AsyncDispatcher central = new AsyncDispatcher("Type1"); try {/* w ww . jav a 2 s .c o m*/ central.register(TestEventType1.class, new TestEventHandler1()); central.registerAndCreateDispatcher(TestEventType1.class, new TestEventHandler2(), "Type2"); Assert.fail(); } catch (IllegalStateException e) { Assert.assertTrue(e.getMessage().contains("Cannot register same event on multiple dispatchers")); } finally { central.close(); } central = new AsyncDispatcher("Type1"); try { central.registerAndCreateDispatcher(TestEventType1.class, new TestEventHandler2(), "Type2"); central.register(TestEventType1.class, new TestEventHandler1()); Assert.fail(); } catch (IllegalStateException e) { Assert.assertTrue(e.getMessage().contains("Cannot register same event on multiple dispatchers")); } finally { central.close(); } }
From source file:org.apache.tez.common.TestAsyncDispatcherConcurrent.java
License:Apache License
@Test(timeout = 5000) public void testBasic() throws Exception { CountDownLatch latch = new CountDownLatch(4); CountDownEventHandler.init(latch);//from w ww . ja v a 2 s . com AsyncDispatcher central = new AsyncDispatcher("Type1"); central.register(TestEventType1.class, new TestEventHandler1()); central.registerAndCreateDispatcher(TestEventType2.class, new TestEventHandler2(), "Type2", 1); central.registerAndCreateDispatcher(TestEventType3.class, new TestEventHandler3(), "Type3", 1); central.init(new Configuration()); central.start(); // 3 threads in different dispatchers will handle 3 events central.getEventHandler().handle(new TestEvent1(TestEventType1.TYPE1, 0)); central.getEventHandler().handle(new TestEvent2(TestEventType2.TYPE2)); central.getEventHandler().handle(new TestEvent3(TestEventType3.TYPE3)); // wait for all events to be run in parallel CountDownEventHandler.checkParallelCountersDoneAndFinish(); central.close(); }
From source file:org.apache.tez.common.TestAsyncDispatcherConcurrent.java
License:Apache License
@Test(timeout = 5000) public void testMultipleRegisterFail() throws Exception { AsyncDispatcher central = new AsyncDispatcher("Type1"); try {/* ww w .jav a2 s .c o m*/ central.register(TestEventType1.class, new TestEventHandler1()); central.registerAndCreateDispatcher(TestEventType1.class, new TestEventHandler2(), "Type2", 1); Assert.fail(); } catch (IllegalStateException e) { Assert.assertTrue(e.getMessage().contains("Cannot register same event on multiple dispatchers")); } finally { central.close(); } central = new AsyncDispatcher("Type1"); try { central.registerAndCreateDispatcher(TestEventType1.class, new TestEventHandler2(), "Type2", 1); central.register(TestEventType1.class, new TestEventHandler1()); Assert.fail(); } catch (IllegalStateException e) { Assert.assertTrue(e.getMessage().contains("Multiple concurrent dispatchers cannot be registered")); } finally { central.close(); } central = new AsyncDispatcher("Type1"); try { central.registerAndCreateDispatcher(TestEventType1.class, new TestEventHandler2(), "Type2", 1); central.registerAndCreateDispatcher(TestEventType1.class, new TestEventHandler2(), "Type2", 1); Assert.fail(); } catch (IllegalStateException e) { Assert.assertTrue(e.getMessage().contains("Multiple concurrent dispatchers cannot be registered")); } finally { central.close(); } central = new AsyncDispatcher("Type1"); try { central.registerAndCreateDispatcher(TestEventType1.class, new TestEventHandler2(), "Type2"); central.registerAndCreateDispatcher(TestEventType1.class, new TestEventHandler2(), "Type2"); Assert.fail(); } catch (IllegalStateException e) { Assert.assertTrue(e.getMessage().contains("Multiple dispatchers cannot be registered for")); } finally { central.close(); } central = new AsyncDispatcher("Type1"); try { AsyncDispatcherConcurrent concDispatcher = central.registerAndCreateDispatcher(TestEventType1.class, new TestEventHandler2(), "Type2", 1); central.registerWithExistingDispatcher(TestEventType1.class, new TestEventHandler1(), concDispatcher); Assert.fail(); } catch (IllegalStateException e) { Assert.assertTrue(e.getMessage().contains("Multiple concurrent dispatchers cannot be registered")); } finally { central.close(); } }