use of org.apache.servicecomb.foundation.vertx.http.AbstractHttpServletRequest in project incubator-servicecomb-java-chassis by apache.
the class TestAbstractRestInvocation method scheduleInvocationException.
@Test
public void scheduleInvocationException(@Mocked OperationMeta operationMeta) {
Executor executor = new ReactiveExecutor();
requestEx = new AbstractHttpServletRequest() {
};
requestEx.setAttribute(RestConst.REST_REQUEST, requestEx);
new Expectations() {
{
restOperation.getOperationMeta();
result = operationMeta;
operationMeta.getExecutor();
result = executor;
}
};
Holder<Throwable> result = new Holder<>();
Error error = new Error("run on executor");
restInvocation = new AbstractRestInvocationForTest() {
@Override
protected void runOnExecutor() {
throw error;
}
@Override
public void sendFailResponse(Throwable throwable) {
result.value = throwable;
}
};
restInvocation.requestEx = requestEx;
restInvocation.restOperationMeta = restOperation;
restInvocation.scheduleInvocation();
Assert.assertSame(error, result.value);
}
use of org.apache.servicecomb.foundation.vertx.http.AbstractHttpServletRequest in project incubator-servicecomb-java-chassis by apache.
the class TestAbstractRestInvocation method scheduleInvocationTimeout.
@Test
public void scheduleInvocationTimeout(@Mocked OperationMeta operationMeta) {
Executor executor = Runnable::run;
new Expectations() {
{
restOperation.getOperationMeta();
result = operationMeta;
operationMeta.getExecutor();
result = executor;
operationMeta.getMicroserviceQualifiedName();
result = "sayHi";
}
};
requestEx = new AbstractHttpServletRequest() {
};
restInvocation = new AbstractRestInvocationForTest() {
@Override
protected void runOnExecutor() {
throw new Error("run on executor");
}
@Override
public void sendFailResponse(Throwable throwable) {
throw (Error) throwable;
}
};
restInvocation.requestEx = requestEx;
restInvocation.restOperationMeta = restOperation;
// will not throw exception
restInvocation.scheduleInvocation();
}
use of org.apache.servicecomb.foundation.vertx.http.AbstractHttpServletRequest in project incubator-servicecomb-java-chassis by apache.
the class TestRestProducerInvocation method findRestOperationNormal.
@Test
public void findRestOperationNormal(@Mocked MicroserviceMeta microserviceMeta, @Mocked ServicePathManager servicePathManager, @Mocked OperationLocator locator) {
requestEx = new AbstractHttpServletRequest() {
@Override
public String getRequestURI() {
return "/path";
}
@Override
public String getMethod() {
return "GET";
}
@Override
public String getHeader(String name) {
return "ms";
}
};
Map<String, String> pathVars = new HashMap<>();
new Expectations(ServicePathManager.class) {
{
microserviceMetaManager.ensureFindValue("ms");
result = microserviceMeta;
ServicePathManager.getServicePathManager(microserviceMeta);
result = servicePathManager;
servicePathManager.producerLocateOperation(anyString, anyString);
result = locator;
locator.getPathVarMap();
result = pathVars;
locator.getOperation();
result = restOperationMeta;
}
};
restProducerInvocation = new RestProducerInvocation();
initRestProducerInvocation();
restProducerInvocation.findRestOperation();
Assert.assertSame(restOperationMeta, restProducerInvocation.restOperationMeta);
Assert.assertSame(pathVars, requestEx.getAttribute(RestConst.PATH_PARAMETERS));
}
use of org.apache.servicecomb.foundation.vertx.http.AbstractHttpServletRequest in project incubator-servicecomb-java-chassis by apache.
the class TestAbstractRestInvocation method scheduleInvocationNormal.
@Test
public void scheduleInvocationNormal(@Mocked OperationMeta operationMeta) {
long time = 123;
new MockUp<System>() {
@Mock
long nanoTime() {
return time;
}
};
Holder<InvocationStartEvent> eventHolder = new Holder<>();
Object subscriber = new Object() {
@Subscribe
public void onStart(InvocationStartEvent event) {
eventHolder.value = event;
}
};
EventManager.register(subscriber);
Executor executor = new ReactiveExecutor();
requestEx = new AbstractHttpServletRequest() {
};
requestEx.setAttribute(RestConst.REST_REQUEST, requestEx);
new Expectations() {
{
restOperation.getOperationMeta();
result = operationMeta;
operationMeta.getExecutor();
result = executor;
}
};
Holder<Boolean> result = new Holder<>();
restInvocation = new AbstractRestInvocationForTest() {
@Override
protected void runOnExecutor() {
result.value = true;
}
};
restInvocation.requestEx = requestEx;
restInvocation.restOperationMeta = restOperation;
restInvocation.scheduleInvocation();
EventManager.unregister(subscriber);
Assert.assertTrue(result.value);
Assert.assertEquals(time, invocation.getStartTime());
Assert.assertSame(invocation, eventHolder.value.getInvocation());
}
use of org.apache.servicecomb.foundation.vertx.http.AbstractHttpServletRequest in project incubator-servicecomb-java-chassis by apache.
the class TestAbstractRestInvocation method findRestOperationNormal.
@Test
public void findRestOperationNormal(@Mocked MicroserviceMeta microserviceMeta, @Mocked ServicePathManager servicePathManager, @Mocked OperationLocator locator) {
restInvocation = new AbstractRestInvocationForTest() {
@Override
protected OperationLocator locateOperation(ServicePathManager servicePathManager) {
return locator;
}
};
requestEx = new AbstractHttpServletRequest() {
};
restInvocation.requestEx = requestEx;
Map<String, String> pathVars = new HashMap<>();
new Expectations(ServicePathManager.class) {
{
ServicePathManager.getServicePathManager(microserviceMeta);
result = servicePathManager;
locator.getPathVarMap();
result = pathVars;
locator.getOperation();
result = restOperation;
}
};
restInvocation.findRestOperation(microserviceMeta);
Assert.assertSame(restOperation, restInvocation.restOperationMeta);
Assert.assertSame(pathVars, requestEx.getAttribute(RestConst.PATH_PARAMETERS));
}
Aggregations