예제 #1
0
        public void CanReplicateSegmentWithDataWhileStillServingRequestForSegment()
        {
            using (var storageProxy = new DistributedHashTableStorageClient(storageHost.Endpoint))
            {
                var topology = new DistributedHashTableMasterClient(masterUri).GetTopology();
                storageProxy.Put(topology.Version, new ExtendedPutRequest
                {
                    Bytes   = new byte[] { 1, 2, 3 },
                    Key     = "test",
                    Segment = 1,
                });

                var result = storageProxy.ReplicateNextPage(NodeEndpoint.ForTest(13), ReplicationType.Ownership, 1);
                Assert.Equal("test", result.PutRequests[0].Key);

                storageProxy.Put(topology.Version, new ExtendedPutRequest
                {
                    Bytes   = new byte[] { 1, 2, 3 },
                    Key     = "test2",
                    Segment = 1,
                });

                result = storageProxy.ReplicateNextPage(NodeEndpoint.ForTest(13), ReplicationType.Ownership, 1);
                Assert.Equal("test2", result.PutRequests[0].Key);
            }
        }
예제 #2
0
            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());
            }
            public void WillGiveExistingKeysFromSegment()
            {
                var result = replication.ReplicateNextPage(NodeEndpoint.ForTest(1), ReplicationType.Ownership, 0);

                Assert.Equal(1, result.PutRequests.Length);
                Assert.Equal(new byte[] { 1 }, result.PutRequests[0].Bytes);
            }
            public void WillSkipSegmentsThatHasItemsInThem()
            {
                var ranges           = Enumerable.Range(0, 500).ToArray();
                var assignedSegments = replication.AssignAllEmptySegments(NodeEndpoint.ForTest(1), ReplicationType.Ownership, ranges);

                Assert.Equal(ranges.Skip(1).ToArray(), assignedSegments);
            }
            public void WillAssignAllSegmentsWeAskForImmediately()
            {
                var ranges           = Enumerable.Range(0, 500).ToArray();
                var assignedSegments = replication.AssignAllEmptySegments(NodeEndpoint.ForTest(1), ReplicationType.Ownership, ranges);

                Assert.Equal(ranges, assignedSegments);
            }
예제 #6
0
            public void WillNotStartReplicationIfCurrentlyReplicatingBackups()
            {
                node.Storage.Stub(x => x.Get(0)).IgnoreArguments().Return(new Value[0][]);

                node.SetTopology(new Topology(new[]
                {
                    new Segment
                    {
                        AssignedEndpoint = NodeEndpoint.ForTest(91),
                        PendingBackups   = { endPoint }
                    },
                }, 1));

                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.Once());
            }
예제 #7
0
            public void AddingNewNodeResultInAllSegmentsHavingAtLeastTwoBackupCopy()
            {
                var yetAnotherEndPoint = NodeEndpoint.ForTest(7);
                var ranges             = master.Join(yetAnotherEndPoint);

                master.CaughtUp(yetAnotherEndPoint, ReplicationType.Ownership, ranges.Select(x => x.Index).ToArray());
                Assert.True(master.Segments.All(x => x.PendingBackups.Count >= 2));
            }
예제 #8
0
 public OnGaveUp()
 {
     master = new DistributedHashTableMaster();
     master.CaughtUp(NodeEndpoint.ForTest(9),
                     ReplicationType.Ownership,
                     master.Join(NodeEndpoint.ForTest(9)).Select(x => x.Index).ToArray());
     endPoint = NodeEndpoint.ForTest(5);
 }
예제 #9
0
 public HandlingAssignedSegments()
 {
     master   = MockRepository.GenerateStub <IDistributedHashTableMaster>();
     executer = MockRepository.GenerateStub <IExecuter>();
     endPoint = NodeEndpoint.ForTest(1);
     node     = new DistributedHashTableNode(master, executer, new BinaryMessageSerializer(), endPoint, MockRepository.GenerateStub <IQueueManager>(),
                                             MockRepository.GenerateStub <IDistributedHashTableNodeReplicationFactory>());
 }
예제 #10
0
            public void DirectlyModifyingTopologyAndThenCallingRefreshEndpointsShouldShowAllEndpoints()
            {
                Assert.False(master.Endpoints.Any(x => x == NodeEndpoint.ForTest(1)));

                master.Topology.Segments[0].AssignedEndpoint = NodeEndpoint.ForTest(1);
                master.RefreshEndpoints();

                Assert.True(master.Endpoints.Any(x => x == NodeEndpoint.ForTest(1)));
            }
            public void WillRememberKeysSentDuringPreviousReplication()
            {
                var result = replication.ReplicateNextPage(NodeEndpoint.ForTest(1), ReplicationType.Ownership, 0);

                Assert.Equal(1, result.PutRequests.Length);

                result = replication.ReplicateNextPage(NodeEndpoint.ForTest(1), ReplicationType.Ownership, 0);
                Assert.Equal(0, result.PutRequests.Length);
            }
