{"id":13798563,"url":"https://github.com/ExpediaGroup/beeju","last_synced_at":"2025-05-13T05:32:22.228Z","repository":{"id":42121247,"uuid":"80200497","full_name":"ExpediaGroup/beeju","owner":"ExpediaGroup","description":"JUnit integration for testing the Apache Hive Metastore and HiveServer2 Thrift APIs","archived":false,"fork":false,"pushed_at":"2024-12-23T21:15:56.000Z","size":335,"stargazers_count":26,"open_issues_count":6,"forks_count":5,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-05-08T03:04:11.936Z","etag":null,"topics":["hive","hive-metastore-api","hive-metastore-client","junit-extension","junit-rule","junit5"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ExpediaGroup.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE-OF-CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-01-27T10:58:58.000Z","updated_at":"2025-01-14T10:45:09.000Z","dependencies_parsed_at":"2024-08-04T00:13:02.202Z","dependency_job_id":null,"html_url":"https://github.com/ExpediaGroup/beeju","commit_stats":null,"previous_names":["hotelsdotcom/beeju"],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExpediaGroup%2Fbeeju","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExpediaGroup%2Fbeeju/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExpediaGroup%2Fbeeju/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExpediaGroup%2Fbeeju/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ExpediaGroup","download_url":"https://codeload.github.com/ExpediaGroup/beeju/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253883137,"owners_count":21978611,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hive","hive-metastore-api","hive-metastore-client","junit-extension","junit-rule","junit5"],"created_at":"2024-08-04T00:00:46.057Z","updated_at":"2025-05-13T05:32:21.894Z","avatar_url":"https://github.com/ExpediaGroup.png","language":"Java","readme":"# BeeJU\n![Hive Bee JUnit.](logo.png \"Project logo of a beeju bee.\")\n\n# Start using\nYou can obtain BeeJU from Maven Central:\n\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.hotels/beeju/badge.svg?subject=com.hotels:beeju)](https://maven-badges.herokuapp.com/maven-central/com.hotels/beeju) ![build](https://github.com/ExpediaGroup/beeju/workflows/build/badge.svg?event=push) [![Coverage Status](https://coveralls.io/repos/github/ExpediaGroup/beeju/badge.svg?branch=main)](https://coveralls.io/github/ExpediaGroup/beeju) ![GitHub license](https://img.shields.io/github/license/ExpediaGroup/beeju.svg)\n\n# Overview\nBeeJU provides [JUnit5 Extensions](https://junit.org/junit5/docs/current/user-guide/#extensions) that can be used to write test code that tests [Hive](https://hive.apache.org/). The JUnit lifecycle extension points are a means to provide resources in a test and automatically tear them down when the life cycle of a test ends.\nThis project is currently built with and tested against Hive 2.3.x (and minor versions back to Hive 1.2.1) but is most likely compatible with older and newer versions of Hive. The available JUnit extensions are explained in more detail below.  \n\nBeeJU also provides [JUnit4 Rules](http://junit.org/junit4/javadoc/4.12/org/junit/Rule.html) that can be used in the same manner as the JUnit5 extensions. Examples of how to use both options can be found below.\n# Usage\nThe BeeJU JUnit rules and extensions provide a way to run tests that have an underlying requirement to use the Hive Metastore API but don't have the ability to mock the [Hive Metastore Client](https://hive.apache.org/javadocs/r2.3.6/api/index.html). The rules and extensions spin up and tear down an in-memory Metastore which may add a few seconds to the test life cycle so if you require tests to run in the sub-second range this is not for you.\n\n## Maven Dependencies\nDepend on BeeJU using:\n\n```xml\n    \u003cdependency\u003e\n        \u003cgroupId\u003ecom.hotels\u003c/groupId\u003e\n        \u003cartifactId\u003ebeeju\u003c/artifactId\u003e\n        \u003cversion\u003e....\u003c/version\u003e\n        \u003cscope\u003etest\u003c/scope\u003e\n    \u003c/dependency\u003e\n```\n\n## Hive version compatibility\n\nThis version of BeeJU is intended for use with Hive 3.1.2. For Hive 2.x support, please use BeeJU 4.0.0.\n\n## JUnit5\n### ThriftHiveMetaStoreJUnitExtension\nThis extension creates an in-memory Hive database and a Thrift Hive Metastore service on top of this. This can then be used to perform Hive Thrift API calls in a test. The extension exposes a Thrift URI that can be injected into the class under test and a Hive Metastore Client which can be used for data setup and assertions.\n\nExample usage: Class under test creates a table via the Hive Metastore Thrift API.\n\n    @RegisterExtension\n    public ThriftHiveMetaStoreJUnitExtension hive = new ThriftHiveMetaStoreJUnitExtension(\"foo_db\");\n\n    @Test\n    public void example() throws Exception {\n      ClassUnderTest classUnderTest = new ClassUnderTest(hive.getThriftConnectionUri());\n      classUnderTest.createTable(\"foo_db\", \"bar_table\");\n\n      assertTrue(hive.client().tableExists(\"foo_db\", \"bar_table\"));\n    }\n\n### HiveMetaStoreJUnitExtension\nThis extension creates an in-memory Hive database without a Thrift Hive Metastore service. This can then be used to perform Hive API calls directly (i.e. without going via Hive's Metastore Thrift service) in a test.\n\nExample usage: Class under test creates a partition using an injected Hive Metastore Client.\n\n    @RegisterExtension\n    public HiveMetaStoreJUnitExtension hive = new HiveMetaStoreJUnitExtension(\"foo_db\");\n\n    @Test\n    public void example() throws Exception {\n      HiveMetaStoreClient client = hive.client();\n      ClassUnderTest classUnderTest = new ClassUnderTest(client);\n      Table table = new Table();\n      table.setDbName(\"foo_db\");\n      table.setTableName(\"bar_table\");\n      hive.createTable(table);\n\n      classUnderTest.createPartition(client, table);\n\n      assertEquals(1, client.listPartitions(\"foo_db\", \"bar_table\", (short) 100));\n    }\n\n### HiveServer2JUnitExtension\nThis extension creates an in-memory Hive database, a Thrift Hive Metastore service on top of this and a HiveServer2 service. This can then be used to perform Hive JDBC calls in a test. The extension exposes a JDBC URI that can be injected into the class under test and a Hive Metastore Client which can be used for data setup and assertions.\n\nExample usage: Class under test drops a table via Hive JDBC.\n\n    @RegisterExtension\n    public HiveServer2JUnitExtension hive = new HiveServer2JUnitExtension(\"foo_db\");\n\n    @Test\n    public void example() {\n      Class.forName(hive.driverClassName());\n      try (Connection connection = DriverManager.getConnection(hive.connectionURL());\n           Statement statement = connection.createStatement()) {\n        String createHql = new StringBuilder(256)\n            .append(\"CREATE TABLE `foo_db.bar_table`(`id` int, `name` string) \")\n            .append(\"ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe' \")\n            .append(\"STORED AS INPUTFORMAT 'org.apache.hadoop.mapred.TextInputFormat' \")\n            .append(\"OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'\")\n            .toString();\n        statement.execute(createHql);\n      }\n\n      ClassUnderTest classUnderTest = new ClassUnderTest(hive.connectionURL());\n      classUnderTest.dropTable(\"foo_db\", \"bar_table\");  \n\n      HiveMetaStoreClient client = hive.newClient();\n      try {\n        assertFalse(client.tableExists(\"foo_db\", \"bar_table\"));\n      } finally {\n        client.close();\n      }\n    }\n\n## JUnit4\nFor JUnit4, ensure you have the [JUnit4](https://github.com/junit-team/junit4) dependency in your POM, as BeeJU no longer supplies it as a transitive dependency.\n\n### ThriftHiveMetaStoreJUnitRule\nThis rule creates an in-memory Hive database and a Thrift Hive Metastore service on top of this. This can then be used to perform Hive Thrift API calls in a test. The rule exposes a Thrift URI that can be injected into the class under test and a Hive Metastore Client which can be used for data setup and assertions.\n\nExample `@Rule` usage: Class under test creates a table via the Hive Metastore Thrift API.\n\n    @Rule\n    public ThriftHiveMetaStoreJUnitRule hive = new ThriftHiveMetaStoreJUnitRule(\"foo_db\");\n\n    @Test\n    public void example() throws Exception {\n      ClassUnderTest classUnderTest = new ClassUnderTest(hive.getThriftConnectionUri());\n      classUnderTest.createTable(\"foo_db\", \"bar_table\");\n\n      assertTrue(hive.client().tableExists(\"foo_db\", \"bar_table\"));\n    }\n\n### HiveMetaStoreJUnitRule\nThis rule creates an in-memory Hive database without a Thrift Hive Metastore service. This can then be used to perform Hive API calls directly (i.e. without going via Hive's Metastore Thrift service) in a test.\n\nExample `@Rule` usage: Class under test creates a partition using an injected Hive Metastore Client.\n\n    @Rule\n    public HiveMetaStoreJUnitRule hive = new HiveMetaStoreJUnitRule(\"foo_db\");\n\n    @Test\n    public void example() throws Exception {\n      HiveMetaStoreClient client = hive.client();\n      ClassUnderTest classUnderTest = new ClassUnderTest(client);\n      Table table = new Table();\n      table.setDbName(\"foo_db\");\n      table.setTableName(\"bar_table\");\n      hive.createTable(table);\n\n      classUnderTest.createPartition(client, table);\n\n      assertEquals(1, client.listPartitions(\"foo_db\", \"bar_table\", (short) 100));\n    }\n\n### HiveServer2JUnitRule\nThis rule creates an in-memory Hive database, a Thrift Hive Metastore service on top of this and a HiveServer2 service. This can then be used to perform Hive JDBC calls in a test. The rule exposes a JDBC URI that can be injected into the class under test and a Hive Metastore Client which can be used for data setup and assertions.\n\nExample `@Rule` usage: Class under test drops a table via Hive JDBC.\n\n    @Rule\n    public HiveServer2JUnitRule hive = new HiveServer2JUnitRule(\"foo_db\");\n\n    @Test\n    public void example() {\n      Class.forName(hive.driverClassName());\n      try (Connection connection = DriverManager.getConnection(hive.connectionURL());\n           Statement statement = connection.createStatement()) {\n        String createHql = new StringBuilder(256)\n            .append(\"CREATE TABLE `foo_db.bar_table`(`id` int, `name` string) \")\n            .append(\"ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe' \")\n            .append(\"STORED AS INPUTFORMAT 'org.apache.hadoop.mapred.TextInputFormat' \")\n            .append(\"OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'\")\n            .toString();\n        statement.execute(createHql);\n      }\n\n      ClassUnderTest classUnderTest = new ClassUnderTest(hive.connectionURL());\n      classUnderTest.dropTable(\"foo_db\", \"bar_table\");  \n\n      HiveMetaStoreClient client = hive.newClient();\n      try {\n        assertFalse(client.tableExists(\"foo_db\", \"bar_table\"));\n      } finally {\n        client.close();\n      }\n    }\n\n## JUnit5 Rule Migration\nSupport is available to enable you to migrate your JUnit4 tests that currently use BeeJU rules without changing them to use extensions. To use JUnit5, ensure you have the following dependency in your POM:\n\n```xml\n    \u003cdependency\u003e\n        \u003cgroupId\u003eorg.junit.jupiter\u003c/groupId\u003e\n        \u003cartifactId\u003ejunit-jupiter-migrationsupport\u003c/artifactId\u003e\n        \u003cversion\u003e${junit.jupiter.version}\u003c/version\u003e\n        \u003cscope\u003etest\u003c/scope\u003e\n    \u003c/dependency\u003e\n```\n\nFor any test classes using the BeeJU rules, add the class annotation `@EnableRuleMigrationSupport`. No further changes are needed to move your JUnit4 tests to JUnit5.\n\n# Legal\nThis project is available under the [Apache 2.0 License](http://www.apache.org/licenses/LICENSE-2.0.html).\n\nCopyright 2016-2021 Expedia, Inc.\n","funding_links":[],"categories":["Tools"],"sub_categories":["Testing"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FExpediaGroup%2Fbeeju","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FExpediaGroup%2Fbeeju","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FExpediaGroup%2Fbeeju/lists"}