Skip to content

Commit

Permalink
SCB-189 fix CI problems and warnings for feature support async restTe…
Browse files Browse the repository at this point in the history
…mplate

Signed-off-by: lijasonvip <libo75@huawei.com>
  • Loading branch information
lijasonvip authored and liubao68 committed Apr 8, 2018
1 parent 03cb63d commit 41228cb
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 27 deletions.
Expand Up @@ -24,7 +24,7 @@ public class HelloConsumer {
private final RestTemplate restTemplate = RestTemplateBuilder.create();

public void invokeHello(){
String result = restTemplate.getForObject("cse://business-service/hello", String.class);
restTemplate.getForObject("cse://business-service/hello", String.class);
}

}
Expand Up @@ -50,12 +50,11 @@ public OutputStream getBody() {
return null;
}

@SuppressWarnings("unchecked")
private ListenableFuture<ClientHttpResponse> invoke(Object[] args) {
Invocation invocation = prepareInvocation(args);
invocation.getHandlerContext().put(RestConst.CONSUMER_HEADER, this.getHeaders());
CompletableFuture<ClientHttpResponse> clientHttpResponseCompletableFuture = doAsyncInvoke(invocation);
return new CompletableToListenableFutureAdapter(clientHttpResponseCompletableFuture);
return new CompletableToListenableFutureAdapter<ClientHttpResponse>(clientHttpResponseCompletableFuture);
}

protected CompletableFuture<ClientHttpResponse> doAsyncInvoke(Invocation invocation) {
Expand Down
Expand Up @@ -34,14 +34,12 @@ public CseAsyncRestTemplate() {
}

@Override
@SuppressWarnings("unchecked")
protected <T> AsyncRequestCallback httpEntityCallback(HttpEntity<T> requestBody) {
return new CseAsyncRequestCallback(requestBody);
return new CseAsyncRequestCallback<T>(requestBody);
}

@Override
@SuppressWarnings("unchecked")
protected <T> AsyncRequestCallback httpEntityCallback(HttpEntity<T> requestBody, Type responseType) {
return new CseAsyncRequestCallback(requestBody);
return new CseAsyncRequestCallback<T>(requestBody);
}
}
Expand Up @@ -59,10 +59,10 @@ public void teardown() {
ReferenceConfigUtils.setReady(false);
}

