Ejemplo n.º 1
0
  @Test
  public void testTransportFailure() throws Exception {
    HCatClient client = HCatClient.create(new Configuration(hcatConf));
    boolean isExceptionCaught = false;
    // Table creation with a long table name causes ConnectionFailureException
    final String tableName = "Temptable" + new BigInteger(200, new Random()).toString(2);

    ArrayList<HCatFieldSchema> cols = new ArrayList<HCatFieldSchema>();
    cols.add(new HCatFieldSchema("id", Type.INT, "id columns"));
    cols.add(new HCatFieldSchema("value", Type.STRING, "id columns"));
    try {
      HCatCreateTableDesc tableDesc =
          HCatCreateTableDesc.create(null, tableName, cols).fileFormat("rcfile").build();
      client.createTable(tableDesc);
    } catch (Exception exp) {
      isExceptionCaught = true;
      assertEquals("Unexpected exception type.", HCatException.class, exp.getClass());
      // The connection was closed, so create a new one.
      client = HCatClient.create(new Configuration(hcatConf));
      String newName = "goodTable";
      client.dropTable(null, newName, true);
      HCatCreateTableDesc tableDesc2 =
          HCatCreateTableDesc.create(null, newName, cols).fileFormat("rcfile").build();
      client.createTable(tableDesc2);
      HCatTable newTable = client.getTable(null, newName);
      assertTrue(newTable != null);
      assertTrue(newTable.getTableName().equalsIgnoreCase(newName));

    } finally {
      client.close();
      assertTrue("The expected exception was never thrown.", isExceptionCaught);
    }
  }
Ejemplo n.º 2
0
 @Test
 public void testOtherFailure() throws Exception {
   HCatClient client = HCatClient.create(new Configuration(hcatConf));
   String tableName = "Temptable";
   boolean isExceptionCaught = false;
   client.dropTable(null, tableName, true);
   ArrayList<HCatFieldSchema> cols = new ArrayList<HCatFieldSchema>();
   cols.add(new HCatFieldSchema("id", Type.INT, "id columns"));
   cols.add(new HCatFieldSchema("value", Type.STRING, "id columns"));
   try {
     HCatCreateTableDesc tableDesc =
         HCatCreateTableDesc.create(null, tableName, cols).fileFormat("rcfile").build();
     client.createTable(tableDesc);
     // The DB foo is non-existent.
     client.getTable("foo", tableName);
   } catch (Exception exp) {
     isExceptionCaught = true;
     assertTrue(exp instanceof HCatException);
     String newName = "goodTable";
     client.dropTable(null, newName, true);
     HCatCreateTableDesc tableDesc2 =
         HCatCreateTableDesc.create(null, newName, cols).fileFormat("rcfile").build();
     client.createTable(tableDesc2);
     HCatTable newTable = client.getTable(null, newName);
     assertTrue(newTable != null);
     assertTrue(newTable.getTableName().equalsIgnoreCase(newName));
   } finally {
     client.close();
     assertTrue("The expected exception was never thrown.", isExceptionCaught);
   }
 }
Ejemplo n.º 3
0
 @Test
 public void testRenameTable() throws Exception {
   HCatClient client = HCatClient.create(new Configuration(hcatConf));
   String tableName = "temptable";
   String newName = "mytable";
   client.dropTable(null, tableName, true);
   client.dropTable(null, newName, true);
   ArrayList<HCatFieldSchema> cols = new ArrayList<HCatFieldSchema>();
   cols.add(new HCatFieldSchema("id", Type.INT, "id columns"));
   cols.add(new HCatFieldSchema("value", Type.STRING, "id columns"));
   HCatCreateTableDesc tableDesc =
       HCatCreateTableDesc.create(null, tableName, cols).fileFormat("rcfile").build();
   client.createTable(tableDesc);
   client.renameTable(null, tableName, newName);
   try {
     client.getTable(null, tableName);
   } catch (HCatException exp) {
     assertTrue(
         "Unexpected exception message: " + exp.getMessage(),
         exp.getMessage().contains("NoSuchObjectException while fetching table"));
   }
   HCatTable newTable = client.getTable(null, newName);
   assertTrue(newTable != null);
   assertTrue(newTable.getTableName().equals(newName));
   client.close();
 }