com.amazonaws.services.glue.model.EntityNotFoundException Java Examples

The following examples show how to use com.amazonaws.services.glue.model.EntityNotFoundException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GlueMetastoreClientDelegateTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateTableWithoutExistingDir() throws Exception {
  Path tblPath = new Path(testTbl.getStorageDescriptor().getLocation());
  setupMockWarehouseForPath(tblPath, false, true);

  when(glueClient.getDatabase(new GetDatabaseRequest().withName(testDb.getName())))
    .thenReturn(new GetDatabaseResult().withDatabase(testDb));
  when(glueClient.getTable(new GetTableRequest().withDatabaseName(testTbl.getDatabaseName())
    .withName(testTbl.getName()))).thenThrow(new EntityNotFoundException(""));
  when(glueClient.getDatabase(any(GetDatabaseRequest.class)))
    .thenReturn(new GetDatabaseResult().withDatabase(testDb));
  metastoreClientDelegate.createTable(CatalogToHiveConverter.convertTable(testTbl, testTbl.getDatabaseName()));

  verify(glueClient, times(1)).createTable(any(CreateTableRequest.class));
  verify(wh).isDir(tblPath);
  verify(wh).mkdirs(tblPath, true);
}
 
Example #2
Source File: AWSCatalogMetastoreClientTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateIndex() throws Exception {
  Table catalogIndexTable = getTestTable();
  org.apache.hadoop.hive.metastore.api.Table hiveIndexTable = CatalogToHiveConverter.convertTable(catalogIndexTable, testDB.getName());
  testIndex.setOrigTableName(testTable.getTableName());
  testIndex.setIndexTableName(hiveIndexTable.getTableName());

  when(glueClient.getDatabase(new GetDatabaseRequest().withName(testDB.getName())))
      .thenReturn(new GetDatabaseResult().withDatabase(HiveToCatalogConverter.convertDatabase(testDB)));
  when(glueClient.getTable(new GetTableRequest().withDatabaseName(testDB.getName()).withName(testTable.getTableName())))
      .thenReturn(new GetTableResult().withTable(HiveToCatalogConverter.convertTable(testTable)));
  when(glueClient.getTable(new GetTableRequest().withDatabaseName(testDB.getName()).withName(hiveIndexTable.getTableName())))
      .thenThrow(EntityNotFoundException.class);
  when(glueClient.getPartitions(any(GetPartitionsRequest.class)))
      .thenReturn(new GetPartitionsResult().withPartitions(ImmutableList.<Partition>of()));

  metastoreClient.createIndex(testIndex, hiveIndexTable);

  TableInput expectedTableInputWithIndex = GlueInputConverter.convertToTableInput(testTable);
  expectedTableInputWithIndex.getParameters().put(INDEX_PREFIX + testIndex.getIndexName(), catalogTableToString(catalogIndexTable));
  verify(glueClient).createTable(any(CreateTableRequest.class));
  verify(glueClient).updateTable(new UpdateTableRequest().withDatabaseName(testDB.getName()).withTableInput(expectedTableInputWithIndex));
}
 
Example #3
Source File: GlueMetastoreClientDelegateTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddPartitionsThrowsEntityNotFoundException() throws Exception {
  when(glueClient.batchCreatePartition(any(BatchCreatePartitionRequest.class)))
    .thenThrow(new EntityNotFoundException("exception"));
  when(glueClient.getTable(any(GetTableRequest.class)))
    .thenReturn(new GetTableResult().withTable(testTbl));

  int numPartitions = 2;
  List<org.apache.hadoop.hive.metastore.api.Partition> partitions = getTestPartitions(numPartitions);

  try {
    metastoreClientDelegate.addPartitions(partitions, false, true);
    fail("Should throw");
  } catch (Exception e) {
    assertThat(e, is(instanceOf(NoSuchObjectException.class)));
    verify(glueClient, times(1)).getTable(any(GetTableRequest.class));
    verify(glueClient, times(1)).batchCreatePartition(any(BatchCreatePartitionRequest.class));
    verify(wh, times(numPartitions)).mkdirs(any(Path.class), eq(true));
    verify(wh, times(numPartitions)).deleteDir(any(Path.class), eq(true));
    assertDaemonThreadPools();
  }
}
 
