Пример #1
0
  private static void verify(RenderTask q) {
    assertEquals(10, q.size());
    assertEquals(17, q.getResults().getFields().size());

    // verify correct results
    for (int i = 0; i < q.size(); i++) {
      assertEquals("row" + i, q.getCellIdx(i, "id"));

      for (int j = 0; j < 5; j++) {
        assertEquals(i + "-" + j, q.getCellIdx(i, "1st" + j));
        assertEquals(i + "-" + j, q.getCellIdx(i, "2nd" + j));
        assertEquals("0-" + j, q.getCellIdx(i, "3rd" + j));
      }
    }
  }
Пример #2
0
  @Test
  public void testMergeAppender() throws Exception {
    ViewDef vd = new TestViewDef();
    vd.addQuery(ViewDefSamples.sq1);
    vd.addQuery(new JoinQueryMapper(ViewDefSamples.sq2));

    RenderTask q = runner.exec(vd).getAction(ViewRenderAction.class).getResults();
    assertEquals(3, q.size());

    assertEquals("a1", q.getCellIdx(0, "a"));
    assertEquals("b1", q.getCellIdx(0, "b"));
    assertEquals("c1", q.getCellIdx(0, "c"));

    assertEquals("x1", q.getCellIdx(0, "x"));
    assertEquals("y1", q.getCellIdx(0, "y"));
    assertEquals("z1", q.getCellIdx(0, "z"));
  }
Пример #3
0
  @Test
  public void testMergeAppenderFK() throws Exception {
    ViewDef vd = new TestViewDef();
    vd.addQuery(ViewDefSamples.sq2);
    vd.addQuery(new JoinQueryMapper(ViewDefSamples.sq1, "id2"));

    FrameTask task = runner.exec(vd);
    System.out.println("testMergeAppenderFK\n" + task.toString());
    RenderTask q = task.getAction(ViewRenderAction.class).getResults();
    assertEquals(3, q.size());

    assertEquals("a1", q.getCellIdx(0, "a"));
    assertEquals("b1", q.getCellIdx(0, "b"));
    assertEquals("c1", q.getCellIdx(0, "c"));

    assertEquals("x1", q.getCellIdx(0, "x"));
    assertEquals("y1", q.getCellIdx(0, "y"));
    assertEquals("z1", q.getCellIdx(0, "z"));
  }
Пример #4
0
  @Test
  public void testPerRowAppendMapper() throws Exception {
    List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
    data.add(Table.buildRow("foo", "bar"));

    // build a query that will just copy the PK field
    Query q2 =
        new AbstractQuery("idcopy", null) {
          @Override
          public void exec(RenderTask task) throws Exception {
            if (task instanceof RowRenderSubTask) {
              RowRenderSubTask subtask = (RowRenderSubTask) task;
              if (subtask.getRowIdx() >= 0) {
                task.add(Table.buildRow("idcopy", subtask.getParentRowKey()));
              }
            }
          }
        };

    // regular three rows, but the second query is appended to each row
    ViewDef vd = new TestViewDef();
    vd.addQuery(ViewDefSamples.sq1);
    vd.addQuery(new PerRowAppendMapper(new StaticQuery("foo", data)));
    vd.addQuery(new PerRowAppendMapper(q2));

    // should append the queries to each other, totaling 3 rows with 7 columns apeice
    RenderTask q = runner.exec(vd).getAction(ViewRenderAction.class).getResults();
    assertEquals(3, q.size());
    assertEquals(7, q.getRowIdx(0).size());
    assertEquals(7, q.getRowIdx(1).size());
    assertEquals(7, q.getRowIdx(2).size());

    // static data just gets added to each row
    assertEquals("bar", q.getCellIdx(0, "foo"));
    assertEquals("bar", q.getCellIdx(1, "foo"));
    assertEquals("bar", q.getCellIdx(2, "foo"));

    // q2 copies the PK
    assertEquals("1", q.getCellIdx(0, "idcopy"));
    assertEquals("2", q.getCellIdx(1, "idcopy"));
    assertEquals("3", q.getCellIdx(2, "idcopy"));
  }
Пример #5
0
  @Test
  public void testNestedViewDefs() throws FrameInitException, FrameExecException {
    ViewDef def = new TestViewDef();
    def.addQuery(new DataGeneratorQuery("id", "1st", 10, 5));
    def.addQuery(new PerRowSubTableMapper("subview", vd));

    // we expect the usual 10 rows
    //		runner.setExecutor(null);
    FrameTask task = runner.exec(def);
    RenderTask results = task.getAction(ViewRenderAction.class).getResults();
    assertEquals(10, results.size());
    for (int i = 0; i < 10; i++) {
      // each one should have 1 column that can be verifyied as the standard results
      Map<String, Object> row = results.getRowIdx(i);
      assertTrue(row.containsKey("subview"));
      assertTrue(row.get("subview") instanceof RenderTask);
      RenderTask subview = (RenderTask) row.get("subview");
      verify(subview);
    }
  }
Пример #6
0
  @Test
  public void testDataGeneratorQuery() throws Exception {
    DataGeneratorQuery qry = new DataGeneratorQuery("id", "col", 10, 10);
    RenderTask tsk = new RenderTask(vd, qry);
    qry.exec(tsk);

    // test our basic data generator query
    assertEquals(10, tsk.size());
    assertEquals(11, tsk.getResults().getFields().size());

    // sample the rows/cols diagonally
    assertEquals("0-0", tsk.getCellIdx(0, "col0"));
    assertEquals("1-1", tsk.getCellIdx(1, "col1"));
    assertEquals("2-2", tsk.getCellIdx(2, "col2"));
    assertEquals("3-3", tsk.getCellIdx(3, "col3"));
    assertEquals("4-4", tsk.getCellIdx(4, "col4"));
    assertEquals("5-5", tsk.getCellIdx(5, "col5"));
    assertEquals("6-6", tsk.getCellIdx(6, "col6"));
    assertEquals("7-7", tsk.getCellIdx(7, "col7"));
    assertEquals("8-8", tsk.getCellIdx(8, "col8"));
    assertEquals("9-9", tsk.getCellIdx(9, "col9"));
  }
Пример #7
0
  @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());
  }