Search in sources :

Example 16 with CatalogEntity

use of io.prestosql.spi.metastore.model.CatalogEntity in project hetu-core by openlookeng.

the class TestJdbcHetuMetastore method testAlterCatalog.

/**
 * test alter catalog
 */
@Test
public void testAlterCatalog() {
    String oldCatalogName = "catalog5";
    CatalogEntity catalog5 = CatalogEntity.builder().setCatalogName(oldCatalogName).setOwner("root8").setComment(Optional.of("mysql3 database source")).setParameters(emptyMap()).setCreateTime(System.currentTimeMillis()).build();
    metastore.createCatalog(catalog5);
    Map<String, String> properties = ImmutableMap.<String, String>builder().put("url11", "117.0.0.1").put("user1", "testcreate").build();
    CatalogEntity catalog6 = CatalogEntity.builder().setCatalogName("catalog6").setOwner("root9").setComment(Optional.of("mysql5 database source")).setParameters(properties).setCreateTime(System.currentTimeMillis()).build();
    try {
        metastore.alterCatalog(oldCatalogName, catalog6);
        fail("Cannot alter a catalog's name");
    } catch (PrestoException e) {
        assertEquals(e.getErrorCode(), HETU_METASTORE_CODE.toErrorCode());
    }
    try {
        metastore.alterCatalog(catalog6.getName(), catalog6);
        fail(format("Catalog '%s' does not exist:", catalog6.getName()));
    } catch (PrestoException e) {
        assertEquals(e.getErrorCode(), HETU_METASTORE_CODE.toErrorCode());
    }
    catalog6.setName(oldCatalogName);
    metastore.alterCatalog(oldCatalogName, catalog6);
    Optional<CatalogEntity> catalog7 = metastore.getCatalog(catalog6.getName());
    assertTrue(catalog7.isPresent());
    assertCatalogEquals(catalog7.get(), catalog6);
    assertEquals(catalog7.get().getCreateTime(), catalog5.getCreateTime());
}
Also used : CatalogEntity(io.prestosql.spi.metastore.model.CatalogEntity) PrestoException(io.prestosql.spi.PrestoException) Test(org.testng.annotations.Test)

Example 17 with CatalogEntity

use of io.prestosql.spi.metastore.model.CatalogEntity in project hetu-core by openlookeng.

the class TestHetuFsMetastore method testAlterCatalog.

/**
 * test alter catalog
 */
@Test
public void testAlterCatalog() {
    String oldCatalogName = "catalog5";
    CatalogEntity catalog5 = CatalogEntity.builder().setCatalogName(oldCatalogName).setOwner("root8").setComment(Optional.of("mysql3 database source")).setParameters(emptyMap()).setCreateTime(System.currentTimeMillis()).build();
    metastore.createCatalog(catalog5);
    Map<String, String> properties = ImmutableMap.<String, String>builder().put("url11", "117.0.0.1").put("user1", "testcreate").build();
    CatalogEntity catalog6 = CatalogEntity.builder().setCatalogName("catalog6").setOwner("root9").setComment(Optional.of("mysql5 database source")).setParameters(properties).setCreateTime(System.currentTimeMillis()).build();
    try {
        metastore.alterCatalog(oldCatalogName, catalog6);
        fail("Cannot alter a catalog's name");
    } catch (PrestoException e) {
        assertEquals(e.getErrorCode(), HETU_METASTORE_CODE.toErrorCode());
    }
    try {
        metastore.alterCatalog(catalog6.getName(), catalog6);
        fail(format("Catalog '%s' does not exist:", catalog6.getName()));
    } catch (PrestoException e) {
        assertEquals(e.getErrorCode(), NOT_FOUND.toErrorCode());
    }
    catalog6.setName(oldCatalogName);
    metastore.alterCatalog(oldCatalogName, catalog6);
    Optional<CatalogEntity> catalog7 = metastore.getCatalog(catalog6.getName());
    assertTrue(catalog7.isPresent());
    assertCatalogEquals(catalog7.get(), catalog6);
    assertEquals(catalog7.get().getCreateTime(), catalog5.getCreateTime());
}
Also used : CatalogEntity(io.prestosql.spi.metastore.model.CatalogEntity) PrestoException(io.prestosql.spi.PrestoException) Test(org.testng.annotations.Test)

Example 18 with CatalogEntity

use of io.prestosql.spi.metastore.model.CatalogEntity in project hetu-core by openlookeng.

the class TestHetuFsMetastore method testCreateCatalog.

/**
 * test create catalog
 */
