示例#1
45
  @Test
  public void testProtocolBestMoveCommand() throws IOException {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    UciProtocol protocol =
        new UciProtocol(
            new BufferedReader(new InputStreamReader(new ByteArrayInputStream("".getBytes()))),
            new PrintStream(buffer));

    // 1. Test
    ProtocolBestMoveCommand command =
        new ProtocolBestMoveCommand(
            new GenericMove(GenericPosition.a2, GenericPosition.a3),
            new GenericMove(GenericPosition.d3, GenericPosition.e5));
    protocol.send(command);

    // 2. Test
    command = new ProtocolBestMoveCommand(null, null);
    protocol.send(command);

    BufferedReader input =
        new BufferedReader(new InputStreamReader(new ByteArrayInputStream(buffer.toByteArray())));

    // 1. Test
    String line = input.readLine();
    assertEquals("bestmove a2a3 ponder d3e5", line);

    // 2. Test
    line = input.readLine();
    assertEquals("bestmove nomove", line);

    assertNull(input.readLine());
  }
示例#2
0
  @Test
  public void testProtocolInitializeAnswerCommand() throws IOException {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    UciProtocol protocol =
        new UciProtocol(
            new BufferedReader(new InputStreamReader(new ByteArrayInputStream("".getBytes()))),
            new PrintStream(buffer));

    ProtocolInitializeAnswerCommand command =
        new ProtocolInitializeAnswerCommand("My Engine", "The Author");
    command.addOption(new Option("Hash", "spin", "16", "4", "64", null));
    protocol.send(command);

    BufferedReader input =
        new BufferedReader(new InputStreamReader(new ByteArrayInputStream(buffer.toByteArray())));
    String line = input.readLine();
    assertEquals("id name My Engine", line);
    line = input.readLine();
    assertEquals("id author The Author", line);
    line = input.readLine();
    assertEquals("option name Hash type spin default 16 min 4 max 64", line);
    line = input.readLine();
    assertEquals("uciok", line);
    assertNull(input.readLine());
  }
示例#3
0
  /** Test of execute method, of class ToolProcessor. */
  public void testExecuteFileIdentify() throws Exception {
    Tool tool = repo.getTool("file");

    String tmpInputFile = this.getClass().getClassLoader().getResource("ps2pdf-input.ps").getFile();

    LOG.debug("tmpInputFile = " + tmpInputFile);

    LOG.info("TEST file-identify");

    ToolProcessor processor = new ToolProcessor(tool);

    Operation operation = processor.findOperation("identify");
    processor.setOperation(operation);

    Map<String, String> mapInput = new HashMap<String, String>();
    mapInput.put("input", tmpInputFile);

    processor.setInputFileParameters(mapInput);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    processor.next(new StreamProcessor(baos));
    try {
      processor.execute();
    } catch (IOException ex) {
      LOG.error("Exception during execution (maybe unresolved system dependency?): " + ex);
    }
    LOG.info("output: " + new String(baos.toByteArray()));
  }
