本文整理汇总了Java中java.util.concurrent.SubmissionPublisher.offer方法的典型用法代码示例。如果您正苦于以下问题:Java SubmissionPublisher.offer方法的具体用法?Java SubmissionPublisher.offer怎么用?Java SubmissionPublisher.offer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.SubmissionPublisher
的用法示例。
在下文中一共展示了SubmissionPublisher.offer方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testLaggedOffer
import java.util.concurrent.SubmissionPublisher; //导入方法依赖的package包/类
/**
* offer returns number of lagged items if not saturated
*/
public void testLaggedOffer() {
SubmissionPublisher<Integer> p = basicPublisher();
TestSubscriber s1 = new TestSubscriber();
s1.request = false;
TestSubscriber s2 = new TestSubscriber();
s2.request = false;
p.subscribe(s1);
p.subscribe(s2);
s2.awaitSubscribe();
s1.awaitSubscribe();
assertTrue(p.offer(1, null) >= 1);
assertTrue(p.offer(2, null) >= 2);
s1.sn.request(4);
assertTrue(p.offer(3, null) >= 3);
s2.sn.request(4);
p.offer(4, null);
p.close();
s2.awaitComplete();
assertEquals(4, s2.nexts);
s1.awaitComplete();
assertEquals(4, s2.nexts);
}
示例2: testDroppedOffer
import java.util.concurrent.SubmissionPublisher; //导入方法依赖的package包/类
/**
* offer reports drops if saturated
*/
public void testDroppedOffer() {
SubmissionPublisher<Integer> p
= new SubmissionPublisher<>(basicExecutor, 4);
TestSubscriber s1 = new TestSubscriber();
s1.request = false;
TestSubscriber s2 = new TestSubscriber();
s2.request = false;
p.subscribe(s1);
p.subscribe(s2);
s2.awaitSubscribe();
s1.awaitSubscribe();
for (int i = 1; i <= 4; ++i)
assertTrue(p.offer(i, null) >= 0);
p.offer(5, null);
assertTrue(p.offer(6, null) < 0);
s1.sn.request(64);
assertTrue(p.offer(7, null) < 0);
s2.sn.request(64);
p.close();
s2.awaitComplete();
assertTrue(s2.nexts >= 4);
s1.awaitComplete();
assertTrue(s1.nexts >= 4);
}
示例3: testHandledDroppedOffer
import java.util.concurrent.SubmissionPublisher; //导入方法依赖的package包/类
/**
* offer invokes drop handler if saturated
*/
public void testHandledDroppedOffer() {
AtomicInteger calls = new AtomicInteger();
SubmissionPublisher<Integer> p
= new SubmissionPublisher<>(basicExecutor, 4);
TestSubscriber s1 = new TestSubscriber();
s1.request = false;
TestSubscriber s2 = new TestSubscriber();
s2.request = false;
p.subscribe(s1);
p.subscribe(s2);
s2.awaitSubscribe();
s1.awaitSubscribe();
for (int i = 1; i <= 4; ++i)
assertTrue(p.offer(i, (s, x) -> noopHandle(calls)) >= 0);
p.offer(4, (s, x) -> noopHandle(calls));
assertTrue(p.offer(6, (s, x) -> noopHandle(calls)) < 0);
s1.sn.request(64);
assertTrue(p.offer(7, (s, x) -> noopHandle(calls)) < 0);
s2.sn.request(64);
p.close();
s2.awaitComplete();
s1.awaitComplete();
assertTrue(calls.get() >= 4);
}
示例4: testRecoveredHandledDroppedOffer
import java.util.concurrent.SubmissionPublisher; //导入方法依赖的package包/类
/**
* offer succeeds if drop handler forces request
*/
public void testRecoveredHandledDroppedOffer() {
AtomicInteger calls = new AtomicInteger();
SubmissionPublisher<Integer> p
= new SubmissionPublisher<>(basicExecutor, 4);
TestSubscriber s1 = new TestSubscriber();
s1.request = false;
TestSubscriber s2 = new TestSubscriber();
s2.request = false;
p.subscribe(s1);
p.subscribe(s2);
s2.awaitSubscribe();
s1.awaitSubscribe();
int n = 0;
for (int i = 1; i <= 8; ++i) {
int d = p.offer(i, (s, x) -> reqHandle(calls, s));
n = n + 2 + (d < 0 ? d : 0);
}
p.close();
s2.awaitComplete();
s1.awaitComplete();
assertEquals(n, s1.nexts + s2.nexts);
assertTrue(calls.get() >= 2);
}
示例5: testLaggedTimedOffer
import java.util.concurrent.SubmissionPublisher; //导入方法依赖的package包/类
/**
* Timed offer returns number of lagged items if not saturated
*/
public void testLaggedTimedOffer() {
SubmissionPublisher<Integer> p = basicPublisher();
TestSubscriber s1 = new TestSubscriber();
s1.request = false;
TestSubscriber s2 = new TestSubscriber();
s2.request = false;
p.subscribe(s1);
p.subscribe(s2);
s2.awaitSubscribe();
s1.awaitSubscribe();
long startTime = System.nanoTime();
assertTrue(p.offer(1, LONG_DELAY_MS, MILLISECONDS, null) >= 1);
assertTrue(p.offer(2, LONG_DELAY_MS, MILLISECONDS, null) >= 2);
s1.sn.request(4);
assertTrue(p.offer(3, LONG_DELAY_MS, MILLISECONDS, null) >= 3);
s2.sn.request(4);
p.offer(4, LONG_DELAY_MS, MILLISECONDS, null);
p.close();
s2.awaitComplete();
assertEquals(4, s2.nexts);
s1.awaitComplete();
assertEquals(4, s2.nexts);
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS / 2);
}
示例6: testDroppedOffer
import java.util.concurrent.SubmissionPublisher; //导入方法依赖的package包/类
/**
* offer reports drops if saturated
*/
public void testDroppedOffer() {
SubmissionPublisher<Integer> p = new SubmissionPublisher<Integer>(
basicExecutor, 4);
TestSubscriber s1 = new TestSubscriber();
s1.request = false;
TestSubscriber s2 = new TestSubscriber();
s2.request = false;
p.subscribe(s1);
p.subscribe(s2);
s2.awaitSubscribe();
s1.awaitSubscribe();
for (int i = 1; i <= 4; ++i)
assertTrue(p.offer(i, null) >= 0);
p.offer(5, null);
assertTrue(p.offer(6, null) < 0);
s1.sn.request(64);
assertTrue(p.offer(7, null) < 0);
s2.sn.request(64);
p.close();
s2.awaitComplete();
assertTrue(s2.nexts >= 4);
s1.awaitComplete();
assertTrue(s1.nexts >= 4);
}
示例7: testHandledDroppedOffer
import java.util.concurrent.SubmissionPublisher; //导入方法依赖的package包/类
/**
* offer invokes drop handler if saturated
*/
public void testHandledDroppedOffer() {
AtomicInteger calls = new AtomicInteger();
SubmissionPublisher<Integer> p = new SubmissionPublisher<Integer>(
basicExecutor, 4);
TestSubscriber s1 = new TestSubscriber();
s1.request = false;
TestSubscriber s2 = new TestSubscriber();
s2.request = false;
p.subscribe(s1);
p.subscribe(s2);
s2.awaitSubscribe();
s1.awaitSubscribe();
for (int i = 1; i <= 4; ++i)
assertTrue(p.offer(i, (s, x) -> noopHandle(calls)) >= 0);
p.offer(4, (s, x) -> noopHandle(calls));
assertTrue(p.offer(6, (s, x) -> noopHandle(calls)) < 0);
s1.sn.request(64);
assertTrue(p.offer(7, (s, x) -> noopHandle(calls)) < 0);
s2.sn.request(64);
p.close();
s2.awaitComplete();
s1.awaitComplete();
assertTrue(calls.get() >= 4);
}
示例8: testRecoveredHandledDroppedOffer
import java.util.concurrent.SubmissionPublisher; //导入方法依赖的package包/类
/**
* offer succeeds if drop handler forces request
*/
public void testRecoveredHandledDroppedOffer() {
AtomicInteger calls = new AtomicInteger();
SubmissionPublisher<Integer> p = new SubmissionPublisher<Integer>(
basicExecutor, 4);
TestSubscriber s1 = new TestSubscriber();
s1.request = false;
TestSubscriber s2 = new TestSubscriber();
s2.request = false;
p.subscribe(s1);
p.subscribe(s2);
s2.awaitSubscribe();
s1.awaitSubscribe();
int n = 0;
for (int i = 1; i <= 8; ++i) {
int d = p.offer(i, (s, x) -> reqHandle(calls, s));
n = n + 2 + (d < 0 ? d : 0);
}
p.close();
s2.awaitComplete();
s1.awaitComplete();
assertEquals(n, s1.nexts + s2.nexts);
assertTrue(calls.get() >= 2);
}
示例9: testNullOffer
import java.util.concurrent.SubmissionPublisher; //导入方法依赖的package包/类
/**
* offer(null) throws NPE
*/
public void testNullOffer() {
SubmissionPublisher<Integer> p = basicPublisher();
try {
p.offer(null, null);
shouldThrow();
} catch (NullPointerException success) {}
}
示例10: testRecoveredHandledDroppedTimedOffer
import java.util.concurrent.SubmissionPublisher; //导入方法依赖的package包/类
/**
* Timed offer succeeds if drop handler forces request
*/
public void testRecoveredHandledDroppedTimedOffer() {
AtomicInteger calls = new AtomicInteger();
SubmissionPublisher<Integer> p
= new SubmissionPublisher<>(basicExecutor, 4);
TestSubscriber s1 = new TestSubscriber();
s1.request = false;
TestSubscriber s2 = new TestSubscriber();
s2.request = false;
p.subscribe(s1);
p.subscribe(s2);
s2.awaitSubscribe();
s1.awaitSubscribe();
int n = 0;
long delay = timeoutMillis();
long startTime = System.nanoTime();
for (int i = 1; i <= 6; ++i) {
int d = p.offer(i, delay, MILLISECONDS, (s, x) -> reqHandle(calls, s));
n = n + 2 + (d < 0 ? d : 0);
}
assertTrue(millisElapsedSince(startTime) >= delay);
p.close();
s2.awaitComplete();
s1.awaitComplete();
assertEquals(n, s1.nexts + s2.nexts);
assertTrue(calls.get() >= 2);
}
示例11: testRecoveredHandledDroppedTimedOffer
import java.util.concurrent.SubmissionPublisher; //导入方法依赖的package包/类
/**
* Timed offer succeeds if drop handler forces request
*/
public void testRecoveredHandledDroppedTimedOffer() {
AtomicInteger calls = new AtomicInteger();
SubmissionPublisher<Integer> p = new SubmissionPublisher<Integer>(
basicExecutor, 4);
TestSubscriber s1 = new TestSubscriber();
s1.request = false;
TestSubscriber s2 = new TestSubscriber();
s2.request = false;
p.subscribe(s1);
p.subscribe(s2);
s2.awaitSubscribe();
s1.awaitSubscribe();
int n = 0;
long delay = timeoutMillis();
long startTime = System.nanoTime();
for (int i = 1; i <= 6; ++i) {
int d = p.offer(i, delay, MILLISECONDS, (s, x) -> reqHandle(calls, s));
n = n + 2 + (d < 0 ? d : 0);
}
assertTrue(millisElapsedSince(startTime) >= delay);
p.close();
s2.awaitComplete();
s1.awaitComplete();
assertEquals(n, s1.nexts + s2.nexts);
assertTrue(calls.get() >= 2);
}