示例#1
0
  @Test
  public void testConnProperties() throws Exception {
    Map<String, String> connProperties = new HashMap<>();
    connProperties.put("user", "postgres");
    connProperties.put("password", "");

    String uri = PgSQLTestServer.getInstance().getJdbcUrl().split("\\?")[0];
    Tablespace space =
        new PgSQLTablespace("t1", URI.create(uri), getJsonTablespace(connProperties));
    try {
      space.init(new TajoConf());
    } finally {
      space.close();
    }
  }
示例#2
0
  @Test
  public void testConnPropertiesNegative() throws Exception {
    Map<String, String> connProperties = new HashMap<>();
    connProperties.put("user", "postgresX");
    connProperties.put("password", "");

    String uri = PgSQLTestServer.getInstance().getJdbcUrl().split("\\?")[0];
    Tablespace space =
        new PgSQLTablespace("t1", URI.create(uri), getJsonTablespace(connProperties));
    try {
      space.init(new TajoConf());
      fail("Must be failed");
    } catch (IOException ioe) {
      assertTrue(ioe.getCause() instanceof PSQLException);
    } finally {
      space.close();
    }
  }
public class TestPgSQLEndPointTests extends QueryTestCaseBase {
  private static final String jdbcUrl = PgSQLTestServer.getInstance().getJdbcUrlForAdmin();
  private static TajoClient client;

  @BeforeClass
  public static void setUp() throws Exception {
    QueryTestCaseBase.testingCluster.getMaster().refresh();
    client = QueryTestCaseBase.testingCluster.newTajoClient();
  }

  @AfterClass
  public static void tearDown() {
    client.close();
  }

  @Test(timeout = 1000)
  public void testGetAllDatabaseNames() {
    Set<String> retrieved = Sets.newHashSet(client.getAllDatabaseNames());
    assertTrue(retrieved.contains(PgSQLTestServer.DATABASE_NAME));
  }

  @Test(timeout = 1000)
  public void testGetTableList() {
    final Set<String> expected = Sets.newHashSet(PgSQLTestServer.TPCH_TABLES);
    expected.add("datetime_types");
    final Set<String> retrieved = Sets.newHashSet(client.getTableList("tpch"));

    assertEquals(expected, retrieved);
  }

  @Test(timeout = 1000)
  public void testGetTable() throws UndefinedTableException {
    for (String tableName : PgSQLTestServer.TPCH_TABLES) {
      TableDesc retrieved = client.getTableDesc(PgSQLTestServer.DATABASE_NAME + "." + tableName);
      assertEquals(PgSQLTestServer.DATABASE_NAME + "." + tableName, retrieved.getName());
      assertEquals(jdbcUrl + "&table=" + tableName, retrieved.getUri().toASCIIString());
    }
  }
}
示例#4
0
public class TestPgSQLJdbcTableSpace {
  static String jdbcUrl = PgSQLTestServer.getInstance().getJdbcUrlForAdmin();

  @Test(timeout = 1000)
  public void testTablespaceHandler() throws Exception {
    assertTrue((TablespaceManager.getByName("pgsql_cluster")) instanceof PgSQLTablespace);
    assertEquals("pgsql_cluster", (TablespaceManager.getByName("pgsql_cluster").getName()));

    assertTrue((TablespaceManager.get(jdbcUrl)) instanceof PgSQLTablespace);
    assertTrue((TablespaceManager.get(jdbcUrl + "&table=tb1")) instanceof PgSQLTablespace);

    assertEquals(jdbcUrl, TablespaceManager.get(jdbcUrl).getUri().toASCIIString());
    assertTrue(
        TablespaceManager.get(jdbcUrl).getMetadataProvider() instanceof PgSQLMetadataProvider);
  }

  @Test(timeout = 1000, expected = TajoRuntimeException.class)
  public void testCreateTable() throws IOException, TajoException {
    Tablespace space = TablespaceManager.getByName("pgsql_cluster");
    space.createTable(null, false);
  }

  @Test(timeout = 1000, expected = TajoRuntimeException.class)
  public void testDropTable() throws IOException, TajoException {
    Tablespace space = TablespaceManager.getByName("pgsql_cluster");
    space.purgeTable(null);
  }

  @Test(timeout = 1000)
  public void testGetSplits() throws IOException, TajoException {
    Tablespace space = TablespaceManager.getByName("pgsql_cluster");
    MetadataProvider provider = space.getMetadataProvider();
    TableDesc table = provider.getTableDesc(null, "lineitem");
    List<Fragment> fragments = space.getSplits("lineitem", table, null);
    assertNotNull(fragments);
    assertEquals(1, fragments.size());
  }

  @Test
  public void testConnProperties() throws Exception {
    Map<String, String> connProperties = new HashMap<>();
    connProperties.put("user", "postgres");
    connProperties.put("password", "");

    String uri = PgSQLTestServer.getInstance().getJdbcUrl().split("\\?")[0];
    Tablespace space =
        new PgSQLTablespace("t1", URI.create(uri), getJsonTablespace(connProperties));
    try {
      space.init(new TajoConf());
    } finally {
      space.close();
    }
  }

  @Test
  public void testConnPropertiesNegative() throws Exception {
    Map<String, String> connProperties = new HashMap<>();
    connProperties.put("user", "postgresX");
    connProperties.put("password", "");

    String uri = PgSQLTestServer.getInstance().getJdbcUrl().split("\\?")[0];
    Tablespace space =
        new PgSQLTablespace("t1", URI.create(uri), getJsonTablespace(connProperties));
    try {
      space.init(new TajoConf());
      fail("Must be failed");
    } catch (IOException ioe) {
      assertTrue(ioe.getCause() instanceof PSQLException);
    } finally {
      space.close();
    }
  }

  public static JSONObject getJsonTablespace(Map<String, String> connProperties)
      throws IOException {
    JSONObject configElements = new JSONObject();
    configElements.put(JdbcTablespace.CONFIG_KEY_MAPPED_DATABASE, PgSQLTestServer.DATABASE_NAME);

    JSONObject connPropertiesJson = new JSONObject();
    for (Map.Entry<String, String> entry : connProperties.entrySet()) {
      connPropertiesJson.put(entry.getKey(), entry.getValue());
    }
    configElements.put(JdbcTablespace.CONFIG_KEY_CONN_PROPERTIES, connPropertiesJson);

    return configElements;
  }

  @Test
  public void testTemporaryTablespace() {
    Optional<Tablespace> ts = TablespaceManager.removeTablespaceForTest("pgsql_cluster");
    assertTrue(ts.isPresent());

    Tablespace tempTs = TablespaceManager.get(jdbcUrl);
    assertNotNull(tempTs);

    TablespaceManager.addTableSpaceForTest(ts.get());
  }
}