Exemplo n.º 1
0
  @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"));
  }
Exemplo n.º 2
0
    @Override
    public void exec(RenderTask task) throws Exception {
      // get the pid list
      RenderTask parent = ((RenderTask) task.getParentContext());
      List<Object> values = parent.getResults().getFieldValues(this.pidField);

      // build the JDS query, Task and execute it
      RenderTask task2 = new RenderTask(parent, this.q);
      task2.setParam("pid", values);
      this.q.exec(task2);

      // now perform the intersection join
      this.intersectJoin(task2);
    }
  /* (non-Javadoc)
   * @see com.aviary.android.feather.widget.ImageButtonRadioGroup.OnCheckedChangeListener#onCheckedChanged(com.aviary.android.feather.widget.ImageButtonRadioGroup, int, boolean)
   */
  @Override
  public void onCheckedChanged(ImageButtonRadioGroup group, int checkedId, boolean isChecked) {
    mLogger.info("onCheckedChange: " + checkedId);

    if (!isActive() || !isEnabled()) return;

    Types type = null;

    killCurrentTask();

    if (checkedId == R.id.button1) {
      type = Types.ENHANCE;
    } else if (checkedId == R.id.button2) {
      type = Types.NIGHTENHANCE;
    } else if (checkedId == R.id.button3) {
      type = Types.BACKLIGHT;
    } else if (checkedId == R.id.button4) {
      type = Types.LABCORRECT;
    }

    if (!isChecked) {
      // restore the original image
      BitmapUtils.copy(mBitmap, mPreview);
      onPreviewChanged(mPreview, true);
      setIsChanged(false);
      mActions = null;
    } else {
      if (type != null) {
        mCurrentTask = new RenderTask();
        mCurrentTask.execute(type);
      }
    }
  }
 /** Kill current task. */
 private void killCurrentTask() {
   if (mCurrentTask != null) {
     synchronized (mCurrentTask) {
       mCurrentTask.cancel(true);
       mCurrentTask.renderFilter.stop();
       onProgressEnd();
     }
     mIsRendering = false;
     mCurrentTask = null;
   }
 }
Exemplo n.º 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);
    }
  }
    @Override
    public void handleMessage(Message msg) {
      if (msg.what == TASK_FINISHED) {
        mViewModificationInProgress = false;
        if (mNextClusters != null) {
          // Run the task that was queued up.
          sendEmptyMessage(RUN_TASK);
        }
        return;
      }
      removeMessages(RUN_TASK);

      if (mViewModificationInProgress) {
        // Busy - wait for the callback.
        return;
      }

      if (mNextClusters == null) {
        // Nothing to do.
        return;
      }

      RenderTask renderTask;
      synchronized (this) {
        renderTask = mNextClusters;
        mNextClusters = null;
        mViewModificationInProgress = true;
      }

      renderTask.setCallback(
          new Runnable() {
            @Override
            public void run() {
              sendEmptyMessage(TASK_FINISHED);
            }
          });
      renderTask.setProjection(mMap.getProjection());
      renderTask.setMapZoom(mMap.getCameraPosition().zoom);
      new Thread(renderTask).start();
    }
Exemplo n.º 7
0
 @Override
 public void exec(RenderTask task) {
   doDelay();
   execCount++;
   for (int i = 0; i < this.rows; i++) {
     HashMap<String, Object> row = new HashMap<String, Object>();
     row.put(getPK(), "row" + i);
     for (int j = 0; j < this.cols; j++) {
       row.put(this.prefix + j, i + "-" + j);
     }
     task.add(row);
   }
 }
Exemplo n.º 8
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"));
  }
Exemplo n.º 9
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"));
  }
Exemplo n.º 10
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));
      }
    }
  }
Exemplo n.º 11
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"));
  }
Exemplo n.º 12
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"));
  }
Exemplo n.º 13
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());
  }