[jboss-svn-commits] JBL Code SVN: r17044 - in labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-core/src: test/java/org/drools/agent and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Dec 5 13:26:07 EST 2007


Author: fmeyer
Date: 2007-12-05 13:26:07 -0500 (Wed, 05 Dec 2007)
New Revision: 17044

Modified:
   labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-core/src/main/java/org/drools/agent/FileScanner.java
   labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-core/src/main/java/org/drools/agent/URLScanner.java
   labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-core/src/test/java/org/drools/agent/RuleAgentTest.java
   labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-core/src/test/java/org/drools/agent/URLScannerTest.java
Log:
SOA-217 Directory scanner for rule agent tripping up on unknown file types  related to JBRULES-1324


Modified: labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-core/src/main/java/org/drools/agent/FileScanner.java
===================================================================
--- labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-core/src/main/java/org/drools/agent/FileScanner.java	2007-12-05 18:15:43 UTC (rev 17043)
+++ labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-core/src/main/java/org/drools/agent/FileScanner.java	2007-12-05 18:26:07 UTC (rev 17044)
@@ -77,8 +77,7 @@
                              this.lastUpdated,
                              f.lastModified() ) ) {
                 Package p = readPackage( f );
-                if ( p == null ) return null;
-                list.add( p );
+                if ( p != null ) list.add( p );
             }
         }
         return (Package[]) list.toArray( new Package[list.size()] );
@@ -90,6 +89,10 @@
      */
     private Package readPackage(File pkgFile) {
 
+    	String name = pkgFile.getName();
+    	if (!(name.endsWith(".pkg") || name.endsWith(".drl"))) {
+    		return null;
+    	}
     	//use reflection to load if its DRL, the provider lives in drools compiler.
     	if (pkgFile.getName().endsWith(".drl")) {
     		try {

Modified: labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-core/src/main/java/org/drools/agent/URLScanner.java
===================================================================
--- labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-core/src/main/java/org/drools/agent/URLScanner.java	2007-12-05 18:15:43 UTC (rev 17043)
+++ labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-core/src/main/java/org/drools/agent/URLScanner.java	2007-12-05 18:26:07 UTC (rev 17044)
@@ -21,14 +21,14 @@
 
     //this is the URLs we are managing
     URL[]       urls;
-    
+
     //this is only set if we are using a local cache - only fall back on this
     //when URL connection is not available.
     FileScanner localCacheFileScanner;
-    
+
     //this is used to access the remote resources
     IHttpClient httpClient = new HttpClientImpl();
-    
+
     //a record of the last updated URL timestamps
     Map         lastUpdated = new HashMap();
 
@@ -73,7 +73,7 @@
         File f;
         try {
             f = new File( cacheDir,
-                          URLEncoder.encode(  u.toExternalForm(), "UTF-8" ) );
+                          URLEncoder.encode(  u.toExternalForm(), "UTF-8" ) + ".pkg" );
         } catch ( UnsupportedEncodingException e ) {
             throw new RuntimeDroolsException( e );
         }
@@ -90,16 +90,16 @@
         } catch ( IOException e ) {
             if (this.localCacheFileScanner != null) {
                 listener.warning( "Falling back to local cache." );
-                return localCacheFileScanner.loadPackageChanges();                
+                return localCacheFileScanner.loadPackageChanges();
             }
             listener.exception( e );
         } catch ( ClassNotFoundException e ) {
             this.listener.exception( e );
             this.listener.warning( "Was unable to load a class when loading a package. Perhaps it is missing from this application." );
-        }        
+        }
         return null;
     }
