01: package distributedcache;
02:
03: import java.net.InetAddress;
04: import java.util.logging.Level;
05:
06: import net.sf.ehcache.Element;
07:
08: import org.junit.Assert;
09: import org.junit.Test;
10: import org.xsocket.stream.IServer;
11: import org.xsocket.stream.Server;
12:
13: import distributedcache.management.MonitoredStoreService;
14:
15: /**
16: *
17: * @author grro@xsocket.org
18: */
19: public final class SimpleTest {
20:
21: @Test
22: public void testSimple() throws Exception {
23: // QAUtil.setLogLevel("org.xsocket.stream.IoSocketHandler", Level.FINE);
24: /*
25: JmxServer server = new JmxServer();
26: server.start("test");
27:
28: InetAddress bAddress = InetAddress.getByName("224.0.0.1");
29: int bPort = 8866;
30:
31:
32: IServer server1 = new Server(new MonitoredStoreService(new StoreService(bAddress, bPort)));
33: Thread t1 = new Thread(server1);
34: t1.setDaemon(true);
35: t1.start();
36:
37: IServer server2 = new Server(new MonitoredStoreService(new StoreService(bAddress, bPort)));
38: Thread t2 = new Thread(server2);
39: t2.setDaemon(true);
40: t2.start();
41:
42: IServer server3 = new Server(new MonitoredStoreService(new StoreService(bAddress, bPort)));
43: Thread t3 = new Thread(server3);
44: t3.setDaemon(true);
45: t3.start();
46:
47: try {
48: Thread.sleep(200);
49: } catch (InterruptedException ignore) { }
50:
51: PartitionedStore store1 = new PartitionedStore(bAddress, bPort);
52:
53: try {
54: Thread.sleep(200);
55: } catch (InterruptedException ignore) { }
56:
57:
58: store1.put(new Element("key" + 0, "A long long long long ling lang lung long long long long long Value" + 0));
59: for (int i = 0; i < 100; i++) {
60: store1.put(new Element("key" + i, "Value"+ i));
61: try {
62: Thread.sleep(20);
63: } catch (InterruptedException ignore) { }
64: }
65:
66: Assert.assertTrue(store1.get("key1").getObjectValue().equals("Value1"));
67: Assert.assertTrue(store1.get("key2").getObjectValue().equals("Value2"));
68:
69:
70: PartitionedStore store2 = new PartitionedStore(bAddress, bPort);
71: Assert.assertTrue(store2.get("key1").getObjectValue().equals("Value1"));
72: Assert.assertTrue(store2.get("key2").getObjectValue().equals("Value2"));
73:
74:
75: Assert.assertTrue(store1.remove("key1") != null);
76: Assert.assertTrue(store1.get("key1") == null);
77: Assert.assertTrue(store2.get("key1") == null);
78: Assert.assertTrue(store2.get("key2") != null);
79:
80:
81: PartitionedStore store3 = new PartitionedStore(bAddress, bPort);
82: Assert.assertTrue(store3.remove("key2") != null);
83: Assert.assertTrue(store1.get("key2") == null);
84: Assert.assertTrue(store2.get("key2") == null);
85: Assert.assertTrue(store3.get("key2") == null);
86:
87:
88: Assert.assertTrue(store3.remove("key2") == null);
89:
90: server1.close();
91: server2.close();
92: server3.close();
93:
94: server.stop();*/
95: }
96: }
|