Ejemplo n.º 1
0
  @Test
  public void testSkippingHeaderWithText() throws IOException {
    TableMeta meta = CatalogUtil.newTableMeta("TEXT");
    meta.putOption(StorageConstants.TEXT_SKIP_HEADER_LINE, "1");
    meta.putOption(StorageConstants.TEXT_DELIMITER, ",");
    FileFragment fragment = getFileFragment("testSkip.txt");
    Scanner scanner = TablespaceManager.getLocalFs().getScanner(meta, schema, fragment);

    scanner.init();

    int lines = 0;

    try {
      while (true) {
        Tuple tuple = scanner.next();
        if (tuple != null) {
          assertEquals(17 + lines, tuple.getInt2(2));
          lines++;
        } else break;
      }
    } finally {
      assertEquals(6, lines);
      scanner.close();
    }
  }
Ejemplo n.º 2
0
 @Test
 public void testAddSingle() {
   Tuple tuple = new Tuple();
   Single single = new Single("single", 4711);
   tuple.addSingle(single);
   assertEquals(1, tuple.getSingleList().size());
   assertEquals(single, tuple.getSingleAt(0));
   assertEquals("(no name): (single = 4711) ", tuple.toString());
 }
  @Test
  public void new_fieldsTest() {
    int length = 10;
    String name = "td";
    Tuple t = new Tuple(Utility.getTupleDesc(length, name));

    Iterator<Field> fs = t.fields();

    int i = 0;
    while (fs.hasNext()) {
      i++;
      fs.next();
    }

    assertEquals(length, i);
  }
  /** Unit test for Tuple.getRecordId() and Tuple.setRecordId() */
  @Test
  public void modifyRecordId() {
    Tuple tup1 = new Tuple(Utility.getTupleDesc(1));
    HeapPageId pid1 = new HeapPageId(0, 0);
    RecordId rid1 = new RecordId(pid1, 0);
    tup1.setRecordId(rid1);

    try {
      assertEquals(rid1, tup1.getRecordId());
    } catch (java.lang.UnsupportedOperationException e) {
      // rethrow the exception with an explanation
      throw new UnsupportedOperationException(
          "modifyRecordId() test failed due to "
              + "RecordId.equals() not being implemented.  This is not required for Lab 1, "
              + "but should pass when you do implement the RecordId class.");
    }
  }
  /** Unit test for Tuple.getField() and Tuple.setField() */
  @Test
  public void modifyFields() {
    TupleDesc td = Utility.getTupleDesc(2);

    Tuple tup = new Tuple(td);
    tup.setField(0, new IntField(-1));
    tup.setField(1, new IntField(0));

    assertEquals(new IntField(-1), tup.getField(0));
    assertEquals(new IntField(0), tup.getField(1));

    tup.setField(0, new IntField(1));
    tup.setField(1, new IntField(37));

    assertEquals(new IntField(1), tup.getField(0));
    assertEquals(new IntField(37), tup.getField(1));
  }
  @Test
  public void new_toStringTest() {
    int length = 10;
    String name = "td";
    Tuple t = new Tuple(Utility.getTupleDesc(length, name));
    for (int i = 0; i < length; i++) {
      t.setField(i, new TestField());
    }

    String tString = t.toString();

    // Last character should be \n.
    assertEquals("\n", tString.substring(tString.length() - 1));

    // Only last character is \n.
    assertFalse(tString.substring(0, tString.length() - 1).contains("\n"));

    // Split string on any white character.
    String[] tStringAr = tString.substring(0, tString.length() - 1).split("\\s+");
    assertEquals(length, tStringAr.length);
  }
Ejemplo n.º 7
0
 @Test
 public void testSetters() {
   Tuple tuple = new Tuple();
   tuple.setName("name");
   assertEquals("name", tuple.getName());
   List<Single> initList = new ArrayList<Single>();
   Single single = new Single("single", 4711);
   initList.add(single);
   tuple.setSingleList(initList);
   assertEquals(initList, tuple.getSingleList());
   assertEquals(single, tuple.getSingleAt(0));
   assertEquals("name: (single = 4711) ", tuple.toString());
 }
Ejemplo n.º 8
0
  @Test
  public void testCreate() {
    Tuple tuple = new Tuple();
    assertNull(tuple.getName());
    assertEquals(0, tuple.getSingleList().size());
    assertEquals("empty tuple with name (no name)", tuple.toString());

    Tuple namedTuple = new Tuple("name");
    assertEquals("name", namedTuple.getName());
    assertEquals(0, namedTuple.getSingleList().size());
    assertEquals("empty tuple with name name", namedTuple.toString());

    List<Single> initList = new ArrayList<Single>();
    Tuple initTuple = new Tuple("name", initList);
    assertEquals("name", initTuple.getName());
    assertTrue(initList == initTuple.getSingleList());
    assertEquals("empty tuple with name name", initTuple.toString());
  }
 /** Unit test for Tuple.getTupleDesc() */
 @Test
 public void getTupleDesc() {
   TupleDesc td = Utility.getTupleDesc(5);
   Tuple tup = new Tuple(td);
   assertEquals(td, tup.getTupleDesc());
 }