sonar issue fix - exception handling 75/27175/5
authorshrek2000 <orenkle@amdocs.com>
Sun, 31 Dec 2017 08:32:59 +0000 (10:32 +0200)
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>
Tue, 2 Jan 2018 09:48:22 +0000 (09:48 +0000)
remove exception handling which does nothing to handle the error
Issue-ID: SDC-835

Change-Id: I45e0bc203e15b41f907641bfda130f20e1f00f54
Signed-off-by: shrek2000 <orenkle@amdocs.com>
openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exportinfo/ExportDataCommand.java
openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exportinfo/ExportSerializer.java
openecomp-be/tools/zusammen-tools/src/test/java/org/openecomp/core/tools/Commands/exportinfo/serialize/VLMExtractTest.java

index b5486f5..aac1202 100644 (file)
@@ -45,7 +45,7 @@ public final class ExportDataCommand {
     public static final String JOIN_DELIMITER_SPLITTER = "\\$\\#";
     public static final String MAP_DELIMITER = "!@";
     public static final String MAP_DELIMITER_SPLITTER = "\\!\\@";
-    public static final int THREAD_POOL_SIZE = 4;
+    public static final int THREAD_POOL_SIZE = 6;
 
     private ExportDataCommand() {
     }
@@ -56,7 +56,7 @@ public final class ExportDataCommand {
             CassandraConnectionInitializer.setCassandraConnectionPropertiesToSystem();
             Path rootDir = Paths.get(ImportProperties.ROOT_DIRECTORY);
             initDir(rootDir);
-            try(Session session = CassandraSessionFactory.getSession()) {
+            try (Session session = CassandraSessionFactory.getSession()) {
                 final Set<String> filteredItems = Sets.newHashSet(filterItem);
                 Set<String> fis = filteredItems.stream().map(fi -> fi.replaceAll("\\r", "")).collect(Collectors.toSet());
                 Map<String, List<String>> queries;
@@ -95,23 +95,28 @@ public final class ExportDataCommand {
     }
 
 
-    private static boolean executeQuery(final Session session, final String query, final Set<String> filteredItems, final String filteredColumn,
+    private static void executeQuery(final Session session, final String query, final Set<String> filteredItems, final String filteredColumn,
                                         final Set<String> vlms, final CountDownLatch donequerying, Executor executor) {
         ResultSetFuture resultSetFuture = session.executeAsync(query);
         Futures.addCallback(resultSetFuture, new FutureCallback<ResultSet>() {
             @Override
             public void onSuccess(ResultSet resultSet) {
-                new ExportSerializer().serializeResult(resultSet, filteredItems, filteredColumn, vlms);
-                donequerying.countDown();
+                try {
+                    Utils.printMessage(logger, "Start to serialize " + query);
+                    new ExportSerializer().serializeResult(resultSet, filteredItems, filteredColumn, vlms);
+                    donequerying.countDown();
+                } catch (Exception e){
+                    Utils.logError(logger, "Serialization failed :" + query, e);
+                    System.exit(-1);
+                }
             }
 
             @Override
             public void onFailure(Throwable t) {
                 Utils.logError(logger, "Query failed :" + query, t);
-                donequerying.countDown();
+                System.exit(-1);
             }
         }, executor);
-        return true;
     }
 
     private static void zipPath(Path rootDir) throws IOException {
index 3c917b1..0098f21 100644 (file)
@@ -52,8 +52,7 @@ public class ExportSerializer {
                     ColumnDefinition columnDefinition = tableData.definitions.get(i);
                     Name name = dataTypesMap.get(columnDefinition.getType());
                     boolean checkForVLM = isElementTable && columnDefinition.getName().equals(ELEMENT_INFO_COLUMN_NAME);
-                    Object data;
-                    data = convertByType(vlms, row, i, name, checkForVLM);
+                    Object data = convertByType(vlms, row, i, name, checkForVLM);
                     rowData.add(data.toString());
                 }
                 tableData.rows.add(rowData);
@@ -128,7 +127,6 @@ public class ExportSerializer {
     }
 
     protected String extractVlm(String injson) {
-        try {
             if (injson == null){
                 return null;
             }
@@ -145,8 +143,5 @@ public class ExportSerializer {
                 return null;
             }
             return vendorId.getAsString();
-        } catch (Exception ex){
-            return null;
-        }
     }
 }
index 7b43c46..a5a1ff2 100644 (file)
@@ -33,11 +33,10 @@ public class VLMExtractTest {
 
     }
 
-    @Test
+    @Test(expectedExceptions = IllegalStateException.class)
     public void failToExtractVLMBecauseJsonIsCorrupted(){
         String elemenet_info_string = "gfhhhghgh";
-        String extractedVlmId = new CustomExportSerializer().extractVlm(elemenet_info_string);
-        assertNull(extractedVlmId);
+        new CustomExportSerializer().extractVlm(elemenet_info_string);
     }
 
     private static final class CustomExportSerializer extends ExportSerializer{