Ejemplo n.º 1
0
        private async Task <IReadOnlyList <TValue> > GetValuesAsync(IPredicate predicate, CancellationToken cancellationToken)
        {
            if (predicate == null)
            {
                throw new ArgumentNullException(nameof(predicate));
            }
            var pagingPredicate = UnwrapPagingPredicate(predicate);

            if (pagingPredicate != null)
            {
                pagingPredicate.IterationType = IterationType.Value;

                var pagingPredicateHolder = PagingPredicateHolder.Of(predicate, SerializationService);
                var requestMessage        = MapValuesWithPagingPredicateCodec.EncodeRequest(Name, pagingPredicateHolder);
                var responseMessage       = await Cluster.Messaging.SendAsync(requestMessage, cancellationToken).CAF();

                var response = MapValuesWithPagingPredicateCodec.DecodeResponse(responseMessage);
                pagingPredicate.UpdateAnchors(response.AnchorDataList.AsAnchorIterator(SerializationService));
                return(new ReadOnlyLazyList <TValue>(response.Response, SerializationService));
            }

            {
                var requestMessage  = MapValuesWithPredicateCodec.EncodeRequest(Name, ToData(predicate));
                var responseMessage = await(predicate is PartitionPredicate pp
                    ? Cluster.Messaging.SendToKeyPartitionOwnerAsync(requestMessage, SerializationService.ToData(pp.PartitionKey), cancellationToken)
                    : Cluster.Messaging.SendAsync(requestMessage, cancellationToken))
                                      .CAF();
                var response = MapValuesWithPredicateCodec.DecodeResponse(responseMessage).Response;
                return(new ReadOnlyLazyList <TValue>(response, SerializationService));
            }
        }
Ejemplo n.º 2
0
        private ISet <KeyValuePair <TKey, TValue> > EntrySetWithPagingPredicate(IPredicate predicate)
        {
            var pagingPredicate = UnwrapPagingPredicate(predicate);

            pagingPredicate.IterationType = IterationType.Entry;
            var pagingPredicateHolder = PagingPredicateHolder.Of(predicate, Client.SerializationService);
            var request          = MapEntriesWithPagingPredicateCodec.EncodeRequest(Name, pagingPredicateHolder);
            var response         = InvokeWithPredicate(request, predicate);
            var resultParameters = MapEntriesWithPagingPredicateCodec.DecodeResponse(response);

            pagingPredicate.AnchorList = resultParameters.AnchorDataList.AsAnchorIterator(Client.SerializationService).ToList();
            return(new ReadOnlyLazyEntrySet <TKey, TValue, IData>(resultParameters.Response, Client.SerializationService));
        }
Ejemplo n.º 3
0
        private ICollection <TValue> ValuesForPagingPredicate(IPredicate predicate)
        {
            var pagingPredicate = UnwrapPagingPredicate(predicate);

            pagingPredicate.IterationType = IterationType.Value;

            var pagingPredicateHolder = PagingPredicateHolder.Of(predicate, Client.SerializationService);
            var request          = MapValuesWithPagingPredicateCodec.EncodeRequest(Name, pagingPredicateHolder);
            var response         = InvokeWithPredicate(request, predicate);
            var resultParameters = MapValuesWithPagingPredicateCodec.DecodeResponse(response);

            pagingPredicate.AnchorList = resultParameters.AnchorDataList.AsAnchorIterator(Client.SerializationService).ToList();
            return(new ReadOnlyLazySet <TValue>(resultParameters.Response, Client.SerializationService));
        }
        public void PagingPredicateHolderTest()
        {
            var serializationService = new SerializationServiceBuilder(new NullLoggerFactory())
                                       .AddHook <PredicateDataSerializerHook>()
                                       .Build();

            var anchorDataListHolder = GetAnchorDataListHolder(serializationService, out var pageList, out var dataList);

            var predicateData    = new HeapData();
            var comparatorData   = new HeapData();
            var partitionKeyData = new HeapData();

            var holder = new PagingPredicateHolder(anchorDataListHolder, predicateData, comparatorData, 5, 12, 3, partitionKeyData);

            Assert.That(holder.AnchorDataListHolder, Is.SameAs(anchorDataListHolder));
            Assert.That(holder.PredicateData, Is.SameAs(predicateData));
            Assert.That(holder.ComparatorData, Is.SameAs(comparatorData));
            Assert.That(holder.PageSize, Is.EqualTo(5));
            Assert.That(holder.Page, Is.EqualTo(12));
            Assert.That(holder.IterationTypeId, Is.EqualTo(3));
            Assert.That(holder.PartitionKeyData, Is.SameAs(partitionKeyData));

            var predicate = new PagingPredicate(5)
            {
                IterationType = IterationType.Key
            };

            predicate.UpdateAnchors(new List <KeyValuePair <int, KeyValuePair <object, object> > >
            {
                new KeyValuePair <int, KeyValuePair <object, object> >(1, new KeyValuePair <object, object>("key", "value"))
            });

            holder = PagingPredicateHolder.Of(predicate, serializationService);
            Assert.That(holder.PageSize, Is.EqualTo(5));

            holder = PagingPredicateHolder.Of(new PartitionPredicate("key", new PagingPredicate(5)
            {
                IterationType = IterationType.Key
            }), serializationService);
            Assert.That(holder.PageSize, Is.EqualTo(5));

            Assert.That(PagingPredicateHolder.Of(null, serializationService), Is.Null);

            Assert.Throws <InvalidOperationException>(() => _ = PagingPredicateHolder.Of(new PagingPredicate(5), serializationService));

            Assert.Throws <InvalidOperationException>(() => _ = PagingPredicateHolder.Of(new AndPredicate(), serializationService));
            Assert.Throws <InvalidOperationException>(() => _ = PagingPredicateHolder.Of(new PartitionPredicate(), serializationService));
        }