List of usage examples for org.apache.hadoop.yarn.event AsyncDispatcher getEventHandler
@Override
public EventHandler<Event> getEventHandler()
From source file:org.apache.tajo.engine.plan.global.TestGlobalQueryPlanner.java
License:Apache License
@BeforeClass public static void setup() throws Exception { util = new TajoTestingCluster(); util.startCatalogCluster();/* w ww . j av a 2 s . c om*/ int i, j; schema = new Schema(); schema.addColumn("id", Type.INT4); schema.addColumn("age", Type.INT4); schema.addColumn("name", Type.TEXT); schema.addColumn("salary", Type.INT4); TableMeta meta; conf = new TajoConf(util.getConfiguration()); catalog = util.getMiniCatalogCluster().getCatalog(); for (FunctionDesc funcDesc : TajoMaster.initBuiltinFunctions()) { catalog.registerFunction(funcDesc); } sm = new StorageManager(util.getConfiguration()); FunctionDesc funcDesc = new FunctionDesc("sumtest", TestSum.class, FunctionType.GENERAL, CatalogUtil.newDataTypesWithoutLen(Type.INT4), CatalogUtil.newDataTypesWithoutLen(Type.INT4)); catalog.registerFunction(funcDesc); FileSystem fs = sm.getFileSystem(); AsyncDispatcher dispatcher = new AsyncDispatcher(); dispatcher.init(conf); dispatcher.start(); planner = new GlobalPlanner(conf, catalog, new StorageManager(conf), dispatcher.getEventHandler()); analyzer = new QueryAnalyzer(catalog); logicalPlanner = new LogicalPlanner(catalog); int tbNum = 2; int tupleNum; Appender appender; Tuple t = new VTuple(4); t.put(new Datum[] { DatumFactory.createInt4(1), DatumFactory.createInt4(32), DatumFactory.createText("h"), DatumFactory.createInt4(10) }); for (i = 0; i < tbNum; i++) { meta = CatalogUtil.newTableMeta((Schema) schema.clone(), StoreType.CSV); meta.putOption(CSVFile.DELIMITER, ","); Path dataRoot = sm.getBaseDir(); Path tablePath = StorageUtil.concatPath(dataRoot, "table" + i, "file.csv"); if (fs.exists(tablePath.getParent())) { fs.delete(tablePath.getParent(), true); } fs.mkdirs(tablePath.getParent()); appender = StorageManager.getAppender(conf, meta, tablePath); appender.init(); tupleNum = 100; for (j = 0; j < tupleNum; j++) { appender.addTuple(t); } appender.close(); TableDesc desc = CatalogUtil.newTableDesc("table" + i, (TableMeta) meta.clone(), tablePath); catalog.addTable(desc); } QueryIdFactory.reset(); queryId = QueryIdFactory.newQueryId(); dispatcher.stop(); }
From source file:org.apache.tajo.engine.planner.global.TestGlobalQueryOptimizer.java
License:Apache License
@BeforeClass public static void setup() throws Exception { util = new TajoTestingCluster(); util.startCatalogCluster();//from w ww. jav a2 s . com int i, j; schema = new Schema(); schema.addColumn("id", Type.INT4); schema.addColumn("age", Type.INT4); schema.addColumn("name", Type.TEXT); schema.addColumn("salary", Type.INT4); TableMeta meta; conf = new TajoConf(util.getConfiguration()); catalog = util.getMiniCatalogCluster().getCatalog(); StorageManager sm = new StorageManager(util.getConfiguration()); FunctionDesc funcDesc = new FunctionDesc("sumtest", TestSum.class, FunctionType.GENERAL, CatalogUtil.newDataTypesWithoutLen(Type.INT4), CatalogUtil.newDataTypesWithoutLen(Type.INT4)); catalog.registerFunction(funcDesc); FileSystem fs = sm.getFileSystem(); AsyncDispatcher dispatcher = new AsyncDispatcher(); planner = new GlobalPlanner(conf, catalog, new StorageManager(conf), dispatcher.getEventHandler()); analyzer = new QueryAnalyzer(catalog); logicalPlanner = new LogicalPlanner(catalog); int tbNum = 2; int tupleNum; Appender appender; Tuple t = new VTuple(4); t.put(new Datum[] { DatumFactory.createInt4(1), DatumFactory.createInt4(32), DatumFactory.createText("h"), DatumFactory.createInt4(10) }); for (i = 0; i < tbNum; i++) { meta = CatalogUtil.newTableMeta((Schema) schema.clone(), StoreType.CSV); meta.putOption(CSVFile.DELIMITER, ","); Path dataRoot = sm.getBaseDir(); Path tablePath = StorageUtil.concatPath(dataRoot, "table" + i, "file.csv"); if (fs.exists(tablePath.getParent())) { fs.delete(tablePath.getParent(), true); } fs.mkdirs(tablePath.getParent()); appender = StorageManager.getAppender(conf, meta, tablePath); appender.init(); tupleNum = 100; for (j = 0; j < tupleNum; j++) { appender.addTuple(t); } appender.close(); TableDesc desc = CatalogUtil.newTableDesc("table" + i, (TableMeta) meta.clone(), sm.getTablePath("table" + i)); catalog.addTable(desc); } QueryIdFactory.reset(); queryId = QueryIdFactory.newQueryId(); optimizer = new GlobalOptimizer(); }
From source file:org.apache.tez.common.TestAsyncDispatcher.java
License:Apache License
@SuppressWarnings("unchecked") @Test(timeout = 5000)/*from w w w .j a v a2 s . co 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.TestAsyncDispatcherConcurrent.java
License:Apache License
@Test(timeout = 5000) public void testBasic() throws Exception { CountDownLatch latch = new CountDownLatch(4); CountDownEventHandler.init(latch);/*from w ww. j av a2 s . co m*/ 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(); }