예제 #12
0
            public OnMasterWithOneExistingNode()
            {
                master   = new DistributedHashTableMaster();
                endPoint = NodeEndpoint.ForTest(9);

                var existingEndpoint = NodeEndpoint.ForTest(3);
                var ranges           = master.Join(existingEndpoint);

                master.CaughtUp(existingEndpoint, ReplicationType.Ownership, ranges.Select(x => x.Index).ToArray());
            }
예제 #13
0
 public WhenFinishedReplicatingSegment()
 {
     master   = MockRepository.GenerateStub <IDistributedHashTableMaster>();
     executer = MockRepository.GenerateStub <IExecuter>();
     endPoint = NodeEndpoint.ForTest(1);
     master.Stub(x => x.Join(Arg.Is(endPoint)))
     .Return(new Segment[0]);
     node = new DistributedHashTableNode(master, executer, new BinaryMessageSerializer(), endPoint, MockRepository.GenerateStub <IQueueManager>(),
                                         MockRepository.GenerateStub <IDistributedHashTableNodeReplicationFactory>());
 }
예제 #14
0
        public void CanReplicateEmptySegments()
        {
            using (var storageProxy = new DistributedHashTableStorageClient(storageHost.Endpoint))
            {
                var segments = new[] { 1, 2, 3 };

                var assignedSegments = storageProxy.AssignAllEmptySegments(NodeEndpoint.ForTest(13), ReplicationType.Ownership, segments);

                Assert.Equal(segments, assignedSegments);
            }
        }
            public void RemovingKeyInSegmentAsisgnedElsewhereShouldThrow()
            {
                var ranges = Enumerable.Range(0, 500).ToArray();

                replication.AssignAllEmptySegments(NodeEndpoint.ForTest(1), ReplicationType.Ownership, ranges);
                var exception = Assert.Throws <SeeOtherException>(() => node.Storage.Remove(topologyVersion, new ExtendedRemoveRequest
                {
                    Key     = "test",
                    Segment = 0,
                }));

                Assert.Equal(NodeEndpoint.ForTest(1), exception.Endpoint);
            }
예제 #16
0
            public void TopologyContainsPendingBackupsForCurrentNodeWillStartsBackupReplication()
            {
                node.SetTopology(new Topology(new[]
                {
                    new Segment
                    {
                        AssignedEndpoint = NodeEndpoint.ForTest(91),
                        PendingBackups   = { endPoint }
                    },
                }, 1));

                executer.AssertWasCalled(x => x.RegisterForExecution(Arg <OnlineSegmentReplicationCommand> .Is.TypeOf));
            }
예제 #17
0
            public void WillRegisterSegmentsNotAssignedToMeForReplication()
            {
                master.Stub(x => x.Join(Arg.Is(endPoint)))
                .Return(new[]
                {
                    new Segment {
                        AssignedEndpoint = NodeEndpoint.ForTest(9)
                    },
                });

                node.Start();

                executer.AssertWasCalled(x => x.RegisterForExecution(Arg <OnlineSegmentReplicationCommand> .Is.TypeOf));
            }
예제 #18
0
            public void WhenNoSegmentIsAssignedToNodeStateWillBeStarting()
            {
                master.Stub(x => x.Join(Arg.Is(endPoint)))
                .Return(new[]
                {
                    new Segment {
                        AssignedEndpoint = NodeEndpoint.ForTest(9)
                    },
                });

                node.Start();

                Assert.Equal(NodeState.Starting, node.State);
            }
            public void WhenItemIsRemovedWillResultInRemovalRequestOnNextReplicationPage()
            {
                var result = replication.ReplicateNextPage(NodeEndpoint.ForTest(1), ReplicationType.Ownership, 0);

                Assert.Equal(1, result.PutRequests.Length);
                node.Storage.Remove(node.GetTopologyVersion(), new ExtendedRemoveRequest
                {
                    Key             = "test",
                    SpecificVersion = putResult.Version,
                    Segment         = 0,
                });

                result = replication.ReplicateNextPage(NodeEndpoint.ForTest(1), ReplicationType.Ownership, 0);
                Assert.Equal(1, result.RemoveRequests.Length);
            }
            public void WhenDoneGettingAllKeysWillAssignSegmentToEndpoint()
            {
                var result = replication.ReplicateNextPage(NodeEndpoint.ForTest(1), ReplicationType.Ownership, 0);

                Assert.Equal(1, result.PutRequests.Length);

                result = replication.ReplicateNextPage(NodeEndpoint.ForTest(1), ReplicationType.Ownership, 0);
                Assert.Equal(0, result.PutRequests.Length);

                var exception = Assert.Throws <SeeOtherException>(() => node.Storage.Remove(topologyVersion, new ExtendedRemoveRequest
                {
                    Key     = "test",
                    Segment = 0,
                }));

                Assert.Equal(NodeEndpoint.ForTest(1), exception.Endpoint);
            }
