Blog Static Headline Banner

Strategies for Testing Volt Active Data Products with TestContainers

Key Takeaways

  • Automated testing with TestContainers allows developers to run real Volt Active Data Docker containers directly within their test suite, eliminating the need for manual setup or brittle custom scripts.
  • Because VoltDB requires a schema and JAR to be available before testing, these tests lean toward integration testing but can still be used effectively at the unit test level for data access layers.
  • Volt provides a Maven quickstart project that lets developers spin up a working sample application with VoltDB or Volt Stream Processor as the backend in minutes.
  • The VoltDBCluster TestContainer wrapper manages multi-node cluster setup, schema loading, deployment configuration, and client connectivity through a clean, fluent Java API.
  • Testing against a real Volt database container gives teams confidence in schema correctness, application behavior during upgrades, and production readiness before code ships.

Strategies for Testing Volt Active Data Products with TestContainers

Why Testing Matters in Modern Engineering

This article focuses on Volt’s products and shows you how to quickly assert that your application works smoothly with Volt Database (VDB) or Volt Stream Processor (VSP).

Testing Volt Active Data with TestContainers

I’ve mentioned Docker. Docker is the central mechanism for running Volt’s products. By running Volt’s Docker containers in tests, you are using the same containers that can be run in a production environment.

An added bonus is that there is no restriction on which database version Docker runs, making it easy to create a test that verifies upgrades between VoltDB versions.

TestContainers enable interaction with a container from a running test process. Testcontainers already offers many modules that provide custom APIs for products you may also use in tests. For example:

  1. Cloud Infrastructures
  2. Databases
  3. Message Brokers
  4. etc…

To view Java modules, select the “Java” Language filter, then choose your preferred category under Categories.

Volt is not listed as an official module for legal reasons. Because Testcontainer is running a real, production-ready Docker image, it still requires a license. Otherwise, it follows the same principles and delivers the same ease of writing tests as any other Testcontainer module.

Volt’s testcontainers are available on Maven’s public repositories:

Unit Tests vs Integration Tests

Bootstrapping a sample application

Before looking at the test code, let’s take a look at the Volt quickstart project.

Volt maintains a GitHub Quickstart (see README.md for details), a command-line tool to generate a sample Maven project that can be used as a playground to run and test an application using Volt’s product as its backend.

The underlying goal of this approach is to reduce, and ultimately eliminate, the risk of hallucination in AI models. At scale, enterprises can afford to include human oversight and intervention only for exception scenarios, rather than for continuous 100% coverage. Hence, the need for deterministic guardrails to ensure AI agents don’t overreach.

This will run in interactive mode and prompt the user to specify additional parameters, such as the package name for the newly created project, if not provided. It can be run in non-interactive mode when all required properties are supplied in the invocation. A sample project will be created in the current directory.

Writing a Java Test for VoltDB

This section expects basic knowledge of:

  • Maven (or similar built tool)
  • JUnit Jupiter project that is a standard test runner for Java
  • I will also use SLF4J and log4j for logging, Volt’s client, and the AssertJ library for easy assertions and to correctly synchronize state.
  • The test requires a valid license.xml in the home directory. Contact us to get your license.

In this section, I will not use generated sources from the quickstart for simplicity.

The project structure is a basic Maven structure. The EventDbResource is an application data access layer that I want to test. See implementation in the next section.

My application’s initial Maven project definition declares the following dependencies:

pom.xml

This allows me to create a basic data access object and test.

deployment.xml

schema.sql

com.acme.sample.EventDbResource.java

com.acme.sample.EventDbResourceTest.java

This will get more impressive shortly. EventDbResource is getting a Volt client to interact with the VoltDB server. This application layer does not care how the client is created; it only wants to write data to a database.

Let’s declare a Volt container that we can interact with from the test.

pom.xml

Having the right dependency, I can write a proper test.

com.acme.sample.EventDbResourceTest

This is a very simple example. I have created a custom procedure using the ddl statement. I don’t have to upload a JAR with Java procedures. For more information on how to add and test custom Java procedures, please follow the quickstart examples: configureTestContainer method in IntegrationTestBase.

Even though this is an extremely simple scenario, I should test whether:

  1. A provided schema is correctly applied.
  2. A connection has been correctly established.
  3. An application fails to insert the same value multiple times
  4. An application succeeds in writing unique values
  5. etc…

The VoltDBCluster extends GenericContainer and provides an API to set up and interact with a container. It requires a license path, Docker image name, host count, k-factor, and optional extra libraries.

It can be as simple as a single-node cluster with no k-factor replication, or a much more complex multi-node setup. The wrapper creates and manages the requested cluster nodes, where each node is an independent Docker container. It is a builder that allows fluent configuration of a Docker container.

Certain methods can only be called before Docker image starts, as some resources are added to the immutable container: withInitialClasses, withInitialSchema, withDeployment*, withKeystore, withTrustStore, etc.

Others can only be called once a cluster is fully initialized, like getMappedPort, callProcedure, runDDL, etc.

In a test, I start the cluster of the given “voltdb/voltdb-enterprise:15.1.0” image and await (lines 43-46) till it is fully initialized. A good indication of the cluster being ready is that a client can connect to it, and we can execute basic operations on it.

As with any other Docker container, ports must be mapped, since each container must coexist on the same host with other images.

To find the real mapped port value, I could call:

Conclusion: Why TestContainers Is Worth the Startup Cost

Being able to run an application code against a real Volt database is a great opportunity to create automatic tests to:

  1. Verify setup correctness
  2. Simulate application behaviour when the database is migrated, updated, scaled, etc
  3. Verify application correctness before it is shipped to test or production environment.

Volt’s database container starts quickly, but it will never be as fast as a basic unit test. When testing a range of scenarios, however, the ease of use of TestContainers outweighs the cost of the one-time startup delay.

To learn more or get started, speak with one of our Solution Engineers today.


What is TestContainers and why does Volt use it for testing?

TestContainers is an open source framework that enables developers to run real Docker containers from within a test process, and Volt uses it because it allows teams to test against the same production-ready VoltDB image in an automated, repeatable way without manual environment setup or custom CI scripts.

Is testing with VoltDB TestContainers considered a unit test or an integration test?

Because VoltDB requires a schema and application JAR to be present before the cluster starts, these tests technically lean toward integration tests, but Volt encourages developers not to be purists about the distinction and to use TestContainers wherever they add value, whether testing a single data access layer or a full application stack.

Does Volt have an official TestContainers module?

Volt is not listed as an official TestContainers module for legal reasons since running the container requires a valid license, but it follows the same principles and developer experience as any official module and is available on Maven’s public repositories.

How do I get started with Volt TestContainers in a Java project?

Volt maintains a Maven quickstart project on GitHub that generates a sample application with VoltDB as the backend, and developers can add the volt-testcontainer dependency from Maven Central to begin writing tests against a real VoltDB cluster immediately.

What scenarios should I be testing with VoltDB TestContainers?

Teams should use VoltDB TestContainers to verify that their schema is correctly applied, confirm that client connections are established properly, test application behavior during database version upgrades, and validate that business logic handles both successful and failed database operations before shipping to production.

back to top

Related blogs