Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
public interface MClient {
@ClientHeaderParam(name = "Accept", value = "application/vnd.finplan-mc.v1+json")
CompletionStage<Response> getClients(
@QueryParam("contextType") String contextType,
@QueryParam("contextKey") String contextKey,
@QueryParam("offset") int offset,
@QueryParam("limit") int limit) throws Exception;
@ClientHeaderParam(name = "Accept", value = "application/vnd.finplan-mc.v1+json")
CompletionStage<Response> getClientsCount(
@QueryParam("contextType") String contextType,
@QueryParam("contextKey") String contextKey) throws Exception;
public class MPartyRepositoryImpl implements MPartyRepository {
private MClient client;
@Timed(name = "M_getClients", absolute = true, description = "Time needed to get the MC client list", unit = MetricUnits.MICROSECONDS)
public MCAdapter getMCClients(String cd1, String cd2, int offset, int limit) throws Exception {
final CompletableFuture<Response> clientCallFuture = (CompletableFuture<Response>) client.getClients(
cd1 + "-" + cd2,
final CompletableFuture<Response> countCallFuture = (CompletableFuture<Response>) client.getClientsCount("CDB",
cd1 + "-" + cd2);
CompletableFuture.allOf(countCallFuture, clientCallFuture);
final Response clientCallRes = clientCallFuture.join();
final Response countCallRes = countCallFuture.join();
MCAdapter adapter = new MCAdapter();
if(countCallRes.getStatus() == 200 && clientCallRes.getStatus()==200){
return adapter;
class MPartyRepositoryImplTest {
MPartyRepositoryImpl repository = new MPartyRepositoryImpl();
private static final String CONTENT_TYPE_HEADER = "Content-Type: application/vnd.finplan-mc.v1+json";
private MClient client;
private static final String CD1 = "039999";
private static final String CD2 = "060267";
private static final int OFFSET = 0;
private static final int LIMIT = 100;
private static final String CONTEXT_KEY = "039996-507311";
private static final String CONTEXT_TYPE = "CDB";
private MockWebServer mockWebServer = new MockWebServer();
static void setupClass() {
System.setProperty("audit-file-folder", "logs");
System.setProperty("audit-logger-standalone", "true");
void setup() throws IOException {
client = RestClientBuilder
.connectTimeout(5, TimeUnit.SECONDS)
.readTimeout(5, TimeUnit.SECONDS)
public void tearDown() throws IOException {
void testTimeOut_getMClients() {
mockWebServer.enqueue(new MockResponse().setResponseCode(Status.GATEWAY_TIMEOUT.getStatusCode()));
mockWebServer.enqueue(new MockResponse().setResponseCode(Status.GATEWAY_TIMEOUT.getStatusCode()));
Exception be = assertThrows(BFFException.class, () -> repository.getMClients(CD1, CD2, OFFSET, LIMIT));
assertEquals(Status.GATEWAY_TIMEOUT.getStatusCode(), be.getCode());
Copy link

andymc12 commented Jul 29, 2019

@manish2aug - are you setting the connect and read timeout for the client instance that is injected into MPartyRepositoryImpl ? I see that you are setting each to 5 seconds in the test class, but that will be a different instance. The timeouts need to be set using MP Config properties com.mypackage.MClient/mp-rest/connectTimeout and com.mypackage.MClient/mp-rest/readTimeout (the values are the time in milliseconds before timing out).

I'm suspecting that the problem is that the base URI for the endpoint may be specified incorrectly, and it is timing out - but using the default timeouts which may seem like it is hung. I'm planning to reproduce this to verify, but thought that you might want to look into the base URI and timeouts in the mean time.

Thanks, Andy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment