Comments (10)
We are planning to add IAerospikeClient and IAsyncClient interfaces that should be more mock friendly. This will be available in the next release.
from aerospike-client-java.
+1
from aerospike-client-java.
The AerospikeClient methods are declared final because it allows the compiler to perform optimizations where method overrides don't have to be checked. You can still inherit from AerospikeClient and add functionality, but the underlying methods do not need to change. It's a reasonable design pattern that is unfortunately hostile to many (but not all) mock frameworks.
from aerospike-client-java.
Thanks for the reply.
I assume you mean using something like PowerMock with the expectNew functionality to mock the behavior of the execute method on subclasses of Command (like DeleteCommand, WriteCommand, etc..). Not a huge fan of that method, but I digress.
I am curious as to if you have metrics supporting the "optimizations" you speak of.
Thanks again...
from aerospike-client-java.
+1. We're having an extremely difficult time working with the client in our tests for this exact same reason. Perhaps all of the methods could be declared in an interface and then actually implemented as final methods in an implementation class? That way tools like mockito and scalamock could use the interface but in the production code you'd get the benefit of the optimized final
methods from the implementation class.
from aerospike-client-java.
FWIW in our infrastructure we use a wrapper class which handles talking to Aerospike and decoding everything to the correct objects. Having this class means for unit testing we can simply cut out the Aerospike library altogether. That might be a workaround until an interface is available.
from aerospike-client-java.
We did the same thing, putting a layer of abstraction between our code and the Aerospike client to better accommodate testing. Once the next release is available it seems will may be able to rip this out.
from aerospike-client-java.
same here, but we also wanted to test the wrapper itself, so we still needed to figure out how to mock Aerospike.
Since we're using scala, we actually wound up creating a type class containing the Aerospike client methods we needed, and had our Aerospike service require that
object ASClientLike {
implicit def aerospikeClientIsASClientLike(as: AerospikeClient): ASClientLike = new ASClientLike {
def get(policy: Policy, key: Key): Record = as.get(policy, key)
}
}
trait ASClientLike {
def get(policy: Policy, key: Key): Record
}
object AerospikeService {
import ASClientLike._
def apply(client: ASClientLike, namespace: String)(implicit ec: ExecutionContext): AerospikeService =
new AerospikeServiceImpl(client, namespace)(ec)
private class AerospikeServiceImpl(client: ASClientLike, namespace: String)(implicit val ec: ExecutionContext) extends AerospikeService
}
trait AerospikeService {
def client: ASClientLike
def namespace: String
def get[T](setName: String, keyName: KeyName, binName: String): Future[Option[T]] = Future {
val key = new Key(namespace, setName, keyName)
Option(client.get(null, key)) flatMap {
rec => Option(rec.getValue(binName)) map { _.asInstanceOf[T] }
}
}
}
So now we can use it in production
import ASClientLike._
val client = new AerospikeClient(policy, clusterNodes: _*)
val aerospike = AerospikeService(client, "namespace")
// ...
as well as in tests (we use scalamock for mocking)
class AerospikeServiceSpec extends WordSpec
with Matchers with OneInstancePerTest MockFactory {
val fakeClient = mock[ASClientLike]
val service = AerospikeService(fakeClient, "namespace")
// ...
}
It's a lot of boilerplate, but that also allows us to keep our implementation super flexible without altering any public APIs
from aerospike-client-java.
Java client 3.0.34 has been released which includes IAerospikeClient and IAsyncClient.
from aerospike-client-java.
I have made a aerospike-unit module, which one can use while writing unit, Integration test cases . (Java Project)
This is a Java wrapper over actual Aerospike Server which can be used for unit + Integration Testing .
Open Source CodeBase: https://github.com/maverickgautam/Aerospike-unit
Readme available at https://github.com/maverickgautam/Aerospike-unit/blob/master/README
Hope Aerospike community finds this useful .
from aerospike-client-java.
Related Issues (20)
- Get namespaces/sets by AerospikeClient.
- Streaming support for batch operations HOT 2
- rename Record to AerospikeRecord HOT 1
- View screenshot link is broken HOT 1
- Type Erasure in 5.1.11 HOT 7
- Fully support surrogates symbol in Strings HOT 5
- Wrong condition for aeropsike client connectivity HOT 6
- Add RetryListener HOT 7
- Security contact? HOT 2
- Aerospike Cluster Peer Invalid Node Docker HOT 3
- Node name is null HOT 1
- Error 20: Partition map empty ( Issue for java client ) HOT 8
- Add support for findBySinceUpdate using since_update in metadata HOT 2
- What is the difference between `BatchRecordArrayListener` and `RecordArrayListener`? HOT 2
- How to make async queries faster? HOT 3
- java.lang.NullPointerException in AerospikeClient.put() HOT 4
- Setters for Spring HOT 2
- Enable releases in github HOT 4
- Problem reading Date type with client version 7.X HOT 2
- When compiling lua, the client discards the exception which has the lua compilation error details. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aerospike-client-java.