Just use MockAerospikeClient
implementation for the interface IAerospikeClient
in your unit tests.
- Lightweight & Embedded
- Easy to use (implements the same interface)
- Reduce effort in unit testing
- Allow extensibility
Currently, Aerospike provides for IAerospikeClient
(in Java) with sole intention of making AerospikeClient testable.
However, there are few issues pointed out - aerospike/aerospike-client-java#34
- Don't mock what you don't own (Mocking
IAerospikeClient
, then mockingRecord
).
Better approach to testing is to create MockAerospikeClient
which implements IAerospikeClient
, thus avoiding mocking RecordSet
and Record
itself.
MockAerospikeClient
implements IAerospikeClient
(version - 3.2.1
)
Currently, MockAerospikeClient
supports the following methods:
- put
- get
- delete
- exists
- getHeader
MockAerospikeClient
internally uses a HashMap
to store Record
corresponding to a Key
- Maven
- Java 1.8 or greater
- pom.xml
Add the following dependency to your pom.xml
<dependency>
<groupId>com.github.srini156</groupId>
<artifactId>mock-aerospike-java</artifactId>
<version>0.0.4</version>
</dependency>
- Code
MockAerospikeClient client = new MockAerospikeClient();
//Put entry into Aerospike
client.put(null, new Key("namespace", "set", "key"), new Bin[] { new Bin("bin1", "value1") });
//Fetch entry from Aerospike
client.get(null, new Key("namespace","set","key"));
It is currently alpha and WIP. Contributions are welcome, please raise a pull request.