Revision 6424
Added by rnahf over 12 years ago
HzObjectPathMapTest.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.util.Map; |
4 | 4 |
|
5 |
import org.dataone.service.types.v1.Identifier; |
|
6 |
import org.junit.Before; |
|
5 | 7 |
import org.junit.Test; |
6 | 8 |
|
7 | 9 |
import com.hazelcast.core.Hazelcast; |
... | ... | |
13 | 15 |
public class HzObjectPathMapTest extends MCTestCase { |
14 | 16 |
|
15 | 17 |
|
18 |
@Before |
|
19 |
public void setUp() { |
|
20 |
|
|
21 |
} |
|
22 |
|
|
16 | 23 |
@Test |
17 |
public void testTwoMemberMapSizes() { |
|
24 |
public void testInstantiation() { |
|
25 |
// start a member |
|
26 |
HazelcastInstance h1 = Hazelcast.newHazelcastInstance(null); |
|
27 |
Map map1 = h1.getMap("hzObjectPath"); |
|
28 |
assertEquals(99, map1.size()); |
|
29 |
} |
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
@Test public void testProducerConsumer() { |
|
35 |
// start a member |
|
18 | 36 |
|
19 | 37 |
System.getProperties().setProperty("hazelcast.config", |
20 |
"/Users/rnahf/projects/nceas/metacat/" +
|
|
38 |
"/Users/rnahf/software/workspace/nceas/metacat/" +
|
|
21 | 39 |
"test/edu/ucsb/nceas/metacat/dataone/hazelcast.test.properties.xml"); |
22 |
// start the first member |
|
23 |
HazelcastInstance h1 = Hazelcast.newHazelcastInstance(null); |
|
24 |
// get the map and put 1000 entries |
|
25 |
Map map1 = h1.getMap("hzObjectPath"); |
|
26 |
|
|
27 |
for (int i = 0; i < 1000; i++) { |
|
28 |
map1.put(i, "value" + i); |
|
29 |
} |
|
30 |
// check the map size |
|
31 |
assertEquals(1000, map1.size()); |
|
32 |
// start the second member |
|
33 |
HazelcastInstance h2 = Hazelcast.newHazelcastInstance(null); |
|
34 |
// get the same map from the second member |
|
35 |
Map map2 = h2.getMap("hzObjectPath"); |
|
36 |
// check the size of map2 |
|
37 |
assertEquals(1000, map2.size()); |
|
38 |
// check the size of map1 again |
|
39 |
assertEquals(1000, map1.size()); |
|
40 |
} |
|
40 |
HazelcastInstance h1 = Hazelcast.newHazelcastInstance(null); |
|
41 |
Map serverMap = h1.getMap("hzObjectPath"); |
|
42 |
|
|
43 |
|
|
44 |
System.getProperties().setProperty("hazelcast.hzObjectPathRole","consumer"); |
|
45 |
|
|
46 |
HazelcastInstance h2 = Hazelcast.newHazelcastInstance(null); |
|
47 |
Map clientMap = h2.getMap("hzObjectPath"); |
|
48 |
|
|
49 |
|
|
50 |
System.out.println(serverMap.get(createIdentifier("testID.35"))); |
|
51 |
System.out.println(serverMap.get(createIdentifier("testID.23434"))); |
|
52 |
|
|
53 |
String pathValue = (String) clientMap.get(createIdentifier("testID.35")); |
|
54 |
|
|
55 |
System.out.println("pathValue: " + pathValue); |
|
56 |
assertEquals("/path/testID.35", pathValue); |
|
57 |
} |
|
41 | 58 |
|
42 | 59 |
|
60 |
|
|
61 |
private Identifier createIdentifier(String idValue) { |
|
62 |
Identifier id = new Identifier(); |
|
63 |
id.setValue(idValue); |
|
64 |
return id; |
|
65 |
} |
|
66 |
|
|
43 | 67 |
} |
Also available in: Unified diff
configuring hazelcast tests