1 17 package org.apache.servicemix.beanflow.util; 18 19 import org.apache.servicemix.beanflow.JoinAll; 20 import org.apache.servicemix.beanflow.JoinSupport; 21 import org.apache.servicemix.beanflow.ParallelActivity; 22 import org.apache.servicemix.beanflow.annotations.Parallel; 23 24 import java.util.concurrent.Executor ; 25 import java.util.concurrent.Executors ; 26 27 35 public abstract class ParallelTestCase extends ActivityTestSupport { 36 private ParallelActivity activity; 37 private Executor executor; 38 private JoinSupport join; 39 private int maxThreadPoolSize = 20; 40 private long testTimeout = 10000; 41 42 @SuppressWarnings ("unchecked") 43 public void testParallelMethods() throws Exception { 44 startActivity(getActivity(), testTimeout); 45 getActivity().join(); 46 assertStopped(getActivity()); 47 } 48 49 53 @SuppressWarnings ("unchecked") 54 public void sync() { 55 getActivity().sync(); 56 } 57 58 65 public boolean sync(long millis) { 66 return getActivity().sync(millis); 67 } 68 69 72 public ParallelActivity getActivity() { 73 if (activity == null) { 74 activity = createActivity(); 75 } 76 return activity; 77 } 78 79 public Executor getExecutor() { 80 if (executor == null) { 81 executor = createExecutor(); 82 } 83 return executor; 84 } 85 86 public void setExecutor(Executor executor) { 87 this.executor = executor; 88 } 89 90 public JoinSupport getJoin() { 91 if (join == null) { 92 join = createJoin(); 93 } 94 return join; 95 } 96 97 public void setJoin(JoinSupport join) { 98 this.join = join; 99 } 100 101 public int getMaxThreadPoolSize() { 102 return maxThreadPoolSize; 103 } 104 105 public void setMaxThreadPoolSize(int maxThreadPoolSize) { 106 this.maxThreadPoolSize = maxThreadPoolSize; 107 } 108 109 protected ParallelActivity createActivity() { 112 return ParallelActivity.newParallelMethodActivity(getJoin(), getExecutor(), this); 113 } 114 115 protected Executor createExecutor() { 116 return Executors.newFixedThreadPool(maxThreadPoolSize); 117 } 118 119 protected JoinSupport createJoin() { 120 return new JoinAll(); 121 } 122 123 protected void sleep(int timeout) { 124 try { 125 Thread.sleep(3000); 126 } 127 catch (InterruptedException e) { 128 Thread.currentThread().interrupt(); 129 } 130 } 131 } 132 | Popular Tags |