Project

General

Profile

« Previous | Next » 

Revision 7841

add MapStore/Loader test for the IndexEvents -- adding and removing events in the DB table through hazelcast. https://projects.ecoinformatics.org/ecoinfo/issues/5944

View differences:

metacat-index/src/test/java/edu/ucsb/nceas/metacat/index/event/IndexEventEntryListenerIT.java
1
package edu.ucsb.nceas.metacat.index.event;
2

  
3
import static org.junit.Assert.*;
4

  
5
import java.util.Calendar;
6

  
7
import org.dataone.service.types.v1.Event;
8
import org.dataone.service.types.v1.Identifier;
9
import org.junit.Before;
10
import org.junit.Test;
11

  
12
import edu.ucsb.nceas.metacat.common.index.event.IndexEvent;
13
import edu.ucsb.nceas.metacat.index.ApplicationController;
14
import edu.ucsb.nceas.metacat.index.DistributedMapsFactory;
15

  
16
public class IndexEventEntryListenerIT {
17
	
18
	
19
	@Test
20
	public void testRoundtrip() {
21
		
22
		try {
23
			Identifier identifier = new Identifier();
24
			identifier.setValue("IndexEventEntryListenerIT" + System.currentTimeMillis());
25
			IndexEvent event = new IndexEvent();
26
			event.setAction(Event.CREATE);
27
			event.setDate(Calendar.getInstance().getTime());
28
			event.setDescription("Testing DAO");
29
			event.setIdentifier(identifier);
30
			DistributedMapsFactory.getIndexEventMap().put(identifier, event);
31
			
32
			// check
33
			IndexEvent savedEvent = DistributedMapsFactory.getIndexEventMap().get(identifier);
34
			assertNotNull(savedEvent);
35
			assertEquals(event.getIdentifier(), savedEvent.getIdentifier());
36
			assertEquals(event.getAction(), savedEvent.getAction());
37
			assertEquals(event.getDate(), savedEvent.getDate());
38
			assertEquals(event.getDescription(), savedEvent.getDescription());
39
			
40
			// remove
41
			DistributedMapsFactory.getIndexEventMap().remove(identifier);
42

  
43
			// check
44
			savedEvent = DistributedMapsFactory.getIndexEventMap().get(identifier);
45
			assertNull(savedEvent);
46
			
47
		} catch (Exception e) {
48
			e.printStackTrace();
49
			fail(e.getMessage());
50
		}
51
		
52
	}
53

  
54
}
0 55

  
metacat-index/src/test/resources/org/dataone/configuration/test.properties
2 2
dataone.hazelcast.storageCluster.systemMetadataMap=hzSystemMetadata
3 3
dataone.hazelcast.storageCluster.objectPathMap=hzObjectPath
4 4
dataone.hazelcast.storageCluster.identifiersSet=hzIdentifiers
5
index.hazelcast.indexqueue=hzIndexQueue
6
index.hazelcast.indexeventmap=hzIndexEventMap
7

  
5 8
#Embedded (default):
6
 solr.server.classname=org.apache.solr.client.solrj.embedded.EmbeddedSolrServer
7
 solr.homeDir=target/classes/solr-home
8
 solr.configFileName=solr.xml
9
 solr.collectionName=collection1
9
solr.server.classname=org.apache.solr.client.solrj.embedded.EmbeddedSolrServer
10
solr.homeDir=target/classes/solr-home
11
solr.configFileName=solr.xml
12
solr.collectionName=collection1
10 13
  
11 14
#HTTP:
12 15
#solr.server.classname=org.apache.solr.client.solrj.impl.CommonsHttpSolrServer
metacat-common/src/main/java/edu/ucsb/nceas/metacat/common/index/event/IndexEvent.java
21 21
 */
22 22
package edu.ucsb.nceas.metacat.common.index.event;
23 23

  
24
import java.io.Serializable;
24 25
import java.util.Date;
25 26

  
26 27
import org.dataone.service.types.v1.Event;
......
32 33
 * @author tao
33 34
 *
34 35
 */
35
public class IndexEvent {
36
public class IndexEvent implements Serializable {
36 37
    
37
    private Event action = null;
38

  
39
	private static final long serialVersionUID = 1L;
40
	
41
	private Event action = null;
38 42
    private Date date = null;
39 43
    private Identifier identifier = null;
40 44
    private String description = null;
src/edu/ucsb/nceas/metacat/dataone/hazelcast/HazelcastService.java
208 208
      // for index events (failures)
209 209
      hzIndexEventMap = PropertyService.getProperty("index.hazelcast.indexeventmap");
210 210
      indexEventMap = this.hzInstance.getMap(hzIndexEventMap);
211
      // TODO: move this where it can be switched off
212
      indexEventMap.addEntryListener(new IndexEventEntryListener(), true);
213 211
      
214 212
      // Listen for changes to the system metadata map
215 213
      systemMetadata.addEntryListener(this, true);

Also available in: Unified diff