示例#1
0
        public void Fetch_ListUploadedAsNull()
        {
            Table<Author> table = new Table<Author>(_session, new MappingConfiguration());
            table.Create();
            var mapper = new Mapper(_session, new MappingConfiguration().Define(new FluentUserMapping()));
            Author expectedAuthor = Author.GetRandom();
            expectedAuthor.Followers = null;
            mapper.Insert(expectedAuthor);

            // Assert values from cql query
            Author expectedAuthorFromQuery = new Author
            {
                Followers = new List<string>(), // not null
                AuthorId = expectedAuthor.AuthorId,
            };

            Cql cql = new Cql("SELECT * from " + table.Name);
            List<Author> actualAuthors = mapper.Fetch<Author>(cql).ToList();
            Assert.AreEqual(1, actualAuthors.Count);
            expectedAuthorFromQuery.AssertEquals(actualAuthors[0]);
        }
示例#2
0
        public void Fetch_UsingCqlObject()
        {
            Table<Author> table = new Table<Author>(_session, new MappingConfiguration());
            table.Create();
            int totalInserts = 10;

            var mapper = new Mapper(_session, new MappingConfiguration().Define(new FluentUserMapping()));
            List<Author> expectedAuthors = Author.GetRandomList(totalInserts);
            foreach (Author expectedAuthor in expectedAuthors)
                mapper.Insert(expectedAuthor);

            Cql cql = new Cql("SELECT * from " + table.Name);
            List<Author> actualAuthors = mapper.Fetch<Author>(cql).ToList();
            Assert.AreEqual(totalInserts, actualAuthors.Count);
            Author.AssertListsContainTheSame(expectedAuthors, actualAuthors);
        }
示例#3
0
        public void Fetch_WithConsistencyLevel_Invalids_OnlySupportedForWrites()
        {
            Table<Author> table = new Table<Author>(_session, new MappingConfiguration());
            table.Create();
            int totalInserts = 10;

            var mapper = new Mapper(_session, new MappingConfiguration().Define(new FluentUserMapping()));
            List<Author> expectedAuthors = Author.GetRandomList(totalInserts);
            foreach (Author expectedAuthor in expectedAuthors)
                mapper.Insert(expectedAuthor);

            Cql cql = new Cql("SELECT * from " + table.Name).WithOptions(c => c.SetConsistencyLevel(ConsistencyLevel.EachQuorum));
            var err = Assert.Throws<InvalidQueryException>(() => mapper.Fetch<Author>(cql).ToList());
            Assert.AreEqual("EACH_QUORUM ConsistencyLevel is only supported for writes", err.Message);

            cql = new Cql("SELECT * from " + table.Name).WithOptions(c => c.SetConsistencyLevel(ConsistencyLevel.Any));
            err = Assert.Throws<InvalidQueryException>(() => mapper.Fetch<Author>(cql).ToList());
            Assert.AreEqual("ANY ConsistencyLevel is only supported for writes", err.Message);
        }
示例#4
0
 /// <inheritdoc />
 public void Delete <T>(string cql, params object[] args)
 {
     Delete <T>(Cql.New(cql, args, CqlQueryOptions.None));
 }
示例#5
0
 /// <inheritdoc />
 public void Execute(Cql cql)
 {
     //Wait async method to be completed or throw
     TaskHelper.WaitToCompleteWithMetrics(_metricsManager, ExecuteAsync(cql), _queryAbortTimeout);
 }
示例#6
0
 /// <inheritdoc />
 public T Single <T>(string cql, params object[] args)
 {
     return(Single <T>(Cql.New(cql, args, CqlQueryOptions.None)));
 }
示例#7
0
 /// <inheritdoc />
 public AppliedInfo <T> UpdateIf <T>(string cql, params object[] args)
 {
     return(UpdateIf <T>(Cql.New(cql, args, CqlQueryOptions.None)));
 }
示例#8
0
 /// <inheritdoc />
 public Task <T> SingleOrDefaultAsync <T>(string cql, params object[] args)
 {
     return(SingleOrDefaultAsync <T>(Cql.New(cql, args, CqlQueryOptions.None)));
 }
示例#9
0
 /// <inheritdoc />
 public Task DeleteAsync <T>(string cql, params object[] args)
 {
     return(DeleteAsync <T>(Cql.New(cql, args, CqlQueryOptions.None)));
 }
示例#10
0
 /// <inheritdoc />
 public Task <IPage <T> > FetchPageAsync <T>(CqlQueryOptions options = null)
 {
     return(FetchPageAsync <T>(Cql.New(string.Empty, new object[0], options ?? new CqlQueryOptions())));
 }
