use of co.paralleluniverse.strands.SuspendableRunnable in project quasar by puniverse.
the class TransferSelectorTest method testSelectReceiveWithClose2.
@Test
public void testSelectReceiveWithClose2() throws Exception {
final Channel<String> channel1 = newChannel();
final Channel<String> channel2 = newChannel();
final Channel<String> channel3 = newChannel();
Fiber fib = new Fiber("fiber", scheduler, new SuspendableRunnable() {
@Override
public void run() throws SuspendExecution, InterruptedException {
Strand.sleep(200);
SelectAction<String> sa1 = select(receive(channel1), receive(channel2), receive(channel3));
String m1 = sa1.message();
Strand.sleep(200);
SelectAction<String> sa2 = select(receive(channel1), receive(channel2), receive(channel3));
String m2 = sa2.message();
assertThat(sa1.index(), is(2));
assertThat(m1, nullValue());
assertThat(m2, nullValue());
}
}).start();
channel3.close();
fib.join();
}
use of co.paralleluniverse.strands.SuspendableRunnable in project quasar by puniverse.
the class TransferSelectorTest method testSelectSend2.
@Test
public void testSelectSend2() throws Exception {
final Channel<String> channel1 = newChannel();
final Channel<String> channel2 = newChannel();
final Channel<String> channel3 = newChannel();
Fiber fib = new Fiber("fiber", scheduler, new SuspendableRunnable() {
@Override
public void run() throws SuspendExecution, InterruptedException {
Strand.sleep(200);
SelectAction<String> sa1 = select(send(channel1, "hi1"), send(channel2, "hi2"), send(channel3, "hi3"));
Strand.sleep(200);
SelectAction<String> sa2 = select(send(channel1, "hi1"), send(channel2, "hi2"), send(channel3, "hi3"));
assertThat(sa1.index(), is(1));
assertThat(sa2.index(), is(0));
}
}).start();
String m1 = channel2.receive();
assertThat(m1, equalTo("hi2"));
String m2 = channel1.receive();
assertThat(m2, equalTo("hi1"));
fib.join();
}
use of co.paralleluniverse.strands.SuspendableRunnable in project quasar by puniverse.
the class TransferSelectorTest method testSelectReceive2.
@Test
public void testSelectReceive2() throws Exception {
final Channel<String> channel1 = newChannel();
final Channel<String> channel2 = newChannel();
final Channel<String> channel3 = newChannel();
Fiber fib = new Fiber("fiber", scheduler, new SuspendableRunnable() {
@Override
public void run() throws SuspendExecution, InterruptedException {
Strand.sleep(200);
SelectAction<String> sa1 = select(receive(channel1), receive(channel2), receive(channel3));
Strand.sleep(200);
SelectAction<String> sa2 = select(receive(channel1), receive(channel2), receive(channel3));
if (sa2.index() < sa1.index()) {
SelectAction<String> tmp = sa1;
sa1 = sa2;
sa2 = tmp;
}
String m1 = sa1.message();
String m2 = sa2.message();
assertThat(sa1.index(), is(0));
assertThat(m1, equalTo("hello"));
assertThat(sa2.index(), is(2));
assertThat(m2, equalTo("world!"));
}
}).start();
channel1.send("hello");
channel3.send("world!");
fib.join();
}
use of co.paralleluniverse.strands.SuspendableRunnable in project quasar by puniverse.
the class TransferSelectorTest method testSelectSendWithClose1.
@Test
public void testSelectSendWithClose1() throws Exception {
final Channel<String> channel1 = newChannel();
final Channel<String> channel2 = newChannel();
final Channel<String> channel3 = newChannel();
Fiber fib = new Fiber("fiber", scheduler, new SuspendableRunnable() {
@Override
public void run() throws SuspendExecution, InterruptedException {
SelectAction<String> sa1 = select(send(channel1, "hi1"), send(channel2, "hi2"), send(channel3, "hi3"));
SelectAction<String> sa2 = select(send(channel1, "hi1"), send(channel2, "hi2"), send(channel3, "hi3"));
assertThat(sa1.index(), is(1));
assertThat(sa2.index(), is(1));
}
}).start();
Thread.sleep(200);
channel2.close();
fib.join();
}
use of co.paralleluniverse.strands.SuspendableRunnable in project quasar by puniverse.
the class TransferSelectorTest method testSelectReceive1.
@Test
public void testSelectReceive1() throws Exception {
final Channel<String> channel1 = newChannel();
final Channel<String> channel2 = newChannel();
final Channel<String> channel3 = newChannel();
Fiber fib = new Fiber("fiber", scheduler, new SuspendableRunnable() {
@Override
public void run() throws SuspendExecution, InterruptedException {
SelectAction<String> sa1 = select(receive(channel1), receive(channel2), receive(channel3));
String m1 = sa1.message();
SelectAction<String> sa2 = select(receive(channel1), receive(channel2), receive(channel3));
String m2 = sa2.message();
assertThat(sa1.index(), is(0));
assertThat(m1, equalTo("hello"));
assertThat(sa2.index(), is(2));
assertThat(m2, equalTo("world!"));
}
}).start();
Thread.sleep(200);
channel1.send("hello");
Thread.sleep(200);
channel3.send("world!");
fib.join();
}
Aggregations