示例#4
0
  @Test
  public void testProtocolInformationCommand() throws IOException {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    UciProtocol protocol =
        new UciProtocol(
            new BufferedReader(new InputStreamReader(new ByteArrayInputStream("".getBytes()))),
            new PrintStream(buffer));

    ProtocolInformationCommand command = new ProtocolInformationCommand();
    command.setDepth(8);
    command.setMaxDepth(20);
    command.setCentipawns(400);
    command.setCurrentMove(new GenericMove(GenericPosition.a2, GenericPosition.a3));
    command.setCurrentMoveNumber(30);
    command.setHash(50);
    command.setNps(300);
    command.setTime(3000);
    command.setNodes(5000);
    protocol.send(command);

    BufferedReader input =
        new BufferedReader(new InputStreamReader(new ByteArrayInputStream(buffer.toByteArray())));
    String line = input.readLine();
    assertEquals(
        "info depth 8 seldepth 20 score cp 400 currmove a2a3 currmovenumber 30 hashfull 50 nps 300 time 3000 nodes 5000",
        line);
    assertNull(input.readLine());
  }
  /**
   * This is Bob's original test, re-written only to allow it to execute as a normal junit test
   * within Eclipse.
   */
  @Test
  public void origTestOfRewritingMHLDtoSameBib() throws IOException {
    String mhldRecFileName = testDataParentPath + File.separator + "summaryHld_1-1000.mrc";
    String bibRecFileName = testDataParentPath + File.separator + "u335.mrc";

    InputStream inStr = null;
    ByteArrayOutputStream resultMrcOutStream = new ByteArrayOutputStream();
    String[] mergeMhldArgs = new String[] {"-s", mhldRecFileName, bibRecFileName};

    // call the code for mhldfile summaryHld_1-1000.mrc  and bibfile u335.mrc
    CommandLineUtils.runCommandLineUtil(
        MERGE_MHLD_CLASS_NAME, MAIN_METHOD_NAME, inStr, resultMrcOutStream, mergeMhldArgs);

    RecordTestingUtils.assertMarcRecsEqual(mergedSummaryHoldingsOutput, resultMrcOutStream);

    // Now merge record again to test the deleting of existing summary holdings info
    ByteArrayInputStream mergedMarcBibRecAsInStream =
        new ByteArrayInputStream(resultMrcOutStream.toByteArray());
    resultMrcOutStream.close();
    resultMrcOutStream = new ByteArrayOutputStream();
    //  do the merge by piping the bib record in to the merge class
    CommandLineUtils.runCommandLineUtil(
        MERGE_MHLD_CLASS_NAME,
        MAIN_METHOD_NAME,
        mergedMarcBibRecAsInStream,
        resultMrcOutStream,
        new String[] {"-s", mhldRecFileName});

    RecordTestingUtils.assertMarcRecsEqual(mergedSummaryHoldingsOutput, resultMrcOutStream);
    System.out.println("Test origTestOfRewritingMHLDtoSameBib() successful");
  }
示例#6
0
  public void testExecuteFileIdentifyStdin() throws Exception {

    LOG.info("TEST file-identify-stdin");

    // This test may throw an "Broken pipe" IOException
    // because file needs not to read the whole file data from
    // stdin and will terminate while the other thread is reading streams.

    Tool tool = repo.getTool("file");

    String tmpInputFile = this.getClass().getClassLoader().getResource("ps2pdf-input.ps").getFile();

    ToolProcessor processor = new ToolProcessor(tool);
    Operation operation = processor.findOperation("identify-stdin");
    processor.setOperation(operation);

    FileInputStream fin = new FileInputStream(new File(tmpInputFile));
    StreamProcessor in = new StreamProcessor(fin);
    in.next(processor);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    baos = new ByteArrayOutputStream();

    processor.next(new StreamProcessor(baos));
    try {
      in.execute();
    } catch (IOException ex) {
      LOG.error("Exception during execution (maybe unresolved system dependency?): " + ex);
    }
    LOG.info("output: " + new String(baos.toByteArray()));
  }
  /**
   * Test method for {@link cpath.converter.internal.UniprotCleanerImpl#cleane(java.lang.String)}.
   *
   * @throws IOException
   */
  @Test
  public void testCleaner() throws IOException {
    // read data from file and look for accessions before being cleaned
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    CPathUtils.unzip(
        new ZipInputStream(
            CPathUtils.LOADER.getResource("/test_uniprot_data.dat.zip").getInputStream()),
        os);
    byte[] bytes = os.toByteArray();
    String data = new String(bytes);
    assertTrue(data.indexOf(CALR3_HUMAN_BEFORE) != -1);
    assertTrue(data.indexOf(CALRL_HUMAN_BEFORE) != -1);

    Cleaner cleaner = new UniProtCleanerImpl();
    os.reset();
    cleaner.clean(new ByteArrayInputStream(bytes), os);
    bytes = os.toByteArray();

    data = new String(bytes);
    assertTrue(data.indexOf(CALR3_HUMAN_AFTER) != -1);
    assertTrue(data.indexOf(CALRL_HUMAN_AFTER) != -1);

    // dump owl for review
    String outFilename =
        getClass().getClassLoader().getResource("").getPath()
            + File.separator
            + "testCleanUniProt.out.dat";
    Writer out = new OutputStreamWriter(new FileOutputStream(outFilename));
    out.write(data);
    out.close();
  }
