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]); }
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); }
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); }
/// <inheritdoc /> public void Delete <T>(string cql, params object[] args) { Delete <T>(Cql.New(cql, args, CqlQueryOptions.None)); }
/// <inheritdoc /> public void Execute(Cql cql) { //Wait async method to be completed or throw TaskHelper.WaitToCompleteWithMetrics(_metricsManager, ExecuteAsync(cql), _queryAbortTimeout); }
/// <inheritdoc /> public T Single <T>(string cql, params object[] args) { return(Single <T>(Cql.New(cql, args, CqlQueryOptions.None))); }
/// <inheritdoc /> public AppliedInfo <T> UpdateIf <T>(string cql, params object[] args) { return(UpdateIf <T>(Cql.New(cql, args, CqlQueryOptions.None))); }
/// <inheritdoc /> public Task <T> SingleOrDefaultAsync <T>(string cql, params object[] args) { return(SingleOrDefaultAsync <T>(Cql.New(cql, args, CqlQueryOptions.None))); }
/// <inheritdoc /> public Task DeleteAsync <T>(string cql, params object[] args) { return(DeleteAsync <T>(Cql.New(cql, args, CqlQueryOptions.None))); }
/// <inheritdoc /> public Task <IPage <T> > FetchPageAsync <T>(CqlQueryOptions options = null) { return(FetchPageAsync <T>(Cql.New(string.Empty, new object[0], options ?? new CqlQueryOptions()))); }
/// <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)))); }
public void Delete <T>(Cql cql) { _cqlGenerator.PrependDelete <T>(cql); _statements.Add(cql); }
public void Execute(Cql cql) { _statements.Add(cql); }
public void Execute(Cql cql) { //Wait async method to be completed or throw TaskHelper.WaitToComplete(ExecuteAsync(cql), _queryAbortTimeout); }
public void Delete <T>(Cql cql) { //Wait async method to be completed or throw TaskHelper.WaitToComplete(DeleteAsync <T>(cql), _queryAbortTimeout); }
/// <inheritdoc /> public Task DeleteAsync <T>(Cql cql) { _cqlGenerator.PrependDelete <T>(cql); return(ExecuteAsync(cql)); }
/// <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)))); }
/// <inheritdoc /> public Task ExecuteAsync(string cql, params object[] args) { return(ExecuteAsync(Cql.New(cql, args, CqlQueryOptions.None))); }
/// <inheritdoc /> public T FirstOrDefault <T>(string cql, params object[] args) { return(FirstOrDefault <T>(Cql.New(cql, args, CqlQueryOptions.None))); }
/// <inheritdoc /> public AppliedInfo <T> DeleteIf <T>(Cql cql) { return(TaskHelper.WaitToCompleteWithMetrics(_metricsManager, DeleteIfAsync <T>(cql), _queryAbortTimeout)); }
/// <inheritdoc /> public AppliedInfo <T> UpdateIf <T>(Cql cql) { //Wait async method to be completed or throw return(TaskHelper.WaitToCompleteWithMetrics(_metricsManager, UpdateIfAsync <T>(cql), _queryAbortTimeout)); }
/// <inheritdoc /> public Task <AppliedInfo <T> > DeleteIfAsync <T>(string cql, params object[] args) { return(DeleteIfAsync <T>(Cql.New(cql, args, CqlQueryOptions.None))); }
/// <inheritdoc /> public void Execute(string cql, params object[] args) { Execute(Cql.New(cql, args, CqlQueryOptions.None)); }
/// <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))); }
/// <inheritdoc /> public Task <IEnumerable <T> > FetchAsync <T>(CqlQueryOptions options = null) { return(FetchAsync <T>(Cql.New(string.Empty, new object[0], options ?? CqlQueryOptions.None))); }
/// <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))); }
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); } }
/// <inheritdoc /> public IEnumerable <T> Fetch <T>(string cql, params object[] args) { return(Fetch <T>(Cql.New(cql, args, CqlQueryOptions.None))); }
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); }
/// <inheritdoc /> public IPage <T> FetchPage <T>(CqlQueryOptions queryOptions = null) { return(FetchPage <T>(Cql.New(string.Empty, new object[0], queryOptions ?? new CqlQueryOptions()))); }
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); } }
public AppliedInfo <T> DeleteIf <T>(Cql cql) { return(TaskHelper.WaitToComplete(DeleteIfAsync <T>(cql), _queryAbortTimeout)); }