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());
}
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());
}
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());
}
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));
}
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());
}
Aggregations