示例#8
0
 @Test
 public void writeToOutputStream() throws IOException {
   XMLDocument doc =
       db.createFolder("/top").documents().load(Name.create(db, "foo"), Source.xml("<root/>"));
   ByteArrayOutputStream out = new ByteArrayOutputStream();
   doc.write(out);
   out.close();
   assertEquals("<root/>", out.toString());
 }
  private void doControlTask() throws IOException, ClassNotFoundException {
    BlockingTaskSummaryResponseHandler handler = new BlockingTaskSummaryResponseHandler();
    client.getTasksAssignedAsPotentialOwner("control", "en-UK", handler);
    List<TaskSummary> sums = handler.getResults();
    assertNotNull(sums);
    assertEquals(1, sums.size());

    BlockingTaskOperationResponseHandler startTaskOperationHandler =
        new BlockingTaskOperationResponseHandler();
    client.start(sums.get(0).getId(), "control", startTaskOperationHandler);

    BlockingGetTaskResponseHandler getTaskHandler = new BlockingGetTaskResponseHandler();
    client.getTask(sums.get(0).getId(), getTaskHandler);
    Task controlTask = getTaskHandler.getTask();

    BlockingGetContentResponseHandler getContentHandler = new BlockingGetContentResponseHandler();
    client.getContent(controlTask.getTaskData().getDocumentContentId(), getContentHandler);
    Content content = getContentHandler.getContent();

    assertNotNull(content);

    ByteArrayInputStream bais = new ByteArrayInputStream(content.getContent());
    ObjectInputStream ois = new ObjectInputStream(bais);
    Map<String, Object> deserializedContent = (Map<String, Object>) ois.readObject();
    Emergency retrivedEmergency = (Emergency) deserializedContent.get("emergency");
    assertNotNull(retrivedEmergency);
    ActivePatients retrivedActivePatients =
        (ActivePatients) deserializedContent.get("activePatients");
    assertNotNull(retrivedActivePatients);
    assertEquals(1, retrivedActivePatients.size());
    SuggestedProcedures retrivedSuggestedProcedures =
        (SuggestedProcedures) deserializedContent.get("suggestedProcedures");
    assertNotNull(retrivedSuggestedProcedures);
    assertEquals(
        "[DefaultHeartAttackProcedure: ]",
        retrivedSuggestedProcedures.getSuggestedProceduresString());

    Map<String, Object> info = new HashMap<String, Object>();
    SelectedProcedures selectedProcedures = new SelectedProcedures(retrivedEmergency.getId());

    selectedProcedures.addSelectedProcedureName("DefaultHeartAttackProcedure");
    info.put("selectedProcedures", selectedProcedures);

    ContentData result = new ContentData();
    result.setAccessType(AccessType.Inline);
    result.setType("java.util.Map");
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(bos);
    out.writeObject(info);
    out.close();
    result.setContent(bos.toByteArray());

    BlockingTaskOperationResponseHandler completeTaskOperationHandler =
        new BlockingTaskOperationResponseHandler();
    client.complete(sums.get(0).getId(), "control", result, completeTaskOperationHandler);
  }
  private void doOperatorTask() throws ClassNotFoundException, IOException {
    BlockingTaskSummaryResponseHandler handler = new BlockingTaskSummaryResponseHandler();
    client.getTasksAssignedAsPotentialOwner("operator", "en-UK", handler);
    List<TaskSummary> sums = handler.getResults();
    assertNotNull(sums);
    assertEquals(1, sums.size());

    BlockingTaskOperationResponseHandler startTaskOperationHandler =
        new BlockingTaskOperationResponseHandler();
    client.start(sums.get(0).getId(), "operator", startTaskOperationHandler);

    BlockingGetTaskResponseHandler getTaskHandler = new BlockingGetTaskResponseHandler();
    client.getTask(sums.get(0).getId(), getTaskHandler);
    Task operatorTask = getTaskHandler.getTask();

    BlockingGetContentResponseHandler getContentHandler = new BlockingGetContentResponseHandler();
    client.getContent(operatorTask.getTaskData().getDocumentContentId(), getContentHandler);
    Content content = getContentHandler.getContent();

    assertNotNull(content);

    ByteArrayInputStream bais = new ByteArrayInputStream(content.getContent());
    ObjectInputStream ois = new ObjectInputStream(bais);
    Map<String, Object> deserializedContent = (Map<String, Object>) ois.readObject();
    Call restoredCall = (Call) deserializedContent.get("call");
    persistenceService.storeCall(restoredCall);

    Emergency emergency = new Emergency();

    emergency.setCall(restoredCall);

    emergency.setLocation(new Location(1, 2));
    emergency.setType(Emergency.EmergencyType.HEART_ATTACK);
    emergency.setNroOfPeople(1);
    persistenceService.storeEmergency(emergency);

    trackingService.attachEmergency(restoredCall.getId(), emergency.getId());

    Map<String, Object> info = new HashMap<String, Object>();
    info.put("emergency", emergency);

    ContentData result = new ContentData();
    result.setAccessType(AccessType.Inline);
    result.setType("java.util.Map");
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(bos);
    out.writeObject(info);
    out.close();
    result.setContent(bos.toByteArray());

    BlockingTaskOperationResponseHandler completeTaskOperationHandler =
        new BlockingTaskOperationResponseHandler();
    client.complete(sums.get(0).getId(), "operator", result, completeTaskOperationHandler);
  }
