aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBogumil Zebek <bogumil.zebek@nokia.com>2020-05-08 10:42:03 +0000
committerGerrit Code Review <gerrit@onap.org>2020-05-08 10:42:03 +0000
commit1337fd3c5452f0836091de285a771832d7f5d005 (patch)
tree80938a3073b6ba6872258b69ae72061895861d35
parentf1effd9cb84a47302a36035cd62fb42b531f557c (diff)
parentba170b0a6bf2cc295a58ddbdc8da0cc2f6dbddfd (diff)
Merge "Fix failing integration test in netconf simulator"
-rw-r--r--netconfsimulator/src/it/java/integration/NetconfFunctionsIT.java53
-rw-r--r--netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/StoreService.java6
2 files changed, 44 insertions, 15 deletions
diff --git a/netconfsimulator/src/it/java/integration/NetconfFunctionsIT.java b/netconfsimulator/src/it/java/integration/NetconfFunctionsIT.java
index 5d1a25a..495714b 100644
--- a/netconfsimulator/src/it/java/integration/NetconfFunctionsIT.java
+++ b/netconfsimulator/src/it/java/integration/NetconfFunctionsIT.java
@@ -53,6 +53,10 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(BeforeAfterSpringTestRunner.class)
public class NetconfFunctionsIT {
+ private static final String NEW_YANG_MODEL_NAME = "newyangmodel";
+ private static final String NEW_YANG_MODEL_FILE = "newYangModel.yang";
+ private static final String INITIAL_CONFIG_XML_FILE = "initialConfig.xml";
+ private static final String CONFIG_NAME = "config2";
private static NetconfSimulatorClient client;
private static ObjectMapper objectMapper;
@@ -104,7 +108,7 @@ public class NetconfFunctionsIT {
public void testShouldLoadModelEditConfigurationAndDeleteModule() throws IOException {
// do load
try (CloseableHttpResponse response = client
- .loadModel("newyangmodel", "newYangModel.yang", "initialConfig.xml")) {
+ .loadModel(NEW_YANG_MODEL_NAME, NEW_YANG_MODEL_FILE, INITIAL_CONFIG_XML_FILE)) {
assertResponseStatusCode(response, HttpStatus.OK);
String original = client.getResponseContentAsString(response);
assertThat(original).isEqualTo("\"Successfully started\"\n");
@@ -116,7 +120,7 @@ public class NetconfFunctionsIT {
assertThat(afterUpdateConfigContent).isEqualTo("New configuration has been activated");
}
// do delete
- try (CloseableHttpResponse deleteResponse = client.deleteModel("newyangmodel")) {
+ try (CloseableHttpResponse deleteResponse = client.deleteModel(NEW_YANG_MODEL_NAME)) {
assertResponseStatusCode(deleteResponse, HttpStatus.OK);
String original = client.getResponseContentAsString(deleteResponse);
assertThat(original).isEqualTo("\"Successfully deleted\"\n");
@@ -179,7 +183,7 @@ public class NetconfFunctionsIT {
@Test
public void testShouldLoadNewYangModelAndReconfigure() throws IOException {
try (CloseableHttpResponse response = client
- .loadModel("newyangmodel", "newYangModel.yang", "initialConfig.xml")) {
+ .loadModel(NEW_YANG_MODEL_NAME, NEW_YANG_MODEL_FILE, INITIAL_CONFIG_XML_FILE)) {
assertResponseStatusCode(response, HttpStatus.OK);
String original = client.getResponseContentAsString(response);
@@ -188,23 +192,44 @@ public class NetconfFunctionsIT {
}
}
- // ToDo: fix this integration test
- // https://jira.onap.org/browse/INT-1535
- public void shouldGetLoadedModelByName() throws IOException {
+ @Test
+ public void shouldGetLoadedModelByName() throws IOException, InterruptedException {
testShouldLoadNewYangModelAndReconfigure();
- try (CloseableHttpResponse response = client.getConfigByModelAndContainerNames("newyangmodel", "config2")) {
- assertResponseStatusCode(response, HttpStatus.OK);
- String config = client.getResponseContentAsString(response);
-
- assertThat(config).isEqualTo(
- "<config2 xmlns=\"http://onap.org/newyangmodel\" xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
- + " <item1>100</item1>\n"
- + "</config2>\n");
+ if(checkIfModelIsPresentWithRetry(NEW_YANG_MODEL_NAME, CONFIG_NAME,4,500)) {
+ try (CloseableHttpResponse response = client.getConfigByModelAndContainerNames(NEW_YANG_MODEL_NAME, CONFIG_NAME)) {
+ assertResponseStatusCode(response, HttpStatus.OK);
+ String config = client.getResponseContentAsString(response);
+
+ assertThat(config).isEqualTo(
+ "<config2 xmlns=\"http://onap.org/newyangmodel\" xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
+ + " <item1>100</item1>\n"
+ + "</config2>\n");
+ }
+ } else {
+ fail("Could not find new YANG model by name");
}
}
+ private boolean checkIfModelIsPresentWithRetry(String model, String container,int retryCount,int interval) throws IOException, InterruptedException {
+ boolean isModelPresent = false;
+
+ for(int i=0 ; i<retryCount ; i++ ) {
+ try (CloseableHttpResponse response =
+ client.getConfigByModelAndContainerNames(model, container)) {
+ if( response.getStatusLine().getStatusCode() == HttpStatus.BAD_REQUEST.value() ) {
+ System.out.println("New yang model not present on kafka, retrying in " + interval + " ms.");
+ Thread.sleep(interval);
+ } else {
+ isModelPresent = true;
+ break;
+ }
+ }
+ }
+ return isModelPresent;
+ }
+
private void assertResponseStatusCode(HttpResponse response, HttpStatus expectedStatus) {
assertThat(response.getStatusLine().getStatusCode()).isEqualTo(expectedStatus.value());
}
diff --git a/netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/StoreService.java b/netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/StoreService.java
index 6bd8390..8f0f0cf 100644
--- a/netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/StoreService.java
+++ b/netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/StoreService.java
@@ -33,13 +33,14 @@ import java.time.Instant;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.NoSuchElementException;
@Slf4j
@Service
public class StoreService {
private static final String CONFIG_TOPIC = "config";
- private static final long CONSUMING_DURATION_IN_MS = 1000;
+ private static final long CONSUMING_DURATION_IN_MS = 5000;
private ConsumerFactory<String, String> consumerFactory;
static final List<String> TOPICS_TO_SUBSCRIBE = Collections.singletonList(CONFIG_TOPIC);
@@ -69,6 +70,9 @@ public class StoreService {
ConsumerRecords<String, String> consumerRecords = pollConsumerRecords(consumer);
consumerRecords.forEach(consumerRecord ->
messages.add(new Message(consumerRecord.timestamp(), consumerRecord.value())));
+ } catch (NoSuchElementException e) {
+ log.warn("not able to create consumer and to poll messages");
+ return Collections.emptyList();
}
return messages;
}