Example #4
Source File: AWSCatalogMetastoreClientTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test(expected=InvalidOperationException.class)
public void testRenamePartitionForUnknownTable() throws Exception {
  String dbName = testDB.getName();
  Table externalTable = getTestTable();
  externalTable.setTableType(TableType.EXTERNAL_TABLE.name());   
  
  StorageDescriptor sd = HiveToCatalogConverter.convertStorageDescriptor(testPartition.getSd());
  
  Partition oldPartition = new Partition()
      .withDatabaseName(dbName).withTableName(externalTable.getName())
      .withValues(Lists.newArrayList("oldval")).withStorageDescriptor(sd);
  
  Partition newPartition = new Partition()
                                    .withDatabaseName(dbName).withTableName(externalTable.getName())
                                    .withValues(Lists.newArrayList("newval")).withStorageDescriptor(sd);    
      
  when(glueClient.getDatabase(any(GetDatabaseRequest.class)))
    .thenReturn(new GetDatabaseResult().withDatabase(HiveToCatalogConverter.convertDatabase(testDB)));
  doThrow(EntityNotFoundException.class).when(glueClient).getTable(any(GetTableRequest.class));
  
  when(glueClient.getPartition(any(GetPartitionRequest.class)))
    .thenReturn(new GetPartitionResult().withPartition(oldPartition));     
  
  metastoreClient.renamePartition(dbName, externalTable.getName(), oldPartition.getValues(),
      CatalogToHiveConverter.convertPartition(newPartition));
}
 
Example #5
Source File: GlueMetastoreClientDelegateTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test
public void testValidateTableAndCreateDirectoryVirtualView() throws Exception {
  testTbl.setTableType(TableType.VIRTUAL_VIEW.toString());
  testTbl.getStorageDescriptor().setLocation(null);
  org.apache.hadoop.hive.metastore.api.Table hiveTbl = CatalogToHiveConverter.convertTable(testTbl, testTbl.getDatabaseName());

  when(glueClient.getDatabase(any(GetDatabaseRequest.class)))
    .thenReturn(new GetDatabaseResult().withDatabase(testDb));
  when(glueClient.getTable(new GetTableRequest()
    .withDatabaseName(testTbl.getDatabaseName()).withName(testTbl.getName())))
    .thenThrow(EntityNotFoundException.class);

  assertFalse(metastoreClientDelegate.validateNewTableAndCreateDirectory(hiveTbl));
  assertNull(testTbl.getStorageDescriptor().getLocation());
  verify(wh, never()).mkdirs(any(Path.class), anyBoolean());
}
 
Example #6
Source File: GlueMetastoreClientDelegateTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateTableWithExistingDirWithCatalogId() throws Exception {
  Path tblPath = new Path(testTbl.getStorageDescriptor().getLocation());
  setupMockWarehouseForPath(tblPath, true, true);

  when(glueClient.getDatabase(new GetDatabaseRequest().withName(testDb.getName()).withCatalogId(CATALOG_ID)))
    .thenReturn(new GetDatabaseResult().withDatabase(testDb));
  when(glueClient.getTable(new GetTableRequest().withDatabaseName(testTbl.getDatabaseName()).withCatalogId(CATALOG_ID)
    .withName(testTbl.getName()))).thenThrow(new EntityNotFoundException(""));
  when(glueClient.getDatabase(any(GetDatabaseRequest.class)))
    .thenReturn(new GetDatabaseResult().withDatabase(testDb));

  metastoreClientDelegateCatalogId.createTable(CatalogToHiveConverter.convertTable(testTbl, testTbl.getDatabaseName()));
  ArgumentCaptor<CreateTableRequest> captor = ArgumentCaptor.forClass(CreateTableRequest.class);
  verify(glueClient, times(1)).createTable(captor.capture());
  verify(wh).isDir(tblPath);
  verify(wh, never()).mkdirs(tblPath, true);
  assertEquals(CATALOG_ID, captor.getValue().getCatalogId());
}
 
