Esempio n. 1
0
        public void CanRemoveItem()
        {
            using (var storageProxy = new DistributedHashTableStorageClient(storageHost.Endpoint))
            {
                var masterProxy = new DistributedHashTableMasterClient(masterUri);
                var topology    = masterProxy.GetTopology();
                var results     = storageProxy.Put(topology.Version, new ExtendedPutRequest
                {
                    Bytes   = new byte[] { 1, 2, 3, 4 },
                    Key     = "test",
                    Segment = 1,
                });
                Assert.False(results[0].ConflictExists);

                var removed = storageProxy.Remove(topology.Version, new ExtendedRemoveRequest
                {
                    Key             = "test",
                    SpecificVersion = results[0].Version,
                    Segment         = 1
                });
                Assert.True(removed[0]);

                var values = storageProxy.Get(topology.Version, new ExtendedGetRequest
                {
                    Key     = "test",
                    Segment = 1
                });

                Assert.Equal(0, values[0].Length);
            }
        }
Esempio n. 2
0
            public void WillReplicateValuesToSecondJoin()
            {
                var masterProxy = new DistributedHashTableMasterClient(masterUri);

                using (var nodeA = new DistributedHashTableStorageClient(storageHostA.Endpoint))
                {
                    Topology topology = masterProxy.GetTopology();
                    nodeA.Put(topology.Version, new ExtendedPutRequest
                    {
                        Bytes   = new byte[] { 2, 2, 0, 0 },
                        Key     = "abc",
                        Segment = 1
                    });
                }

                storageHostB.Start(); //will replicate all odd segments here now

                for (int i = 0; i < 500; i++)
                {
                    Topology topology = masterProxy.GetTopology();
                    if (topology.Segments[1].AssignedEndpoint ==
                        storageHostB.Endpoint)
                    {
                        break;
                    }
                    Thread.Sleep(500);
                }


                Value[][] values = null;
                RepeatWhileThereAreTopologyChangedErrors(() =>
                {
                    using (var nodeB = new DistributedHashTableStorageClient(storageHostB.Endpoint))
                    {
                        Topology topology = masterProxy.GetTopology();
                        values            = nodeB.Get(topology.Version, new ExtendedGetRequest
                        {
                            Key     = "abc",
                            Segment = 1
                        });
                    }
                });
                Assert.Equal(new byte[] { 2, 2, 0, 0 }, values[0][0].Data);
            }
Esempio n. 3
0
            public void AfterBothNodesJoinedWillAutomaticallyReplicateToBackupNode()
            {
                storageHostB.Start();

                var masterProxy = new DistributedHashTableMasterClient(masterUri);

                Topology topology;

                for (int i = 0; i < 50; i++)
                {
                    topology = masterProxy.GetTopology();
                    int count = topology.Segments
                                .Where(x => x.AssignedEndpoint == storageHostA.Endpoint)
                                .Count();

                    if (count == 4096)
                    {
                        break;
                    }
                    Thread.Sleep(500);
                }

                topology = masterProxy.GetTopology();
                int segment = topology.Segments.First(x => x.AssignedEndpoint == storageHostA.Endpoint).Index;

                RepeatWhileThereAreTopologyChangedErrors(() =>
                {
                    using (var nodeA = new DistributedHashTableStorageClient(storageHostA.Endpoint))
                    {
                        nodeA.Put(topology.Version, new ExtendedPutRequest
                        {
                            Bytes   = new byte[] { 2, 2, 0, 0 },
                            Key     = "abc",
                            Segment = segment
                        });
                    }
                });

                RepeatWhileThereAreTopologyChangedErrors(() =>
                {
                    using (var nodeB = new DistributedHashTableStorageClient(storageHostB.Endpoint))
                    {
                        topology         = masterProxy.GetTopology();
                        Value[][] values = null;
                        for (int i = 0; i < 100; i++)
                        {
                            values = nodeB.Get(topology.Version, new ExtendedGetRequest
                            {
                                Key     = "abc",
                                Segment = segment
                            });
                            if (values[0].Length != 0)
                            {
                                break;
                            }
                            Thread.Sleep(250);
                        }
                        Assert.Equal(new byte[] { 2, 2, 0, 0 }, values[0][0].Data);
                    }
                });
            }