public void Should_be_only_work_with_greater_etag_in_pending_queue() { using (var sigGenerator = new SigGenerator()) { transactionalStorage.Batch(accessor => accessor.PutFile(FileName, 0, EmptyETagMetadata)); queue.EnqueueSynchronization(Destination, new ContentUpdateWorkItem(FileName, "http://localhost:12345", transactionalStorage, sigGenerator)); Assert.Equal(1, queue.Pending.Count()); var greaterGuid = Guid.NewGuid(); transactionalStorage.Batch(accessor => accessor.UpdateFileMetadata(FileName, new RavenJObject().WithETag(greaterGuid))); queue.EnqueueSynchronization(Destination, new ContentUpdateWorkItem(FileName, "http://localhost:12345", transactionalStorage, new SigGenerator())); Assert.Equal(1, queue.Pending.Count()); Assert.Equal(greaterGuid, queue.Pending.ToArray()[0].FileETag); } }
public void Should_be_only_work_with_greater_etag_in_pending_queue() { using (var sigGenerator = new SigGenerator()) { transactionalStorage.Batch(accessor => accessor.PutFile(FileName, 0, new RavenJObject())); queue.EnqueueSynchronization(Destination, new ContentUpdateWorkItem(FileName, "http://localhost:12345", transactionalStorage, sigGenerator, configuration)); Assert.Equal(1, queue.Pending.Count()); Etag newerEtag = null; transactionalStorage.Batch(accessor => newerEtag = accessor.UpdateFileMetadata(FileName, new RavenJObject(), null).Etag); queue.EnqueueSynchronization(Destination, new ContentUpdateWorkItem(FileName, "http://localhost:12345", transactionalStorage, new SigGenerator(), configuration)); Assert.Equal(1, queue.Pending.Count()); Assert.True(newerEtag.CompareTo(queue.Pending.ToArray()[0].FileETag) == 0); } }
public void Synchronize_file_with_different_beginning() { const int size = 5000; var differenceChunk = new MemoryStream(); var sw = new StreamWriter(differenceChunk); sw.Write("Coconut is Stupid"); sw.Flush(); var sourceContent = PrepareSourceStream(size); sourceContent.Position = 0; var seedContent = new CombinedStream(differenceChunk, sourceContent); using (var sourceSignatureRepository = CreateSignatureRepositoryFor("test2")) using (var seedSignatureRepository = CreateSignatureRepositoryFor("test1")) { IList <SignatureInfo> seedSignatureInfos; using (var generator = new SigGenerator()) { seedContent.Seek(0, SeekOrigin.Begin); seedSignatureInfos = generator.GenerateSignatures(seedContent, "test1", seedSignatureRepository); } IList <SignatureInfo> sourceSignatureInfos; using (var generator = new SigGenerator()) { sourceContent.Seek(0, SeekOrigin.Begin); sourceSignatureInfos = generator.GenerateSignatures(sourceContent, "test2", sourceSignatureRepository); } var sourceSize = sourceContent.Length; using (var tested = new NeedListGenerator(seedSignatureRepository, sourceSignatureRepository)) { var result = tested.CreateNeedsList(seedSignatureInfos.Last(), sourceSignatureInfos.Last()); Assert.NotNull(result); Assert.Equal(2, result.Count); Assert.Equal(0, sourceSize - result.Sum(x => Convert.ToInt32(x.BlockLength))); } } }
public void Synchronize_file_with_different_sizes_and_completely_different_content() { var seedBuffer = new byte[1024 * 1024 * 2]; // 2 MB new Random().NextBytes(seedBuffer); var seedContent = new MemoryStream(seedBuffer); var smallerBuffer = new byte[1024 * 1024]; new Random().NextBytes(smallerBuffer); var changedContent = new MemoryStream(smallerBuffer); using (var seedSignatureRepository = CreateSignatureRepositoryFor("seed")) using (var sourceSignatureRepository = CreateSignatureRepositoryFor("source")) { IList <SignatureInfo> seedSignatureInfos; using (var generator = new SigGenerator()) { seedContent.Seek(0, SeekOrigin.Begin); seedSignatureInfos = generator.GenerateSignatures(seedContent, "seed", seedSignatureRepository); } IList <SignatureInfo> sourceSignatureInfos; using (var generator = new SigGenerator()) { changedContent.Seek(0, SeekOrigin.Begin); sourceSignatureInfos = generator.GenerateSignatures(changedContent, "source", sourceSignatureRepository); } var sourceSize = changedContent.Length; using (var tested = new NeedListGenerator(seedSignatureRepository, sourceSignatureRepository)) { var result = tested.CreateNeedsList(seedSignatureInfos.Last(), sourceSignatureInfos.Last()); Assert.NotNull(result); Assert.Equal(0, sourceSize - result.Sum(x => Convert.ToInt32(x.BlockLength))); } } }
public RavenFileSystem(InMemoryRavenConfiguration systemConfiguration, string name, TransportState receivedTransportState = null) { ExtensionsState = new AtomicDictionary <object>(); Name = name; ResourceName = string.Concat(Abstractions.Data.Constants.FileSystem.UrlPrefix, "/", name); this.systemConfiguration = systemConfiguration; systemConfiguration.Container.SatisfyImportsOnce(this); transportState = receivedTransportState ?? new TransportState(); storage = CreateTransactionalStorage(systemConfiguration); sigGenerator = new SigGenerator(); fileLockManager = new FileLockManager(); BufferPool = new BufferPool(1024 * 1024 * 1024, 65 * 1024); conflictDetector = new ConflictDetector(); conflictResolver = new ConflictResolver(storage, new CompositionContainer(systemConfiguration.Catalog)); notificationPublisher = new NotificationPublisher(transportState); synchronizationTask = new SynchronizationTask(storage, sigGenerator, notificationPublisher, systemConfiguration); metricsCounters = new MetricsCountersManager(); search = new IndexStorage(name, systemConfiguration); conflictArtifactManager = new ConflictArtifactManager(storage, search); Tasks = new TaskActions(this, Log); Files = new FileActions(this, Log); Synchronizations = new SynchronizationActions(this, Log); AppDomain.CurrentDomain.ProcessExit += ShouldDispose; AppDomain.CurrentDomain.DomainUnload += ShouldDispose; }
public SynchronizationStrategy(ITransactionalStorage storage, SigGenerator sigGenerator) { this.storage = storage; this.sigGenerator = sigGenerator; }
public ContentUpdateWorkItem(string file, string sourceServerUrl, ITransactionalStorage storage, SigGenerator sigGenerator) : base(file, sourceServerUrl, storage) { this.sigGenerator = sigGenerator; }
public SynchronizationStrategy(ITransactionalStorage storage, SigGenerator sigGenerator, InMemoryRavenConfiguration configuration) { this.storage = storage; this.sigGenerator = sigGenerator; this.configuration = configuration; }
public ContentUpdateWorkItem(string file, string sourceServerUrl, ITransactionalStorage storage, SigGenerator sigGenerator, InMemoryRavenConfiguration configuration) : base(file, sourceServerUrl, storage) { this.sigGenerator = sigGenerator; this.configuration = configuration; }