Example #7
Source File: GlueMetastoreClientDelegateTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateTableWithExistingDir() throws Exception {
  Path tblPath = new Path(testTbl.getStorageDescriptor().getLocation());
  setupMockWarehouseForPath(tblPath, true, true);

  when(glueClient.getDatabase(new GetDatabaseRequest().withName(testDb.getName())))
    .thenReturn(new GetDatabaseResult().withDatabase(testDb));
  when(glueClient.getTable(new GetTableRequest().withDatabaseName(testTbl.getDatabaseName())
    .withName(testTbl.getName()))).thenThrow(new EntityNotFoundException(""));
  when(glueClient.getDatabase(any(GetDatabaseRequest.class)))
    .thenReturn(new GetDatabaseResult().withDatabase(testDb));

  metastoreClientDelegate.createTable(CatalogToHiveConverter.convertTable(testTbl, testTbl.getDatabaseName()));

  verify(glueClient, times(1)).createTable(any(CreateTableRequest.class));
  verify(wh).isDir(tblPath);
  verify(wh, never()).mkdirs(tblPath, true);
}
 
Example #8
Source File: BatchDeletePartitionsHelperTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeletePartitionsWithFailures() throws Exception {
  List<String> values1 = Lists.newArrayList("val1");
  List<String> values2 = Lists.newArrayList("val2");
  Partition partition1 = TestObjects.getTestPartition(NAMESPACE_NAME, TABLE_NAME, values1);
  Partition partition2 = TestObjects.getTestPartition(NAMESPACE_NAME, TABLE_NAME, values2);
  List<Partition> partitions = Lists.newArrayList(partition1, partition2);

  PartitionError error1 = getPartitionError(values1, new EntityNotFoundException("foo error msg"));
  PartitionError error2 = getPartitionError(values2, new InvalidInputException("foo error msg2"));
  mockBatchDeleteWithFailures(Lists.newArrayList(error1, error2));

  batchDeletePartitionsHelper = new BatchDeletePartitionsHelper(client, NAMESPACE_NAME, TABLE_NAME, null, partitions)
        .deletePartitions();

  assertEquals(0, batchDeletePartitionsHelper.getPartitionsDeleted().size());
  assertTrue(batchDeletePartitionsHelper.getFirstTException() instanceof NoSuchObjectException);
}
 
Example #9
Source File: BatchDeletePartitionsHelperTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeletePartitionsWithFailure() throws Exception {
  List<String> values1 = Lists.newArrayList("val1");
  List<String> values2 = Lists.newArrayList("val2");
  Partition partition1 = TestObjects.getTestPartition(NAMESPACE_NAME, TABLE_NAME, values1);
  Partition partition2 = TestObjects.getTestPartition(NAMESPACE_NAME, TABLE_NAME, values2);
  List<Partition> partitions = Lists.newArrayList(partition1, partition2);

  PartitionError error = getPartitionError(values1, new EntityNotFoundException("foo error msg"));
  mockBatchDeleteWithFailures(Lists.newArrayList(error));

  batchDeletePartitionsHelper = new BatchDeletePartitionsHelper(client, NAMESPACE_NAME, TABLE_NAME, null, partitions)
        .deletePartitions();

  assertEquals(1, batchDeletePartitionsHelper.getPartitionsDeleted().size());
  assertTrue(batchDeletePartitionsHelper.getPartitionsDeleted().contains(partition2));
  assertTrue(batchDeletePartitionsHelper.getFirstTException() instanceof NoSuchObjectException);
}
 
