tikv / client-java

TiKV Java Client
https://tikv.github.io/client-java/
Apache License 2.0
109 stars 105 forks source link

Mock server plan #531

Open iosmanthus opened 2 years ago

iosmanthus commented 2 years ago

Feature Request

The code coverage of client-java is insufficient. Planty of code logic can be only covered by the internal integration tests without more granular unit tests. There is a pull request: https://github.com/tikv/client-java/pull/518 on the way that is trying to increase the coverage of the retry logic of RawKVClient. However, this is not enough, we still get plenty of TODOs.

Including:

These may introduce us a more important problem: build a scalable mock server for TiKV and PD:

For now, PDMockServer is partially refactored by https://github.com/tikv/client-java/pull/518. It supports registering callbacks for gRPC service methods. Just like:


leader.addGetRegionListener(
    request ->
        GrpcUtils.makeGetRegionResponse(
            leader.getClusterId(),
            GrpcUtils.makeRegion(
                1,
                ByteString.copyFrom(startKey),
                ByteString.copyFrom(endKey),
                GrpcUtils.makeRegionEpoch(confVer, ver),
                GrpcUtils.makePeer(1, 10),
                GrpcUtils.makePeer(2, 20))));

When a getRegion RPC is made, the callback will be triggered.

This design might make it more flexible to mock everything the test caller need but may result in more repeat some "server"'s code in the tests. We might need to discuss if this design could fit our needs. If it does, the same refactoring could be applied to KVMockServer.

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 30 days with no activity.