use of java.util.ArrayDeque in project qi4j-sdk by Qi4j.
the class AbstractSQLStartup method constructApplicationInfo.
private ApplicationInfo constructApplicationInfo(Boolean setQNameTableNameToNull) throws SQLException {
final ApplicationInfo appInfo = new ApplicationInfo();
final List<CompositeDescriptorInfo> valueDescriptors = new ArrayList<>();
final Deque<Object> currentPath = new ArrayDeque<>();
_app.descriptor().accept(new HierarchicalVisitorAdapter<Object, Object, RuntimeException>() {
@Override
public boolean visitEnter(Object visited) throws RuntimeException {
if (visited instanceof LayerDescriptor || visited instanceof ModuleDescriptor) {
currentPath.push(visited);
}
if (visited instanceof EntityDescriptor || visited instanceof ValueDescriptor) {
// TODO filter non-visible descriptors away.
if (visited instanceof EntityDescriptor) {
EntityDescriptor entityDescriptor = (EntityDescriptor) visited;
if (entityDescriptor.queryable()) {
LOGGER.debug("THIS ONE WORKS: {}", entityDescriptor);
appInfo.entityDescriptors.put(first(entityDescriptor.types()).getName(), entityDescriptor);
}
} else {
valueDescriptors.add(new CompositeDescriptorInfo((LayerDescriptor) Iterables.first(Iterables.skip(1, currentPath)), (ModuleDescriptor) Iterables.first(currentPath), (CompositeDescriptor) visited));
}
return false;
}
return true;
}
@Override
public boolean visitLeave(Object visited) {
if (visited instanceof LayerDescriptor || visited instanceof ModuleDescriptor) {
currentPath.pop();
}
return true;
}
});
for (EntityDescriptor descriptor : appInfo.entityDescriptors.values()) {
Set<QualifiedName> newQNames = new HashSet<>();
this.extractPropertyQNames(descriptor, this._state.qNameInfos().get(), newQNames, valueDescriptors, appInfo.enumValues, setQNameTableNameToNull);
this.extractAssociationQNames(descriptor, this._state.qNameInfos().get(), newQNames, setQNameTableNameToNull);
this.extractManyAssociationQNames(descriptor, this._state.qNameInfos().get(), newQNames, setQNameTableNameToNull);
this._state.entityUsedQNames().get().put(descriptor, newQNames);
}
appInfo.usedValueComposites.addAll(valueDescriptors);
return appInfo;
}
use of java.util.ArrayDeque in project RxJava by ReactiveX.
the class QueueDrainHelperTest method postCompleteCancelledAfterOne.
@Test
public void postCompleteCancelledAfterOne() {
final TestSubscriber<Integer> ts = new TestSubscriber<Integer>() {
@Override
public void onNext(Integer t) {
super.onNext(t);
cancel();
}
};
ArrayDeque<Integer> queue = new ArrayDeque<Integer>();
AtomicLong state = new AtomicLong();
BooleanSupplier isCancelled = new BooleanSupplier() {
@Override
public boolean getAsBoolean() throws Exception {
return ts.isCancelled();
}
};
ts.onSubscribe(new BooleanSubscription());
queue.offer(1);
state.getAndIncrement();
QueueDrainHelper.postComplete(ts, queue, state, isCancelled);
ts.assertValue(1).assertNoErrors().assertNotComplete();
}
use of java.util.ArrayDeque in project RxJava by ReactiveX.
the class QueueDrainHelperTest method postCompleteEmpty.
@Test
public void postCompleteEmpty() {
TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
ArrayDeque<Integer> queue = new ArrayDeque<Integer>();
AtomicLong state = new AtomicLong();
BooleanSupplier isCancelled = new BooleanSupplier() {
@Override
public boolean getAsBoolean() throws Exception {
return false;
}
};
ts.onSubscribe(new BooleanSubscription());
QueueDrainHelper.postComplete(ts, queue, state, isCancelled);
ts.assertResult();
}
use of java.util.ArrayDeque in project netty by netty.
the class ResourceLeakDetectorTest method testConcurentUsage.
@Test(timeout = 60000)
public void testConcurentUsage() throws Throwable {
final AtomicBoolean finished = new AtomicBoolean();
final AtomicReference<Throwable> error = new AtomicReference<Throwable>();
// With 50 threads issue #6087 is reproducible on every run.
Thread[] threads = new Thread[50];
final CyclicBarrier barrier = new CyclicBarrier(threads.length);
for (int i = 0; i < threads.length; i++) {
Thread t = new Thread(new Runnable() {
Queue<LeakAwareResource> resources = new ArrayDeque<LeakAwareResource>(100);
@Override
public void run() {
try {
barrier.await();
// Run 10000 times or until the test is marked as finished.
for (int b = 0; b < 1000 && !finished.get(); b++) {
// Allocate 100 LeakAwareResource per run and close them after it.
for (int a = 0; a < 100; a++) {
DefaultResource resource = new DefaultResource();
ResourceLeakTracker<Resource> leak = DefaultResource.detector.track(resource);
LeakAwareResource leakAwareResource = new LeakAwareResource(resource, leak);
resources.add(leakAwareResource);
}
if (closeResources(true)) {
finished.set(true);
}
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (Throwable e) {
error.compareAndSet(null, e);
} finally {
// Just close all resource now without assert it to eliminate more reports.
closeResources(false);
}
}
private boolean closeResources(boolean checkClosed) {
for (; ; ) {
LeakAwareResource r = resources.poll();
if (r == null) {
return false;
}
boolean closed = r.close();
if (checkClosed && !closed) {
error.compareAndSet(null, new AssertionError("ResourceLeak.close() returned 'false' but expected 'true'"));
return true;
}
}
}
});
threads[i] = t;
t.start();
}
// Just wait until all threads are done.
for (Thread t : threads) {
t.join();
}
// Check if we had any leak reports in the ResourceLeakDetector itself
DefaultResource.detector.assertNoErrors();
assertNoErrors(error);
}
use of java.util.ArrayDeque in project netty by netty.
the class CombinedChannelDuplexHandlerTest method testOutboundEvents.
@Test
public void testOutboundEvents() {
final Queue<Event> queue = new ArrayDeque<Event>();
ChannelInboundHandler inboundHandler = new ChannelInboundHandlerAdapter();
ChannelOutboundHandler outboundHandler = new ChannelOutboundHandlerAdapter() {
@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
queue.add(Event.HANDLER_ADDED);
}
@Override
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
queue.add(Event.HANDLER_REMOVED);
}
@Override
public void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) throws Exception {
queue.add(Event.BIND);
}
@Override
public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) throws Exception {
queue.add(Event.CONNECT);
}
@Override
public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
queue.add(Event.DISCONNECT);
}
@Override
public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
queue.add(Event.CLOSE);
}
@Override
public void deregister(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
queue.add(Event.DEREGISTER);
}
@Override
public void read(ChannelHandlerContext ctx) throws Exception {
queue.add(Event.READ);
}
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
queue.add(Event.WRITE);
}
@Override
public void flush(ChannelHandlerContext ctx) throws Exception {
queue.add(Event.FLUSH);
}
};
CombinedChannelDuplexHandler<ChannelInboundHandler, ChannelOutboundHandler> handler = new CombinedChannelDuplexHandler<ChannelInboundHandler, ChannelOutboundHandler>(inboundHandler, outboundHandler);
EmbeddedChannel channel = new EmbeddedChannel();
channel.pipeline().addFirst(handler);
doOutboundOperations(channel);
assertEquals(Event.HANDLER_ADDED, queue.poll());
assertEquals(Event.BIND, queue.poll());
assertEquals(Event.CONNECT, queue.poll());
assertEquals(Event.WRITE, queue.poll());
assertEquals(Event.FLUSH, queue.poll());
assertEquals(Event.READ, queue.poll());
assertEquals(Event.CLOSE, queue.poll());
assertEquals(Event.CLOSE, queue.poll());
assertEquals(Event.DEREGISTER, queue.poll());
handler.removeOutboundHandler();
assertEquals(Event.HANDLER_REMOVED, queue.poll());
// These should not be handled by the inboundHandler anymore as it was removed before
doOutboundOperations(channel);
// Should have not received any more events as it was removed before via removeInboundHandler()
assertTrue(queue.isEmpty());
assertTrue(channel.finish());
assertTrue(queue.isEmpty());
}
Aggregations