Пример #1
0
 /**
  * Test result formatter failure.
  *
  * @throws InterruptedException the interrupted exception
  * @throws IOException Signals that an I/O exception has occurred.
  */
 @Test
 public void testResultFormatterFailure() throws InterruptedException, IOException {
   LensConf conf = new LensConf();
   conf.addProperty(LensConfConstants.QUERY_PERSISTENT_RESULT_INDRIVER, "false");
   conf.addProperty(LensConfConstants.QUERY_OUTPUT_SERDE, "NonexistentSerde.class");
   testResultFormatter(conf, QueryStatus.Status.FAILED, false, null);
 }
Пример #2
0
 /**
  * Test persistent result with max size.
  *
  * @throws InterruptedException the interrupted exception
  * @throws IOException Signals that an I/O exception has occurred.
  */
 @Test
 public void testPersistentResultWithMaxSize() throws InterruptedException, IOException {
   LensConf conf = new LensConf();
   conf.addProperty(LensConfConstants.QUERY_PERSISTENT_RESULT_INDRIVER, "true");
   conf.addProperty(LensConfConstants.RESULT_FORMAT_SIZE_THRESHOLD, "1");
   testResultFormatter(conf, QueryStatus.Status.SUCCESSFUL, true, null);
 }
Пример #3
0
  /**
   * Test result formatter hdfs persistent result.
   *
   * @throws InterruptedException the interrupted exception
   * @throws IOException Signals that an I/O exception has occurred.
   */
  @Test
  public void testResultFormatterHDFSpersistentResult() throws InterruptedException, IOException {
    LensConf conf = new LensConf();
    conf.addProperty(LensConfConstants.QUERY_PERSISTENT_RESULT_INDRIVER, "true");
    testResultFormatter(conf, QueryStatus.Status.SUCCESSFUL, false, null);

    queryService.conf.set(LensConfConstants.RESULT_FS_READ_URL, "filereadurl://");
    testResultFormatter(conf, QueryStatus.Status.SUCCESSFUL, false, "filereadurl://");
    queryService.conf.unset(LensConfConstants.RESULT_FS_READ_URL);
  }
Пример #4
0
  /**
   * Test result formatter in memory result.
   *
   * @throws InterruptedException the interrupted exception
   * @throws IOException Signals that an I/O exception has occurred.
   */
  @Test
  public void testResultFormatterInMemoryResult() throws InterruptedException, IOException {
    LensConf conf = new LensConf();
    conf.addProperty(LensConfConstants.QUERY_PERSISTENT_RESULT_INDRIVER, "false");
    conf.addProperty(
        LensConfConstants.QUERY_OUTPUT_SERDE, LazySimpleSerDe.class.getCanonicalName());
    testResultFormatter(conf, QueryStatus.Status.SUCCESSFUL, false, null);

    queryService.conf.set(LensConfConstants.RESULT_FS_READ_URL, "filereadurl://");
    testResultFormatter(conf, QueryStatus.Status.SUCCESSFUL, false, "filereadurl://");
    queryService.conf.unset(LensConfConstants.RESULT_FS_READ_URL);
  }
Пример #5
0
 /**
  * Create a new session with Lens server.
  *
  * @param username User name of the Lens server user
  * @param password Password of the Lens server user
  * @param database (Optional) Set current database to supplied value
  * @param sessionconf Key-value properties which will be used to configure this session
  * @return A Session handle unique to this session
  */
 @POST
 @Consumes({MediaType.MULTIPART_FORM_DATA})
 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN})
 public LensSessionHandle openSession(
     @FormDataParam("username") String username,
     @FormDataParam("password") String password,
     @FormDataParam("database") @DefaultValue("") String database,
     @FormDataParam("sessionconf") LensConf sessionconf) {
   try {
     Map<String, String> conf;
     if (sessionconf != null) {
       conf = sessionconf.getProperties();
     } else {
       conf = new HashMap<String, String>();
     }
     LensSessionHandle handle = sessionService.openSession(username, password, database, conf);
     openSessions.put(handle.getPublicId(), handle);
     return handle;
   } catch (LensException e) {
     throw new WebApplicationException(e);
   }
 }
