public void AfterBackupsCompleteWillStartReplicationAgain() { node.Storage.Stub(x => x.Get(0)).IgnoreArguments().Return(new Value[0][]); OnlineSegmentReplicationCommand command = null; executer.Stub(x => x.RegisterForExecution(Arg <OnlineSegmentReplicationCommand> .Is.TypeOf)) .WhenCalled(invocation => command = (OnlineSegmentReplicationCommand)invocation.Arguments[0]); node.SetTopology(new Topology(new[] { new Segment { AssignedEndpoint = NodeEndpoint.ForTest(91), PendingBackups = { endPoint } }, }, 1)); command.RaiseCompleted(); node.SetTopology(new Topology(new[] { new Segment { AssignedEndpoint = NodeEndpoint.ForTest(91), PendingBackups = { endPoint } }, }, 2)); executer.AssertWasCalled( x => x.RegisterForExecution(Arg <OnlineSegmentReplicationCommand> .Is.TypeOf), o => o.Repeat.Twice()); }
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); } }
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); }