示例#11
0
 @Test
 public void testWriteRead() throws IOException {
   BeforeTimePredicate predicate = new BeforeTimePredicate(sevenDaysBefore);
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   DataOutputStream out = new DataOutputStream(baos);
   predicate.write(out);
   ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
   DataInputStream in = new DataInputStream(bais);
   BeforeTimePredicate read = new BeforeTimePredicate();
   read.readFields(in);
   assertEquals(predicate, read);
 }
示例#12
0
 @After
 public void tearDown() throws IOException {
   out.close();
   if (tajoCli != null) {
     tajoCli.close();
   }
 }
示例#13
0
 @Test
 public void testTimeZoneSessionVars2() throws Exception {
   tajoCli.executeScript("SET TIME ZONE 'GMT+2'");
   tajoCli.executeMetaCommand("\\set");
   String output = new String(out.toByteArray());
   assertTrue(output.contains("'TIMEZONE'='GMT+2'"));
 }
示例#14
0
  // Test the change plan when trying to change a student plan
  @Test
  public void transferpairtest() {
    Backend b = new Backend();
    String[] args = new String[1];
    args[0] = "MasterBankAccounts.txt";

    tlist.clear();

    Transaction t = new Transaction();
    t.setCode("10");
    t.setMisc("A");
    t.setName("");

    Transaction t2 = new Transaction();
    t2.setCode("02");
    t2.setNum("00005");

    Transaction t3 = new Transaction();
    t3.setCode("00");

    tlist.add(t);
    tlist.add(t2);
    tlist.add(t3);

    b.load(args);
    b.setTransactions(tlist);
    b.handletransactions();
    assertEquals("Transfer transactions must come in pairs\n", outContent.toString());
  }
示例#15
0
 @Test
 public void dataRoundTrip() throws IOException {
   dos.writeUTF("Hello, world!");
   dos.writeInt(0xCAFEBABE);
   dos.writeUTF("Over & out.");
   dos.close();
   //    aos.close(); // important?
   byte[] bs = bos.toByteArray();
   if (verbose) {
     for (int i = 0; i < bs.length; i++) {
       System.out.printf("%02x ", bs[i]);
       if (i % 16 == 15) System.out.println();
     }
     System.out.println();
   }
   PPMModel pi = new PPMModel(4);
   ByteArrayInputStream bis = new ByteArrayInputStream(bs);
   ArithCodeInputStream ais = new ArithCodeInputStream(bis, pi);
   DataInputStream dis = new DataInputStream(ais);
   String s1 = dis.readUTF();
   assert s1.equals("Hello, world!") : s1;
   int i1 = dis.readInt();
   assert 0xCAFEBABE == i1 : i1;
   String s2 = dis.readUTF();
   assert s2.equals("Over & out.") : s2;
   int i2 = dis.read();
   assert -1 == i2 : i2;
 }
示例#16
0
  private UciProtocol createUciProtocol(String[] commands) {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    PrintStream stream = new PrintStream(buffer);
    try {
      for (String command : commands) {
        stream.println(command);
      }
    } finally {
      if (stream != null) {
        stream.close();
      }
    }

    return new UciProtocol(
        new BufferedReader(new InputStreamReader(new ByteArrayInputStream(buffer.toByteArray()))),
        new PrintStream(new ByteArrayOutputStream()));
  }