Пример #6
0
  /**
   * Test result formatter.
   *
   * @param conf the conf
   * @param status the status
   * @param isDir the is dir
   * @param reDirectUrl the re direct url
   * @throws InterruptedException the interrupted exception
   * @throws IOException Signals that an I/O exception has occurred.
   */
  private void testResultFormatter(LensConf conf, Status status, boolean isDir, String reDirectUrl)
      throws InterruptedException, IOException {
    // test post execute op
    final WebTarget target = target().path("queryapi/queries");

    final FormDataMultiPart mp = new FormDataMultiPart();
    conf.addProperty(LensConfConstants.QUERY_PERSISTENT_RESULT_SET, "true");
    mp.bodyPart(
        new FormDataBodyPart(
            FormDataContentDisposition.name("sessionid").build(),
            lensSessionId,
            MediaType.APPLICATION_XML_TYPE));
    mp.bodyPart(
        new FormDataBodyPart(
            FormDataContentDisposition.name("query").build(),
            "select ID, IDSTR, IDARR, IDSTRARR from " + testTable));
    mp.bodyPart(
        new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "execute"));
    mp.bodyPart(
        new FormDataBodyPart(
            FormDataContentDisposition.name("conf").fileName("conf").build(),
            conf,
            MediaType.APPLICATION_XML_TYPE));
    QueryHandle handle =
        target
            .request()
            .post(
                Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE),
                new GenericType<LensAPIResult<QueryHandle>>() {})
            .getData();

    Assert.assertNotNull(handle);

    // Get query
    LensQuery ctx =
        target
            .path(handle.toString())
            .queryParam("sessionid", lensSessionId)
            .request()
            .get(LensQuery.class);
    // wait till the query finishes
    QueryStatus stat = ctx.getStatus();
    while (!stat.finished()) {
      ctx =
          target
              .path(handle.toString())
              .queryParam("sessionid", lensSessionId)
              .request()
              .get(LensQuery.class);
      stat = ctx.getStatus();
      Thread.sleep(1000);
    }

    Assert.assertEquals(ctx.getStatus().getStatus(), status);

    if (status.equals(QueryStatus.Status.SUCCESSFUL)) {
      QueryContext qctx = queryService.getQueryContext(handle);
      if (qctx == null) {
        // This shouldn't occur. It is appearing when query gets purged. So adding extra logs
        // for debugging in the future.
        log.info("successful query's QueryContext is null");
        log.info("query handle: {}", handle);
        log.info("allQueries: {}", queryService.allQueries);
        // not doing formatter validation if qctx is null
      } else if (!isDir) {
        // isDir is true if the formatter is skipped due to result being the max size allowed
        if (qctx.isDriverPersistent()) {
          Assert.assertTrue(qctx.getQueryOutputFormatter() instanceof PersistedOutputFormatter);
        } else {
          Assert.assertTrue(qctx.getQueryOutputFormatter() instanceof InMemoryOutputFormatter);
        }
      } else {
        Assert.assertNull(qctx.getQueryOutputFormatter());
      }
      // fetch results
      TestQueryService.validatePersistedResult(
          handle,
          target(),
          lensSessionId,
          new String[][] {
            {"ID", "INT"}, {"IDSTR", "STRING"}, {"IDARR", "ARRAY"}, {"IDSTRARR", "ARRAY"},
          },
          isDir);
      if (!isDir) {
        TestQueryService.validateHttpEndPoint(target(), lensSessionId, handle, reDirectUrl);
      }
    } else {
      assertTrue(ctx.getSubmissionTime() > 0);
      assertTrue(ctx.getLaunchTime() > 0);
      assertTrue(ctx.getDriverStartTime() > 0);
      assertTrue(ctx.getDriverFinishTime() > 0);
      assertTrue(ctx.getFinishTime() > 0);
      Assert.assertEquals(ctx.getStatus().getStatus(), QueryStatus.Status.FAILED);
    }
  }