use of java.util.concurrent.SubmissionPublisher in project reactive-streams-jvm by reactive-streams.
the class FlowAdaptersTest method flowToReactiveError.
@Test
public void flowToReactiveError() {
SubmissionPublisher<Integer> p = new SubmissionPublisher<Integer>(new Executor() {
@Override
public void execute(Runnable command) {
command.run();
}
}, Flow.defaultBufferSize());
TestEitherConsumer<Integer> tc = new TestEitherConsumer<Integer>();
FlowAdapters.toPublisher(p).subscribe(tc);
p.submit(1);
p.submit(2);
p.submit(3);
p.submit(4);
p.submit(5);
p.closeExceptionally(new IOException());
tc.assertFailure(IOException.class, 1, 2, 3, 4, 5);
}
use of java.util.concurrent.SubmissionPublisher in project reactive-streams-jvm by reactive-streams.
the class FlowAdaptersTest method flowToReactiveNormal.
@Test
public void flowToReactiveNormal() {
SubmissionPublisher<Integer> p = new SubmissionPublisher<Integer>(new Executor() {
@Override
public void execute(Runnable command) {
command.run();
}
}, Flow.defaultBufferSize());
TestEitherConsumer<Integer> tc = new TestEitherConsumer<Integer>();
FlowAdapters.toPublisher(p).subscribe(tc);
p.submit(1);
p.submit(2);
p.submit(3);
p.submit(4);
p.submit(5);
p.close();
tc.assertRange(1, 5);
}
use of java.util.concurrent.SubmissionPublisher in project Java-9-Spring-Webflux by kkTranslation.
the class TestStockMaintain method teststockRemoval.
@Test
public void teststockRemoval() throws InterruptedException {
Stock stock = new Stock();
SubmissionPublisher<Order> p = new SubmissionPublisher<>();
p.subscribe(new StockMaintain(stock));
Product product = new Product();
stock.store(product, 40);
OrderItem item = new OrderItem();
item.setProduct(product);
item.setAmount(10);
Order order = new Order();
List<OrderItem> items = new LinkedList<>();
items.add(item);
order.setItems(items);
for (int i = 0; i < 10; i++) p.submit(order);
log.info("所有订单已经提交完毕");
for (int j = 0; j < 10; j++) {
log.info("Sleeping a bit...");
Thread.sleep(50);
}
p.close();
log.info("Publisher已关闭");
}
use of java.util.concurrent.SubmissionPublisher in project javaBook-src by huifer.
the class ProcessorTest method main.
public static void main(String[] args) throws InterruptedException {
SubmissionPublisher<Integer> publisher = new SubmissionPublisher<>();
Processor processor = new Processor();
SubscrioberForString subscrioberForString = new SubscrioberForString();
publisher.subscribe(processor);
processor.subscribe(subscrioberForString);
for (int i = 0; i < 300; i++) {
int i1 = new Random().nextInt(100);
publisher.submit(i1);
}
TimeUnit.SECONDS.sleep(500);
System.out.println("main work end");
}
use of java.util.concurrent.SubmissionPublisher in project helidon by oracle.
the class SubscriberInputStreamTest method testSingle.
@Test
public void testSingle() throws IOException {
String value = "the long value I want to push through";
SubmissionPublisher<ByteBuffer> publisher = new SubmissionPublisher<>();
SubscriberInputStream is = new SubscriberInputStream();
publisher.subscribe(is);
// asynchronously publish
new Thread(() -> {
publisher.submit(ByteBuffer.wrap(value.getBytes(StandardCharsets.UTF_8)));
publisher.close();
}).start();
byte[] buffer = new byte[16];
int len;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
while ((len = is.read(buffer)) != -1) {
baos.write(buffer, 0, len);
}
String result = new String(baos.toByteArray(), StandardCharsets.UTF_8);
assertThat(result, is(value));
}
Aggregations