Expanded static imports.

This commit is contained in:
Simone Bordet 2016-05-04 15:01:44 +02:00
parent 5d3283af0f
commit 903a6cb49c
1 changed files with 19 additions and 22 deletions

View File

@ -27,15 +27,12 @@ import java.util.concurrent.Executor;
import org.eclipse.jetty.util.BlockingArrayQueue;
import org.eclipse.jetty.util.ConcurrentArrayQueue;
import org.eclipse.jetty.util.thread.ExecutionStrategy.Producer;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
public class ExecuteProduceConsumeTest
{
private static final Runnable NULLTASK = () -> {};
@ -80,8 +77,8 @@ public class ExecuteProduceConsumeTest
public void after()
{
// All done and checked
assertThat(_produce.size(),equalTo(0));
assertThat(_executions.size(),equalTo(0));
Assert.assertThat(_produce.size(), Matchers.equalTo(0));
Assert.assertThat(_executions.size(), Matchers.equalTo(0));
}
@Test
@ -98,7 +95,7 @@ public class ExecuteProduceConsumeTest
_produce.add(t0);
_produce.add(NULLTASK);
_ewyk.execute();
assertThat(t0.hasRun(),equalTo(true));
Assert.assertThat(t0.hasRun(), Matchers.equalTo(true));
Assert.assertEquals(_ewyk,_executions.poll());
}
@ -115,7 +112,7 @@ public class ExecuteProduceConsumeTest
_ewyk.execute();
for (Task task : tasks)
assertThat(task.hasRun(), equalTo(true));
Assert.assertThat(task.hasRun(), Matchers.equalTo(true));
Assert.assertEquals(_ewyk,_executions.poll());
}
@ -137,13 +134,13 @@ public class ExecuteProduceConsumeTest
// wait for execute thread to block in
t0.awaitRun();
assertEquals(thread,t0.getThread());
Assert.assertEquals(thread,t0.getThread());
// Should have dispatched only one helper
assertEquals(_ewyk,_executions.poll());
Assert.assertEquals(_ewyk,_executions.poll());
// which is make us idle
_ewyk.run();
assertThat(_ewyk.isIdle(),equalTo(true));
Assert.assertThat(_ewyk.isIdle(), Matchers.equalTo(true));
// unblock task
@ -178,7 +175,7 @@ public class ExecuteProduceConsumeTest
t0.unblock();
// will run to completion because are become idle
thread.join();
assertThat(_ewyk.isIdle(),equalTo(true));
Assert.assertThat(_ewyk.isIdle(), Matchers.equalTo(true));
// because we are idle, dispatched thread is noop
_ewyk.run();
@ -201,7 +198,7 @@ public class ExecuteProduceConsumeTest
// wait for execute thread to block in task
t0.awaitRun();
assertEquals(thread0,t0.getThread());
Assert.assertEquals(thread0,t0.getThread());
// Should have dispatched another helper
Assert.assertEquals(_ewyk,_executions.poll());
@ -215,7 +212,7 @@ public class ExecuteProduceConsumeTest
Thread.yield();
// thread1 is blocked in producing
assertEquals(thread1,_producer);
Assert.assertEquals(thread1,_producer);
// because we are producing, any other dispatched threads are noops
_ewyk.run();
@ -229,7 +226,7 @@ public class ExecuteProduceConsumeTest
// task will be run by thread1
t1.awaitRun();
assertEquals(thread1,t1.getThread());
Assert.assertEquals(thread1,t1.getThread());
// and another thread will have been requested
Assert.assertEquals(_ewyk,_executions.poll());
@ -240,7 +237,7 @@ public class ExecuteProduceConsumeTest
// Now thread1 is producing again
while(_producer==null)
Thread.yield();
assertEquals(thread1,_producer);
Assert.assertEquals(thread1,_producer);
// If we unblock t0, it will decide it is not needed
t0.unblock();
@ -254,7 +251,7 @@ public class ExecuteProduceConsumeTest
// Which will eventually idle the producer
thread1.join();
assertEquals(null,_producer);
Assert.assertEquals(null,_producer);
}
@Test
@ -274,7 +271,7 @@ public class ExecuteProduceConsumeTest
// wait for execute thread to block in task
t0.awaitRun();
assertEquals(thread0,t0.getThread());
Assert.assertEquals(thread0,t0.getThread());
// Should have dispatched another helper
Assert.assertEquals(_ewyk,_executions.poll());
@ -291,21 +288,21 @@ public class ExecuteProduceConsumeTest
// but because there was a pending execute it will try producing again
while(_producer==null)
Thread.yield();
assertEquals(thread0,_producer);
Assert.assertEquals(thread0,_producer);
// and will see new tasks
final Task t1 = new Task(true);
_produce.add(t1);
t1.awaitRun();
assertThat(t1.getThread(),equalTo(thread0));
Assert.assertThat(t1.getThread(), Matchers.equalTo(thread0));
// Should NOT have dispatched another helper, because the last is still pending
assertThat(_executions.size(),equalTo(0));
Assert.assertThat(_executions.size(), Matchers.equalTo(0));
// When the dispatched thread turns up, it will see the second idle
_produce.add(NULLTASK);
_ewyk.run();
assertThat(_ewyk.isIdle(),equalTo(true));
Assert.assertThat(_ewyk.isIdle(), Matchers.equalTo(true));
// So that when t1 completes it does not produce again.
t1.unblock();