Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jphalip committed Apr 27, 2024
1 parent b17526b commit a7ad624
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,29 @@ public class HiveUtilsTest {
@Test
public void testHiveQueryId() {
Configuration conf = new Configuration();
Throwable exception = assertThrows(RuntimeException.class, () -> HiveUtils.getQueryId(conf));
assertEquals("No query id found in Hadoop conf", exception.getMessage());
conf.set("hive.query.id", "abcd");
assertEquals("hive-query-id-abcd", HiveUtils.getQueryId(conf));
}

@Test
public void testPigQueryId() {
Configuration conf = new Configuration();
conf.set("pig.script.id", "abcd");
conf.set("pig.job.submitted.timestamp", "999");
assertEquals("pig-abcd-999", HiveUtils.getQueryId(conf));
}

@Test
public void testMapreduceQueryId() {
Configuration conf = new Configuration();
conf.set("mapreduce.workflow.id", "abcd");
assertEquals("mapreduce-abcd", HiveUtils.getQueryId(conf));
}

@Test
public void testHCatQueryId() {
Configuration conf = new Configuration();
conf.set("mapreduce.lib.hcatoutput.id", "abcd");
assertEquals("hcat-output-abcd", HiveUtils.getQueryId(conf));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
*/
package com.google.cloud.hive.bigquery.connector.utils;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.text.MatchesPattern.matchesPattern;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;

import com.google.cloud.bigquery.TableId;
import com.google.cloud.hive.bigquery.connector.JobDetails;
import com.google.cloud.hive.bigquery.connector.output.WriterRegistry;
import com.google.common.truth.Truth;
import java.util.Properties;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
Expand Down Expand Up @@ -49,10 +49,10 @@ public void testGetWorkDir() {
Configuration conf = new Configuration();
conf.set("hadoop.tmp.dir", "/tmp");
Path path = JobUtils.getQueryWorkDir(conf);
assertEquals("/tmp/hive-bq-hive-query-id-query123", path.toString());
assertThat(path.toString()).matches("/tmp/hive-bq-custom-query-id-.*");
conf.set("bq.work.dir.parent.path", "/my/workdir");
path = JobUtils.getQueryWorkDir(conf);
assertEquals("/my/workdir/hive-bq-hive-query-id-query123", path.toString());
assertThat(path.toString()).matches("/my/workdir/hive-bq-custom-query-id-.*");
}

@Test
Expand All @@ -61,9 +61,8 @@ public void testGetJobDetailsFilePath() {
conf.set("hadoop.tmp.dir", "/tmp");
String hmsDbTable = "default.mytable";
Path jobDetailsFilePath = JobUtils.getJobDetailsFilePath(conf, hmsDbTable);
assertEquals(
"/tmp/hive-bq-hive-query-id-query123/default.mytable/job-details.json",
jobDetailsFilePath.toString());
Truth.assertThat(jobDetailsFilePath.toString())
.matches("/tmp/hive-bq-custom-query-id-.*/default\\.mytable/job-details\\.json");
}

@Test
Expand All @@ -79,7 +78,7 @@ public void testGetTaskWriterOutputFile() {
String writerId = WriterRegistry.getWriterId();
Path path = JobUtils.getTaskWriterOutputFile(conf, jobDetails, taskAttemptID, writerId, "jpeg");
String pattern =
"^/hadoop-tmp/hive-bq-hive-query-id-query123/default.mytable/myproject_mydataset_mytable_abcd1234_w\\d+\\.jpeg";
assertThat(path.toString(), matchesPattern(pattern));
"^/hadoop-tmp/hive-bq-custom-query-id-.*/default.mytable/myproject_mydataset_mytable_abcd1234_w\\d+\\.jpeg";
assertThat(path.toString()).matches(pattern);
}
}

0 comments on commit a7ad624

Please sign in to comment.