@Test
public void testCreateCatalog() {
    Map<String, String> properties = ImmutableMap.<String, String>builder().build();
    CatalogEntity vdm = CatalogEntity.builder().setCatalogName("catalog1").setOwner("root1").setComment(Optional.of("Hetu VDM")).setParameters(properties).setCreateTime(System.currentTimeMillis()).build();
    metastore.createCatalog(vdm);
    CatalogEntity vdm1 = CatalogEntity.builder().setCatalogName("catalog2").setOwner("root2").setComment(Optional.of("Hetu VDM")).setParameters(emptyMap()).setCreateTime(System.currentTimeMillis()).build();
    metastore.createCatalog(vdm1);
    try {
        metastore.createCatalog(vdm);
        fail("expected exception");
    } catch (PrestoException e) {
        assertEquals(e.getErrorCode(), ALREADY_EXISTS.toErrorCode());
    }
    metastore.dropCatalog(vdm.getName());
    metastore.dropCatalog(vdm1.getName());
}
Also used : CatalogEntity(io.prestosql.spi.metastore.model.CatalogEntity) PrestoException(io.prestosql.spi.PrestoException) Test(org.testng.annotations.Test)

Example 19 with CatalogEntity

use of io.prestosql.spi.metastore.model.CatalogEntity in project hetu-core by openlookeng.

the class TestHetuFsMetastore method testGetAllCatalogs.

/**
 * test get All catalogs
 */
@Test
public void testGetAllCatalogs() {
    Map<String, String> properties = ImmutableMap.<String, String>builder().put("hive.metastore", "130.0.0.1").put("hive.config", "hdfs-site.xml").build();
    CatalogEntity catalog2 = CatalogEntity.builder().setCatalogName("catalog2").setOwner("root6").setComment(Optional.of("mysql database source")).setParameters(properties).setCreateTime(System.currentTimeMillis()).build();
    metastore.createCatalog(catalog2);
    CatalogEntity catalog3 = CatalogEntity.builder().setCatalogName("catalog3").setOwner("root7").setComment(Optional.of("mysql1 database source")).setParameters(emptyMap()).setCreateTime(System.currentTimeMillis()).build();
    metastore.createCatalog(catalog3);
    CatalogEntity catalog4 = CatalogEntity.builder().setCatalogName("catalog4").setOwner("root8").setComment(Optional.of("oracle database source")).setParameters(emptyMap()).setCreateTime(System.currentTimeMillis()).build();
    metastore.createCatalog(catalog4);
    final int catalogNumer = 3;
    assertTrue(metastore.getCatalogs().size() > catalogNumer);
    List<CatalogEntity> catalogs = new ArrayList<>();
    metastore.getCatalogs().stream().forEach(catalog -> {
        String name = catalog.getName();
        if (name.equals(catalog2.getName()) || name.equals(catalog3.getName()) || name.equals(catalog4.getName())) {
            catalogs.add(catalog);
        }
    });
    Collections.sort(catalogs, new Comparator<CatalogEntity>() {

        @Override
        public int compare(CatalogEntity o1, CatalogEntity o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });
    assertEquals(ImmutableList.copyOf(catalogs), ImmutableList.of(catalog2, catalog3, catalog4));
}
Also used : ArrayList(java.util.ArrayList) CatalogEntity(io.prestosql.spi.metastore.model.CatalogEntity) Test(org.testng.annotations.Test)

Example 20 with CatalogEntity

use of io.prestosql.spi.metastore.model.CatalogEntity in project hetu-core by openlookeng.

the class TestHetuFsMetastore method testCreateCatalogParallel.

/**
 * test create catalog parallel
 */
@Test
public void testCreateCatalogParallel() throws InterruptedException {
    Map<String, String> properties = ImmutableMap.<String, String>builder().build();
    CatalogEntity catalog = CatalogEntity.builder().setCatalogName("catalog100").setOwner("root1").setComment(Optional.of("create catalog parallel")).setParameters(properties).setCreateTime(System.currentTimeMillis()).build();
    testResult = true;
    Thread[] threads = new Thread[5];
    for (int i = 0; i < 5; i++) {
        threads[i] = new Thread(() -> {
            try {
                metastore.createCatalogIfNotExist(catalog);
            } catch (PrestoException e) {
                testResult = false;
            }
        });
        threads[i].start();
    }
    for (Thread thread : threads) {
        thread.join();
    }
    assertTrue(testResult);
    metastore.dropCatalog(catalog.getName());
}
Also used : CatalogEntity(io.prestosql.spi.metastore.model.CatalogEntity) PrestoException(io.prestosql.spi.PrestoException) Test(org.testng.annotations.Test)

Aggregations

CatalogEntity (io.prestosql.spi.metastore.model.CatalogEntity)34 Test (org.testng.annotations.Test)24 PrestoException (io.prestosql.spi.PrestoException)15 DatabaseEntity (io.prestosql.spi.metastore.model.DatabaseEntity)7 BeforeTest (org.testng.annotations.BeforeTest)5 ImmutableList (com.google.common.collect.ImmutableList)4 TableEntity (io.prestosql.spi.metastore.model.TableEntity)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 InputStream (java.io.InputStream)3 InputStreamReader (java.io.InputStreamReader)3 OutputStream (java.io.OutputStream)3 List (java.util.List)3 Logger (io.airlift.log.Logger)2 Path (java.nio.file.Path)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 CharStreams (com.google.common.io.CharStreams)1 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)1