/* **************************************************************************** * testConcurrent() **************************************************************************** */ /** * */ public void testConcurrent() { Cache oCache = new Cache(1000); oCache.prune((XRIAuthority) AuthorityPath.buildAuthorityPath("@")); assertTrue("Initial cache not empty", oCache.getNumNodes() == 0); XRD oDesc = new XRD(); Service atAuthService = new Service(); atAuthService.addMediaType(Tags.CONTENT_TYPE_XRDS + ";trust=none"); atAuthService.addType(Tags.SERVICE_AUTH_RES); atAuthService.addURI("http://gcs.epok.net/xri/resolve?ns=at"); oDesc.addService(atAuthService); GCSAuthority oAuth = new GCSAuthority("@"); oCache.stuff(oAuth, oDesc); assertTrue("Initial cache incorrect", oCache.getNumNodes() == 1); oCache.setMaxSize(5); Random oRand = new Random(); try { Thread[] oThreads = new StuffPruneThread[100]; for (int i = 0; i < oThreads.length; i++) { oThreads[i] = new StuffPruneThread(oRand); } for (int i = 0; i < oThreads.length; i++) { oThreads[i].start(); } for (int i = 0; i < oThreads.length; i++) { oThreads[i].join(); } } catch (Exception e) { assertTrue("Unexpected exception" + e, false); } oCache.dump(); assertTrue( "Max cache size not honored", oCache.getNumNodes() <= oCache.getMaxSize()); Cache.CachedValue oVal = oCache.find( (XRIAuthority) AuthorityPath.buildAuthorityPath("@"), false); assertTrue("Cached value for @ not found", oVal != null); }