package alma.managertest.client; import java.util.ArrayList; import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import alma.managertest.DummyComponent; import alma.managertest.DummyComponentHelper; import alma.acs.component.client.ComponentClientTestCase; import alma.acs.container.ContainerServicesBase; import si.ijs.maci.ComponentInfo; import si.ijs.maci.ComponentSpec; import si.ijs.maci.COMPONENT_SPEC_ANY; public class managerClientTest extends ComponentClientTestCase { static int totalComponents;// =10000;//Integer.parseInt(args[0]); static int nThreads; //= 20; static int totalContainers;// = 40; //this variable is to know how many times has been run to initialize the sequence from that number static int nRun; static public void main(String args[]){ try{ managerClientTest m = new managerClientTest(); totalComponents = Integer.parseInt(args[0]); totalContainers = Integer.parseInt(args[1]); nThreads = Integer.parseInt(args[2]); m.testGetManyComponents(); }catch(Exception e){} } public managerClientTest() throws Exception { super("managerClientTest"); } public void testGetManyComponents(){ final String compNameHeader = "DUMMY_COMP_"; final AtomicInteger sequenceNumber = new AtomicInteger(0); totalComponents = 20000; totalContainers = 60; nThreads = 10; class ComponentGetter implements Callable { int components,containers; ComponentGetter(int components, int containers) { this.components = components; this.containers = containers; } public Boolean call() throws Exception { int j; String compName,contName; ComponentSpec corbaSpec = new ComponentSpec(); corbaSpec.component_type = "IDL:alma/managertest/DummyComponent:1.0"; corbaSpec.component_code = COMPONENT_SPEC_ANY.value; for(int i=0; i> results = new ArrayList>(); //Components must be multiple of the threads try{ for (int i = 0; i < nThreads; i++) { results.add(pool.submit(new ComponentGetter(totalComponents/nThreads, totalContainers))); } pool.shutdown(); int n = 0; while(!pool.isTerminated()){ n++; Thread.sleep(60 * 1000); m_logger.info("Waiting 60 seconds more. Total now is "+ n + " minutes."); } //if(!pool.awaitTermination(60, TimeUnit.SECONDS)){ //m_logger.info("The threads haven't finished yet, after 60 seconds."); //} for (Future future : results) { try { Boolean threadResult = future.get(); if(!threadResult) m_logger.info("The thead couldn't get a reference"); m_logger.info("CARLI b="+threadResult); assertTrue(threadResult); } catch (ExecutionException ex) { m_logger.info("Unexpected exception 1"+ ex.getCause().toString()); } catch (Throwable thr) { m_logger.info("Unexpected exception 2"+ thr.toString()); } } }catch(InterruptedException e){ assertTrue(false); m_logger.info("A timeout occurs when waiting the tasks to finish execution" + e); } finally { try{ Thread.sleep(60* 1000);//sleep 1 minute }catch(InterruptedException e){} //release all components for(int i=0; i < totalComponents;i++){ getContainerServices().releaseComponent(compNameHeader+i); } assertTrue(false); } } }