示例#17
0
  @Test
  public void testGetConf() throws Exception {
    TajoConf tajoConf = TpchTestBase.getInstance().getTestingCluster().getConfiguration();
    setVar(tajoCli, SessionVars.CLI_FORMATTER_CLASS, TajoCliOutputTestFormatter.class.getName());

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    TajoCli tajoCli = new TajoCli(tajoConf, new String[] {}, System.in, out);
    try {
      tajoCli.executeMetaCommand("\\getconf tajo.rootdir");

      String consoleResult = new String(out.toByteArray());
      assertEquals(
          consoleResult, tajoCli.getContext().getConf().getVar(TajoConf.ConfVars.ROOT_DIR) + "\n");
    } finally {
      tajoCli.close();
    }
  }
  /** code should end smoothly if it encounters no matches between bib and mhld */
  @Test
  public void testNoOutputMessagesWhenNoMatches() throws IOException {
    // bib46, mhld235
    String bibFilePath = testDataParentPath + File.separator + "mhldMergeBibs46.mrc";
    String mhldFilePath = testDataParentPath + File.separator + "mhldMergeMhlds235.mrc";

    // ensure no error message was printed
    ByteArrayOutputStream sysBAOS = new ByteArrayOutputStream();

    mergeBibAndMhldFiles(bibFilePath, mhldFilePath, sysBAOS);

    // ensure no error message was printed
    assertTrue(
        "Output messages written when none were expected: " + sysBAOS.toString(),
        sysBAOS.size() == 0);
    System.out.println("Test testNoOutputMessagesWhenNoMatches() successful");
  }
示例#19
0
  @Test
  public void testProtocolReadyAnswerCommand() throws IOException {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    UciProtocol protocol =
        new UciProtocol(
            new BufferedReader(new InputStreamReader(new ByteArrayInputStream("".getBytes()))),
            new PrintStream(buffer));

    ProtocolReadyAnswerCommand command = new ProtocolReadyAnswerCommand("does not matter");
    protocol.send(command);

    BufferedReader input =
        new BufferedReader(new InputStreamReader(new ByteArrayInputStream(buffer.toByteArray())));
    String line = input.readLine();
    assertEquals("readyok", line);
    assertNull(input.readLine());
  }
示例#20
0
  @Test
  public void testShowMasters() throws Exception {
    TajoConf tajoConf = TpchTestBase.getInstance().getTestingCluster().getConfiguration();
    setVar(tajoCli, SessionVars.CLI_FORMATTER_CLASS, TajoCliOutputTestFormatter.class.getName());

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    TajoCli tajoCli = new TajoCli(tajoConf, new String[] {}, System.in, out);
    tajoCli.executeMetaCommand("\\admin -showmasters");

    String consoleResult = new String(out.toByteArray());

    String masterAddress =
        tajoCli.getContext().getConf().getVar(TajoConf.ConfVars.TAJO_MASTER_UMBILICAL_RPC_ADDRESS);
    String host = masterAddress.split(":")[0];
    tajoCli.close();
    assertEquals(consoleResult, host + "\n");
  }
示例#21
0
  @Test
  public void testLocalQueryWithoutFrom() throws Exception {
    String sql = "select 'abc', '123'; select substr('123456', 1,3);";
    setVar(tajoCli, SessionVars.CLI_FORMATTER_CLASS, TajoCliOutputTestFormatter.class.getName());
    tajoCli.executeScript(sql);
    String consoleResult = new String(out.toByteArray());

    assertOutputResult(consoleResult);
  }
