Revision 6431
Added by ben leinfelder over 12 years ago
HazelcastServiceTest.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
package edu.ucsb.nceas.metacat.dataone.hazelcast; |
27 | 27 |
|
28 |
import java.io.ByteArrayInputStream; |
|
28 | 29 |
import java.io.FileNotFoundException; |
30 |
import java.io.InputStream; |
|
29 | 31 |
|
30 | 32 |
import org.dataone.configuration.Settings; |
31 | 33 |
import org.dataone.service.types.v1.Identifier; |
34 |
import org.dataone.service.types.v1.Session; |
|
32 | 35 |
import org.dataone.service.types.v1.SystemMetadata; |
33 | 36 |
|
34 | 37 |
import com.hazelcast.config.Config; |
... | ... | |
39 | 42 |
import junit.framework.Test; |
40 | 43 |
import junit.framework.TestSuite; |
41 | 44 |
import edu.ucsb.nceas.MCTestCase; |
45 |
import edu.ucsb.nceas.metacat.dataone.CNodeService; |
|
42 | 46 |
import edu.ucsb.nceas.metacat.dataone.CNodeServiceTest; |
43 | 47 |
import edu.ucsb.nceas.metacat.properties.PropertyService; |
44 | 48 |
|
... | ... | |
56 | 60 |
configFileName = Settings.getConfiguration().getString("hazelcast.config"); |
57 | 61 |
Config config = new FileSystemXmlConfig(configFileName); |
58 | 62 |
Hazelcast.init(config); |
63 |
|
|
64 |
// initialize the entry listeners |
|
65 |
CNodeService.getInstance(); |
|
66 |
|
|
59 | 67 |
} catch (FileNotFoundException e) { |
60 | 68 |
e.printStackTrace(); |
61 | 69 |
fail(); |
62 | 70 |
} |
63 | 71 |
} |
64 |
|
|
65 |
private static Identifier pid = null; |
|
66 |
|
|
72 |
|
|
67 | 73 |
/** |
68 | 74 |
* constructor for the test |
69 | 75 |
*/ |
... | ... | |
80 | 86 |
{ |
81 | 87 |
TestSuite suite = new TestSuite(); |
82 | 88 |
suite.addTest(new HazelcastServiceTest("initialize")); |
83 |
suite.addTest(new HazelcastServiceTest("createSystemMetadata")); |
|
84 |
suite.addTest(new HazelcastServiceTest("retrieveSystemMetadata")); |
|
89 |
suite.addTest(new HazelcastServiceTest("retrieveSystemMetadataFromMap")); |
|
90 |
suite.addTest(new HazelcastServiceTest("storeSystemMetadataToMap")); |
|
91 |
|
|
85 | 92 |
return suite; |
86 | 93 |
} |
87 | 94 |
|
88 | 95 |
|
89 |
public void createSystemMetadata() { |
|
90 |
CNodeServiceTest cnst = new CNodeServiceTest("testRegisterSystemMetadata"); |
|
91 |
pid = cnst.testRegisterSystemMetadata(); |
|
92 |
assertNotNull(pid); |
|
93 |
} |
|
94 |
|
|
95 |
public void retrieveSystemMetadata() { |
|
96 |
public void retrieveSystemMetadataFromMap() { |
|
96 | 97 |
try { |
98 |
Identifier pid = null; |
|
99 |
// create the systemMetadata the normal way |
|
100 |
CNodeServiceTest cnst = new CNodeServiceTest("testRegisterSystemMetadata"); |
|
101 |
pid = cnst.testRegisterSystemMetadata(); |
|
102 |
assertNotNull(pid); |
|
103 |
// look it up from the "shared" map |
|
97 | 104 |
HazelcastService.getInstance(); |
98 | 105 |
IMap<Object, Object> systemMetadataMap = Hazelcast.getMap(PropertyService.getProperty("dataone.hazelcast.storageCluster.systemMetadataMap")); |
99 | 106 |
SystemMetadata sm = (SystemMetadata) systemMetadataMap.get(pid); |
... | ... | |
104 | 111 |
} |
105 | 112 |
} |
106 | 113 |
|
114 |
public void storeSystemMetadataToMap() { |
|
115 |
try { |
|
116 |
// create the systemMetadata and save to map |
|
117 |
CNodeServiceTest cnst = new CNodeServiceTest("testGetSystemMetadata"); |
|
118 |
Session session = cnst.getTestSession(); |
|
119 |
Identifier guid = new Identifier(); |
|
120 |
guid.setValue("testCreate." + System.currentTimeMillis()); |
|
121 |
InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8")); |
|
122 |
SystemMetadata sysmeta = cnst.createSystemMetadata(guid, session.getSubject(), object); |
|
123 |
assertNotNull(sysmeta); |
|
124 |
// put it in the "shared" map |
|
125 |
System.out.println("Saving System Metadata to in-memory shared map: " + guid.getValue()); |
|
126 |
IMap<Identifier, SystemMetadata> systemMetadataMap = Hazelcast.getMap(PropertyService.getProperty("dataone.hazelcast.storageCluster.systemMetadataMap")); |
|
127 |
systemMetadataMap.put(guid, sysmeta); |
|
128 |
|
|
129 |
// get it from the store |
|
130 |
SystemMetadata sysmetaFromStore = CNodeService.getInstance().getSystemMetadata(session, guid); |
|
131 |
assertNotNull(sysmetaFromStore); |
|
132 |
|
|
133 |
} catch (Exception e) { |
|
134 |
e.printStackTrace(); |
|
135 |
fail(); |
|
136 |
} |
|
137 |
} |
|
138 |
|
|
107 | 139 |
/** |
108 | 140 |
* Establish a testing framework by initializing appropriate objects |
109 | 141 |
*/ |
Also available in: Unified diff
exercise the shared hazelecast system metadata map and custom loader/store by inserting normally and also directly into the map. both mechanisms allow up to read the same system metadata (only tested on single local instance)