Example #10
Source File: BatchDeletePartitionsHelperTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeletePartitionsThrowsServiceException() throws Exception {
  List<String> values1 = Lists.newArrayList("val1");
  List<String> values2 = Lists.newArrayList("val2");
  List<String> values3 = Lists.newArrayList("val3");
  Partition partition1 = TestObjects.getTestPartition(NAMESPACE_NAME, TABLE_NAME, values1);
  Partition partition2 = TestObjects.getTestPartition(NAMESPACE_NAME, TABLE_NAME, values2);
  Partition partition3 = TestObjects.getTestPartition(NAMESPACE_NAME, TABLE_NAME, values3);
  List<Partition> partitions = Lists.newArrayList(partition1, partition2, partition3);

  Exception e = new InternalServiceException("foo");
  mockBatchDeleteThrowsException(e);
  Mockito.when(client.getPartition(Mockito.any(GetPartitionRequest.class)))
        .thenReturn(new GetPartitionResult().withPartition(partition1))
        .thenThrow(new EntityNotFoundException("bar"))
        .thenThrow(new NullPointerException("baz"));

  batchDeletePartitionsHelper = new BatchDeletePartitionsHelper(client, NAMESPACE_NAME, TABLE_NAME, null, partitions)
        .deletePartitions();

  assertThat(batchDeletePartitionsHelper.getFirstTException(), is(instanceOf(MetaException.class)));
  assertThat(batchDeletePartitionsHelper.getPartitionsDeleted(), hasItems(partition2));
  assertThat(batchDeletePartitionsHelper.getPartitionsDeleted(), not(hasItems(partition1, partition3)));
}
 
Example #11
Source File: BatchCreatePartitionsHelperTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreatePartitionsThrowsServiceExceptionAndPartitionPartiallyCreated() throws Exception {
  Exception e = new InternalServiceException("foo");
  mockBatchCreateThrowsException(e);
  List<String> values1 = Lists.newArrayList("val1");
  List<String> values2 = Lists.newArrayList("val2");
  List<String> values3 = Lists.newArrayList("val3");
  Partition partition1 = TestObjects.getTestPartition(NAMESPACE_NAME, TABLE_NAME, values1);
  Partition partition2 = TestObjects.getTestPartition(NAMESPACE_NAME, TABLE_NAME, values2);
  Partition partition3 = TestObjects.getTestPartition(NAMESPACE_NAME, TABLE_NAME, values3);
  List<Partition> partitions = Lists.newArrayList(partition1, partition2, partition3);
  Mockito.when(awsGlueMetastore.getPartition(Mockito.anyString(), Mockito.anyString(), Mockito.anyList()))
      .thenReturn(partition1)
      .thenThrow(new EntityNotFoundException("bar"))
      .thenThrow(new NullPointerException("baz"));

  batchCreatePartitionsHelper = new BatchCreatePartitionsHelper(awsGlueMetastore, NAMESPACE_NAME, TABLE_NAME, null, partitions, false)
      .createPartitions();

  assertThat(batchCreatePartitionsHelper.getFirstTException(), is(instanceOf(MetaException.class)));
  assertThat(batchCreatePartitionsHelper.getPartitionsCreated(), hasItems(partition1));
  assertThat(batchCreatePartitionsHelper.getPartitionsCreated(), not(hasItems(partition2, partition3)));
  assertThat(batchCreatePartitionsHelper.getPartitionsFailed(), hasItems(partition2, partition3));
  assertThat(batchCreatePartitionsHelper.getPartitionsFailed(), not(hasItems(partition1)));
}
 
