public OnlineSegmentReplicationCommandTest() { node = MockRepository.GenerateStub<IDistributedHashTableNode>(); replication = MockRepository.GenerateStub<IDistributedHashTableNodeReplication>(); endpoint = NodeEndpoint.ForTest(1); node.Stub(x => x.Endpoint).Return(NodeEndpoint.ForTest(2)); storage = MockRepository.GenerateStub<IDistributedHashTableStorage>(); node.Storage = storage; node.Stub(x => x.GetTopologyVersion()).Return(topologyVersion); var factory = MockRepository.GenerateStub<IDistributedHashTableNodeReplicationFactory>(); factory.Stub(x => x.Create(null)).IgnoreArguments().Return(replication); command = new OnlineSegmentReplicationCommand( endpoint, new[] { new Segment { Index = 0 }, new Segment { Index = 1 }, }, ReplicationType.Ownership, node, factory); }
private void StartPendingBackupsForCurrentNode(Topology topology) { if (Topology == null) return; if (Interlocked.CompareExchange(ref currentlyReplicatingBackups, 0, 0) != 0) return; foreach (var segmentToReplicate in topology.Segments .Where(x => x.AssignedEndpoint != null) .Where(x => x.PendingBackups.Contains(endpoint)) .GroupBy(x => x.AssignedEndpoint)) { var command = new OnlineSegmentReplicationCommand( segmentToReplicate.Key, segmentToReplicate.ToArray(), ReplicationType.Backup, this, replicationFactory); Interlocked.Increment(ref currentlyReplicatingBackups); command.Completed += (() => Interlocked.Decrement(ref currentlyReplicatingBackups)); executer.RegisterForExecution(command); } }