https://github.com/abaddon/hbasetestcontainer
An HBase container based on TestContainer
https://github.com/abaddon/hbasetestcontainer
container hbase java test testcontainers testing
Last synced: 9 months ago
JSON representation
An HBase container based on TestContainer
- Host: GitHub
- URL: https://github.com/abaddon/hbasetestcontainer
- Owner: abaddon
- License: apache-2.0
- Created: 2021-10-20T14:22:05.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-01-30T17:13:24.000Z (over 2 years ago)
- Last Synced: 2025-10-07T05:35:52.763Z (9 months ago)
- Topics: container, hbase, java, test, testcontainers, testing
- Language: Java
- Homepage:
- Size: 72.3 KB
- Stars: 2
- Watchers: 1
- Forks: 3
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://maven-badges.herokuapp.com/maven-central/io.github.abaddon.testcontainer/hbasetestcontainer)
[](https://codecov.io/gh/abaddon/HBaseTestContainer)
# HBaseTestContainer
The scope of this project is offer a simple way to execute tests with HBase.
HBase uses hostnames to pass connection data back out of the container (from it's internal Zookeeper) and this behaviour creates 2 problems:
1. a hostname is needed
2. TestContainer follow this principle: _From the host's perspective Testcontainers actually exposes this on a random free port. This is by design, to avoid port collisions that may arise with locally running software or in between parallel test runs._
## How it works
The class HBase Container breaks the Testcontainers' principle, mapping exposed ports to the same container ports.
With this workaround we can call HBase from the host or from the container using the same address.
#### Important Note
Remember to define a custom *hosts* file to use when you run your test.
This file has to contain something like this:
```
127.0.0.1 hbase_container_name
```
You can see an example in the repository.
There are multiple ways to load this files: below some of them:
1. as java option: `-Djdk.net.hosts.file=./path/hosts`
2. you can create a file on the root of the project `.mvn/jvm.config` and add the java option
3. in the pom.xml, you can add the parameter in the surfer plugin like this:
```
-Djdk.net.hosts.file=./path/hosts
...
...
maven-surefire-plugin
2.22.2
${jvm.options}
```
## Usage
1. Add the HBaseContainer as dependency in your pom.xml file. The last version is: [](https://maven-badges.herokuapp.com/maven-central/io.github.abaddon.testcontainer/hbasetestcontainer)
```
io.github.abaddon.testcontainer
hbasetestcontainer
0.0.2
```
2. Use HBaseContainer class in your test class:
```
public class HBaseStoreTest {
private final static String HBASE_HOSTNAME = "hbase-docker";
@ClassRule
public static HBaseContainer hbaseContainer = new HBaseContainer(HBASE_HOSTNAME);
@Test
public void test() throws IOException {
....
}
```
3. create a `hosts` file and load it when you run your tests (if you need it).
## Extra features
### Bind HBase data folder
You can use the method `withDataFolderBind(String hostPath)`. Where hostPath is the folder on the host.
If it's not exist it will be created automatically.
At the moment, the folder is deleted and recreated at each run.
```
@ClassRule
public static HBaseContainer hbaseContainer = new HBaseContainer(HBASE_HOSTNAME)
.withDataFolderBind("./hbase_data");;
```