use of org.apache.servicecomb.foundation.vertx.http.AbstractHttpServletResponse in project java-chassis by ServiceComb.
the class TestAbstractRestInvocation method scheduleInvocation_invocationContextDeserializeError.
@Test
public void scheduleInvocation_invocationContextDeserializeError(@Mocked AsyncContext asyncContext) {
requestEx = new AbstractHttpServletRequest() {
@Override
public String getHeader(String name) {
return "{\"x-cse-src-microservice\":'source\"}";
}
@Override
public AsyncContext getAsyncContext() {
return asyncContext;
}
};
Holder<Integer> status = new Holder<>();
Holder<String> reasonPhrase = new Holder<>();
Holder<Integer> endCount = new Holder<>(0);
responseEx = new AbstractHttpServletResponse() {
@SuppressWarnings("deprecation")
@Override
public void setStatus(int sc, String sm) {
status.value = sc;
reasonPhrase.value = sm;
}
@Override
public void flushBuffer() {
endCount.value = endCount.value + 1;
}
@Override
public void setContentType(String type) {
assertEquals("application/json; charset=utf-8", type);
}
};
restInvocation.requestEx = requestEx;
restInvocation.responseEx = responseEx;
restInvocation.scheduleInvocation();
assertEquals(Integer.valueOf(590), status.value);
assertEquals("Unexpected producer error, please check logs for details", reasonPhrase.value);
assertEquals(Integer.valueOf(1), endCount.value);
}
use of org.apache.servicecomb.foundation.vertx.http.AbstractHttpServletResponse in project java-chassis by ServiceComb.
the class TestAbstractRestInvocation method scheduleInvocation_flowControlReject.
@SuppressWarnings("deprecation")
@Test
public void scheduleInvocation_flowControlReject() {
new Expectations(operationMeta) {
{
operationMeta.getProviderQpsFlowControlHandler();
result = (Handler) (invocation, asyncResp) -> asyncResp.producerFail(new InvocationException(new HttpStatus(429, "Too Many Requests"), new CommonExceptionData("rejected by qps flowcontrol")));
}
};
Holder<Integer> status = new Holder<>();
Holder<String> reasonPhrase = new Holder<>();
Holder<Integer> endCount = new Holder<>(0);
Holder<String> responseBody = new Holder<>();
responseEx = new AbstractHttpServletResponse() {
@SuppressWarnings("deprecation")
@Override
public void setStatus(int sc, String sm) {
status.value = sc;
reasonPhrase.value = sm;
}
@Override
public void flushBuffer() {
endCount.value = endCount.value + 1;
}
@Override
public void setContentType(String type) {
assertEquals("application/json; charset=utf-8", type);
}
@Override
public void setBodyBuffer(Buffer bodyBuffer) {
responseBody.value = bodyBuffer.toString();
}
};
initRestInvocation();
restInvocation.scheduleInvocation();
assertEquals(Integer.valueOf(429), status.value);
assertEquals("Too Many Requests", reasonPhrase.value);
assertEquals("{\"message\":\"rejected by qps flowcontrol\"}", responseBody.value);
assertEquals(Integer.valueOf(1), endCount.value);
}
use of org.apache.servicecomb.foundation.vertx.http.AbstractHttpServletResponse in project incubator-servicecomb-java-chassis by apache.
the class TestAbstractRestInvocation method scheduleInvocation_invocationContextDeserializeError.
@Test
public void scheduleInvocation_invocationContextDeserializeError(@Mocked AsyncContext asyncContext) {
requestEx = new AbstractHttpServletRequest() {
@Override
public String getHeader(String name) {
return "{\"x-cse-src-microservice\":'source\"}";
}
@Override
public AsyncContext getAsyncContext() {
return asyncContext;
}
};
Holder<Integer> status = new Holder<>();
Holder<String> reasonPhrase = new Holder<>();
Holder<Integer> endCount = new Holder<>(0);
responseEx = new AbstractHttpServletResponse() {
@SuppressWarnings("deprecation")
@Override
public void setStatus(int sc, String sm) {
status.value = sc;
reasonPhrase.value = sm;
}
@Override
public void flushBuffer() {
endCount.value = endCount.value + 1;
}
@Override
public void setContentType(String type) {
assertEquals("application/json; charset=utf-8", type);
}
};
restInvocation.requestEx = requestEx;
restInvocation.responseEx = responseEx;
restInvocation.scheduleInvocation();
assertEquals(Integer.valueOf(590), status.value);
assertEquals("Unexpected producer error, please check logs for details", reasonPhrase.value);
assertEquals(Integer.valueOf(1), endCount.value);
}
use of org.apache.servicecomb.foundation.vertx.http.AbstractHttpServletResponse in project incubator-servicecomb-java-chassis by apache.
the class TestAbstractRestInvocation method scheduleInvocation_flowControlReject.
@SuppressWarnings("deprecation")
@Test
public void scheduleInvocation_flowControlReject() {
new Expectations(operationMeta) {
{
operationMeta.getProviderQpsFlowControlHandler();
result = (Handler) (invocation, asyncResp) -> asyncResp.producerFail(new InvocationException(new HttpStatus(429, "Too Many Requests"), new CommonExceptionData("rejected by qps flowcontrol")));
}
};
Holder<Integer> status = new Holder<>();
Holder<String> reasonPhrase = new Holder<>();
Holder<Integer> endCount = new Holder<>(0);
Holder<String> responseBody = new Holder<>();
responseEx = new AbstractHttpServletResponse() {
@SuppressWarnings("deprecation")
@Override
public void setStatus(int sc, String sm) {
status.value = sc;
reasonPhrase.value = sm;
}
@Override
public void flushBuffer() {
endCount.value = endCount.value + 1;
}
@Override
public void setContentType(String type) {
assertEquals("application/json; charset=utf-8", type);
}
@Override
public void setBodyBuffer(Buffer bodyBuffer) {
responseBody.value = bodyBuffer.toString();
}
};
initRestInvocation();
restInvocation.scheduleInvocation();
assertEquals(Integer.valueOf(429), status.value);
assertEquals("Too Many Requests", reasonPhrase.value);
assertEquals("{\"message\":\"rejected by qps flowcontrol\"}", responseBody.value);
assertEquals(Integer.valueOf(1), endCount.value);
}
Aggregations