Changeset 54 for trunk/src/test/java/omq
- Timestamp:
- 06/21/13 12:42:25 (11 years ago)
- Location:
- trunk/src/test/java/omq/test
- Files:
-
- 1 added
- 8 deleted
- 6 edited
- 5 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/test/java/omq/test/calculator/CalculatorImpl.java
r46 r54 3 3 import java.io.IOException; 4 4 5 import omq.common.broker.Broker;6 5 import omq.exception.SerializerException; 7 6 import omq.server.RemoteObject; … … 36 35 @Override 37 36 public void asyncDivideByZero() throws IOException, SerializerException { 38 ZeroEvent ze = new ZeroEvent("my zero event", "zero-event");39 Broker.trigger(ze);40 // notifyEvent(ze);37 // ZeroEvent ze = new ZeroEvent("my zero event", "zero-event"); 38 // Broker.trigger(ze); 39 // notifyEvent(ze); 41 40 } 42 41 43 42 @Override 44 43 public void sendMessage(Message m) { 45 System.out.println("Code = " +m.getCode());46 System.out.println("Message = " +m.getMessage());44 System.out.println("Code = " + m.getCode()); 45 System.out.println("Message = " + m.getMessage()); 47 46 } 48 47 -
trunk/src/test/java/omq/test/calculator/CalculatorTest.java
r51 r54 12 12 13 13 import org.junit.After; 14 import org.junit.BeforeClass; 14 15 import org.junit.Test; 15 16 import org.junit.runner.RunWith; … … 18 19 19 20 @RunWith(value = Parameterized.class) 20 public class C lientTest {21 public class CalculatorTest { 21 22 23 private static Broker broker; 22 24 private static Calculator remoteCalc; 23 25 private static Calculator remoteCalc2; 24 26 25 public C lientTest(String type) throws Exception {27 public CalculatorTest(String type) throws Exception { 26 28 Properties env = new Properties(); 27 29 env.setProperty(ParameterQueue.USER_NAME, "guest"); … … 44 46 env.setProperty(ParameterQueue.EVENT_REPLY_QUEUE, "event_queue"); 45 47 46 Broker.initBroker(env);47 remoteCalc = (Calculator) Broker.lookup("calculator1", Calculator.class);48 remoteCalc2 = (Calculator) Broker.lookup("calculator2", Calculator.class);48 broker = new Broker(env); 49 remoteCalc = broker.lookup("calculator1", Calculator.class); 50 remoteCalc2 = broker.lookup("calculator2", Calculator.class); 49 51 } 50 52 … … 55 57 } 56 58 59 @BeforeClass 60 public static void server() throws Exception { 61 Properties env = new Properties(); 62 env.setProperty(ParameterQueue.USER_NAME, "guest"); 63 env.setProperty(ParameterQueue.USER_PASS, "guest"); 64 65 // Get host info of rabbimq (where it is) 66 env.setProperty(ParameterQueue.SERVER_HOST, "127.0.0.1"); 67 env.setProperty(ParameterQueue.SERVER_PORT, "5672"); 68 env.setProperty(ParameterQueue.DURABLE_QUEUES, "false"); 69 env.setProperty(ParameterQueue.ENABLECOMPRESSION, "false"); 70 71 // Set info about where the message will be sent 72 env.setProperty(ParameterQueue.RPC_EXCHANGE, "rpc_exchange"); 73 env.setProperty(ParameterQueue.RETRY_TIME_CONNECTION, "2000"); 74 75 CalculatorImpl calc = new CalculatorImpl(); 76 CalculatorImpl calc2 = new CalculatorImpl(); 77 78 Broker broker = new Broker(env); 79 broker.bind("calculator1", calc); 80 broker.bind("calculator2", calc2); 81 82 System.out.println("Server started"); 83 } 84 57 85 @After 58 86 public void stop() throws Exception { 59 Broker.stopBroker();87 broker.stopBroker(); 60 88 } 61 89 -
trunk/src/test/java/omq/test/exception/ExceptionTest.java
r47 r54 13 13 14 14 import org.junit.After; 15 import org.junit.BeforeClass; 15 16 import org.junit.Test; 16 17 import org.junit.runner.RunWith; … … 19 20 20 21 @RunWith(value = Parameterized.class) 21 public class ClientTest { 22 private ClientInterface client; 22 public class ExceptionTest { 23 private static Broker broker; 24 private static ClientInterface client; 23 25 24 public ClientTest(String type) throws Exception {26 public ExceptionTest(String type) throws Exception { 25 27 Properties env = new Properties(); 26 28 env.setProperty(ParameterQueue.USER_NAME, "guest"); … … 42 44 env.setProperty(ParameterQueue.EVENT_REPLY_QUEUE, "event_queue"); 43 45 44 Broker.initBroker(env);45 client = (ClientInterface) Broker.lookup("server", ClientInterface.class);46 broker = new Broker(env); 47 client = broker.lookup("server", ClientInterface.class); 46 48 } 47 49 … … 52 54 } 53 55 56 @BeforeClass 57 public static void serverTest() throws Exception { 58 Properties env = new Properties(); 59 env.setProperty(ParameterQueue.USER_NAME, "guest"); 60 env.setProperty(ParameterQueue.USER_PASS, "guest"); 61 62 // Get host info of rabbimq (where it is) 63 env.setProperty(ParameterQueue.SERVER_HOST, "127.0.0.1"); 64 env.setProperty(ParameterQueue.SERVER_PORT, "5672"); 65 env.setProperty(ParameterQueue.DURABLE_QUEUES, "false"); 66 env.setProperty(ParameterQueue.ENABLECOMPRESSION, "false"); 67 68 // Set info about where the message will be sent 69 env.setProperty(ParameterQueue.RPC_EXCHANGE, "rpc_exchange"); 70 env.setProperty(ParameterQueue.RETRY_TIME_CONNECTION, "2000"); 71 72 OmqServerImpl server = new OmqServerImpl(); 73 74 Broker broker = new Broker(env); 75 broker.bind("server", server); 76 } 77 54 78 @After 55 79 public void stop() throws Exception { 56 Broker.stopBroker();80 broker.stopBroker(); 57 81 } 58 82 -
trunk/src/test/java/omq/test/exception/ServerTest.java
r47 r54 28 28 OmqServerImpl server = new OmqServerImpl(); 29 29 30 Broker .initBroker(env);31 Broker.bind("server", server);30 Broker broker = new Broker(env); 31 broker.bind("server", server); 32 32 33 33 Thread.sleep(60 * 60 * 1000); 34 34 } 35 35 } 36 ; -
trunk/src/test/java/omq/test/faultTolerance/FaultToleranceTest.java
r46 r54 3 3 import static org.junit.Assert.assertEquals; 4 4 5 import java.util.Arrays; 6 import java.util.Collection; 5 7 import java.util.Properties; 6 8 … … 9 11 import omq.common.util.Serializer; 10 12 import omq.test.calculator.Calculator; 13 import omq.test.calculator.CalculatorImpl; 11 14 15 import org.junit.After; 12 16 import org.junit.BeforeClass; 13 17 import org.junit.Test; 18 import org.junit.runner.RunWith; 19 import org.junit.runners.Parameterized; 20 import org.junit.runners.Parameterized.Parameters; 14 21 15 16 public class ClientTest { 22 @RunWith(value = Parameterized.class) 23 public class FaultToleranceTest { 24 private static Broker broker; 17 25 private static Calculator remoteCalc; 18 26 19 @BeforeClass 20 public static void startClient() throws Exception { 27 public FaultToleranceTest(String type) throws Exception { 21 28 Properties env = new Properties(); 22 29 env.setProperty(ParameterQueue.USER_NAME, "guest"); … … 27 34 env.setProperty(ParameterQueue.SERVER_PORT, "5672"); 28 35 env.setProperty(ParameterQueue.DURABLE_QUEUES, "false"); 29 env.setProperty(ParameterQueue.SERIALIZER_NAME, Serializer.java);36 env.setProperty(ParameterQueue.SERIALIZER_NAME, type); 30 37 env.setProperty(ParameterQueue.ENABLECOMPRESSION, "false"); 31 38 … … 40 47 env.setProperty(ParameterQueue.RETRY_TIME_CONNECTION, "5000"); 41 48 42 Broker.initBroker(env); 43 remoteCalc = (Calculator) Broker.lookup("calculator1", Calculator.class); 49 broker = new Broker(env); 50 remoteCalc = broker.lookup("calculator1", Calculator.class); 51 } 52 53 @Parameters 54 public static Collection<Object[]> data() { 55 Object[][] data = new Object[][] { { Serializer.java }, { Serializer.gson }, { Serializer.kryo } }; 56 return Arrays.asList(data); 57 } 58 59 @After 60 public void stop() throws Exception { 61 broker.stopBroker(); 62 } 63 64 @BeforeClass 65 public static void serverTest() throws Exception { 66 Properties env = new Properties(); 67 env.setProperty(ParameterQueue.USER_NAME, "guest"); 68 env.setProperty(ParameterQueue.USER_PASS, "guest"); 69 70 // Get host info of rabbimq (where it is) 71 env.setProperty(ParameterQueue.SERVER_HOST, "127.0.0.1"); 72 env.setProperty(ParameterQueue.SERVER_PORT, "5672"); 73 env.setProperty(ParameterQueue.DURABLE_QUEUES, "false"); 74 env.setProperty(ParameterQueue.ENABLECOMPRESSION, "false"); 75 76 // Set info about where the message will be sent 77 env.setProperty(ParameterQueue.RPC_EXCHANGE, "rpc_exchange"); 78 env.setProperty(ParameterQueue.RETRY_TIME_CONNECTION, "2000"); 79 80 CalculatorImpl calc = new CalculatorImpl(); 81 82 broker = new Broker(env); 83 broker.bind("calculator1", calc); 84 85 System.out.println("Server started"); 44 86 } 45 87 -
trunk/src/test/java/omq/test/multiProcess/MultiProcessTest.java
r48 r54 12 12 13 13 import org.junit.After; 14 import org.junit.BeforeClass; 14 15 import org.junit.Test; 15 16 import org.junit.runner.RunWith; … … 18 19 19 20 @RunWith(value = Parameterized.class) 20 public class ClientTest {21 // Execute ServerTest.java 2 times before start this test22 public Number remoteNumber;21 public class MultiProcessTest { 22 public static Broker broker; 23 public static Number remoteNumber; 23 24 24 public ClientTest(String type) throws Exception {25 public MultiProcessTest(String type) throws Exception { 25 26 Properties env = new Properties(); 26 27 env.setProperty(ParameterQueue.USER_NAME, "guest"); … … 42 43 env.setProperty(ParameterQueue.EVENT_REPLY_QUEUE, "event_queue"); 43 44 44 Broker.initBroker(env);45 remoteNumber = Broker.lookup("number", Number.class);45 broker = new Broker(env); 46 remoteNumber = broker.lookup("number", Number.class); 46 47 } 47 48 … … 52 53 } 53 54 55 @BeforeClass 56 public static void serverTest() throws Exception { 57 Properties env = new Properties(); 58 env.setProperty(ParameterQueue.USER_NAME, "guest"); 59 env.setProperty(ParameterQueue.USER_PASS, "guest"); 60 61 // Get host info of rabbimq (where it is) 62 env.setProperty(ParameterQueue.SERVER_HOST, "127.0.0.1"); 63 env.setProperty(ParameterQueue.SERVER_PORT, "5672"); 64 env.setProperty(ParameterQueue.DURABLE_QUEUES, "false"); 65 env.setProperty(ParameterQueue.ENABLECOMPRESSION, "false"); 66 67 // Set info about where the message will be sent 68 env.setProperty(ParameterQueue.RPC_EXCHANGE, "rpc_exchange"); 69 env.setProperty(ParameterQueue.RETRY_TIME_CONNECTION, "2000"); 70 71 Broker broker = new Broker(env); 72 broker.bind("number", new NumberImpl()); 73 74 Broker broker2 = new Broker(env); 75 broker2.bind("number", new NumberImpl()); 76 } 77 54 78 @After 55 79 public void stop() throws Exception { 56 Broker.stopBroker();80 broker.stopBroker(); 57 81 } 58 82 59 83 @Test 60 public void test() {84 public void fifoTest() { 61 85 int x = 10; 62 86 remoteNumber.setNumber(x); … … 68 92 } 69 93 94 @Test 95 public void multiTest() throws Exception { 96 int x = 10; 97 remoteNumber.setMultiNumber(x); 98 Thread.sleep(200); 99 int a = remoteNumber.getNumer(); 100 assertEquals(x, a); 101 remoteNumber.setMultiNumber(0); 102 Thread.sleep(200); 103 } 104 70 105 } -
trunk/src/test/java/omq/test/multiProcess/Number.java
r46 r54 2 2 3 3 import omq.Remote; 4 import omq.client.annotation.AsyncMethod; 5 import omq.client.annotation.MultiMethod; 4 6 import omq.client.annotation.RemoteInterface; 5 7 import omq.client.annotation.SyncMethod; … … 12 14 @SyncMethod(timeout = 1000) 13 15 public int getNumer(); 16 17 @MultiMethod 18 @AsyncMethod 19 public void setMultiNumber(int x); 14 20 } -
trunk/src/test/java/omq/test/multiProcess/NumberImpl.java
r46 r54 1 1 package omq.test.multiProcess; 2 2 3 import omq.client.annotation.AsyncMethod; 4 import omq.client.annotation.MultiMethod; 3 5 import omq.client.annotation.SyncMethod; 4 6 import omq.server.RemoteObject; … … 30 32 } 31 33 34 @Override 35 @MultiMethod 36 @AsyncMethod 37 public void setMultiNumber(int x) { 38 this.x = x; 39 } 40 32 41 } -
trunk/src/test/java/omq/test/stopBroker/BrokerKillerImpl.java
r46 r54 12 12 private static final long serialVersionUID = 1L; 13 13 14 private Broker broker; 15 16 public BrokerKillerImpl(Broker broker) { 17 this.broker = broker; 18 } 19 14 20 @Override 15 21 @AsyncMethod … … 24 30 try { 25 31 Thread.sleep(1000); 26 Broker.stopBroker();32 broker.stopBroker(); 27 33 } catch (Exception e) { 28 34 e.printStackTrace(); -
trunk/src/test/java/omq/test/stopBroker/StopBrokerTest.java
r46 r54 1 1 package omq.test.stopBroker; 2 2 3 import java.util.Arrays; 4 import java.util.Collection; 3 5 import java.util.Properties; 4 6 … … 7 9 import omq.common.util.Serializer; 8 10 9 public class ClientTest { 11 import org.junit.After; 12 import org.junit.BeforeClass; 13 import org.junit.Test; 14 import org.junit.runner.RunWith; 15 import org.junit.runners.Parameterized; 16 import org.junit.runners.Parameterized.Parameters; 10 17 11 /** 12 * @param args 13 * @throws Exception 14 */ 15 public static void main(String[] args) throws Exception { 18 @RunWith(value = Parameterized.class) 19 public class StopBrokerTest { 20 21 private static Broker broker; 22 private static BrokerKiller bk; 23 24 public StopBrokerTest(String type) throws Exception { 16 25 Properties env = new Properties(); 17 26 env.setProperty(ParameterQueue.USER_NAME, "guest"); … … 22 31 env.setProperty(ParameterQueue.SERVER_PORT, "5672"); 23 32 env.setProperty(ParameterQueue.DURABLE_QUEUES, "false"); 24 env.setProperty(ParameterQueue.SERIALIZER_NAME, Serializer.java);33 env.setProperty(ParameterQueue.SERIALIZER_NAME, type); 25 34 env.setProperty(ParameterQueue.ENABLECOMPRESSION, "false"); 26 35 … … 35 44 env.setProperty(ParameterQueue.RETRY_TIME_CONNECTION, "5000"); 36 45 37 Broker.initBroker(env); 38 BrokerKiller bk = (BrokerKiller) Broker.lookup("bk", BrokerKiller.class); 46 broker = new Broker(env); 47 bk = broker.lookup("bk", BrokerKiller.class); 48 } 39 49 50 @Parameters 51 public static Collection<Object[]> data() { 52 Object[][] data = new Object[][] { { Serializer.java }, { Serializer.gson }, { Serializer.kryo } }; 53 return Arrays.asList(data); 54 } 55 56 @BeforeClass 57 public static void server() throws Exception { 58 Properties env = new Properties(); 59 env.setProperty(ParameterQueue.USER_NAME, "guest"); 60 env.setProperty(ParameterQueue.USER_PASS, "guest"); 61 62 // Get host info of rabbimq (where it is) 63 env.setProperty(ParameterQueue.SERVER_HOST, "127.0.0.1"); 64 env.setProperty(ParameterQueue.SERVER_PORT, "5672"); 65 env.setProperty(ParameterQueue.DURABLE_QUEUES, "false"); 66 env.setProperty(ParameterQueue.ENABLECOMPRESSION, "false"); 67 68 // Set info about where the message will be sent 69 env.setProperty(ParameterQueue.RPC_EXCHANGE, "rpc_exchange"); 70 env.setProperty(ParameterQueue.RETRY_TIME_CONNECTION, "2000"); 71 72 Broker broker = new Broker(env); 73 BrokerKillerImpl bki = new BrokerKillerImpl(broker); 74 broker.bind("bk", bki); 75 } 76 77 @After 78 public void stop() throws Exception { 79 broker.stopBroker(); 80 } 81 82 @Test 83 public void stopBroker() throws Exception { 40 84 bk.killServerBroker(); 41 Broker.stopBroker();42 85 } 43 86 -
trunk/src/test/java/omq/test/stopBroker/UnbindTest.java
r46 r54 5 5 import omq.common.broker.Broker; 6 6 import omq.common.util.ParameterQueue; 7 import omq.common.util.Serializer;8 7 import omq.test.calculator.CalculatorImpl; 9 8 9 import org.junit.Test; 10 10 11 public class UnbindTest { 11 private static CalculatorImpl calc;12 12 13 /** 14 * @param args 15 */ 16 public static void main(String[] args) throws Exception { 13 @Test 14 public void serverTest() throws Exception { 17 15 Properties env = new Properties(); 18 16 env.setProperty(ParameterQueue.USER_NAME, "guest"); … … 23 21 env.setProperty(ParameterQueue.SERVER_PORT, "5672"); 24 22 env.setProperty(ParameterQueue.DURABLE_QUEUES, "false"); 25 env.setProperty(ParameterQueue.SERIALIZER_NAME, Serializer.java);26 23 env.setProperty(ParameterQueue.ENABLECOMPRESSION, "false"); 27 24 … … 31 28 32 29 String reference = "calculator1"; 33 calc = new CalculatorImpl();30 CalculatorImpl calc = new CalculatorImpl(); 34 31 35 Broker .initBroker(env);36 Broker.bind(reference, calc);32 Broker broker = new Broker(env); 33 broker.bind(reference, calc); 37 34 38 Broker.unbind(reference);35 broker.unbind(reference); 39 36 40 Broker.closeConnection();37 broker.closeConnection(); 41 38 } 42 39
Note: See TracChangeset
for help on using the changeset viewer.