From ae265192c138ac4d8ce299f304bf771ec9325e24 Mon Sep 17 00:00:00 2001 From: javsanbel2 Date: Wed, 27 Nov 2024 11:56:48 +0100 Subject: [PATCH] fix validator tests --- .../cleanup/validation/IcebergValidator.java | 3 +- .../validation/IcebergValidatorTest.java | 40 ++++--------------- 2 files changed, 9 insertions(+), 34 deletions(-) diff --git a/beekeeper-cleanup/src/main/java/com/expediagroup/beekeeper/cleanup/validation/IcebergValidator.java b/beekeeper-cleanup/src/main/java/com/expediagroup/beekeeper/cleanup/validation/IcebergValidator.java index 55fb07aa..048a3ba5 100644 --- a/beekeeper-cleanup/src/main/java/com/expediagroup/beekeeper/cleanup/validation/IcebergValidator.java +++ b/beekeeper-cleanup/src/main/java/com/expediagroup/beekeeper/cleanup/validation/IcebergValidator.java @@ -48,9 +48,8 @@ public void throwExceptionIfIceberg(String databaseName, String tableName) { try (CleanerClient client = cleanerClientFactory.newInstance()) { Map 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)); } diff --git a/beekeeper-cleanup/src/test/java/com/expediagroup/beekeeper/cleanup/validation/IcebergValidatorTest.java b/beekeeper-cleanup/src/test/java/com/expediagroup/beekeeper/cleanup/validation/IcebergValidatorTest.java index dcaf308c..84eb88f8 100644 --- a/beekeeper-cleanup/src/test/java/com/expediagroup/beekeeper/cleanup/validation/IcebergValidatorTest.java +++ b/beekeeper-cleanup/src/test/java/com/expediagroup/beekeeper/cleanup/validation/IcebergValidatorTest.java @@ -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; @@ -49,7 +50,6 @@ 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(); @@ -57,12 +57,11 @@ public void shouldThrowExceptionWhenTableTypeIsIceberg() throws Exception { } @Test(expected = BeekeeperIcebergException.class) - public void shouldThrowExceptionWhenFormatIsIceberg() throws Exception { + public void shouldThrowExceptionWhenMetadataIsIceberg() throws Exception { Map 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"); } @@ -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 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 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 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); } }