-
Notifications
You must be signed in to change notification settings - Fork 803
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SCB-1305] add IT and ITSCBAsyncRestTemplate
- Loading branch information
1 parent
4083f5b
commit 6d5d662
Showing
6 changed files
with
183 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...sumer/src/main/java/org/apache/servicecomb/it/extend/engine/ITAsyncClientHttpRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.servicecomb.it.extend.engine; | ||
|
||
import java.net.URI; | ||
|
||
import org.apache.servicecomb.core.CseContext; | ||
import org.apache.servicecomb.core.provider.consumer.ReferenceConfig; | ||
import org.apache.servicecomb.provider.springmvc.reference.async.CseAsyncClientHttpRequest; | ||
import org.springframework.http.HttpMethod; | ||
|
||
public class ITAsyncClientHttpRequest extends CseAsyncClientHttpRequest { | ||
private String transport; | ||
|
||
public ITAsyncClientHttpRequest(URI uri, HttpMethod method, String transport) { | ||
super(uri, method); | ||
this.transport = transport; | ||
} | ||
|
||
@Override | ||
protected ReferenceConfig findReferenceConfig(String microserviceName) { | ||
ReferenceConfig referenceConfig = CseContext.getInstance().getConsumerProviderManager() | ||
.createReferenceConfig(microserviceName); | ||
if (transport != null) { | ||
referenceConfig.setTransport(transport); | ||
} | ||
return referenceConfig; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...rc/main/java/org/apache/servicecomb/it/extend/engine/ITAsyncClientHttpRequestFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.servicecomb.it.extend.engine; | ||
|
||
import java.net.URI; | ||
|
||
import org.apache.servicecomb.it.junit.ITJUnitUtils; | ||
import org.apache.servicecomb.provider.springmvc.reference.async.CseAsyncClientHttpRequestFactory; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.client.AsyncClientHttpRequest; | ||
|
||
public class ITAsyncClientHttpRequestFactory extends CseAsyncClientHttpRequestFactory { | ||
private String transport; | ||
|
||
public ITAsyncClientHttpRequestFactory() { | ||
this.transport = ITJUnitUtils.getTransport(); | ||
} | ||
|
||
@Override | ||
public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) { | ||
return new ITAsyncClientHttpRequest(uri, httpMethod, transport); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
...onsumer/src/main/java/org/apache/servicecomb/it/extend/engine/ITSCBAsyncRestTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.servicecomb.it.extend.engine; | ||
|
||
import java.util.Optional; | ||
|
||
import org.apache.servicecomb.core.definition.MicroserviceVersionMeta; | ||
import org.apache.servicecomb.core.definition.SchemaMeta; | ||
import org.apache.servicecomb.it.junit.ITJUnitUtils; | ||
import org.apache.servicecomb.provider.springmvc.reference.async.CseAsyncRestTemplate; | ||
import org.apache.servicecomb.serviceregistry.RegistryUtils; | ||
import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance; | ||
import org.apache.servicecomb.serviceregistry.consumer.MicroserviceVersionRule; | ||
import org.apache.servicecomb.serviceregistry.definition.DefinitionConst; | ||
|
||
public class ITSCBAsyncRestTemplate extends CseAsyncRestTemplate { | ||
private String urlPrefix; | ||
|
||
private String schemaId; | ||
|
||
private String basePath; | ||
|
||
private MicroserviceInstance instance; | ||
|
||
public ITSCBAsyncRestTemplate(String schemaId) { | ||
this.schemaId = schemaId; | ||
} | ||
|
||
public ITSCBAsyncRestTemplate init() { | ||
String producerName = ITJUnitUtils.getProducerName(); | ||
MicroserviceVersionRule microserviceVersionRule = RegistryUtils.getServiceRegistry().getAppManager() | ||
.getOrCreateMicroserviceVersionRule(RegistryUtils.getAppId(), producerName, | ||
DefinitionConst.VERSION_RULE_ALL); | ||
MicroserviceVersionMeta microserviceVersionMeta = microserviceVersionRule.getLatestMicroserviceVersion(); | ||
SchemaMeta schemaMeta = microserviceVersionMeta.getMicroserviceMeta().ensureFindSchemaMeta(schemaId); | ||
basePath = schemaMeta.getSwagger().getBasePath(); | ||
urlPrefix = String.format("cse://%s%s", producerName, basePath); | ||
instance = RegistryUtils.getServiceRegistry().getAppManager() | ||
.getOrCreateMicroserviceManager(RegistryUtils.getAppId()) | ||
.getOrCreateMicroserviceVersions(producerName).getPulledInstances().get(0); | ||
|
||
setUriTemplateHandler(new ITUriTemplateHandler(urlPrefix)); | ||
setAsyncRequestFactory(new ITAsyncClientHttpRequestFactory()); | ||
|
||
return this; | ||
} | ||
|
||
public String getBasePath() { | ||
return basePath; | ||
} | ||
|
||
public String getUrlPrefix() { | ||
return urlPrefix; | ||
} | ||
|
||
public String getAddress(String transport) { | ||
Optional<String> addressHolder = instance.getEndpoints().stream() | ||
.filter(endpoint -> endpoint.startsWith(transport)) | ||
.findFirst(); | ||
return addressHolder.get(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters