use of com.oath.cyclops.util.SimpleTimer in project cyclops by aol.
the class SyncBatchingTest method xPer.
@Test
public void xPer() {
SimpleTimer timer = new SimpleTimer();
assertThat(of(1, 2, 3, 4, 5, 6).xPer(6, 100000000, TimeUnit.NANOSECONDS).collect(Collectors.toList()).size(), is(6));
assertThat(timer.getElapsedNanoseconds(), lessThan(60000000l));
}
use of com.oath.cyclops.util.SimpleTimer in project cyclops by aol.
the class BaseSeqTest method debounce.
@Test
public void debounce() {
SimpleTimer timer = new SimpleTimer();
assertThat(of(1, 2, 3, 4, 5, 6).debounce(1000, TimeUnit.SECONDS).collect(Collectors.toList()).size(), is(1));
}
use of com.oath.cyclops.util.SimpleTimer in project cyclops by aol.
the class BaseSeqTest method onePer.
@Test
public void onePer() {
SimpleTimer timer = new SimpleTimer();
System.out.println(of(1, 2, 3, 4, 5, 6).onePer(1000, TimeUnit.NANOSECONDS).collect(Collectors.toList()));
assertThat(of(1, 2, 3, 4, 5, 6).onePer(1000, TimeUnit.NANOSECONDS).collect(Collectors.toList()).size(), is(6));
assertThat(timer.getElapsedNanoseconds(), greaterThan(600l));
}
use of com.oath.cyclops.util.SimpleTimer in project cyclops by aol.
the class BaseSeqTest method fixedDelay.
@Test
public void fixedDelay() {
SimpleTimer timer = new SimpleTimer();
assertThat(of(1, 2, 3, 4, 5, 6).fixedDelay(10000, TimeUnit.NANOSECONDS).collect(Collectors.toList()).size(), is(6));
assertThat(timer.getElapsedNanoseconds(), greaterThan(60000l));
}
use of com.oath.cyclops.util.SimpleTimer in project cyclops by aol.
the class Queue method ensureOpen.
private T ensureOpen(final long timeout, final TimeUnit timeUnit) {
if (!open && queue.size() == 0)
throw new ClosedQueueException();
final SimpleTimer timer = new SimpleTimer();
try {
final long timeoutNanos = timeUnit.toNanos(timeout);
T data = null;
try {
if (this.continuationStrategy != null) {
final SimpleTimer streamTimer = new SimpleTimer();
try {
while (open && (data = ensureClear(queue.poll())) == null) {
final SimpleTimer contTimer = new SimpleTimer();
this.continuationStrategy.handleContinuation();
if (timeout != -1)
handleTimeout(timer, timeoutNanos);
}
if (data != null)
return (T) nillSafe(ensureNotPoisonPill(ensureClear(data)));
} finally {
}
}
if (!open && queue.size() == 0)
throw new ClosedQueueException();
if (timeout == -1) {
if (this.sub != null && this.sub.timeLimit() > -1) {
data = ensureClear(consumerWait.take(() -> queue.poll(sub.timeLimit(), TimeUnit.NANOSECONDS)));
if (data == null)
throw new QueueTimeoutException();
} else {
SimpleTimer takeTimer = new SimpleTimer();
data = ensureClear(consumerWait.take(() -> queue.take()));
if (data == null)
throw new QueueTimeoutException();
}
} else {
data = ensureClear(consumerWait.take(() -> queue.poll(timeout, timeUnit)));
if (data == null)
throw new QueueTimeoutException();
}
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
throw ExceptionSoftener.throwSoftenedException(e);
}
ensureNotPoisonPill(data);
if (sizeSignal != null)
this.sizeSignal.set(queue.size());
return (T) nillSafe(data);
} finally {
}
}
Aggregations