Example usage for org.apache.hadoop.yarn.event AsyncDispatcher close

List of usage examples for org.apache.hadoop.yarn.event AsyncDispatcher close

Introduction

In this page you can find the example usage for org.apache.hadoop.yarn.event AsyncDispatcher close.

Prototype

@Override
public final void close() throws IOException 

Source Link

Document

Relay to #stop()

Usage

From source file:org.apache.tez.common.TestAsyncDispatcher.java

License:Apache License

@SuppressWarnings("unchecked")
@Test(timeout = 5000)// w  ww.  jav  a 2s .  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 {/*from  ww  w . ja v  a2s. co  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 w  w . j a  va  2  s .c  om*/

    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 {/*from   w  w w .  j av  a 2 s . co 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();
    }
}