@Test public void testParams() throws FrameInitException, FrameExecException { // create a mock ViewDef with no a specific declared params TestViewDef vd = new TestViewDef(); vd.declareParam("myparam", "mydefaultval"); vd.addQuery(ViewDefSamples.sq1); vd.addQuery(ViewDefSamples.sq2); // run the renderer with some specified params, examine the working parameter set that is // returned Map<String, Object> inparams = Table.buildRow("foo", 1, "bar", 2, "myparam", 3); RenderTask result = runner.exec(vd, inparams).getAction(ViewRenderAction.class).getResults(); Map<String, Object> params = result.getParams(); // params will contain a bunch of default stuff assertTrue(params.containsKey("row.count")); assertTrue(params.containsKey("view.class")); assertTrue(params.containsKey("col.list")); // plus the param we declared assertTrue(params.containsKey("myparam")); // also all the params we specified, which overrite the defaults (if any) assertEquals(1, params.get("foo")); assertEquals(2, params.get("bar")); assertEquals(3, params.get("myparam")); // nested queries (tasks) don't hold any params by default themselves FrameTask subtask = result.getSubTasks().get(0); // but will delegate to the parent task to find them assertEquals(1, subtask.getParamObj("foo")); assertEquals(2, subtask.getParamObj("bar")); assertEquals(3, subtask.getParamObj("myparam")); }
@Test public void testUINotifyAppender() throws Exception { DummyFrameAction act = DummyFrameAction.INSTANCE; // setup JMS topic/connection/session String brokerURL = "vm://hmp-test?waitForStart=1000&broker.persistent=false&broker.deleteAllMessagesOnStartup=true"; ConnectionFactory fact = new ActiveMQConnectionFactory(brokerURL); Connection conn = fact.createConnection(); conn.start(); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); // setup a JMS template JmsTemplate tpl = new JmsTemplate(fact); tpl.setPubSubDomain(true); tpl.setDefaultDestinationName("ui.notify"); tpl.setReceiveTimeout(JmsTemplate.RECEIVE_TIMEOUT_NO_WAIT); Topic dest = sess.createTopic("ui.notify"); MessageConsumer consumer = sess.createConsumer(dest); assertNull(tpl.receive()); // configure the runner runner.setTimeoutMS(60000); // 1m runner.addResource(tpl); // create a viewdef with a nested UINotifier viewdef that should be done in 100ms // the rest of the time (10x100ms) should run in parallel and be done in 200ms; ((DataGeneratorQuery) vd.getPrimaryQuery()).setDelay(100); ViewDef view = new TestViewDef(); DataGeneratorQuery q1 = view.addQuery(new DataGeneratorQuery("id", "1st", 10, 5).setDelay(150)); UINotifyQueryMapper q2 = view.addQuery(new UINotifyQueryMapper("subview", vd)); // query should be done in ~150ms, rest will take another 200ms long start = System.currentTimeMillis(); FrameTask task = runner.exec(view); RenderTask q = task.getAction(ViewRenderAction.class).getResults(); assertTrue(task.getTotalTimeMS() <= 200); // generous fudge factor assertEquals(task.getTotalTimeMS(), (System.currentTimeMillis() - start), 50); // should return 10 placeholder values assertEquals(10, q.size()); assertEquals(1, q1.execCount); List<String> uuids = new ArrayList<String>(); for (int i = 0; i < q.size(); i++) { Object subview = q.getCellIdx(i, "subview"); assertTrue(subview instanceof String); uuids.add(subview.toString()); } // expecting the main task to have a single subtask (RenderTask) assertEquals(1, task.getSubTasks().size()); assertTrue(task.getSubTasks().get(0) instanceof RenderTask); assertSame(q, task.getSubTasks().get(0)); assertEquals(1, q.getSubTasks().size()); // main render task has one empty subtask for the UINotifyQueryMapper RenderTask task2 = (RenderTask) q.getSubTasks().get(0); assertSame(q2, task2.getQuery()); assertEquals(0, task2.getSubTasks().size()); // check that the JMS topic has 10 items on it, with the corresponding UUIDs for (int i = 0; i < 10; i++) { Message msg = consumer.receive(500); assertNotNull(msg); String uuid = msg.getStringProperty("uid"); uuids.remove(uuid); } assertNull(consumer.receiveNoWait()); // nothing left // vd should have been executed 10x and found all UUIDs DataGeneratorQuery q3 = (DataGeneratorQuery) vd.getPrimaryQuery(); assertEquals(10, q3.execCount); assertEquals(0, uuids.size()); }