示例#22
0
 @Test
 public void testTimeZoneTest2() throws Exception {
   String tableName = "test1";
   tajoCli.executeMetaCommand("\\set TIMEZONE GMT+1");
   tajoCli.executeScript("create table " + tableName + " (col1 TIMESTAMP)");
   tajoCli.executeScript("insert into " + tableName + " select to_timestamp(0)");
   tajoCli.executeScript("select * from " + tableName);
   String consoleResult = new String(out.toByteArray());
   tajoCli.executeScript("DROP TABLE " + tableName + " PURGE");
   assertTrue(consoleResult.contains("1970-01-01 01:00:00"));
 }
  private void runStreamTest(final int pLength) throws Exception {
    byte[] data = createData(pLength);
    ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
    OutputStream out = new EncoderStream(outBytes, createEncoder(), true);

    try {
      // Provoke failure for encoders that doesn't take array offset properly into account
      int off = (data.length + 1) / 2;
      out.write(data, 0, off);
      if (data.length > off) {
        out.write(data, off, data.length - off);
      }
    } finally {
      out.close();
    }

    byte[] encoded = outBytes.toByteArray();

    //        System.err.println("encoded.length: " + encoded.length);
    //        System.err.println("encoded: " + Arrays.toString(encoded));

    byte[] decoded =
        FileUtil.read(
            new DecoderStream(new ByteArrayInputStream(encoded), createCompatibleDecoder()));
    assertTrue(Arrays.equals(data, decoded));

    InputStream in =
        new DecoderStream(new ByteArrayInputStream(encoded), createCompatibleDecoder());
    outBytes = new ByteArrayOutputStream();

    try {
      FileUtil.copy(in, outBytes);
    } finally {
      outBytes.close();
      in.close();
    }

    decoded = outBytes.toByteArray();
    assertTrue(Arrays.equals(data, decoded));
  }
示例#24
0
  private void verifyStopWhenError() throws Exception {
    setVar(tajoCli, SessionVars.CLI_FORMATTER_CLASS, TajoCliOutputTestFormatter.class.getName());

    assertSessionVar(tajoCli, SessionVars.ON_ERROR_STOP.keyname(), "true");

    tajoCli.executeScript(
        "select count(*) from lineitem; "
            + "select count(*) from lineitem2; "
            + "select count(*) from orders");

    String consoleResult = new String(out.toByteArray());
    assertOutputResult(consoleResult);
  }
  @FixFor("MODE-1308")
  @Test
  public void shouldAllowAnyBinaryImplementation() throws Exception {
    Node node = rootNode.addNode("nodeWithBinaryProperty", "nt:unstructured");
    final String stringValue = "This is the string stringValue";
    Binary binaryValue =
        new Binary() {
          public InputStream getStream() throws RepositoryException {
            return new ByteArrayInputStream(stringValue.getBytes());
          }

          public int read(byte[] b, long position) throws IOException, RepositoryException {
            byte[] content = stringValue.getBytes();
            int length =
                b.length + position < content.length ? b.length : (int) (content.length - position);
            System.arraycopy(content, (int) position, b, 0, length);
            return length;
          }

          public long getSize() throws RepositoryException {
            return stringValue.getBytes().length;
          }

          public void dispose() {}
        };
    node.setProperty("binProp", binaryValue);
    Binary nodeValue = node.getProperty("binProp").getBinary();
    assertNotNull(nodeValue);
    assertEquals(stringValue.getBytes().length, nodeValue.getSize());
    byte[] buffer = new byte[100];
    int available;
    InputStream inputStream = nodeValue.getStream();
    ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
    while ((available = inputStream.read(buffer)) != -1) {
      byteOut.write(buffer, 0, available);
    }
    assertArrayEquals(stringValue.getBytes(), byteOut.toByteArray());
  }
  @Test
  public void testSomething() throws FileNotFoundException, UnsupportedEncodingException {
    DefaultResultFormater defaultResultFormater = new DefaultResultFormater();
    defaultResultFormater.AddSuiteResult(suiteResult);

    ByteArrayOutputStream output = new ByteArrayOutputStream();
    String expectedString =
        "[anonymous]\r\n"
            + "Tests executed:3\r\n"
            + "Tests failed:1\r\n"
            + "\r\n"
            + "{anonymous}\r\n"
            + "0: <open> url='http://google.com'\r\n"
            + "1: <open> url='http://google.com'\r\n\r\n\r\n\n";

    PrintStream out = new PrintStream(output);
    PrintStream backUp = System.out;
    System.setOut(out);
    defaultResultFormater.Process();
    System.setOut(backUp);

    String outputString = output.toString("UTF8");
    assertEquals(expectedString, outputString);
  }
