1 17 package org.alfresco.repo.node.index; 18 19 import java.util.ArrayList ; 20 import java.util.List ; 21 22 import junit.framework.TestCase; 23 24 import org.alfresco.model.ContentModel; 25 import org.alfresco.repo.search.Indexer; 26 import org.alfresco.repo.transaction.AlfrescoTransactionSupport; 27 import org.alfresco.repo.transaction.TransactionUtil; 28 import org.alfresco.repo.transaction.TransactionUtil.TransactionWork; 29 import org.alfresco.service.cmr.repository.ChildAssociationRef; 30 import org.alfresco.service.cmr.repository.InvalidStoreRefException; 31 import org.alfresco.service.cmr.repository.NodeRef; 32 import org.alfresco.service.cmr.repository.NodeService; 33 import org.alfresco.service.cmr.repository.StoreRef; 34 import org.alfresco.service.namespace.NamespaceService; 35 import org.alfresco.service.namespace.QName; 36 import org.alfresco.service.transaction.TransactionService; 37 import org.alfresco.util.ApplicationContextHelper; 38 import org.springframework.context.ApplicationContext; 39 40 45 public class FullIndexRecoveryComponentTest extends TestCase 46 { 47 private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext(); 48 49 private TransactionService transactionService; 50 private FullIndexRecoveryComponent indexRecoverer; 51 private NodeService nodeService; 52 private TransactionService txnService; 53 private Indexer indexer; 54 55 private List <StoreRef> storeRefs; 56 57 public void setUp() throws Exception 58 { 59 transactionService = (TransactionService) ctx.getBean("transactionComponent"); 60 indexRecoverer = (FullIndexRecoveryComponent) ctx.getBean("indexRecoveryComponent"); 61 txnService = (TransactionService) ctx.getBean("transactionComponent"); 62 nodeService = (NodeService) ctx.getBean("nodeService"); 63 indexer = (Indexer) ctx.getBean("indexerComponent"); 64 65 TransactionWork<List <StoreRef>> createStoresWork = new TransactionWork<List <StoreRef>>() 67 { 68 public List <StoreRef> doWork() throws Exception 69 { 70 List <StoreRef> storeRefs = new ArrayList <StoreRef>(2); 71 storeRefs.add(nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, getName() + System.nanoTime())); 72 storeRefs.add(nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, getName() + System.nanoTime())); 73 return storeRefs; 74 } 75 }; 76 storeRefs = TransactionUtil.executeInUserTransaction(transactionService, createStoresWork); 77 } 78 79 public void testNothing() throws Exception 80 { 81 82 } 83 84 public void xtestReindexing() throws Exception 85 { 86 if (FullIndexRecoveryComponent.isStarted()) 88 { 89 return; 90 } 91 final List <String > storeRefStrings = new ArrayList <String >(2); 93 TransactionWork<String > dropNodeIndexWork = new TransactionWork<String >() 94 { 95 public String doWork() 96 { 97 for (StoreRef storeRef : storeRefs) 99 { 100 try 101 { 102 NodeRef rootNodeRef = nodeService.getRootNode(storeRef); 103 ChildAssociationRef assocRef = nodeService.createNode( 104 rootNodeRef, 105 ContentModel.ASSOC_CONTAINS, 106 QName.createQName(NamespaceService.ALFRESCO_URI, "unindexedChild" + System.currentTimeMillis()), 107 ContentModel.TYPE_BASE); 108 indexer.deleteNode(assocRef); 110 storeRefStrings.add(storeRef.toString()); 112 } 113 catch (InvalidStoreRefException e) 114 { 115 } 117 } 118 return AlfrescoTransactionSupport.getTransactionId(); 119 } 120 }; 121 122 String txnId = TransactionUtil.executeInNonPropagatingUserTransaction(txnService, dropNodeIndexWork); 124 125 indexRecoverer.setExecuteFullRecovery(true); 126 indexRecoverer.setStores(storeRefStrings); 127 indexRecoverer.reindex(); 129 130 try 132 { 133 indexRecoverer.reindex(); 134 fail("Reindexer failed to prevent reindex from being called twice"); 135 } 136 catch (RuntimeException e) 137 { 138 } 140 141 String lastProcessedTxnId = null; 143 for (int i = 0; i < 60; i++) 144 { 145 lastProcessedTxnId = FullIndexRecoveryComponent.getCurrentTransactionId(); 146 if (lastProcessedTxnId.equals(txnId)) 147 { 148 break; 149 } 150 synchronized(this) 152 { 153 this.wait(1000L); 154 } 155 } 156 assertEquals("Index transaction not up to date", txnId, lastProcessedTxnId); 158 } 159 } 160 | Popular Tags |