Skip to content

Commit

Permalink
Fixed runtime problem with observer registrations.
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@358 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
drallen committed Nov 24, 2008
1 parent 08eec85 commit aac8a6f
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 109 deletions.
Expand Up @@ -19,7 +19,6 @@

import java.lang.annotation.Annotation;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -148,14 +147,8 @@ public <T> void notifyObservers(Set<Observer<T>> observers, T event)
public <T> void removeObserver(Observer<T> observer, Class<T> eventType, Annotation... bindings)
{
List<EventObserver<?>> observers = registeredObservers.get(eventType);
for (Iterator<EventObserver<?>> i = observers.iterator(); i.hasNext();)
{
if (observer.equals(i.next().getObserver()))
{
i.remove();
break;
}
}
EventObserver<T> eventObserver = new EventObserver<T>(observer, eventType, bindings);
observers.remove(eventObserver);
}

@Override
Expand Down
201 changes: 101 additions & 100 deletions webbeans-ri/src/test/java/org/jboss/webbeans/test/EventManagerTest.java
Expand Up @@ -24,7 +24,7 @@
* Tests for the EventManager implementation used by the Web Beans RI.
*
* @author David Allen
*
*
*/
@SpecVersion("PDR")
public class EventManagerTest extends AbstractTest
Expand All @@ -37,7 +37,7 @@ public void notify(T event)
}

private Synchronization registeredSynch;

/**
* Tests adding an observer to the event bus and verified that it can still
* be retrieved for a corresponding event.
Expand All @@ -49,11 +49,11 @@ public void testAddObserver()
Observer<DangerCall> observer = new AnObserver<DangerCall>();
eventManager.addObserver(observer, DangerCall.class);
DangerCall event = new DangerCall();

Set<Observer<DangerCall>> observerSet = eventManager.getObservers(event);
assert observerSet.size() == 1;
assert observerSet.iterator().next().equals(observer);

// Add another observer for the same event, but with an event binding
observer = new AnObserver<DangerCall>();
eventManager.addObserver(observer, DangerCall.class, new TameAnnotationLiteral());
Expand All @@ -62,12 +62,12 @@ public void testAddObserver()
observerSet = eventManager.getObservers(event, new TameAnnotationLiteral());
assert observerSet.size() == 2;
}

/**
* Tests the remove operation and verifies that the observer is no longer
* registered for events.
*/
@Test(groups = {"observerMethod", "broken"})
@Test(groups = { "observerMethod" })
public void testRemoveObserver()
{
EventManager eventManager = new EventManager(manager);
Expand All @@ -77,114 +77,115 @@ public void testRemoveObserver()
// FIXME CopyOnWrite broke remove, have to check later
assert eventManager.getObservers(new DangerCall()).isEmpty();
}

/**
* Tests the deferred event feature associated with transactions.
*/
@Test(groups = {"deferredEvent", "broken"})
@Test(groups = { "deferredEvent", "broken" })
public void testDeferEvent()
{
// Setup a transaction manager for this test and inject into the event bus
// TransactionManager tm = new TransactionManager() {
// public void begin() throws NotSupportedException, SystemException
// {
// }
//
// public void commit() throws RollbackException,
// HeuristicMixedException, HeuristicRollbackException,
// SecurityException, IllegalStateException, SystemException
// {
// }
//
// public int getStatus() throws SystemException
// {
// return 0;
// }
//
// public Transaction getTransaction() throws SystemException
// {
// return new Transaction() {
//
// public void commit() throws RollbackException,
// HeuristicMixedException, HeuristicRollbackException,
// SecurityException, IllegalStateException, SystemException
// {
// }
//
// public boolean delistResource(XAResource arg0, int arg1)
// throws IllegalStateException, SystemException
// {
// return false;
// }
//
// public boolean enlistResource(XAResource arg0)
// throws RollbackException, IllegalStateException,
// SystemException
// {
// return false;
// }
//
// public int getStatus() throws SystemException
// {
// return 0;
// }
//
// public void registerSynchronization(Synchronization synchronization)
// throws RollbackException, IllegalStateException,
// SystemException
// {
// registeredSynch = synchronization;
// }
//
// public void rollback() throws IllegalStateException,
// SystemException
// {
// }
//
// public void setRollbackOnly() throws IllegalStateException,
// SystemException
// {
// }
//
// };
// }
//
// public void resume(Transaction arg0)
// throws InvalidTransactionException, IllegalStateException,
// SystemException
// {
// }
//
// public void rollback() throws IllegalStateException,
// SecurityException, SystemException
// {
// }
//
// public void setRollbackOnly() throws IllegalStateException,
// SystemException
// {
// }
//
// public void setTransactionTimeout(int arg0) throws SystemException
// {
// }
//
// public Transaction suspend() throws SystemException
// {
// return null;
// }
//
// };
// TransactionManager tm = new TransactionManager() {
// public void begin() throws NotSupportedException, SystemException
// {
// }
//
// public void commit() throws RollbackException,
// HeuristicMixedException, HeuristicRollbackException,
// SecurityException, IllegalStateException, SystemException
// {
// }
//
// public int getStatus() throws SystemException
// {
// return 0;
// }
//
// public Transaction getTransaction() throws SystemException
// {
// return new Transaction() {
//
// public void commit() throws RollbackException,
// HeuristicMixedException, HeuristicRollbackException,
// SecurityException, IllegalStateException, SystemException
// {
// }
//
// public boolean delistResource(XAResource arg0, int arg1)
// throws IllegalStateException, SystemException
// {
// return false;
// }
//
// public boolean enlistResource(XAResource arg0)
// throws RollbackException, IllegalStateException,
// SystemException
// {
// return false;
// }
//
// public int getStatus() throws SystemException
// {
// return 0;
// }
//
// public void registerSynchronization(Synchronization synchronization)
// throws RollbackException, IllegalStateException,
// SystemException
// {
// registeredSynch = synchronization;
// }
//
// public void rollback() throws IllegalStateException,
// SystemException
// {
// }
//
// public void setRollbackOnly() throws IllegalStateException,
// SystemException
// {
// }
//
// };
// }
//
// public void resume(Transaction arg0)
// throws InvalidTransactionException, IllegalStateException,
// SystemException
// {
// }
//
// public void rollback() throws IllegalStateException,
// SecurityException, SystemException
// {
// }
//
// public void setRollbackOnly() throws IllegalStateException,
// SystemException
// {
// }
//
// public void setTransactionTimeout(int arg0) throws SystemException
// {
// }
//
// public Transaction suspend() throws SystemException
// {
// return null;
// }
//
// };
EventManager eventManager = new EventManager(manager);
Observer<DangerCall> observer = new AnObserver<DangerCall>();
try
{
// eventManager.deferEvent(new DangerCall(), observer);
} catch (Exception e)
}
catch (Exception e)
{
}

assert this.registeredSynch != null;
assert ((DeferredEventNotification)this.registeredSynch).getObserver().equals(observer);
assert ((DeferredEventNotification) this.registeredSynch).getObserver().equals(observer);
}
}

0 comments on commit aac8a6f

Please sign in to comment.