@RequestMapping(path = "SpringmvcImpl")
static class SpringmvcImpl {
@RequestMapping(path = "/bytes", method = RequestMethod.POST)
public byte[] bytes(@RequestBody byte[] input) {
@RequestMapping(path = "CseAsyncClientHttpRequestTestSchema")
static class CseAsyncClientHttpRequestTestSchema {
@RequestMapping(path = "/testbytes", method = RequestMethod.POST)
public byte[] testbytes(@RequestBody byte[] input) {
input[0] = (byte) (input[0] + 1);
return input;
}
Expand All @@ -89,17 +89,18 @@ public void testNormal() {
serviceRegistry.init();
RegistryUtils.setServiceRegistry(serviceRegistry);
UnitTestMeta meta = new UnitTestMeta();

CseContext.getInstance()
.getSchemaListenerManager()
.setSchemaListenerList(Arrays.asList(new RestEngineSchemaListener()));

SchemaMeta schemaMeta = meta.getOrCreateSchemaMeta(CseAsyncClientHttpRequestTest.SpringmvcImpl.class);
SchemaMeta schemaMeta = meta.getOrCreateSchemaMeta(CseAsyncClientHttpRequestTest.CseAsyncClientHttpRequestTestSchema.class);
CseContext.getInstance().getSchemaListenerManager().notifySchemaListener(schemaMeta);

Holder<Invocation> holder = new Holder<>();
CseAsyncClientHttpRequest client =
new CseAsyncClientHttpRequest(URI.create(
"cse://app:test/" + CseAsyncClientHttpRequestTest.SpringmvcImpl.class.getSimpleName() + "/bytes"),
"cse://app:test/" + CseAsyncClientHttpRequestTest.CseAsyncClientHttpRequestTestSchema.class.getSimpleName() + "/testbytes"),
HttpMethod.POST) {
@Override
protected CompletableFuture<ClientHttpResponse> doAsyncInvoke(Invocation invocation) {
Expand All @@ -124,16 +125,15 @@ public void testFail() {
CseContext.getInstance()
.getSchemaListenerManager()
.setSchemaListenerList(Arrays.asList(new RestEngineSchemaListener()));

SchemaMeta schemaMeta = meta.getOrCreateSchemaMeta(CseAsyncClientHttpRequestTest.SpringmvcImpl.class);
SchemaMeta schemaMeta = meta.getOrCreateSchemaMeta(CseAsyncClientHttpRequestTest.CseAsyncClientHttpRequestTestSchema.class);
CseContext.getInstance().getSchemaListenerManager().notifySchemaListener(schemaMeta);

Throwable error = new Error("failed");
Response response = Response.createConsumerFail(error);

CseAsyncClientHttpRequest client =
new CseAsyncClientHttpRequest(URI.create(
"cse://app:test/" + CseAsyncClientHttpRequestTest.SpringmvcImpl.class.getSimpleName() + "/bytes"),
"cse://app:test/" + CseAsyncClientHttpRequestTest.CseAsyncClientHttpRequestTestSchema.class.getSimpleName() + "/testbytes"),
HttpMethod.POST) {
@Override
protected CompletableFuture<ClientHttpResponse> doAsyncInvoke(Invocation invocation) {
Expand Down
Expand Up @@ -28,27 +28,24 @@ public class CseAsyncRequestCallbackTest {
@Test
public void testNormal() {
CseAsyncClientHttpRequest request = new CseAsyncClientHttpRequest();
@SuppressWarnings("unchecked")
CseAsyncRequestCallback cb = new CseAsyncRequestCallback(null);
CseAsyncRequestCallback<HttpEntity<?>> cb = new CseAsyncRequestCallback<>(null);
cb.doWithRequest(request);
Assert.assertEquals(null, request.getContext());
}

@Test
@SuppressWarnings("unchecked")
public void testHttpEntity(@Injectable HttpEntity<?> entity) {
CseAsyncRequestCallback cb = new CseAsyncRequestCallback(entity);
public void testHttpEntity(@Injectable HttpEntity<String> entity) {
CseAsyncRequestCallback<String> cb = new CseAsyncRequestCallback<>(entity);
CseAsyncClientHttpRequest request = new CseAsyncClientHttpRequest();
cb.doWithRequest(request);
Assert.assertEquals(entity.getBody(), request.getBody());
}

@Test
@SuppressWarnings("unchecked")
public void testCseEntity(@Injectable CseHttpEntity<?> entity) {
public void testCseEntity(@Injectable CseHttpEntity<String> entity) {
CseAsyncClientHttpRequest request = new CseAsyncClientHttpRequest();
entity.addContext("c1", "c2");
CseAsyncRequestCallback cb = new CseAsyncRequestCallback(entity);
CseAsyncRequestCallback<String> cb = new CseAsyncRequestCallback<>(entity);
cb.doWithRequest(request);
Assert.assertEquals(entity.getContext(), request.getContext());
}
Expand Down
Expand Up @@ -16,8 +16,6 @@
*/
package org.apache.servicecomb.samples.springmvc.consumer;

import java.lang.invoke.MethodHandles;

import org.apache.servicecomb.foundation.common.utils.BeanUtils;
import org.apache.servicecomb.foundation.common.utils.Log4jUtils;
import org.apache.servicecomb.provider.pojo.RpcReference;
Expand All @@ -37,7 +35,7 @@

@Component
public class SpringmvcConsumerMain {
private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private static final Logger LOG = LoggerFactory.getLogger(SpringmvcConsumerMain.class);
private static RestTemplate restTemplate = RestTemplateBuilder.create();

@RpcReference(microserviceName = "springmvc", schemaId = "springmvcHello")
Expand Down

0 comments on commit 41228cb

Please sign in to comment.