Changeset 72 for trunk/src/test
- Timestamp:
- 06/29/13 20:44:27 (11 years ago)
- Location:
- trunk/src/test/java/omq/test
- Files:
-
- 2 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/test/java/omq/test/calculator/Calculator.java
r47 r72 1 1 package omq.test.calculator; 2 3 import java.io.IOException;4 2 5 3 import omq.Remote; … … 7 5 import omq.client.annotation.RemoteInterface; 8 6 import omq.client.annotation.SyncMethod; 9 import omq.exception.SerializerException;10 7 11 8 @RemoteInterface … … 20 17 public void sendMessage(Message m); 21 18 22 @AsyncMethod23 public void asyncDivideByZero() throws IOException, SerializerException;24 25 19 @SyncMethod(timeout = 1500) 26 20 public int divideByZero(); -
trunk/src/test/java/omq/test/calculator/CalculatorImpl.java
r63 r72 1 1 package omq.test.calculator; 2 2 3 import java.io.IOException;4 5 import omq.common.broker.Broker;6 import omq.exception.SerializerException;7 3 import omq.server.RemoteObject; 8 4 9 5 public class CalculatorImpl extends RemoteObject implements Calculator { 10 6 private int mult = 0; 11 private Broker broker;12 7 13 8 public CalculatorImpl() throws Exception { 14 9 super(); 15 }16 17 public CalculatorImpl(Broker broker) throws Exception {18 super();19 this.broker = broker;20 10 } 21 11 … … 41 31 42 32 @Override 43 public void asyncDivideByZero() throws IOException, SerializerException {44 ZeroEvent ze = new ZeroEvent("my zero event", "zero-event");45 broker.trigger(ze);46 // notifyEvent(ze);47 }48 49 @Override50 33 public void sendMessage(Message m) { 51 34 System.out.println("Code = " + m.getCode()); -
trunk/src/test/java/omq/test/calculator/CalculatorTest.java
r62 r72 120 120 121 121 @Test 122 public void notifyEvent() throws Exception {123 ZeroListener zL = new ZeroListener("zero-event");124 125 remoteCalc.addListener(zL);126 127 remoteCalc.asyncDivideByZero();128 129 Thread.sleep(200);130 }131 132 @Test133 122 public void sendMessage() throws Exception { 134 123 Message m = new Message(2334, "Hello objectmq"); -
trunk/src/test/java/omq/test/observer/ObserverTest.java
r71 r72 23 23 private static String OBSERVER = "observer"; 24 24 private static Broker broker; 25 private static RemoteSubjectImpl subject; 25 26 private static RemoteSubject remoteSubject; 26 27 … … 71 72 env.setProperty(ParameterQueue.RETRY_TIME_CONNECTION, "2000"); 72 73 74 // Set info about the queue & the exchange where the ResponseListener 75 // will listen to. 76 env.setProperty(ParameterQueue.RPC_REPLY_QUEUE, "server_reply_queue"); 77 env.setProperty(ParameterQueue.EVENT_REPLY_QUEUE, "server_event_queue"); 78 73 79 Broker broker = new Broker(env); 74 RemoteSubjectImpl subject = new RemoteSubjectImpl();80 subject = new RemoteSubjectImpl(broker); 75 81 broker.bind(SUBJECT, subject); 76 82 … … 90 96 RemoteObserverImpl observer = new RemoteObserverImpl(); 91 97 broker.bind(OBSERVER, observer); 98 observer.setSubject(remoteSubject); 92 99 93 remoteSubject.addObserver(observer );100 remoteSubject.addObserver(observer.getRef()); 94 101 remoteSubject.setState(expected); 95 remoteSubject.notifyObservers(); 102 // both proxies are in the same thread for this reason since subject has 103 // a proxy inside we need to use subject or create a new thread 104 subject.notifyObservers(); 96 105 actual = observer.getObsState(); 97 106 98 107 assertEquals(expected, actual); 99 remoteSubject.setState( null);108 remoteSubject.setState(""); 100 109 } 101 110 -
trunk/src/test/java/omq/test/observer/RemoteSubject.java
r71 r72 4 4 import omq.client.annotation.RemoteInterface; 5 5 import omq.client.annotation.SyncMethod; 6 import omq.exception.RemoteException; 6 7 7 8 @RemoteInterface … … 15 16 16 17 @SyncMethod(timeout = 1000) 17 public void addObserver( RemoteObserver o);18 public void addObserver(String ref) throws RemoteException; 18 19 19 20 @SyncMethod(timeout = 1000) 20 public void removeObserver( RemoteObserver o);21 public void removeObserver(String ref) throws RemoteException; 21 22 22 23 @SyncMethod(timeout = 1000) -
trunk/src/test/java/omq/test/observer/RemoteSubjectImpl.java
r71 r72 4 4 import java.util.List; 5 5 6 import omq.common.broker.Broker; 7 import omq.exception.RemoteException; 6 8 import omq.server.RemoteObject; 7 9 … … 13 15 private static final long serialVersionUID = 1L; 14 16 private String state; 15 private List<RemoteObserver> list = new ArrayList<RemoteObserver>(); 17 private Broker broker; 18 private List<RemoteObserver> list; 16 19 17 @Override18 public void addObserver(RemoteObserver o) {19 list .add(o);20 public RemoteSubjectImpl(Broker broker) { 21 this.broker = broker; 22 list = new ArrayList<RemoteObserver>(); 20 23 } 21 24 22 25 @Override 23 public void removeObserver(RemoteObserver o) { 24 list.remove(o); 26 public void addObserver(String ref) throws RemoteException { 27 RemoteObserver obs = broker.lookup(ref, RemoteObserver.class); 28 list.add(obs); 29 } 30 31 @Override 32 public void removeObserver(String ref) throws RemoteException { 33 RemoteObserver obs = broker.lookup(ref, RemoteObserver.class); 34 list.remove(obs); 25 35 } 26 36
Note: See TracChangeset
for help on using the changeset viewer.