Example #12
Source File: AWSCatalogMetastoreClientTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test(expected=InvalidOperationException.class)
public void testRenamePartitionForUnknownPartition() throws Exception {
  String dbName = testDB.getName();
  Table externalTable = getTestTable();
  externalTable.setTableType(TableType.EXTERNAL_TABLE.name());   
  
  StorageDescriptor sd = HiveToCatalogConverter.convertStorageDescriptor(testPartition.getSd());
  
  Partition oldPartition = new Partition()
      .withDatabaseName(dbName).withTableName(externalTable.getName())
      .withValues(Lists.newArrayList("oldval")).withStorageDescriptor(sd);
  
  Partition newPartition = new Partition()
                                    .withDatabaseName(dbName).withTableName(externalTable.getName())
                                    .withValues(Lists.newArrayList("newval")).withStorageDescriptor(sd);

  when(glueClient.getDatabase(any(GetDatabaseRequest.class)))
    .thenReturn(new GetDatabaseResult().withDatabase(HiveToCatalogConverter.convertDatabase(testDB)));
  when(glueClient.getTable(any(GetTableRequest.class)))
  .thenReturn(new GetTableResult().withTable(externalTable));
  doThrow(EntityNotFoundException.class).when(glueClient).getPartition(any(GetPartitionRequest.class));
  
  metastoreClient.renamePartition(dbName, externalTable.getName(), oldPartition.getValues(),
      CatalogToHiveConverter.convertPartition(newPartition));
}
 
Example #13
Source File: PartitionUtilsTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 5 votes vote down vote up
@Test
public void testIsInvalidUserInputException() {
  assertTrue(PartitionUtils.isInvalidUserInputException(new InvalidInputException("foo")));
  assertTrue(PartitionUtils.isInvalidUserInputException(new EntityNotFoundException("bar")));
  assertFalse(PartitionUtils.isInvalidUserInputException(new InternalServiceException("bar2")));
  assertFalse(PartitionUtils.isInvalidUserInputException(new ResourceNumberLimitExceededException("bar3")));
  assertFalse(PartitionUtils.isInvalidUserInputException(new NullPointerException("bar4")));
}
 
Example #14
Source File: AWSCatalogMetastoreClientTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 5 votes vote down vote up
@Test
public void testDropPartitionsPartialFailure() throws Exception {
  Table table = HiveToCatalogConverter.convertTable(testTable);
  String namespaceName = testDB.getName();
  String tableName = table.getName();
  List<String> values1 = Arrays.asList("foo1", "bar1");
  List<String> values2 = Arrays.asList("foo2", "bar2");
  Partition partition1 = getTestPartition(namespaceName, tableName, values1);
  Partition partition2 = getTestPartition(namespaceName, tableName, values2);
  List<Partition> partitions = Lists.newArrayList(partition1, partition2);

  mockGetPartitionsSuccess(partitions);
  mockBatchDeleteWithFailures(Lists.newArrayList(getPartitionError(values1,
      new EntityNotFoundException("EntityNotFoundException"))));
  when(glueClient.getTable(any(GetTableRequest.class)))
      .thenReturn(new GetTableResult().withTable(HiveToCatalogConverter.convertTable(testTable)));

  try {
    metastoreClient.dropPartitions(namespaceName, tableName,
        Lists.newArrayList(getDumbExpression()), true, false, false);
    fail("should throw");
  } catch (TException e) {
    verify(glueClient, times(1)).batchDeletePartition(any(BatchDeletePartitionRequest.class));
    verify(glueClient, never()).getPartition(any(GetPartitionRequest.class));
    verify(wh, times(1)).deleteDir(any(Path.class), eq(true), eq(false));
    assertThat(e, is(instanceOf(NoSuchObjectException.class)));
    assertThat(e.getMessage(), containsString("EntityNotFoundException"));
    assertDaemonThreadPools();
  }
}
 
