Changeset 1402
- Timestamp:
- 04/13/07 13:09:42 (20 months ago)
- Location:
- trunk/components/tools/licenses
- Files:
-
- 3 modified
-
src/ome/services/licenses/LicenseSessionListener.java (modified) (2 diffs)
-
src/ome/services/licenses/LicenseWiring.java (modified) (2 diffs)
-
test/ome/services/licenses/test/BlitzLicenseTest.java (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/components/tools/licenses/src/ome/services/licenses/LicenseSessionListener.java
r1383 r1402 22 22 /** 23 23 * Listens for {@link AbstractSessionMessages} sent by 24 * {@link ome.services.icy.fire.SesssionManagerI} and 24 * {@link ome.services.icy.fire.SesssionManagerI} and 25 25 * {@link ome.services.icy.impl.ServiceFactoryI} and creates licenses 26 * when necessary for the user. The listener decouples the session 26 * when necessary for the user. The listener decouples the session 27 27 * creation from the licensing logic. 28 28 * 29 29 * This is notably different from the process needed to acquire a 30 * license in the application server case, since there is no 30 * license in the application server case, since there is no 31 31 * central session. 32 32 * … … 60 60 try { 61 61 byte[] token = lic.acquireLicense(); 62 wiring.setToken(create.getSessionId(),token); 62 63 } finally { 63 64 logout(); -
trunk/components/tools/licenses/src/ome/services/licenses/LicenseWiring.java
r1383 r1402 56 56 LicenseStore store = new LicenseBean(); 57 57 58 private Map<String, byte[]> tokensBySession = Collections58 private static Map<String, byte[]> tokensBySession = Collections 59 59 .synchronizedMap(new HashMap<String, byte[]>()); 60 60 … … 64 64 byte[] getToken(String sessionName) { 65 65 return tokensBySession.get(sessionName); 66 } 67 68 void setToken(String sessionName, byte[] token) { 69 tokensBySession.put(sessionName, token); 66 70 } 67 71 -
trunk/components/tools/licenses/test/ome/services/licenses/test/BlitzLicenseTest.java
r1383 r1402 11 11 import ome.services.icy.client.IceServiceFactory; 12 12 import ome.services.licenses.LicensedServiceFactory; 13 import ome.system.Login; 14 import ome.system.OmeroContext; 15 import omero.ServerError; 13 16 import omero.api.ServiceInterfacePrx; 14 17 import omero.licenses.ILicense; … … 18 21 import org.testng.annotations.AfterClass; 19 22 import org.testng.annotations.BeforeClass; 23 import org.testng.annotations.BeforeMethod; 20 24 import org.testng.annotations.Test; 21 25 22 26 @Test( groups = {"client","integration","blitz"} ) 23 public class BlitzLicenseTest extends TestCase {27 public class BlitzLicenseTest extends TestCase { 24 28 25 IceServiceFactory ice; 29 OmeroContext context; 30 Login rootLogin; 31 IceServiceFactory ice, root; 26 32 ILicensePrx licenseService; 27 33 byte[] token; 28 34 29 35 @Override 30 @Before Class36 @BeforeMethod 31 37 protected void setUp() throws Exception { 32 38 super.setUp(); 33 39 40 context = OmeroContext.getInstance("ome.client.test"); 41 rootLogin = (Login) context.getBean("rootLogin"); 34 42 ice = new IceServiceFactory(null,null,null); 35 43 ice.createSession(); 36 ServiceInterfacePrx prx = ice.getProxy().getByName("omero.licenses.ILicense"); 37 licenseService = ILicensePrxHelper.uncheckedCast(prx); 44 root = new IceServiceFactory(null, null, rootLogin); 45 root.createSession(); 46 47 licenseService = licensePrx(ice); 48 38 49 } 39 50 40 51 @Override 41 52 @AfterClass 42 53 protected void tearDown() throws Exception { 43 license Service.resetLicenses();54 licensePrx(root).resetLicenses(); 44 55 super.tearDown(); 45 56 } 46 57 47 58 @Test 48 59 public void testAcquireLicenseAutomatically() throws Exception { … … 50 61 passes(true); 51 62 } 52 63 53 64 @Test 54 65 public void testAcquireLicenseManually() throws Exception { 55 66 passes(true); 56 licenseService.releaseLicense(token);67 assertTrue( licenseService.releaseLicense(token) ); 57 68 passes(false); 58 69 token = licenseService.acquireLicense(); 59 70 passes(true); 60 71 } 61 72 62 73 @Test 63 74 public void testReset() throws Exception { 64 75 65 76 long totalA = licenseService.getTotalLicenseCount(); 66 77 long availA = licenseService.getAvailableLicenseCount(); 67 78 68 79 token = licenseService.acquireLicense(); 69 80 70 81 long totalB = licenseService.getTotalLicenseCount(); 71 82 long availB = licenseService.getAvailableLicenseCount(); 72 73 license Service.resetLicenses();74 83 84 licensePrx(root).resetLicenses(); 85 75 86 long totalC = licenseService.getTotalLicenseCount(); 76 87 long availC = licenseService.getAvailableLicenseCount(); 77 88 78 89 assertTrue(totalA == totalB && totalB == totalC); 79 assertTrue(availA ==totalA && totalC == availC);80 assertTrue(availB == totalB - 1);81 90 assertTrue(availA < totalA && totalC == availC); 91 assertTrue(availB == (availA - 1)); 92 82 93 } 83 84 @Test 94 95 @Test(groups = {"ignore","NYI"}) 85 96 public void testTimeouts() { 86 97 fail("Not implemented."); … … 89 100 // // ~ Helpers 90 101 // ========================================================================= 91 102 92 103 protected void passes(boolean shouldpass) throws Exception { 93 104 try { … … 103 114 104 115 } 116 117 private ILicensePrx licensePrx(IceServiceFactory sf) throws ServerError { 118 ServiceInterfacePrx prx = sf.getProxy().getByName("omero.licenses.ILicense"); 119 ILicensePrx licenses = ILicensePrxHelper.uncheckedCast(prx); 120 return licenses; 121 } 105 122 }