-    
+
     private Package[] getChangeSet() throws IOException, ClassNotFoundException {
         if ( this.urls == null ) return new Package[0];
         List list = new ArrayList();
@@ -120,7 +120,7 @@
     private void writeLocalCacheCopy(Package p, URL u, File localCacheDir) {
         File local = getLocalCacheFileForURL( localCacheDir, u );
         if (local.exists()) local.delete();
-        
+
         try {
             ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(local));
             out.writeObject( p );
@@ -130,11 +130,11 @@
             listener.exception( e );
             listener.warning( "Was an error with the local cache directory " + localCacheDir.getPath() );
         }
-        
+
     }
 
     private Package readPackage(URL u) throws IOException, ClassNotFoundException {
-        return httpClient.fetchPackage( u );        
+        return httpClient.fetchPackage( u );
     }
 
     private boolean hasChanged(URL u, Map updates) throws IOException {
@@ -143,7 +143,7 @@
             listener.warning( "Was an error contacting " + u.toExternalForm() + ". Reponse header: " + pong.responseMessage );
             throw new IOException("Was unable to reach server.");
         }
-        
+
         String url = u.toExternalForm();
         if ( !updates.containsKey( url ) ) {
             updates.put( url,
@@ -158,9 +158,9 @@
             } else {
                 return false;
             }
-        }        
-    }    
-    
+        }
+    }
+
     public String toString() {
         String s = "URLScanner monitoring URLs: ";
         if (this.urls != null) {

Modified: labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-core/src/test/java/org/drools/agent/RuleAgentTest.java
===================================================================
--- labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-core/src/test/java/org/drools/agent/RuleAgentTest.java	2007-12-05 18:15:43 UTC (rev 17043)
+++ labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-core/src/test/java/org/drools/agent/RuleAgentTest.java	2007-12-05 18:26:07 UTC (rev 17044)
@@ -1,6 +1,7 @@
 package org.drools.agent;
 
 import java.io.File;
+import java.io.FileOutputStream;
 import java.io.InputStream;
 import java.util.HashMap;
 import java.util.List;
@@ -229,6 +230,13 @@
 
         Package p1 = new Package("p1");
         File p1f = new File(dir, "p43_.pkg");
+
+        File junk = new File(dir, "xxx.poo");
+        FileOutputStream ojunk = new FileOutputStream(junk);
+        ojunk.write("ignore me".getBytes());
+        ojunk.flush();
+        ojunk.close();
+
         RuleBaseAssemblerTest.writePackage( p1, p1f );
 
         Properties props = new Properties();

Modified: labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-core/src/test/java/org/drools/agent/URLScannerTest.java
===================================================================
--- labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-core/src/test/java/org/drools/agent/URLScannerTest.java	2007-12-05 18:15:43 UTC (rev 17043)
+++ labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-core/src/test/java/org/drools/agent/URLScannerTest.java	2007-12-05 18:26:07 UTC (rev 17044)
@@ -59,8 +59,8 @@
 
         File f1 = result[0];
         File f2 = result[1];
-        assertEquals( "http%3A%2F%2Flocalhost%3A8080%2Ffoo%2Fbar.bar%2Fpackages%2FIMINYRURL%2FLATEST", f1.getName() );
-        assertEquals( "http%3A%2F%2Flocalhost%3A8080%2Ffoo%2Fbar.bar%2Fpackages%2FIMINYRURL%2FPROD", f2.getName() );
+        assertEquals( "http%3A%2F%2Flocalhost%3A8080%2Ffoo%2Fbar.bar%2Fpackages%2FIMINYRURL%2FLATEST.pkg", f1.getName() );
+        assertEquals( "http%3A%2F%2Flocalhost%3A8080%2Ffoo%2Fbar.bar%2Fpackages%2FIMINYRURL%2FPROD.pkg", f2.getName() );
 
     }
 
@@ -83,8 +83,8 @@
 
         assertEquals( 2, scan.localCacheFileScanner.files.length );
 
-        assertEquals( "http%3A%2F%2Fgoo.ber", scan.localCacheFileScanner.files[0].getName() );
-        assertEquals( "http%3A%2F%2Fwee.waa", scan.localCacheFileScanner.files[1].getName() );
+        assertEquals( "http%3A%2F%2Fgoo.ber.pkg", scan.localCacheFileScanner.files[0].getName() );
+        assertEquals( "http%3A%2F%2Fwee.waa.pkg", scan.localCacheFileScanner.files[1].getName() );
 
     }
 
