1 15 package org.apache.hivemind.util; 16 17 import org.apache.hivemind.ApplicationRuntimeException; 18 import org.apache.hivemind.Registry; 19 import org.apache.hivemind.ShutdownCoordinator; 20 import org.apache.hivemind.events.RegistryShutdownListener; 21 import org.apache.hivemind.impl.RegistryBuilder; 22 import org.apache.hivemind.impl.ShutdownCoordinatorImpl; 23 24 import hivemind.test.FrameworkTestCase; 25 26 31 public class TestShutdownCoordinator extends FrameworkTestCase 32 { 33 private static class Fixture implements RegistryShutdownListener 34 { 35 private boolean _shutdown; 36 37 public boolean isShutdown() 38 { 39 return _shutdown; 40 } 41 42 public void registryDidShutdown() 43 { 44 _shutdown = true; 45 } 46 47 } 48 49 public void testShutdownCoordinator() 50 { 51 ShutdownCoordinator c = new ShutdownCoordinatorImpl(); 52 53 Fixture f = new Fixture(); 54 55 c.addRegistryShutdownListener(f); 56 57 c.shutdown(); 58 59 assertEquals(true, f.isShutdown()); 60 61 63 c.shutdown(); 64 } 65 66 public void testShutdownCoordinatorService() 67 { 68 Registry r = RegistryBuilder.constructDefaultRegistry(); 69 70 ShutdownCoordinator c = 71 (ShutdownCoordinator) r.getService( 72 "hivemind.ShutdownCoordinator", 73 ShutdownCoordinator.class); 74 75 Fixture f = new Fixture(); 76 77 c.addRegistryShutdownListener(f); 78 79 c.shutdown(); 80 81 assertEquals(true, f.isShutdown()); 82 } 83 84 public void testShutdownFailure() throws Exception 85 { 86 ShutdownCoordinator c = new ShutdownCoordinatorImpl(); 87 88 c.addRegistryShutdownListener(new RegistryShutdownListener() 89 { 90 public void registryDidShutdown() 91 { 92 throw new ApplicationRuntimeException("I'm just not in the mood."); 93 } 94 }); 95 96 interceptLogging(); 97 98 c.shutdown(); 99 100 assertLoggedMessagePattern("Unable to shutdown .*: I'm just not in the mood\\."); 101 } 102 103 } 104 | Popular Tags |