示例#27
0
  @Test
  public void testSelectResultWithNullFalse() throws Exception {
    String sql =
        "select\n"
            + "  c_custkey,\n"
            + "  orders.o_orderkey,\n"
            + "  orders.o_orderstatus \n"
            + "from\n"
            + "  orders full outer join customer on c_custkey = o_orderkey\n"
            + "order by\n"
            + "  c_custkey,\n"
            + "  orders.o_orderkey;\n";

    setVar(tajoCli, SessionVars.CLI_FORMATTER_CLASS, TajoCliOutputTestFormatter.class.getName());
    tajoCli.executeScript(sql);

    String consoleResult = new String(out.toByteArray());
    assertOutputResult(consoleResult);
  }
示例#28
0
  private void verifyDescTable(String sql, String tableName, String resultFileName)
      throws Exception {
    setVar(tajoCli, SessionVars.CLI_FORMATTER_CLASS, TajoCliOutputTestFormatter.class.getName());
    tajoCli.executeScript(sql);

    tajoCli.executeMetaCommand("\\d " + tableName);
    tajoCli.executeMetaCommand("\\d \"" + tableName + "\"");

    String consoleResult = new String(out.toByteArray());

    if (!cluster.isHiveCatalogStoreRunning()) {
      assertOutputResult(
          resultFileName,
          consoleResult,
          new String[] {"${table.path}"},
          new String[] {
            TablespaceManager.getDefault().getTableUri("default", tableName).toString()
          });
    }
  }
示例#29
0
  @Test
  public void testAlterTableAddDropPartition() throws Exception {
    String tableName = CatalogUtil.normalizeIdentifier("testAlterTableAddPartition");

    tajoCli.executeScript(
        "create table " + tableName + " (col1 int4, col2 int4) partition by column(key float8)");
    tajoCli.executeScript("alter table " + tableName + " add partition (key2 = 0.1)");
    tajoCli.executeScript("alter table " + tableName + " add partition (key = 0.1)");
    tajoCli.executeScript("alter table " + tableName + " drop partition (key = 0.1)");
    tajoCli.executeScript("alter table " + tableName + " drop partition (key = 0.1)");

    tajoCli.executeScript("drop table " + tableName);
    tajoCli.executeScript(
        "create table "
            + tableName
            + " (col1 int4, col2 int4) partition by column(col3 float8, col4 int4)");

    TajoClient client = testBase.getTestingCluster().newTajoClient();
    TableDesc tableDesc = client.getTableDesc(tableName);

    String partitionLocation = tableDesc.getUri().toString() + "/col5=0.1/col6=10";
    tajoCli.executeScript(
        "alter table "
            + tableName
            + " add partition (col3 = 0.1, col4 = 10)"
            + " location '"
            + partitionLocation
            + "'");

    Path partitionPath = new Path(partitionLocation);
    FileSystem fs = testBase.getTestingCluster().getDefaultFileSystem();
    assertTrue(fs.exists(partitionPath));

    tajoCli.executeScript("alter table " + tableName + " drop partition (col3 = 0.1, col4 = 10)");

    String consoleResult = new String(out.toByteArray());
    assertOutputResult(consoleResult);
  }
示例#30
0
  @Test(timeout = 3000)
  public void testNonForwardQueryPause() throws Exception {
    final String sql = "select * from default.lineitem";
    TajoCli cli = null;
    try {
      TableDesc tableDesc = cluster.getMaster().getCatalog().getTableDesc("default", "lineitem");
      assertNotNull(tableDesc);
      assertEquals(0L, tableDesc.getStats().getNumRows().longValue());

      InputStream testInput =
          new ByteArrayInputStream(new byte[] {(byte) DefaultTajoCliOutputFormatter.QUIT_COMMAND});
      cli = new TajoCli(cluster.getConfiguration(), new String[] {}, testInput, out);
      setVar(cli, SessionVars.CLI_PAGE_ROWS, "2");
      setVar(cli, SessionVars.CLI_FORMATTER_CLASS, TajoCliOutputTestFormatter.class.getName());

      cli.executeScript(sql);

      String consoleResult;
      consoleResult = new String(out.toByteArray());
      assertOutputResult(consoleResult);
    } finally {
      cli.close();
    }
  }