[DMAAP-MR] Set topic replica & partition from config 46/132446/3 1.4.4
authorefiacor <fiachra.corcoran@est.tech>
Thu, 24 Nov 2022 15:54:58 +0000 (15:54 +0000)
committerefiacor <fiachra.corcoran@est.tech>
Fri, 25 Nov 2022 09:33:31 +0000 (09:33 +0000)
Signed-off-by: efiacor <fiachra.corcoran@est.tech>
Change-Id: Ie672075ca65ad4f24f0b163cd84d31c373e331c8
Issue-ID: DMAAP-1842

csit/prepare-csit.sh
csit/run-csit.sh
src/main/java/org/onap/dmaap/dmf/mr/service/impl/TopicServiceImpl.java
src/test/java/org/onap/dmaap/dmf/mr/service/impl/TopicServiceImplTest.java

index a65368c..65c8351 100755 (executable)
@@ -24,15 +24,15 @@ fi
 
 TESTPLANDIR=${WORKSPACE}/${TESTPLAN}
 
-# Assume that if ROBOT_VENV is set and virtualenv with system site packages can be activated, 
+# Assume that if ROBOT3_VENV is set and virtualenv with system site packages can be activated,
 # ci-management/jjb/integration/include-raw-integration-install-robotframework.sh has already
 # been executed
 
 if [ -f ${WORKSPACE}/env.properties ]; then
     source ${WORKSPACE}/env.properties
 fi
-if [ -f ${ROBOT_VENV}/bin/activate ]; then
-    source ${ROBOT_VENV}/bin/activate
+if [ -f ${ROBOT3_VENV}/bin/activate ]; then
+    source ${ROBOT3_VENV}/bin/activate
 else
     rm -rf /tmp/ci-management
     rm -f ${WORKSPACE}/env.properties
@@ -42,8 +42,8 @@ else
 fi
 
 # install eteutils
-mkdir -p ${ROBOT_VENV}/src/onap
-rm -rf ${ROBOT_VENV}/src/onap/testsuite
+mkdir -p ${ROBOT3_VENV}/src/onap
+rm -rf ${ROBOT3_VENV}/src/onap/testsuite
 pip install --upgrade --extra-index-url="https://nexus3.onap.org/repository/PyPi.staging/simple" 'robotframework-onap==0.5.1.*' --pre
 
 pip freeze
index b987e60..038c55c 100755 (executable)
@@ -154,13 +154,13 @@ TESTPLANDIR="${WORKSPACE}/${TESTPLAN}"
 source_safely "${WORKSPACE}/prepare-csit.sh"
 
 # Activate the virtualenv containing all the required libraries installed by prepare-csit.sh
-source_safely "${ROBOT_VENV}/bin/activate"
+source_safely "${ROBOT3_VENV}/bin/activate"
 
 WORKDIR=$(mktemp -d --suffix=-robot-workdir)
 cd "${WORKDIR}"
 
 # Add csit scripts to PATH
-export PATH="${PATH}:${WORKSPACE}/docker/scripts:${WORKSPACE}/scripts:${ROBOT_VENV}/bin"
+export PATH="${PATH}:${WORKSPACE}/docker/scripts:${WORKSPACE}/scripts:${ROBOT3_VENV}/bin"
 export SCRIPTS="${WORKSPACE}/scripts"
 export ROBOT_VARIABLES=
 
