[java-identity-provider COMMIT] /trunk/idp-core/src/test/java/net/shibboleth/idp/service/ReloadableSpringServiceTest....

noreply at shibboleth.net noreply at shibboleth.net
Thu Dec 5 14:04:01 EST 2013


Author: rdw
Date: Thu Dec  5 14:04:01 2013
New Revision: 4988

URL: http://svn.shibboleth.net/view/java-identity-provider?rev=4988&view=rev
Log:
IdP-330 Gotta love timing windows in tests

Modified:
    trunk/idp-core/src/test/java/net/shibboleth/idp/service/ReloadableSpringServiceTest.java

Modified: trunk/idp-core/src/test/java/net/shibboleth/idp/service/ReloadableSpringServiceTest.java
URL: http://svn.shibboleth.net/view/java-identity-provider/trunk/idp-core/src/test/java/net/shibboleth/idp/service/ReloadableSpringServiceTest.java?rev=4988&r1=4987&r2=4988&view=diff
==============================================================================
--- trunk/idp-core/src/test/java/net/shibboleth/idp/service/ReloadableSpringServiceTest.java (original)
+++ trunk/idp-core/src/test/java/net/shibboleth/idp/service/ReloadableSpringServiceTest.java Thu Dec  5 14:04:01 2013
@@ -71,24 +71,31 @@
 
         service.start();
 
-        ServiceableComponent<TestServiceableComponent> component = service.getServiceableComponent();
-
-        Assert.assertEquals(component.getComponent().getTheValue(), "One");
+        ServiceableComponent<TestServiceableComponent> serviceableComponent = service.getServiceableComponent();
+        TestServiceableComponent component  = serviceableComponent.getComponent();
+
+        Assert.assertEquals(component.getTheValue(), "One");
         Assert.assertFalse(component.getComponent().isDestroyed());
 
-        component.unpinComponent();
-        overwriteFileWith("net/shibboleth/idp/service/ServiceableBean2.xml");
-
-        Thread.sleep(RELOAD_DELAY * 2);
+        serviceableComponent.unpinComponent();
+        overwriteFileWith("net/shibboleth/idp/service/ServiceableBean2.xml");
+
+        long count = 70;
+        while (count > 0 && !component.isDestroyed()) {
+            Thread.sleep(RELOAD_DELAY);
+            count--;
+        }
+        Assert.assertTrue("After 7 second initial component has still not be destroyed", component.isDestroyed());
 
         //
         // The reload will have destroyed the old component
         //
-        Assert.assertTrue(component.getComponent().isDestroyed());
-
-        component = service.getServiceableComponent();
-
-        Assert.assertEquals(component.getComponent().getTheValue(), "Two");
+        Assert.assertTrue(serviceableComponent.getComponent().isDestroyed());
+
+        serviceableComponent = service.getServiceableComponent();
+
+        Assert.assertEquals(serviceableComponent.getComponent().getTheValue(), "Two");
+        serviceableComponent.unpinComponent();
     }
 
     @Test public void deferedReload() throws IOException, InterruptedException {
@@ -107,29 +114,40 @@
         ServiceableComponent<TestServiceableComponent> serviceableComponent = service.getServiceableComponent();
         TestServiceableComponent component = serviceableComponent.getComponent();
 
-        Assert.assertEquals(component.getTheValue(), "One");
+        Assert.assertEquals("One", component.getTheValue());
         Assert.assertFalse(component.isDestroyed());
 
         overwriteFileWith("net/shibboleth/idp/service/ServiceableBean2.xml");
 
-        Thread.sleep(RELOAD_DELAY*2);
-
         //
         // The reload will not have destroyed the old component yet
         //
         Assert.assertFalse(component.isDestroyed());
+
+        long count = 70;
+        TestServiceableComponent component2 = null;
+        while (count > 0) {
+            serviceableComponent = service.getServiceableComponent();
+            component2 = serviceableComponent.getComponent();
+            if ("Two".equals(component2.getTheValue())) {
+                break;
+            }
+            component2.unpinComponent();
+            component2 = null;
+            Thread.sleep(RELOAD_DELAY);
+            count--;
+        }
+        Assert.assertNotNull("After 7 second initial component has still not got new value", component2);
+        
         component.unpinComponent();
 
-        serviceableComponent = service.getServiceableComponent();
-
-        Assert.assertEquals(serviceableComponent.getComponent().getTheValue(), "Two");
-
-        long count = 50;
+        count = 70;
         while (count > 0 && !component.isDestroyed()) {
-            Thread.sleep(100);
-            count--;
-        }
-        Assert.assertTrue("After 5 second initial component has still not be destroyed", component.isDestroyed());
+            Thread.sleep(RELOAD_DELAY);
+            count--;
+        }
+        Assert.assertTrue("After 7 second initial component has still not be destroyed", component.isDestroyed());
+        
     }
     
     @Test
@@ -183,18 +201,18 @@
         Thread.sleep(RELOAD_DELAY*2);
         final ServiceableComponent<TestServiceableComponent> serviceableComponent = service.getServiceableComponent();
         final TestServiceableComponent component = serviceableComponent.getComponent();
-        Assert.assertEquals(component.getTheValue(), "Two");

[... 21 lines stripped ...]


More information about the commits mailing list