summary |
shortlog |
log |
commit | commitdiff |
review |
tree
raw |
patch |
inline | side by side (from parent 1:
19f034b)
- this reduces the test execution time, when test cases run into timouts
Issue-ID: AAI-3703
Change-Id: Ie683f55e5ce8d59b10d2788aea6933854dcb7e99
Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.Optional;
import java.util.Properties;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.jetty.util.security.Password;
import org.onap.sdc.api.consumer.IConfiguration;
import java.util.Properties;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.jetty.util.security.Password;
import org.onap.sdc.api.consumer.IConfiguration;
/**
* Properties for the Model Loader
*
/**
* Properties for the Model Loader
*
protected static final String PROP_DEBUG_INGEST_SIMULATOR = PREFIX_DEBUG + "INGEST_SIMULATOR";
protected static final String FILESEP =
(System.getProperty("file.separator") == null) ? "/" : System.getProperty("file.separator");
protected static final String PROP_DEBUG_INGEST_SIMULATOR = PREFIX_DEBUG + "INGEST_SIMULATOR";
protected static final String FILESEP =
(System.getProperty("file.separator") == null) ? "/" : System.getProperty("file.separator");
+ protected static final String PROP_AAI_CLIENT_CONNECT_TIMEOUT_MS = PREFIX_AAI + "RESTCLIENT_CONNECT_TIMEOUT";
+ protected static final String PROP_AAI_CLIENT_READ_TIMEOUT_MS = PREFIX_AAI + "RESTCLIENT_READ_TIMEOUT";
private static String configHome;
private Properties modelLoaderProperties = null;
private static String configHome;
private Properties modelLoaderProperties = null;
+ public int getClientConnectTimeoutMs() {
+ String connectTimeout = Optional.ofNullable(get(PROP_AAI_CLIENT_CONNECT_TIMEOUT_MS)).orElse("120000");
+ return Integer.parseInt(connectTimeout);
+ }
+
+ public int getClientReadTimeoutMs() {
+ String connectTimeout = Optional.ofNullable(get(PROP_AAI_CLIENT_READ_TIMEOUT_MS)).orElse("120000");
+ return Integer.parseInt(connectTimeout);
+ }
+
private RestClient setupClient() {
RestClient restClient = new RestClient();
private RestClient setupClient() {
RestClient restClient = new RestClient();
+ restClient.validateServerHostname(false)
+ .validateServerCertChain(false)
+ .connectTimeoutMs(config.getClientConnectTimeoutMs())
+ .readTimeoutMs(config.getClientReadTimeoutMs());
//Use certs only if SSL is enabled
if (config.useHttpsWithAAI())
{// @formatter:off
//Use certs only if SSL is enabled
if (config.useHttpsWithAAI())
{// @formatter:off
- restClient.validateServerHostname(false)
- .validateServerCertChain(false)
- .clientCertFile(config.getAaiKeyStorePath())
- .clientCertPassword(config.getAaiKeyStorePassword())
- .connectTimeoutMs(120000)
- .readTimeoutMs(120000);
+ restClient
+ .clientCertFile(config.getAaiKeyStorePath())
+ .clientCertPassword(config.getAaiKeyStorePassword());
- else {
- restClient.validateServerHostname(false)
- .validateServerCertChain(false)
- .connectTimeoutMs(120000)
- .readTimeoutMs(120000);
- }
if (useBasicAuth()) {
restClient.authenticationMode(RestAuthenticationMode.SSL_BASIC);
if (useBasicAuth()) {
restClient.authenticationMode(RestAuthenticationMode.SSL_BASIC);
}
client = Client.create(new DefaultClientConfig());
}
client = Client.create(new DefaultClientConfig());
+ client.setConnectTimeout(config.getClientConnectTimeoutMs());
+ client.setReadTimeout(config.getClientReadTimeoutMs());
logger.debug(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Jersey client created");
}
logger.debug(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Jersey client created");
}
@BeforeEach
public void startJetty() throws Exception {
@BeforeEach
public void startJetty() throws Exception {
- server = new Server(8080);
+ server = new Server(0);
server.setHandler(getMockHandler());
server.start();
Properties props = new Properties();
props.put("ml.aai.KEYSTORE_PASSWORD", "2244");
server.setHandler(getMockHandler());
server.start();
Properties props = new Properties();
props.put("ml.aai.KEYSTORE_PASSWORD", "2244");
+ props.put("ml.aai.RESTCLIENT_CONNECT_TIMEOUT", "3000");
+ props.put("ml.aai.RESTCLIENT_READ_TIMEOUT", "3000");
ModelLoaderConfig config = new ModelLoaderConfig(props, ".");
aaiClient = new AaiRestClient(config);
}
ModelLoaderConfig config = new ModelLoaderConfig(props, ".");
aaiClient = new AaiRestClient(config);
}
@Test
public void testOperations() {
@Test
public void testOperations() {
- String url = "http://localhost:8080";
+ String url = server.getURI().toString();
String transId = "";
MediaType mediaType = MediaType.APPLICATION_JSON_TYPE;
aaiClient.getResource(url, "", mediaType);
String transId = "";
MediaType mediaType = MediaType.APPLICATION_JSON_TYPE;
aaiClient.getResource(url, "", mediaType);
- aaiClient.deleteResource("http://localhost", transId, "");
+ aaiClient.deleteResource(url, "", transId);
aaiClient.getAndDeleteResource(url, transId);
aaiClient.postResource(url, "", transId, mediaType);
aaiClient.putResource(url, "", transId, mediaType);
aaiClient.getAndDeleteResource(url, transId);
aaiClient.postResource(url, "", transId, mediaType);
aaiClient.putResource(url, "", transId, mediaType);
response.add(new BabelArtifact("", null, ""));
responseBody = new Gson().toJson(response);
response.add(new BabelArtifact("", null, ""));
responseBody = new Gson().toJson(response);
- server = new Server(8080);
+ server = new Server(0);
server.setHandler(getMockHandler());
server.start();
}
server.setHandler(getMockHandler());
server.start();
}
@Test
public void testRestClient() throws BabelServiceClientException, IOException, URISyntaxException {
@Test
public void testRestClient() throws BabelServiceClientException, IOException, URISyntaxException {
+ String url = server.getURI().toString();
Properties configProperties = new Properties();
configProperties.put("ml.babel.KEYSTORE_PASSWORD", "OBF:1vn21ugu1saj1v9i1v941sar1ugw1vo0");
configProperties.put("ml.babel.KEYSTORE_FILE", "src/test/resources/auth/aai-client-dummy.p12");
configProperties.put("ml.babel.TRUSTSTORE_PASSWORD", "OBF:1vn21ugu1saj1v9i1v941sar1ugw1vo0");
// In a real deployment this would be a different file (to the client keystore)
configProperties.put("ml.babel.TRUSTSTORE_FILE", "src/test/resources/auth/aai-client-dummy.p12");
Properties configProperties = new Properties();
configProperties.put("ml.babel.KEYSTORE_PASSWORD", "OBF:1vn21ugu1saj1v9i1v941sar1ugw1vo0");
configProperties.put("ml.babel.KEYSTORE_FILE", "src/test/resources/auth/aai-client-dummy.p12");
configProperties.put("ml.babel.TRUSTSTORE_PASSWORD", "OBF:1vn21ugu1saj1v9i1v941sar1ugw1vo0");
// In a real deployment this would be a different file (to the client keystore)
configProperties.put("ml.babel.TRUSTSTORE_FILE", "src/test/resources/auth/aai-client-dummy.p12");
- configProperties.put("ml.babel.BASE_URL", "http://localhost:8080/");
+ configProperties.put("ml.babel.BASE_URL", url);
configProperties.put("ml.babel.GENERATE_ARTIFACTS_URL", "generate");
BabelServiceClient client =
new HttpsBabelServiceClientFactory().create(new ModelLoaderConfig(configProperties, "."));
configProperties.put("ml.babel.GENERATE_ARTIFACTS_URL", "generate");
BabelServiceClient client =
new HttpsBabelServiceClientFactory().create(new ModelLoaderConfig(configProperties, "."));
@Test
public void testRestClientHttp() throws BabelServiceClientException, IOException, URISyntaxException {
@Test
public void testRestClientHttp() throws BabelServiceClientException, IOException, URISyntaxException {
+ String url = server.getURI().toString();
Properties configProperties = new Properties();
configProperties.put("ml.babel.USE_HTTPS", "false");
Properties configProperties = new Properties();
configProperties.put("ml.babel.USE_HTTPS", "false");
- configProperties.put("ml.babel.BASE_URL", "http://localhost:8080/");
+ configProperties.put("ml.babel.BASE_URL", url);
configProperties.put("ml.babel.GENERATE_ARTIFACTS_URL", "generate");
configProperties.put("ml.babel.GENERATE_ARTIFACTS_URL", "generate");
+ configProperties.put("ml.aai.RESTCLIENT_CONNECT_TIMEOUT", "3000");
+ configProperties.put("ml.aai.RESTCLIENT_READ_TIMEOUT", "3000");
BabelServiceClient client =
new HttpsBabelServiceClientFactory().create(new ModelLoaderConfig(configProperties, "."));
List<BabelArtifact> result =
BabelServiceClient client =
new HttpsBabelServiceClientFactory().create(new ModelLoaderConfig(configProperties, "."));
List<BabelArtifact> result =