Exemple #1
0
  @Test
  public void testCustomListener() {
    Properties p = new Properties();
    p.setProperty(
        Main.PROGRESS_NOTIFICATION_LISTENER_KEY, TestNotificationListener2.class.getName());
    TestNotificationListener2 listener = (TestNotificationListener2) Main.makeListener(p);
    assertEquals(TestNotificationListener2.class, Main.makeListener(p).getClass());
    assertFalse(listener.hadArgs);

    p.setProperty(Main.PROGRESS_NOTIFICATION_LISTENER_ARG_KEY, "foo");
    listener = (TestNotificationListener2) Main.makeListener(p);
    assertEquals(TestNotificationListener2.class, Main.makeListener(p).getClass());
    assertTrue(listener.hadArgs);
  }
Exemple #2
0
  @Test
  public void testRun_setsErrorThrowableForParamSubstitution() {
    File outputFile = null;
    try {
      String filename =
          this.getClass().getSimpleName() + "_" + "testRun_setsErrorThrowableForParamSubstitution";
      outputFile = File.createTempFile(filename, ".out");
      outputFile.delete();

      File scriptFile = File.createTempFile(filename, ".pig");
      BufferedWriter bw = new BufferedWriter(new FileWriter(scriptFile));
      bw.write("a = load '$NOEXIST';\n");
      bw.write("b = group a by $0\n");
      bw.write("c = foreach b generate group, COUNT(a) as cnt;\n");
      bw.write("store c into 'out'\n");
      bw.close();

      Main.run(new String[] {"-x", "local", scriptFile.getAbsolutePath()}, null);
      PigStats stats = PigStats.get();

      Throwable t = stats.getErrorThrowable();
      assertTrue(t instanceof IOException);

      Throwable cause = t.getCause();
      assertTrue(cause instanceof ParameterSubstitutionException);

      ParameterSubstitutionException pse = (ParameterSubstitutionException) cause;
      assertTrue(pse.getMessage().contains("NOEXIST"));
    } catch (Exception e) {
      log.error("Encountered exception", e);
      fail("Encountered Exception");
    }
  }
Exemple #3
0
  @Test
  public void testlog4jConf() throws Exception {
    Properties properties = Main.log4jConfAsProperties(null);
    assertTrue(properties.isEmpty());
    properties = Main.log4jConfAsProperties("");
    assertTrue(properties.isEmpty());
    // Test for non-existent file
    properties = Main.log4jConfAsProperties("non-existing-" + System.currentTimeMillis());
    assertTrue(properties.isEmpty());

    // Create tmp file in under build/test/classes
    File tmpFile =
        File.createTempFile("pig-log4jconf", ".properties", new File("build/test/classes"));
    tmpFile.deleteOnExit();
    Files.write("A=B", tmpFile, Charset.forName("UTF-8"));
    // Read it as a resource
    properties = Main.log4jConfAsProperties(tmpFile.getName());
    assertEquals("B", properties.getProperty("A"));
    // Read it as a file
    properties = Main.log4jConfAsProperties(tmpFile.getAbsolutePath());
    assertEquals("B", properties.getProperty("A"));
  }
Exemple #4
0
  @Test
  public void testRun_setsErrorThrowableOnPigStats() {
    File outputFile = null;
    try {
      String filename =
          this.getClass().getSimpleName() + "_" + "testRun_setsErrorThrowableOnPigStats";
      outputFile = File.createTempFile(filename, ".out");
      outputFile.delete();

      File scriptFile = File.createTempFile(filename, ".pig");
      BufferedWriter bw = new BufferedWriter(new FileWriter(scriptFile));
      bw.write("a = load 'test/org/apache/pig/test/data/passwd';\n");
      bw.write("b = group a by $0\n");
      bw.write("c = foreach b generate group, COUNT(a) as cnt;\n");
      bw.write("store c into 'out'\n");
      bw.close();

      Main.run(new String[] {"-x", "local", scriptFile.getAbsolutePath()}, null);
      PigStats stats = PigStats.get();

      Throwable t = stats.getErrorThrowable();
      assertTrue(t instanceof FrontendException);

      FrontendException fe = (FrontendException) t;
      SourceLocation sl = fe.getSourceLocation();
      assertEquals(2, sl.line());
      assertEquals(15, sl.offset());

      Throwable cause = fe.getCause();
      assertTrue(cause instanceof ParserException);

    } catch (Exception e) {
      log.error("Encountered exception", e);
      fail("Encountered Exception");
    }
  }