Example #15
Source File: AWSCatalogMetastoreClientTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 5 votes vote down vote up
@Test
public void testDropPartitionsExceptionTwoPages() throws Exception {
  Table table = HiveToCatalogConverter.convertTable(testTable);
  String namespaceName = testDB.getName();
  String tableName = table.getName();
  final int pageSize = 25;
  final int reqSize = (int) (pageSize * 1.5); // 2 pages
  List<Partition> partitions = Lists.newArrayList();
  for (int i = 0; i < reqSize; i++) {
    partitions.add(TestObjects.getTestPartition(namespaceName, tableName, Arrays.asList("" + i)));
  }

  mockGetPartitionsSuccess(partitions);
  when(glueClient.batchDeletePartition(Mockito.any(BatchDeletePartitionRequest.class)))
      .thenThrow(new InternalServiceException("InternalServiceException"));
  when(glueClient.getTable(any(GetTableRequest.class)))
      .thenReturn(new GetTableResult().withTable(HiveToCatalogConverter.convertTable(testTable)));
  when(glueClient.getPartition(any(GetPartitionRequest.class)))
      .thenReturn(new GetPartitionResult().withPartition(partitions.get(0)))
      .thenThrow(new EntityNotFoundException("EntityNotFoundException"))
      .thenThrow(new NullPointerException("NullPointerException"));

  try {
    metastoreClient.dropPartitions(namespaceName, tableName,
        Lists.newArrayList(getDumbExpression()), true, false, false);
    fail("should throw");
  } catch (TException e) {
    verify(glueClient, times(2)).batchDeletePartition(any(BatchDeletePartitionRequest.class));
    verify(glueClient, times(reqSize)).getPartition(any(GetPartitionRequest.class));
    verify(wh, times(1)).deleteDir(any(Path.class), eq(true), eq(false));
    assertThat(e, is(instanceOf(MetaException.class)));
    assertThat(e.getMessage(), containsString("InternalServiceException"));
    assertDaemonThreadPools();
  }
}
 
Example #16
Source File: AWSCatalogMetastoreClientTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 5 votes vote down vote up
@Test
public void testDropPartitionsServiceException() throws Exception {
  Table table = HiveToCatalogConverter.convertTable(testTable);
  String namespaceName = testDB.getName();
  String tableName = table.getName();

  List<String> values1 = Arrays.asList("foo1", "bar1");
  List<String> values2 = Arrays.asList("foo2", "bar2");
  List<String> values3 = Arrays.asList("foo3", "bar3");
  Partition partition1 = getTestPartition(namespaceName, tableName, values1);
  Partition partition2 = getTestPartition(namespaceName, tableName, values2);
  Partition partition3 = getTestPartition(namespaceName, tableName, values3);
  List<Partition> partitions = Lists.newArrayList(partition1, partition2, partition3);
  List<org.apache.hadoop.hive.metastore.api.Partition> hivePartitions =
      CatalogToHiveConverter.convertPartitions(partitions);

  mockGetPartitionsSuccess(partitions);
  mockBatchDeleteThrowsException(new InternalServiceException("InternalServiceException"));
  when(glueClient.getPartition(any(GetPartitionRequest.class)))
      .thenReturn(new GetPartitionResult().withPartition(partition1))
      .thenThrow(new EntityNotFoundException("EntityNotFoundException"))
      .thenThrow(new NullPointerException("NullPointerException"));
  when(glueClient.getTable(any(GetTableRequest.class)))
      .thenReturn(new GetTableResult().withTable(HiveToCatalogConverter.convertTable(testTable)));

  try {
    metastoreClient.dropPartitions(namespaceName, tableName,
        Lists.newArrayList(getDumbExpression()), true, false, false);
    fail("should throw");
  } catch (TException e) {
    verify(glueClient, times(1)).batchDeletePartition(any(BatchDeletePartitionRequest.class));
    verify(glueClient, times(3)).getPartition(any(GetPartitionRequest.class));
    verify(wh, times(1)).deleteDir(any(Path.class), eq(true), eq(false));
    assertThat(e, is(instanceOf(MetaException.class)));
    assertThat(e.getMessage(), containsString("InternalServiceException"));
    assertDaemonThreadPools();
  }
}
 
