Skip to content

Commit

Permalink
CDITCK-486 move SynchronousQueue to ApplicationScoped bean.
Browse files Browse the repository at this point in the history
  • Loading branch information
tremes committed May 26, 2015
1 parent c52d72a commit 669074d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 29 deletions.
Expand Up @@ -16,17 +16,24 @@
*/
package org.jboss.cdi.tck.tests.context.request.event.timeout;

import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.Destroyed;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.event.Observes;
import javax.inject.Inject;

@ApplicationScoped
public class ApplicationScopedObserver {

@Inject
private RequestScopedObserver observer;

private final AtomicBoolean destroyedCalled = new AtomicBoolean();
private SynchronousQueue<Boolean> queue = new SynchronousQueue<Boolean>();

void observeRequestDestroyed(@Observes @Destroyed(RequestScoped.class) Object event) {
destroyedCalled.set(true);
Expand All @@ -39,4 +46,18 @@ void reset() {
boolean isDestroyedCalled() {
return destroyedCalled.get();
}

public void offerQueue() {
queue.offer(observer.isInitializedObserved());
}

public Boolean pollQueue(long timeout, TimeUnit timeUnit) {
Boolean result = new Boolean(false);
try {
result = queue.poll(timeout, timeUnit);
} catch (InterruptedException e) {
e.printStackTrace();
}
return result;
}
}
Expand Up @@ -18,7 +18,6 @@
package org.jboss.cdi.tck.tests.context.request.event.timeout;

import java.io.IOException;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.TimeUnit;

import javax.inject.Inject;
Expand All @@ -33,7 +32,6 @@

/**
* @author Martin Kouba
*
*/
@SuppressWarnings("serial")
@WebServlet("/info")
Expand All @@ -49,20 +47,13 @@ public InfoServlet(ApplicationScopedObserver observingBean) {
this.observingBean = observingBean;
}



@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

SynchronousQueue<Boolean> queue = new SynchronousQueue<Boolean>();
timeoutService.start(queue);
timeoutService.start();

Boolean initializedResult;
try {
initializedResult = queue.poll(5, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new ServletException(e);
}
initializedResult = observingBean.pollQueue(5, TimeUnit.SECONDS);

resp.getWriter().append("Initialized:" + initializedResult);
resp.getWriter().append("\n");
Expand Down
Expand Up @@ -17,9 +17,6 @@

package org.jboss.cdi.tck.tests.context.request.event.timeout;

import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.TimeUnit;

import javax.annotation.Resource;
import javax.ejb.Stateless;
import javax.ejb.Timeout;
Expand All @@ -34,29 +31,19 @@ public class TimeoutService {
@Resource
private TimerService timerService;

@Inject
private RequestScopedObserver observer;

@Inject
private ApplicationScopedObserver appObserver;

public void start(SynchronousQueue<Boolean> queue) {
TimerConfig config = new TimerConfig(queue, false);
public void start() {
TimerConfig config = new TimerConfig();
config.setPersistent(false);
timerService.createSingleActionTimer(100, config);
}

@Timeout
public void onTimeout(Timer timer) {
if (timer.getInfo() instanceof SynchronousQueue<?>) {
appObserver.reset();
@SuppressWarnings("unchecked")
SynchronousQueue<Boolean> queue = (SynchronousQueue<Boolean>) timer.getInfo();
try {
queue.offer(observer.isInitializedObserved(), 5, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
appObserver.reset();
appObserver.offerQueue();
}

}
7 changes: 7 additions & 0 deletions impl/src/main/resources/tck-tests.xml
Expand Up @@ -45,6 +45,13 @@
</methods>
</class>

<!-- CDITCK-486 -->
<class name="org.jboss.cdi.tck.tests.context.request.event.timeout.RequestScopeEventTimeoutTest">
<methods>
<exclude name=".*"/>
</methods>
</class>

</classes>

</test>
Expand Down

0 comments on commit 669074d

Please sign in to comment.