1 17 package org.alfresco.repo.content.replication; 18 19 import java.io.File ; 20 import java.util.Set ; 21 22 import junit.framework.TestCase; 23 24 import org.alfresco.repo.content.AbstractContentStore; 25 import org.alfresco.repo.content.ContentStore; 26 import org.alfresco.repo.content.filestore.FileContentStore; 27 import org.alfresco.service.cmr.repository.ContentWriter; 28 import org.alfresco.util.GUID; 29 import org.alfresco.util.TempFileProvider; 30 31 38 public class ContentStoreReplicatorTest extends TestCase 39 { 40 private static final String SOME_CONTENT = "The No. 1 Ladies' Detective Agency"; 41 42 private ContentStoreReplicator replicator; 43 private ContentStore sourceStore; 44 private ContentStore targetStore; 45 46 @Override 47 public void setUp() throws Exception 48 { 49 super.setUp(); 50 51 File tempDir = TempFileProvider.getTempDir(); 52 String storeDir = tempDir.getAbsolutePath() + File.separatorChar + getName() + File.separatorChar + GUID.generate(); 54 sourceStore = new FileContentStore(storeDir); 55 storeDir = tempDir.getAbsolutePath() + File.separatorChar + getName() + File.separatorChar + GUID.generate(); 57 targetStore = new FileContentStore(storeDir); 58 59 replicator = new ContentStoreReplicator(); 61 replicator.setSourceStore(sourceStore); 62 replicator.setTargetStore(targetStore); 63 replicator.setRunContinuously(false); replicator.setWaitTime(0); 65 } 66 67 70 public void testSinglePassReplication() throws Exception 71 { 72 ContentWriter writer = sourceStore.getWriter(null, null); 73 writer.putContent("123"); 74 75 replicator.start(); 77 78 synchronized(this) 80 { 81 this.wait(1000L); 82 } 83 84 assertTrue("Target store doesn't have content added to source", 85 targetStore.exists(writer.getContentUrl())); 86 87 writer = sourceStore.getWriter(null, null); 89 writer.putContent("456"); 90 91 synchronized(this) 93 { 94 this.wait(1000L); 95 } 96 97 assertFalse("Replication should have been single-pass", 98 targetStore.exists(writer.getContentUrl())); 99 } 100 101 111 public void testContinuousReplication() throws Exception 112 { 113 replicator.setRunContinuously(true); 114 replicator.setWaitTime(0L); 115 replicator.start(); 116 117 String duplicateUrl = AbstractContentStore.createNewUrl(); 118 for (int i = 0; i < 10; i++) 120 { 121 duplicateUrl = AbstractContentStore.createNewUrl(); 123 ContentWriter duplicateTargetWriter = targetStore.getWriter(null, duplicateUrl); 124 ContentWriter duplicateSourceWriter = sourceStore.getWriter(null, duplicateUrl); 125 duplicateTargetWriter.putContent("Duplicate Target Content: " + i); 126 duplicateSourceWriter.putContent(duplicateTargetWriter.getReader()); 127 128 for (int j = 0; j < 100; j++) 129 { 130 ContentWriter writer = sourceStore.getWriter(null, null); 132 writer.putContent("Repeated put: " + j); 133 } 134 } 135 136 targetStore.delete(duplicateUrl); 138 139 synchronized(this) 141 { 142 this.wait(1000L); 143 } 144 145 Set <String > sourceUrls = sourceStore.getUrls(); 147 Set <String > targetUrls = targetStore.getUrls(); 148 149 sourceUrls.containsAll(targetUrls); 150 targetUrls.contains(sourceUrls); 151 } 152 } 153 | Popular Tags |