Example #17
Source File: AWSCatalogMetastoreClientTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 5 votes vote down vote up
@Test
public void testListPartitionNamesWithEntityNotFoundException() throws Exception {
  when(glueClient.getPartitions(any(GetPartitionsRequest.class)))
      .thenThrow(EntityNotFoundException.class);
  when(glueClient.getTable(any(GetTableRequest.class)))
      .thenReturn(new GetTableResult().withTable(HiveToCatalogConverter.convertTable(testTable)));
  List<String> partitionNames = metastoreClient.listPartitionNames(
      testDB.getName(), testTable.getTableName(), (short) -1);
  assertTrue(partitionNames.isEmpty());
}
 
Example #18
Source File: AWSCatalogMetastoreClientTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 5 votes vote down vote up
@Test
public void testDefaultNamespaceCreation() throws Exception {
  doThrow(new EntityNotFoundException("")).when(glueClient).getDatabase(any(GetDatabaseRequest.class));

  when(conf.getVar(conf, ConfVars.USERS_IN_ADMIN_ROLE, "")).thenReturn("");
  metastoreClient = new AWSCatalogMetastoreClient.Builder().withClientFactory(clientFactory)
      .withMetastoreFactory(metastoreFactory).withWarehouse(wh).createDefaults(true).withHiveConf(conf).build();

  verify(glueClient, times(1)).createDatabase(any(CreateDatabaseRequest.class));
  verify(wh, times(1)).getDefaultDatabasePath(DEFAULT_DATABASE_NAME);
  verify(wh, times(1)).isDir(defaultWhPath);
}
 
Example #19
Source File: MetastoreClientDatabaseIntegrationTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 5 votes vote down vote up
@After
public void clean() {
  try {
    glueClient.deleteDatabase(new DeleteDatabaseRequest().withName(hiveDB.getName()));
    
    for (String db : additionalDbForCleanup) {
      glueClient.deleteDatabase(new DeleteDatabaseRequest().withName(db));
    }
  } catch (EntityNotFoundException e) {
    //there will be no database to drop after drop database test, so swallow the exception
  }
}
 
Example #20
Source File: SparkCatalogMetastoreClientTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetFunctionNoSuchObjectExceptionMessage() throws Exception {
  expectedException.expect(NoSuchObjectException.class);
  expectedException.expectMessage(testFunction.getFunctionName() + " does not exist");

  when(glueClient.getUserDefinedFunction(any(GetUserDefinedFunctionRequest.class)))
    .thenThrow(new EntityNotFoundException(""));
  metastoreClient.getFunction(testDB.getName(), testFunction.getFunctionName());
}
 
Example #21
Source File: GlueMetastoreClientDelegateTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetPartitionsByNamePropagateException() throws Exception {
  String exceptionMessage = "Partition not found";
  when(glueClient.batchGetPartition(any(BatchGetPartitionRequest.class)))
      .thenThrow(new EntityNotFoundException(exceptionMessage));

  try {
    metastoreClientDelegate.getPartitionsByNames(testDb.getName(), testTbl.getName(), ImmutableList.of("/a=foo/b=bar"));
  } catch (Exception e) {
    assertThat(e, instanceOf(NoSuchObjectException.class));
    assertThat(e.getMessage(), containsString(exceptionMessage));
  }
  verify(glueClient, times(1)).batchGetPartition(any(BatchGetPartitionRequest.class));
}
 
Example #22
Source File: GlueMetastoreClientDelegateTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 5 votes vote down vote up
@Test(expected=NoSuchObjectException.class)
public void testGetPartitionEntityNotFound() throws Exception {
  when(glueClient.getPartition(any(GetPartitionRequest.class)))
    .thenThrow(new EntityNotFoundException("Test exception: partition not found"));
  metastoreClientDelegate.getPartition(testDb.getName(), testTbl.getName(), "testPart");
  verify(glueClient, times(1)).getPartition(any(GetPartitionRequest.class));
}
 
Example #23
Source File: PartitionUtils.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 4 votes vote down vote up
public static boolean isInvalidUserInputException(Exception e) {
  // exceptions caused by invalid requests, in which case we know all partitions creation failed
  return e instanceof EntityNotFoundException || e instanceof InvalidInputException;
}
 
