[ 
https://issues.apache.org/jira/browse/KARAF-5879?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16594955#comment-16594955
 ] 

ASF GitHub Bot commented on KARAF-5879:
---------------------------------------

jbonofre closed pull request #11: KARAF-5879 - Close input and output streams 
in CaveFeatureGateway/Test.
URL: https://github.com/apache/karaf-cave/pull/11
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/server/storage/src/main/java/org/apache/karaf/cave/server/storage/CaveFeatureGatewayImpl.java
 
b/server/storage/src/main/java/org/apache/karaf/cave/server/storage/CaveFeatureGatewayImpl.java
index 0d2bd76..3a39166 100644
--- 
a/server/storage/src/main/java/org/apache/karaf/cave/server/storage/CaveFeatureGatewayImpl.java
+++ 
b/server/storage/src/main/java/org/apache/karaf/cave/server/storage/CaveFeatureGatewayImpl.java
@@ -21,6 +21,7 @@
 import org.apache.karaf.features.internal.model.JaxbUtil;
 
 import java.io.File;
+import java.io.OutputStream;
 import java.io.FileOutputStream;
 import java.util.ArrayList;
 import java.util.List;
@@ -43,7 +44,8 @@ public void register(String url) throws Exception {
             throw new IllegalArgumentException("Features repository " + url + 
" already registered in the gateway");
         }
         features.getRepository().add(url);
-        JaxbUtil.marshal(features, new FileOutputStream(storage));
+        
+        marshalStorageFile(storage, features);
     }
 
     @Override
@@ -59,7 +61,8 @@ public void remove(String url) throws Exception {
             throw new IllegalArgumentException("Features repository " + url + 
" is not registered in the gateway");
         }
         features.getRepository().remove(url);
-        JaxbUtil.marshal(features, new FileOutputStream(storage));
+        
+        marshalStorageFile(storage, features);
     }
 
     @Override
@@ -83,4 +86,11 @@ private boolean isFeaturesRepositoryRegistered(String url, 
List<String> reposito
         }
         return false;
     }
+    
+    private void marshalStorageFile(File storage, Features features)
+                       throws Exception {
+        OutputStream storageFileOs = new FileOutputStream(storage);
+        JaxbUtil.marshal(features, storageFileOs);
+        storageFileOs.close();
+       }
 }
diff --git 
a/server/storage/src/test/java/org/apache/karaf/cave/server/storage/CaveFeatureGatewayImplTest.java
 
b/server/storage/src/test/java/org/apache/karaf/cave/server/storage/CaveFeatureGatewayImplTest.java
index b6d8c7f..d1eea29 100644
--- 
a/server/storage/src/test/java/org/apache/karaf/cave/server/storage/CaveFeatureGatewayImplTest.java
+++ 
b/server/storage/src/test/java/org/apache/karaf/cave/server/storage/CaveFeatureGatewayImplTest.java
@@ -73,6 +73,7 @@ private String readCaveFile() throws Exception {
         while ((line = reader.readLine()) != null) {
             builder.append(line);
         }
+        reader.close();
         return builder.toString();
     }
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> CaveFeatureGatewayImplTest.testRemove fails due to OutputStream not being 
> closed
> --------------------------------------------------------------------------------
>
>                 Key: KARAF-5879
>                 URL: https://issues.apache.org/jira/browse/KARAF-5879
>             Project: Karaf
>          Issue Type: Bug
>          Components: cave-maven
>    Affects Versions: cave-4.1.1
>         Environment: Windows 10
> Java 8
>            Reporter: Bob Paulin
>            Assignee: Jean-Baptiste Onofré
>            Priority: Minor
>             Fix For: cave-4.1.1
>
>
> The CaveFeatureGatewayImplTest.setup method is suppose to delete the 
> cave-features-gateway.xml file before each test is run.  This does not 
> succeed on my machine because the marshalling that occurs in the 
> CaveFeatureGatewayImpl.register and CaveFeatureGatewayImpl.remove contains an 
> OutputStream that does not get properly closed.  Similarly the InputStreams 
> within CaveFeatureGatewayImplTest.readCaveFile are also not being properly 
> closed.  
>  
> Results :
> Failed tests: 
>   CaveFeatureGatewayImplTest.testRemove:61 
> expected:<...repository>mvn:test/[]second/1.0-SNAPSHOT<...> but 
> was:<...repository>mvn:test/[test/1.0-SNAPSHOT</repository>    
> <repository>mvn:test/]second/1.0-SNAPSHOT<...>
> Tests run: 8, Failures: 1, Errors: 0, Skipped: 0



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to