Mercurial > hg > blitz_condensed
comparison src/org/dancres/blitz/remote/transport/TestClient.java @ 0:3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
author | Dan Creswell <dan.creswell@gmail.com> |
---|---|
date | Sat, 21 Mar 2009 11:00:06 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3dc0c5604566 |
---|---|
1 package org.dancres.blitz.remote.transport; | |
2 | |
3 import java.io.Serializable; | |
4 | |
5 import net.jini.space.JavaSpace; | |
6 import net.jini.core.entry.Entry; | |
7 | |
8 import org.dancres.blitz.remote.LocalSpace; | |
9 import org.dancres.blitz.remote.ProxyFactory; | |
10 import org.dancres.blitz.test.TxnGatewayImpl; | |
11 | |
12 /** | |
13 */ | |
14 public class TestClient { | |
15 public static void main(String args[]) throws Exception { | |
16 new TestClient().test(); | |
17 } | |
18 | |
19 private JavaSpace space; | |
20 | |
21 private void test() throws Exception { | |
22 StubImpl myStub = new StubImpl(); | |
23 | |
24 space = ProxyFactory.newBlitzProxy(myStub, null); | |
25 | |
26 for (int j = 0; j < 10; j++) { | |
27 long myStart = System.currentTimeMillis(); | |
28 | |
29 for (int i = 0; i < 1000; i++) { | |
30 myStub.ping(); | |
31 | |
32 // myHandler.waitForResponse(); | |
33 } | |
34 | |
35 long myTotal = System.currentTimeMillis() - myStart; | |
36 System.out.println("1000 iterations in: " + myTotal); | |
37 | |
38 double myTimePerIter = ((double) myTotal) / (double) 1000; | |
39 System.out.println("Time per roundtrip: " + myTimePerIter); | |
40 } | |
41 | |
42 testWriteTake(); | |
43 testWriteRead(); | |
44 testMatch(); | |
45 } | |
46 | |
47 public static class TestEntry implements Entry { | |
48 public Integer reference; | |
49 public String name; | |
50 public Serializable box; | |
51 } | |
52 | |
53 | |
54 public void testWriteTake() { | |
55 TestEntry entry = new TestEntry(); | |
56 | |
57 entry.reference = new Integer(23); | |
58 entry.name = | |
59 "A longer string that represent a cached http address for example - 1234567890"; | |
60 entry.box = null; | |
61 | |
62 long soak = 100001; | |
63 | |
64 long start = System.currentTimeMillis(); | |
65 | |
66 for (long i = 0; i < soak; i++) { | |
67 try { | |
68 space.write(entry, null, 10 * 1000); | |
69 space.take(entry, null, 0); | |
70 } | |
71 catch (Exception e) { | |
72 e.printStackTrace(); | |
73 } | |
74 | |
75 if (i % 10000 == 0) { | |
76 long elapsed = System.currentTimeMillis() - start; | |
77 System.out.println(i + "Write/Take :" + elapsed); | |
78 } | |
79 } | |
80 } | |
81 | |
82 public void testWriteRead() { | |
83 TestEntry entry = new TestEntry(); | |
84 | |
85 entry.reference = new Integer(23); | |
86 entry.name = "Steam"; | |
87 entry.box = null; | |
88 | |
89 long soak = 100001; | |
90 long start = System.currentTimeMillis(); | |
91 | |
92 for (long i = 0; i < soak; i++) { | |
93 try { | |
94 space.write(entry, null, 10 * 1000); | |
95 space.read(entry, null, 0); | |
96 } | |
97 catch (Exception e) { | |
98 e.printStackTrace(); | |
99 } | |
100 | |
101 if (i % 10000 == 0) { | |
102 long elapsed = System.currentTimeMillis() - start; | |
103 System.out.println(i + "Write/Read :" + elapsed); | |
104 } | |
105 } | |
106 } | |
107 | |
108 public void testMatch() { | |
109 // write 1000 entries into the space and match randomly | |
110 TestEntry entry = new TestEntry(); | |
111 | |
112 entry.reference = new Integer(0); | |
113 entry.name = "Steam"; | |
114 entry.box = null; | |
115 | |
116 long soak = 100001; | |
117 long start = System.currentTimeMillis(); | |
118 | |
119 // write the objects in | |
120 long matchables = 100; | |
121 for (long i = 0; i < matchables; i++) { | |
122 entry.reference = new Integer((int) matchables); | |
123 try { | |
124 space.write(entry, null, | |
125 60 * 60 * 1000); // make a decent length lease | |
126 } | |
127 catch (Exception e) { | |
128 e.printStackTrace(); | |
129 } | |
130 } | |
131 | |
132 | |
133 for (long i = 0; i < soak; i++) { | |
134 entry.reference = new Integer((int) (Math.random() * matchables)); | |
135 try { | |
136 space.read(entry, null, 0); | |
137 } | |
138 catch (Exception e) { | |
139 e.printStackTrace(); | |
140 } | |
141 | |
142 if (i % 10000 == 0) { | |
143 long elapsed = System.currentTimeMillis() - start; | |
144 System.out.println(i + "Matching :" + elapsed); | |
145 } | |
146 } | |
147 } | |
148 } |