@@ -103,8 +103,8 @@
         File dir = RuleBaseAssemblerTest.getTempDirectory();
 
         int numfiles = dir.list().length;
-        
-        
+
+
         Properties config = new Properties();
         //config.setProperty( RuleAgent.LOCAL_URL_CACHE, dir.getPath() );
         config.setProperty( RuleAgent.URLS, "http://goo2.ber http://wee2.waa" );
@@ -141,9 +141,9 @@
         assertEquals( 2, rb.getPackages().length );
 
         assertExists(new String[] {"goo2.ber", "wee2.waa"}, rb.getPackages());
-        
 
 
+
         assertEquals( numfiles, dir.list().length );
     }
 
@@ -164,7 +164,7 @@
             }
             assertEquals("Should only have one package named " + name, 1, matches);
         }
-        
+
     }
 
     public void testUpdateWithLocalCache() {
@@ -219,7 +219,7 @@
                 if (url.toExternalForm().equals( "http://wee.waa" )) {
                     ping.lastUpdated = -1;
                     ping.responseMessage = "XXX";
-                    
+
                 } else {
                     ping.lastUpdated = 123;
                     ping.responseMessage = "200 OK";
@@ -231,18 +231,18 @@
                 throw new IOException("poo");
             }
 
-        };      
-        
+        };
+
         rb = RuleBaseFactory.newRuleBase();
         assertEquals(0, rb.getPackages().length);
         PackageProvider.applyChanges( rb, true, scan.loadPackageChanges(), getNilListener() );
 
         assertEquals(2, rb.getPackages().length);
-        
+
         final boolean[] fetchCalled = new boolean[1];
-        
+
         fetchCalled[0] = false;
-        
+
         //now check with IOExceptions
         scan.httpClient = new IHttpClient() {
 
@@ -258,14 +258,14 @@
                 throw new IOException("poo");
             }
 
-        };          
-        
+        };
+
         Package[] changes = scan.loadPackageChanges();
         assertEquals(0, changes.length);
         assertEquals(true, fetchCalled[0]);
 
     }
-    
+
     public void testColdStartWithError() throws Exception {
         //this will show starting up and reading packages from the dir when the remote one doesn't respond
         URLScanner scan = new URLScanner();
@@ -274,13 +274,13 @@
 
         Package p1 = new Package("goo.ber");
         Package p2 = new Package("wee.waa");
-        
-        File f1 = URLScanner.getLocalCacheFileForURL( dir, new URL("http://goo.ber") );        
+
+        File f1 = URLScanner.getLocalCacheFileForURL( dir, new URL("http://goo.ber") );
         File f2 = URLScanner.getLocalCacheFileForURL( dir, new URL("http://wee.waa") );
-        
+
         RuleBaseAssemblerTest.writePackage( p1, f1 );
         RuleBaseAssemblerTest.writePackage( p2, f2 );
-        
+
         Properties config = new Properties();
         config.setProperty( RuleAgent.LOCAL_URL_CACHE, dir.getPath() );
         config.setProperty( RuleAgent.URLS, "http://goo.ber http://wee.waa" );
@@ -301,12 +301,12 @@
 
         assertNotNull( scan.localCacheFileScanner );
         assertNotNull( scan.localCacheDir );
-        
+
         RuleBase rb = RuleBaseFactory.newRuleBase();
         PackageProvider.applyChanges( rb, true, scan.loadPackageChanges(), getNilListener() );
         assertEquals(2, rb.getPackages().length);
-        
-        
+
+
     }
 
 




More information about the jboss-svn-commits mailing list