public WhenThereAreKeysInTable()
 {
     node = MockRepository.GenerateStub<IDistributedHashTableNode>();
     topologyVersion = 9;
     node.Stub(x => x.GetTopologyVersion()).Return(topologyVersion);
     distributedHashTableStorage = new DistributedHashTableStorage("test.esent",
                                                                   node);
     replication = distributedHashTableStorage.Replication;
     putResult = distributedHashTableStorage.Put(topologyVersion, new ExtendedPutRequest
     {
         Tag = 0,
         Bytes = new byte[] {1},
         Key = "test",
         Segment = 0
     })[0];
 }
Ejemplo n.º 2
0
        private PutResult[] PutInternal(PutRequest[] valuesToAdd, int backupIndex)
        {
            var results = new PutResult[valuesToAdd.Length];

            var groupedByEndpoint = from req in valuesToAdd
                                    let er = new
                                    {
                                        OriginalIndex = Array.IndexOf(valuesToAdd, req),
                                        Put = new ExtendedPutRequest
                                        {
                                            Bytes = req.Bytes,
                                            ExpiresAt = req.ExpiresAt,
                                            IsReadOnly = req.IsReadOnly,
                                            Key = req.Key,
                                            OptimisticConcurrency = req.OptimisticConcurrency,
                                            ParentVersions = req.ParentVersions,
                                            Segment = GetSegmentFromKey(req.Key),
                                        }
                                    }
                                    group er by GetEndpointByBackupIndex(topology.Segments[er.Put.Segment], backupIndex) into g
                                    select g;

            foreach (var endpoint in groupedByEndpoint)
            {
                if (endpoint.Key == null)
                    throw new NoMoreBackupsException();

                var requests = endpoint.ToArray();
                var putRequests = requests.Select(x => x.Put).ToArray();

                var putsResults = GetPutsResults(endpoint.Key, putRequests, backupIndex);
                for (var i = 0; i < putsResults.Length; i++)
                {
                    results[requests[i].OriginalIndex] = putsResults[i];
                }
            }
            return results;
        }