示例#11
0
 /// <inheritdoc />
 public Task <IPage <T> > FetchPageAsync <T>(int pageSize, byte[] pagingState, string query, object[] args)
 {
     return(FetchPageAsync <T>(Cql.New(query, args, new CqlQueryOptions().SetPageSize(pageSize).SetPagingState(pagingState))));
 }
示例#12
0
 public void Delete <T>(Cql cql)
 {
     _cqlGenerator.PrependDelete <T>(cql);
     _statements.Add(cql);
 }
示例#13
0
 public void Execute(Cql cql)
 {
     _statements.Add(cql);
 }
示例#14
0
 public void Execute(Cql cql)
 {
     //Wait async method to be completed or throw
     TaskHelper.WaitToComplete(ExecuteAsync(cql), _queryAbortTimeout);
 }
示例#15
0
 public void Delete <T>(Cql cql)
 {
     //Wait async method to be completed or throw
     TaskHelper.WaitToComplete(DeleteAsync <T>(cql), _queryAbortTimeout);
 }
示例#16
0
 /// <inheritdoc />
 public Task DeleteAsync <T>(Cql cql)
 {
     _cqlGenerator.PrependDelete <T>(cql);
     return(ExecuteAsync(cql));
 }
示例#17
0
 /// <inheritdoc />
 public IPage <T> FetchPage <T>(int pageSize, byte[] pagingState, string cql, params object[] args)
 {
     return(FetchPage <T>(Cql.New(cql, args, new CqlQueryOptions().SetPageSize(pageSize).SetPagingState(pagingState))));
 }
示例#18
0
 /// <inheritdoc />
 public Task ExecuteAsync(string cql, params object[] args)
 {
     return(ExecuteAsync(Cql.New(cql, args, CqlQueryOptions.None)));
 }
示例#19
0
 /// <inheritdoc />
 public T FirstOrDefault <T>(string cql, params object[] args)
 {
     return(FirstOrDefault <T>(Cql.New(cql, args, CqlQueryOptions.None)));
 }
示例#20
0
 /// <inheritdoc />
 public AppliedInfo <T> DeleteIf <T>(Cql cql)
 {
     return(TaskHelper.WaitToCompleteWithMetrics(_metricsManager, DeleteIfAsync <T>(cql), _queryAbortTimeout));
 }
示例#21
0
 /// <inheritdoc />
 public AppliedInfo <T> UpdateIf <T>(Cql cql)
 {
     //Wait async method to be completed or throw
     return(TaskHelper.WaitToCompleteWithMetrics(_metricsManager, UpdateIfAsync <T>(cql), _queryAbortTimeout));
 }
示例#22
0
 /// <inheritdoc />
 public Task <AppliedInfo <T> > DeleteIfAsync <T>(string cql, params object[] args)
 {
     return(DeleteIfAsync <T>(Cql.New(cql, args, CqlQueryOptions.None)));
 }
示例#23
0
 /// <inheritdoc />
 public void Execute(string cql, params object[] args)
 {
     Execute(Cql.New(cql, args, CqlQueryOptions.None));
 }
示例#24
0
 /// <inheritdoc />
 public Task <AppliedInfo <T> > DeleteIfAsync <T>(Cql cql)
 {
     _cqlGenerator.PrependDelete <T>(cql);
     return(ExecuteAsyncAndAdapt(cql, (stmt, rs) => AppliedInfo <T> .FromRowSet(_mapperFactory, cql.Statement, rs)));
 }
示例#25
0
 /// <inheritdoc />
 public Task <IEnumerable <T> > FetchAsync <T>(CqlQueryOptions options = null)
 {
     return(FetchAsync <T>(Cql.New(string.Empty, new object[0], options ?? CqlQueryOptions.None)));
 }
示例#26
0
 /// <inheritdoc />
 public IEnumerable <T> Fetch <T>(CqlQueryOptions queryOptions = null)
 {
     // Just let the SQL be auto-generated
     return(Fetch <T>(Cql.New(string.Empty, new object[0], queryOptions ?? CqlQueryOptions.None)));
 }