index 386fb97..69c1414 100644 (file)
@@ -198,8 +198,9 @@ public class TopicServiceImpl implements TopicService {
                LOGGER.info("Creating topic {}",topicName);
                String key = authorizeClient(dmaapContext, topicName, TOPIC_CREATE_OP);
                try {
-                       final int partitions = getValueOrDefault(topicBean.getPartitionCount(), "default.partitions");
-                       final int replicas = getValueOrDefault(topicBean.getReplicationCount(), "default.replicas");
+                       final int partitions = getIntValueOrDefault("default.partitions");
+                       final int replicas = getIntValueOrDefault("default.replicas");
+                       LOGGER.info("Attempting to create topic {} with replicas={}, partitions={}", topicName, replicas, partitions);
                        final Topic t = getMetaBroker(dmaapContext).createTopic(topicName, topicBean.getTopicDescription(),
                                key, partitions, replicas, topicBean.isTransactionEnabled());
                        LOGGER.info("Topic {} created successfully. Sending response", topicName);
@@ -258,13 +259,11 @@ public class TopicServiceImpl implements TopicService {
                return enfTopicNamespace != null && topicName.startsWith(enfTopicNamespace);
        }
 
-       int getValueOrDefault(int value, String defaultProperty) {
-               int returnValue = value;
-               if (returnValue <= 0) {
-                       String defaultValue = getPropertyFromAJSCmap(defaultProperty);
-                       returnValue = StringUtils.isNotEmpty(defaultValue) ? NumberUtils.toInt(defaultValue) : 1;
-                       returnValue = (returnValue <= 0) ? 1 : returnValue;
-               }
+       int getIntValueOrDefault(String defaultProperty) {
+               int returnValue;
+               String defaultValue = getPropertyFromAJSCmap(defaultProperty);
+               returnValue = StringUtils.isNotEmpty(defaultValue) ? NumberUtils.toInt(defaultValue) : 1;
+               returnValue = (returnValue <= 0) ? 1 : returnValue;
                return returnValue;
        }
 
index 4424aa9..90c379e 100644 (file)
@@ -290,73 +290,42 @@ public class TopicServiceImplTest {
     }
 
     @Test
-    public void getValueOrDefault_shouldParseDeafultAndReturnIt_whenGivenValueIsZero() {
+    public void getIntValueOrDefault_shouldReturnOne_whenDefaultNotProvided() {
         //given
-        int value = 0;
         String defaultPropertyName = "propertyName";
-        when(topicService.getPropertyFromAJSCmap(defaultPropertyName)).thenReturn("6");
-
-        //when
-        int extracted = topicService.getValueOrDefault(value, defaultPropertyName);
-
-        //then
-        assertEquals(6, extracted);
-    }
-
-    @Test
-    public void getValueOrDefault_shouldReturnGivenValue_whenGreaterThanZero() {
-        //given
-        int value = 3;
-        String defaultPropertyName = "propertyName";
-
-        //when
-        int extracted = topicService.getValueOrDefault(value, defaultPropertyName);
-
-        //then
-        assertEquals(value, extracted);
-        verify(topicService, never()).getPropertyFromAJSCmap(defaultPropertyName);
-    }
-
-    @Test
-    public void getValueOrDefault_shouldParseDeafultAndReturnIt_whenGivenValueIsNegative() {
-        //given
-        int value = -3;
-        String defaultPropertyName = "propertyName";
-        when(topicService.getPropertyFromAJSCmap(defaultPropertyName)).thenReturn("6");
+        when(topicService.getPropertyFromAJSCmap(defaultPropertyName)).thenReturn("");
 
         //when
-        int extracted = topicService.getValueOrDefault(value, defaultPropertyName);
+        int extracted = topicService.getIntValueOrDefault(defaultPropertyName);
 
         //then
-        assertEquals(6, extracted);
+        assertEquals(1, extracted);
     }
 
     @Test
-    public void getValueOrDefault_shouldReturnOne_whenGivenValueIsZero_andDefaultNotProvided() {
+    public void getIntValueOrDefault_shouldReturnOne_whenValueIsNegative() {
         //given
-        int value = 0;
         String defaultPropertyName = "propertyName";
-        when(topicService.getPropertyFromAJSCmap(defaultPropertyName)).thenReturn("");
+        when(topicService.getPropertyFromAJSCmap(defaultPropertyName)).thenReturn("-1");
 
         //when
-        int extracted = topicService.getValueOrDefault(value, defaultPropertyName);
+        int extracted = topicService.getIntValueOrDefault(defaultPropertyName);
 
         //then
         assertEquals(1, extracted);
     }
 
     @Test
-    public void getValueOrDefault_shouldReturnOne_whenGivenValueIsZero_andDefaultNaN() {
+    public void getIntValueOrDefault_shouldParseDefaultAndReturnIt_whenGivenValueIsPositive() {
         //given
-        int value = 0;
         String defaultPropertyName = "propertyName";
-        when(topicService.getPropertyFromAJSCmap(defaultPropertyName)).thenReturn("a");
+        when(topicService.getPropertyFromAJSCmap(defaultPropertyName)).thenReturn("3");
 
         //when
-        int extracted = topicService.getValueOrDefault(value, defaultPropertyName);
+        int extracted = topicService.getIntValueOrDefault(defaultPropertyName);
 
         //then
-        assertEquals(1, extracted);
+        assertEquals(3, extracted);
     }
 
     @Test(expected = TopicExistsException.class)