To be able to validate the response object from the application, Pibify provides a Parity Check feature.
An application can run in parity check mode where the response object is intercepted before sending to the client.
The response object is run through Pibify Serializer and then deserialized back.
This object is then compared with the expected response object is deepEquals and callbacks are triggered based on the
result.
Client can hook a IParityCheckerListener
to get the details and emit metrics/log as needed.
- Add the maven dependency for assertJ
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.26.3</version>
</dependency>
- Register the appropriate filter in the Dropwizard application -
JakartaJsonResponseFilter
orJavaxJsonResponseFilter
. This filter needs an instance ofIParityChecker
andAbstractPibifySampler
to be passed.
This class holds the logic of running the parity check. It expects an implementation of IParityCheckerListener
for triggering parity check status callbacks and a supplier for request context to be passed.
The PibifyHandlerCache
is needed to run a cycle of serde for the actual parity check.
IParityChecker parityChecker = new PibifyParityChecker(PibifyHandlerCache.getInstance(), new IParityCheckerListener() {...
}, Optional.of(() -> null), new AbstractPibifySampler() {...
});
This class holds the logic of sampling the request for parity check. Implementation expect a sample % to be returned in a call back method.
This interface contains the callbacks for the parity check results. The methods are called with the expected and actual objects and the result of the comparison. Implementations of this class can hook up to the respective metric/logging systems to emit the results.
- Add the maven dependency for assertJ
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.26.3</version>
</dependency>
- Pass the parity checker instance to the decorator
IParityChecker parityChecker = new PibifyParityChecker(PibifyHandlerCache.getInstance(), new IParityCheckerListener() {...
},
null, new AbstractPibifySampler() {...
});
This resource is exposed to help visualize the proto returned from the server. The proto can be sent back to server along with the FQDN of the class to deserialize the proto.
- Register the appropriate resource by instance in the Dropwizard application -
JakartaParityCheckResource
orJavaxParityCheckResource
environment.jersey().
register(new JakartaParityCheckResource(PibifyHandlerCache.getInstance()));
- Curl for storing the proto on local
curl http://localhost:8080/sample -H 'Accept:application/proto' --output protoout.bin
- Curl for sending the proto to server
curl --request POST --data-binary "@protoout.bin"
http://localhost:8080/pibify/paritychecker?fqdn=com.flipkart.pibify.resources.SampleResponse
-H 'Content-Type:application/octet-stream'