2525import org .hamcrest .Matcher ;
2626
2727import java .util .concurrent .CountDownLatch ;
28+ import java .util .concurrent .CyclicBarrier ;
2829import java .util .concurrent .ThreadPoolExecutor ;
2930import java .util .concurrent .TimeUnit ;
3031import java .util .concurrent .atomic .AtomicBoolean ;
@@ -169,7 +170,7 @@ public void run() {
169170 public void testScaleUp () throws Exception {
170171 final int min = between (1 , 3 );
171172 final int max = between (min + 1 , 6 );
172- final ThreadBarrier barrier = new ThreadBarrier (max + 1 );
173+ final CyclicBarrier barrier = new CyclicBarrier (max + 1 );
173174
174175 ThreadPoolExecutor pool =
175176 EsExecutors .newScaling (getClass ().getName () + "/" + getTestName (), min , max , between (1 , 100 ), randomTimeUnit (),
@@ -179,16 +180,13 @@ public void testScaleUp() throws Exception {
179180
180181 for (int i = 0 ; i < max ; ++i ) {
181182 final CountDownLatch latch = new CountDownLatch (1 );
182- pool .execute (new Runnable () {
183- @ Override
184- public void run () {
185- latch .countDown ();
186- try {
187- barrier .await ();
188- barrier .await ();
189- } catch (Exception e ) {
190- barrier .reset (e );
191- }
183+ pool .execute (() -> {
184+ latch .countDown ();
185+ try {
186+ barrier .await ();
187+ barrier .await ();
188+ } catch (Exception e ) {
189+ throw new AssertionError (e );
192190 }
193191 });
194192
@@ -207,7 +205,7 @@ public void run() {
207205 public void testScaleDown () throws Exception {
208206 final int min = between (1 , 3 );
209207 final int max = between (min + 1 , 6 );
210- final ThreadBarrier barrier = new ThreadBarrier (max + 1 );
208+ final CyclicBarrier barrier = new CyclicBarrier (max + 1 );
211209
212210 final ThreadPoolExecutor pool =
213211 EsExecutors .newScaling (getClass ().getName () + "/" + getTestName (), min , max , between (1 , 100 ), TimeUnit .MILLISECONDS ,
@@ -217,16 +215,13 @@ public void testScaleDown() throws Exception {
217215
218216 for (int i = 0 ; i < max ; ++i ) {
219217 final CountDownLatch latch = new CountDownLatch (1 );
220- pool .execute (new Runnable () {
221- @ Override
222- public void run () {
223- latch .countDown ();
224- try {
225- barrier .await ();
226- barrier .await ();
227- } catch (Exception e ) {
228- barrier .reset (e );
229- }
218+ pool .execute (() -> {
219+ latch .countDown ();
220+ try {
221+ barrier .await ();
222+ barrier .await ();
223+ } catch (Exception e ) {
224+ throw new AssertionError (e );
230225 }
231226 });
232227
0 commit comments