示例#27
0
        public void Fetch_WithConsistencyLevel_Valids()
        {
            Table<Author> table = new Table<Author>(_session, new MappingConfiguration());
            table.Create();
            int totalInserts = 10;

            var mapper = new Mapper(_session, new MappingConfiguration().Define(new FluentUserMapping()));
            List<Author> expectedAuthors = Author.GetRandomList(totalInserts);
            foreach (Author expectedAuthor in expectedAuthors)
                mapper.Insert(expectedAuthor);

            var consistencyLevels = new[]
            {
                ConsistencyLevel.All,
                ConsistencyLevel.LocalOne,
                ConsistencyLevel.LocalQuorum,
                ConsistencyLevel.Quorum,
                ConsistencyLevel.One,
            };
            foreach (var consistencyLevel in consistencyLevels)
            {
                Cql cql = new Cql("SELECT * from " + table.Name).WithOptions(c => c.SetConsistencyLevel(consistencyLevel));
                List<Author> actualAuthors = mapper.Fetch<Author>(cql).ToList();
                Assert.AreEqual(totalInserts, actualAuthors.Count);
                Author.AssertListsContainTheSame(expectedAuthors, actualAuthors);
            }
        }
示例#28
0
 /// <inheritdoc />
 public IEnumerable <T> Fetch <T>(string cql, params object[] args)
 {
     return(Fetch <T>(Cql.New(cql, args, CqlQueryOptions.None)));
 }
示例#29
0
        public void Fetch_WithConsistencyLevel_Invalids_NotEnoughReplicas()
        {
            Table<Author> table = new Table<Author>(_session, new MappingConfiguration());
            table.Create();
            int totalInserts = 10;

            var mapper = new Mapper(_session, new MappingConfiguration().Define(new FluentUserMapping()));
            List<Author> expectedAuthors = Author.GetRandomList(totalInserts);
            foreach (Author expectedAuthor in expectedAuthors)
                mapper.Insert(expectedAuthor);

            Cql cql = new Cql("SELECT * from " + table.Name).WithOptions(c => c.SetConsistencyLevel(ConsistencyLevel.Two));
            var err = Assert.Throws<UnavailableException>(() => mapper.Fetch<Author>(cql));
            Assert.AreEqual("Not enough replicas available for query at consistency Two (2 required but only 1 alive)", err.Message);

            cql = new Cql("SELECT * from " + table.Name).WithOptions(c => c.SetConsistencyLevel(ConsistencyLevel.Three));
            err = Assert.Throws<UnavailableException>(() => mapper.Fetch<Author>(cql));
            Assert.AreEqual("Not enough replicas available for query at consistency Three (3 required but only 1 alive)", err.Message);
        }
示例#30
0
 /// <inheritdoc />
 public IPage <T> FetchPage <T>(CqlQueryOptions queryOptions = null)
 {
     return(FetchPage <T>(Cql.New(string.Empty, new object[0], queryOptions ?? new CqlQueryOptions())));
 }
示例#31
0
        public void Fetch_Lazy()
        {
            Table<Author> table = new Table<Author>(_session, new MappingConfiguration());
            table.Create();

            var mapper = new Mapper(_session, new MappingConfiguration().Define(new FluentUserMapping()));
            List<Author> expectedAuthors = Author.GetRandomList(100);
            foreach (Author expectedAuthor in expectedAuthors)
                mapper.Insert(expectedAuthor);

            // wait until all records are available to be fetched: 
            List<Author> authors = mapper.Fetch<Author>("SELECT * from " + table.Name).ToList();
            DateTime futureDateTime = DateTime.Now.AddSeconds(10);
            while (authors.Count < expectedAuthors.Count && DateTime.Now < futureDateTime)
                authors = mapper.Fetch<Author>("SELECT * from " + table.Name).ToList();
            Assert.AreEqual(expectedAuthors.Count, authors.Count, "Setup FAIL: Less than expected number of authors uploaded");

            Cql cql = new Cql("SELECT * from " + table.Name).WithOptions(o => o.SetConsistencyLevel(ConsistencyLevel.Quorum));
            List<Author> authorsFetchedAndSaved = new List<Author>();
            var authorsFetched = mapper.Fetch<Author>(cql).GetEnumerator();
            while (authorsFetched.MoveNext())
                authorsFetchedAndSaved.Add(authorsFetched.Current);

            Assert.AreEqual(expectedAuthors.Count, authorsFetchedAndSaved.Count);
            foreach (var authorFetched in authorsFetchedAndSaved)
            {
                Author.AssertListContains(expectedAuthors, authorFetched);
            }
        }
示例#32
0
 public AppliedInfo <T> DeleteIf <T>(Cql cql)
 {
     return(TaskHelper.WaitToComplete(DeleteIfAsync <T>(cql), _queryAbortTimeout));
 }