Skip to content

Commit

Permalink
fix validator tests
Browse files Browse the repository at this point in the history
  • Loading branch information
javsanbel2 committed Nov 27, 2024
1 parent 804be2f commit ae26519
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ public void throwExceptionIfIceberg(String databaseName, String tableName) {
try (CleanerClient client = cleanerClientFactory.newInstance()) {
Map<String, String> parameters = client.getTableProperties(databaseName, tableName);
String tableType = parameters.getOrDefault("table_type", "").toLowerCase();
String format = parameters.getOrDefault("format", "").toLowerCase();
String metadataLocation = parameters.getOrDefault("metadata_location", "").toLowerCase();
if (tableType.contains("iceberg") || format.contains("iceberg") || !metadataLocation.isEmpty()) {
if (tableType.contains("iceberg") || !metadataLocation.isEmpty()) {
throw new BeekeeperIcebergException(
format("Iceberg table %s.%s is not currently supported in Beekeeper.", databaseName, tableName));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.expediagroup.beekeeper.cleanup.validation;

import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -49,20 +50,18 @@ public void shouldThrowExceptionWhenTableTypeIsIceberg() throws Exception {
properties.put("table_type", "ICEBERG");

when(cleanerClient.getTableProperties("db", "table")).thenReturn(properties);
when(cleanerClient.getOutputFormat("db", "table")).thenReturn("");

icebergValidator.throwExceptionIfIceberg("db", "table");
verify(cleanerClientFactory).newInstance();
verify(cleanerClient).close();
}

@Test(expected = BeekeeperIcebergException.class)
public void shouldThrowExceptionWhenFormatIsIceberg() throws Exception {
public void shouldThrowExceptionWhenMetadataIsIceberg() throws Exception {
Map<String, String> properties = new HashMap<>();
properties.put("format", "iceberg");
properties.put("metadata_location", "s3://db/table/metadata/0000.json");

when(cleanerClient.getTableProperties("db", "table")).thenReturn(properties);
when(cleanerClient.getOutputFormat("db", "table")).thenReturn("");

icebergValidator.throwExceptionIfIceberg("db", "table");
}
Expand All @@ -73,44 +72,21 @@ public void shouldNotThrowExceptionForNonIcebergTable() throws Exception {
properties.put("table_type", "HIVE_TABLE");

when(cleanerClient.getTableProperties("db", "table")).thenReturn(properties);
when(cleanerClient.getOutputFormat("db", "table"))
.thenReturn("org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat");

icebergValidator.throwExceptionIfIceberg("db", "table");
verify(cleanerClientFactory).newInstance();
verify(cleanerClient).close();
}

@Test(expected = BeekeeperIcebergException.class)
public void shouldThrowExceptionWhenOutputFormatContainsIceberg() throws Exception {
Map<String, String> properties = new HashMap<>();

when(cleanerClient.getTableProperties("db", "table")).thenReturn(properties);
when(cleanerClient.getOutputFormat("db", "table"))
.thenReturn("org.apache.iceberg.mr.hive.HiveIcebergOutputFormat");

icebergValidator.throwExceptionIfIceberg("db", "table");
}

@Test(expected = BeekeeperIcebergException.class)
public void shouldThrowExceptionWhenFormatIsNullButTableTypeIsIceberg() throws Exception {
Map<String, String> properties = new HashMap<>();
properties.put("table_type", "ICEBERG");

when(cleanerClient.getTableProperties("db", "table")).thenReturn(properties);
when(cleanerClient.getOutputFormat("db", "table")).thenReturn("");

icebergValidator.throwExceptionIfIceberg("db", "table");
}

@Test
public void shouldNotThrowExceptionWhenOutputFormatIsNull() throws Exception {
public void shouldThrowExceptionWhenOutputFormatIsNull() throws Exception {
Map<String, String> properties = new HashMap<>();
properties.put("table_type", "HIVE_TABLE");
properties.put("table_type", null);
properties.put("metadata_location", null);

when(cleanerClient.getTableProperties("db", "table")).thenReturn(properties);
when(cleanerClient.getOutputFormat("db", "table")).thenReturn(null);

icebergValidator.throwExceptionIfIceberg("db", "table");
assertThatThrownBy(() -> icebergValidator.throwExceptionIfIceberg("db", "table")).isInstanceOf(
BeekeeperIcebergException.class);
}
}

0 comments on commit ae26519

Please sign in to comment.