Example #24
Source File: AWSCatalogMetastoreClientTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 4 votes vote down vote up
@Test (expected = NoSuchObjectException.class)
public void testListFunctionsInValidWithNoSuchObjectException() throws Exception {
  when(glueClient.getUserDefinedFunctions(any(GetUserDefinedFunctionsRequest.class)))
          .thenThrow(new EntityNotFoundException(""));
  metastoreClient.getFunctions(testDB.getName(), ".*");
}
 
Example #25
Source File: AWSCatalogMetastoreClientTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 4 votes vote down vote up
@Test (expected = NoSuchObjectException.class)
public void testGetFunctionInValidWithEntityNotFoundException() throws Exception {
  when(glueClient.getUserDefinedFunction(any(GetUserDefinedFunctionRequest.class)))
          .thenThrow(new EntityNotFoundException(""));
  metastoreClient.getFunction(testDB.getName(), testFunction.getFunctionName());
}
 
Example #26
Source File: AWSCatalogMetastoreClientTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 4 votes vote down vote up
@Test (expected =  NoSuchObjectException.class)
public void testCreateFunctionInValidWithUnknownNamespace() throws Exception {
  when(glueClient.createUserDefinedFunction(any(CreateUserDefinedFunctionRequest.class)))
          .thenThrow(new EntityNotFoundException(""));
  metastoreClient.createFunction(testFunction);
}
 
Example #27
Source File: GlueMetastoreClientDelegateTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 4 votes vote down vote up
@Test
public void testAddPartitionsCallGetPartitionForInternalServiceException() throws Exception {
  int numPartitions = 3;
  String dbName = testDb.getName();
  String tableName = testTbl.getName();
  List<String> values1 = Lists.newArrayList("val1");
  List<String> values2 = Lists.newArrayList("val2");
  List<String> values3 = Lists.newArrayList("val3");
  Partition partition1 = TestObjects.getTestPartition(dbName, tableName, values1);
  Partition partition2 = TestObjects.getTestPartition(dbName, tableName, values2);
  Partition partition3 = TestObjects.getTestPartition(dbName, tableName, values3);
  List<Partition> partitions = Lists.newArrayList(partition1, partition2, partition3);

  when(glueClient.batchCreatePartition(any(BatchCreatePartitionRequest.class)))
    .thenThrow(new InternalServiceException("InternalServiceException"));
  when(glueClient.getTable(any(GetTableRequest.class)))
    .thenReturn(new GetTableResult().withTable(testTbl));
  when(glueClient.getPartition(new GetPartitionRequest()
    .withDatabaseName(dbName)
    .withTableName(tableName)
    .withPartitionValues(partition1.getValues())))
    .thenReturn(new GetPartitionResult().withPartition(partition1));
  when(glueClient.getPartition(new GetPartitionRequest()
    .withDatabaseName(dbName)
    .withTableName(tableName)
    .withPartitionValues(partition2.getValues())))
    .thenThrow(new EntityNotFoundException("EntityNotFoundException"));
  when(glueClient.getPartition(new GetPartitionRequest()
    .withDatabaseName(dbName)
    .withTableName(tableName)
    .withPartitionValues(partition3.getValues())))
    .thenThrow(new NullPointerException("NullPointerException"));

  try {
    metastoreClientDelegate.addPartitions(CatalogToHiveConverter.convertPartitions(partitions), false, true);
    fail("Should throw");
  } catch (Exception e) {
    assertThat(e, is(instanceOf(MetaException.class)));
    verify(glueClient, times(1)).getTable(any(GetTableRequest.class));
    verify(glueClient, times(1)).batchCreatePartition(any(BatchCreatePartitionRequest.class));
    verify(glueClient, times(numPartitions)).getPartition(any(GetPartitionRequest.class));
    verify(wh, times(numPartitions)).mkdirs(any(Path.class), eq(true));
    verify(wh, times(2)).deleteDir(any(Path.class), eq(true));
    assertDaemonThreadPools();
  }
}