예제 #21
0
        public void WhenFinishedReplicatingWillTellTheReplicatorSo()
        {
            using (var storageProxy = new DistributedHashTableStorageClient(storageHost.Endpoint))
            {
                var topology = new DistributedHashTableMasterClient(masterUri).GetTopology();
                storageProxy.Put(topology.Version, new ExtendedPutRequest
                {
                    Bytes   = new byte[] { 1, 2, 3 },
                    Key     = "test",
                    Segment = 1,
                });

                var result = storageProxy.ReplicateNextPage(NodeEndpoint.ForTest(13), ReplicationType.Ownership, 1);
                Assert.Equal("test", result.PutRequests[0].Key);

                result = storageProxy.ReplicateNextPage(NodeEndpoint.ForTest(13), ReplicationType.Ownership, 1);
                Assert.True(result.Done);
            }
        }
예제 #22
0
        public void WhenReplicatingEmptySegmentsWillNotReplicateSegmentsThatHasValues()
        {
            using (var storageProxy = new DistributedHashTableStorageClient(storageHost.Endpoint))
            {
                var topology = new DistributedHashTableMasterClient(masterUri).GetTopology();
                storageProxy.Put(topology.Version, new ExtendedPutRequest
                {
                    Bytes   = new byte[] { 1, 2, 3 },
                    Key     = "test",
                    Segment = 1,
                });

                var segments = new[] { 1, 2, 3 };

                var assignedSegments = storageProxy.AssignAllEmptySegments(NodeEndpoint.ForTest(13), ReplicationType.Ownership, segments);

                Assert.Equal(new[] { 2, 3 }, assignedSegments);
            }
        }
예제 #23
0
            public void WhenCatchingUpOnBackupsWillMoveFromPendingBackupsToBackups()
            {
                master.CaughtUp(endPoint, ReplicationType.Ownership,
                                master.Join(endPoint).Select(x => x.Index).ToArray());

                var anotherEndpoint = NodeEndpoint.ForTest(54);

                master.CaughtUp(anotherEndpoint, ReplicationType.Ownership,
                                master.Join(anotherEndpoint).Select(x => x.Index).ToArray());

                var segment = master.Topology.Segments.First(x => x.PendingBackups.Count > 0);

                master.CaughtUp(segment.PendingBackups.First(), ReplicationType.Backup,
                                segment.Index);

                segment = master.Topology.Segments[segment.Index];

                Assert.Empty(segment.PendingBackups);
                Assert.Equal(1, segment.Backups.Count);
            }
예제 #24
0
            public WhenReplicatingRequestToOwner()
            {
                master   = MockRepository.GenerateStub <IDistributedHashTableMaster>();
                endPoint = NodeEndpoint.ForTest(1);
                backup1  = NodeEndpoint.ForTest(2);
                backup2  = NodeEndpoint.ForTest(3);
                topology = new Topology(new[]
                {
                    new Segment
                    {
                        Index            = 0,
                        AssignedEndpoint = endPoint,
                        PendingBackups   =
                        {
                            backup1,
                            backup2,
                        }
                    },
                    new Segment
                    {
                        Index            = 1,
                        AssignedEndpoint = backup1,
                        PendingBackups   =
                        {
                            endPoint,
                            backup2,
                        }
                    },
                }, 1);
                master.Stub(x => x.GetTopology()).Return(topology);
                executer = MockRepository.GenerateStub <IExecuter>();
                master.Stub(x => x.Join(Arg.Is(endPoint)))
                .Return(new Segment[0]);
                queueManager = MockRepository.GenerateStub <IQueueManager>();

                node = new DistributedHashTableNode(master, executer, new BinaryMessageSerializer(), endPoint,
                                                    queueManager, MockRepository.GenerateStub <IDistributedHashTableNodeReplicationFactory>());
                node.Start();
            }
예제 #25
0
        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);
        }
예제 #26
0
 public OnCaughtUp()
 {
     master   = new DistributedHashTableMaster();
     endPoint = NodeEndpoint.ForTest(9);
 }