incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r693820 - in /incubator/sling/trunk/extensions/jcrinstall/src: main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/ test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/
Date Wed, 10 Sep 2008 12:44:34 GMT
Author: bdelacretaz
Date: Wed Sep 10 05:44:33 2008
New Revision: 693820

URL: http://svn.apache.org/viewvc?rev=693820&view=rev
Log:
SLING-646 - processResourceQueue test added

Modified:
    incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessor.java
    incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessorTest.java
    incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/Utilities.java

Modified: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessor.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessor.java?rev=693820&r1=693819&r2=693820&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessor.java
(original)
+++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessor.java
Wed Sep 10 05:44:33 2008
@@ -105,30 +105,31 @@
         while(iter.hasNext()) {
             final Long id = iter.next();
             final Bundle bundle = ctx.getBundle(id.longValue());
+            final int state = bundle.getState();
             
             if(bundle == null) {
                 log.debug("Bundle id {} not found in processResourceQueue(), removed from
pending bundles queue");
                 iter.remove();
                 
-            } else if ((bundle.getState() & Bundle.ACTIVE) > 0) {
+            } else if ((state & Bundle.ACTIVE) > 0) {
                 log.info("Bundle {} is already active, removed from pending bundles queue",
bundle.getLocation());
                 iter.remove();
             
-            } else if ((bundle.getState() & Bundle.STARTING) > 0) {
+            } else if ((state & Bundle.STARTING) > 0) {
                 log.info("Bundle {} is starting.", bundle.getLocation());
                 
-            } else if ((bundle.getState() & Bundle.STOPPING) > 0) {
+            } else if ((state & Bundle.STOPPING) > 0) {
                 log.info("Bundle {} is stopping.", bundle.getLocation());
                 
-            } else if ((bundle.getState() & Bundle.UNINSTALLED) > 0) {
+            } else if ((state & Bundle.UNINSTALLED) > 0) {
                 log.info("Bundle {} is uninstalled, removed from pending bundles queue",
bundle.getLocation());
                 iter.remove();
                 
-            } else if ((bundle.getState() & Bundle.RESOLVED) > 0) {
+            } else if ((state & Bundle.RESOLVED) > 0) {
                 log.info("Bundle {} is resolved, trying to start it.", bundle.getLocation());
                 bundle.start();
                 
-            } else if ((bundle.getState() & Bundle.INSTALLED) > 0) {
+            } else if ((state & Bundle.INSTALLED) > 0) {
                 log.info("Bundle {} is installed but not resolved.", bundle.getLocation());
             }
         }

Modified: incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessorTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessorTest.java?rev=693820&r1=693819&r2=693820&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessorTest.java
(original)
+++ incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessorTest.java
Wed Sep 10 05:44:33 2008
@@ -29,6 +29,8 @@
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.jmock.Expectations;
 import org.jmock.Mockery;
@@ -122,4 +124,63 @@
         // And verify expectations
         mockery.assertIsSatisfied();
     }
+    
+    @org.junit.Test public void testBundleProcessingQueue() throws Exception {
+        
+        // Fill the pending bundles queue with one bundle in each of the
+        // possible states, process the queue and verify results
+        final BundleContext bc = mockery.mock(BundleContext.class);
+        final Bundle [] b = new Bundle[6];
+        for(int i = 0; i < b.length; i++) {
+            b[i] = mockery.mock(Bundle.class);
+        };
+        
+        mockery.checking(new Expectations() {{
+            allowing(bc).getBundle(0L); will(returnValue(b[0]));
+            allowing(bc).getBundle(1L); will(returnValue(b[1]));
+            allowing(bc).getBundle(2L); will(returnValue(b[2]));
+            allowing(bc).getBundle(3L); will(returnValue(b[3]));
+            allowing(bc).getBundle(4L); will(returnValue(b[4]));
+            allowing(bc).getBundle(5L); will(returnValue(b[5]));
+            
+            allowing(b[0]).getBundleId(); will(returnValue(0L));
+            allowing(b[1]).getBundleId(); will(returnValue(1L));
+            allowing(b[2]).getBundleId(); will(returnValue(2L));
+            allowing(b[3]).getBundleId(); will(returnValue(3L));
+            allowing(b[4]).getBundleId(); will(returnValue(4L));
+            allowing(b[5]).getBundleId(); will(returnValue(5L));
+
+            allowing(b[0]).getState(); will(returnValue(Bundle.ACTIVE));
+            allowing(b[1]).getState(); will(returnValue(Bundle.STARTING));
+            allowing(b[2]).getState(); will(returnValue(Bundle.STOPPING));
+            allowing(b[3]).getState(); will(returnValue(Bundle.UNINSTALLED));
+            allowing(b[4]).getState(); will(returnValue(Bundle.INSTALLED));
+            allowing(b[5]).getState(); will(returnValue(Bundle.RESOLVED));
+            
+            allowing(b[0]).getLocation();
+            allowing(b[1]).getLocation();
+            allowing(b[2]).getLocation();
+            allowing(b[3]).getLocation();
+            allowing(b[4]).getLocation();
+            allowing(b[5]).getLocation();
+            
+            one(b[5]).start();
+        }});
+        
+        final BundleResourceProcessor p = new BundleResourceProcessor(bc);
+        final Map<Long, Bundle> pendingBundles = new HashMap<Long, Bundle>();
+        Utilities.setField(p, "pendingBundles", pendingBundles);
+
+        for(Bundle bu : b) {
+            pendingBundles.put(new Long(bu.getBundleId()), bu);
+        }
+        p.processResourceQueue();
+        
+        assertEquals("Only 4 bundles must be left in queue", 4, pendingBundles.size());
+        assertTrue("STARTING bundle must be left in queue", pendingBundles.containsKey(b[1].getBundleId()));
+        assertTrue("STOPPING bundle must be left in queue", pendingBundles.containsKey(b[2].getBundleId()));
+        assertTrue("INSTALLED bundle must be left in queue", pendingBundles.containsKey(b[4].getBundleId()));
+        assertTrue("RESOLVED bundle must be left in queue", pendingBundles.containsKey(b[5].getBundleId()));
+    }
+    
 }

Modified: incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/Utilities.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/Utilities.java?rev=693820&r1=693819&r2=693820&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/Utilities.java
(original)
+++ incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/Utilities.java
Wed Sep 10 05:44:33 2008
@@ -39,10 +39,7 @@
         for(OsgiResourceProcessor p : processors) {
             list.add(p);
         }
-        
-        final Field f = c.getClass().getDeclaredField("processors");
-        f.setAccessible(true);
-        f.set(c, list);
+        setField(c, "processors", list);
     }
     
     static void setStorage(OsgiControllerImpl c, Storage s) throws Exception {
@@ -50,5 +47,11 @@
         f.setAccessible(true);
         f.set(c, s);
     }
+    
+    static void setField(Object o, String name, Object value) throws Exception {
+        final Field f = o.getClass().getDeclaredField(name);
+        f.setAccessible(true);
+        f.set(o, value);
+    }
 
 }



Mime
View raw message