Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added app.config and additonal methods in sandbox. #46

Closed
wants to merge 2 commits into from

2 participants

@lhowlader

Added app.config to Fluentcassandra.Tests and Sanbox. It hosts the TestServer, TestPort and TestKeyspace params. Users can now change these and run all xunitunit tests in local environment. Also added a few more methods to sandbox to be able to debug a few more tests. Tombstone test in Sandbox verifies that open issue #26 is no longer an issue and it can be closed.

Lotus Howlader added some commits
Lotus Howlader Modified Sandbox to test columnfamily with uuidcomparator and timesta…
…mpcomparator.
aec99ac
Lotus Howlader Added app.config to Sandbox and "FluentCassandra.Tests".
App.config now stores TestServer, TestPort and TestKeyspace settings.
Added TombstoneTest and BigDecimalTest in sandbox to step through and verify
the results.
b0d3096
@nberardi
Owner

Thanks for doing this, I will take a look at it later today.

@nberardi nberardi referenced this pull request from a commit
@nberardi nberardi merge from @lhowlader for issue #46 4c03b49
@nberardi nberardi closed this
@nberardi nberardi was assigned
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 9, 2012
  1. Modified Sandbox to test columnfamily with uuidcomparator and timesta…

    Lotus Howlader authored
    …mpcomparator.
Commits on Aug 13, 2012
  1. Added app.config to Sandbox and "FluentCassandra.Tests".

    Lotus Howlader authored
    App.config now stores TestServer, TestPort and TestKeyspace settings.
    Added TombstoneTest and BigDecimalTest in sandbox to step through and verify
    the results.
This page is out of date. Refresh to see the latest.
View
36 FluentCassandra_All.sln
@@ -79,16 +79,6 @@ Global
{9DAF7022-5820-4214-B13E-AC0A1B37691F}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{9DAF7022-5820-4214-B13E-AC0A1B37691F}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{9DAF7022-5820-4214-B13E-AC0A1B37691F}.Release|x86.ActiveCfg = Release|Any CPU
- {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Debug|Any CPU.ActiveCfg = Debug|x86
- {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
- {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Debug|Mixed Platforms.Build.0 = Debug|x86
- {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Debug|x86.ActiveCfg = Debug|x86
- {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Debug|x86.Build.0 = Debug|x86
- {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Release|Any CPU.ActiveCfg = Release|x86
- {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Release|Mixed Platforms.ActiveCfg = Release|x86
- {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Release|Mixed Platforms.Build.0 = Release|x86
- {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Release|x86.ActiveCfg = Release|x86
- {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Release|x86.Build.0 = Release|x86
{CACA3463-BBEE-4C7E-AC89-49240B0D8F46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CACA3463-BBEE-4C7E-AC89-49240B0D8F46}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{CACA3463-BBEE-4C7E-AC89-49240B0D8F46}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
@@ -100,26 +90,6 @@ Global
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
- {DE6B46DE-C37A-49AF-8B9A-B9B6D4F03A55}.Debug|Any CPU.ActiveCfg = Debug|x86
- {DE6B46DE-C37A-49AF-8B9A-B9B6D4F03A55}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
- {DE6B46DE-C37A-49AF-8B9A-B9B6D4F03A55}.Debug|Mixed Platforms.Build.0 = Debug|x86
- {DE6B46DE-C37A-49AF-8B9A-B9B6D4F03A55}.Debug|x86.ActiveCfg = Debug|x86
- {DE6B46DE-C37A-49AF-8B9A-B9B6D4F03A55}.Debug|x86.Build.0 = Debug|x86
- {DE6B46DE-C37A-49AF-8B9A-B9B6D4F03A55}.Release|Any CPU.ActiveCfg = Release|x86
- {DE6B46DE-C37A-49AF-8B9A-B9B6D4F03A55}.Release|Mixed Platforms.ActiveCfg = Release|x86
- {DE6B46DE-C37A-49AF-8B9A-B9B6D4F03A55}.Release|Mixed Platforms.Build.0 = Release|x86
- {DE6B46DE-C37A-49AF-8B9A-B9B6D4F03A55}.Release|x86.ActiveCfg = Release|x86
- {DE6B46DE-C37A-49AF-8B9A-B9B6D4F03A55}.Release|x86.Build.0 = Release|x86
- {EAA32600-3C2A-4B34-B9B2-5764F280FCE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {EAA32600-3C2A-4B34-B9B2-5764F280FCE3}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {EAA32600-3C2A-4B34-B9B2-5764F280FCE3}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
- {EAA32600-3C2A-4B34-B9B2-5764F280FCE3}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
- {EAA32600-3C2A-4B34-B9B2-5764F280FCE3}.Debug|x86.ActiveCfg = Debug|Any CPU
- {EAA32600-3C2A-4B34-B9B2-5764F280FCE3}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {EAA32600-3C2A-4B34-B9B2-5764F280FCE3}.Release|Any CPU.Build.0 = Release|Any CPU
- {EAA32600-3C2A-4B34-B9B2-5764F280FCE3}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
- {EAA32600-3C2A-4B34-B9B2-5764F280FCE3}.Release|Mixed Platforms.Build.0 = Release|Any CPU
- {EAA32600-3C2A-4B34-B9B2-5764F280FCE3}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{AC3818E2-E260-4193-A3D1-6E3FF87383F6} = {1A88B962-9A09-4692-80D3-E88712A9E516}
@@ -151,10 +121,4 @@ Global
$6.inheritsSet = Mono
version = 1.0.0
EndGlobalSection
- GlobalSection(TestCaseManagementSettings) = postSolution
- CategoryFile = FluentCassandra.vsmdi
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
EndGlobal
View
3  test/FluentCassandra.Sandbox/FluentCassandra.Sandbox.csproj
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -36,6 +36,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
+ <Reference Include="System.configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
<Reference Include="System.Xml.Linq" />
View
775 test/FluentCassandra.Sandbox/Program.cs
@@ -2,367 +2,490 @@
using System.Linq;
using FluentCassandra.Connections;
using FluentCassandra.Types;
+using FluentCassandra.Linq;
+using System.Collections.Generic;
+using System.Configuration;
+
namespace FluentCassandra.Sandbox
{
- internal class Program
- {
- private const string KeyspaceName = "Blog";
- private static readonly Server Server = new Server("localhost");
-
- #region Setup
-
- private static void SetupKeyspace()
- {
- using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
- {
- if (db.KeyspaceExists(KeyspaceName))
- db.DropKeyspace(KeyspaceName);
-
- var keyspace = new CassandraKeyspace(new CassandraKeyspaceSchema {
- Name = KeyspaceName,
- }, db);
-
- keyspace.TryCreateSelf();
-
- // create column family using CQL
- db.ExecuteNonQuery(@"
-CREATE COLUMNFAMILY Posts (
- KEY ascii PRIMARY KEY,
- Title text,
- Body text,
- Author text,
- PostedOn timestamp
-);");
-
- // create column family using API
- keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema {
- FamilyName = "Tags",
- KeyValueType = CassandraType.AsciiType,
- ColumnNameType = CassandraType.Int32Type,
- DefaultColumnValueType = CassandraType.UTF8Type
- });
-
- // create super column family using API
- keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema {
- FamilyName = "Comments",
- FamilyType = ColumnType.Super,
- KeyValueType = CassandraType.AsciiType,
- SuperColumnNameType = CassandraType.DateType,
- ColumnNameType = CassandraType.UTF8Type,
- DefaultColumnValueType = CassandraType.UTF8Type
- });
- }
- }
-
- #endregion
-
- #region Console Helpers
-
- private static void ConsoleHeader(string header)
- {
- Console.WriteLine(@"
+ internal class Program
+ {
+ public static readonly string KeyspaceName = ConfigurationManager.AppSettings["TestKeySpace"];
+ public static readonly Server Server = new Server(ConfigurationManager.AppSettings["TestServer"]);
+
+
+ #region Setup
+
+ private static void SetupKeyspace()
+ {
+ using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
+ {
+ if (db.KeyspaceExists(KeyspaceName))
+ db.DropKeyspace(KeyspaceName);
+
+ var keyspace = new CassandraKeyspace(new CassandraKeyspaceSchema
+ {
+ Name = KeyspaceName,
+ }, db);
+
+ keyspace.TryCreateSelf();
+
+ // create column family using CQL
+ db.ExecuteNonQuery(@"
+ CREATE COLUMNFAMILY Posts (
+ KEY ascii PRIMARY KEY,
+ Title text,
+ Body text,
+ Author text,
+ PostedOn timestamp
+ );");
+
+ // create column family using API
+ keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema
+ {
+ FamilyName = "Tags",
+ KeyValueType = CassandraType.AsciiType,
+ ColumnNameType = CassandraType.Int32Type,
+ DefaultColumnValueType = CassandraType.UTF8Type
+ });
+
+ // create super column family using API
+ keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema
+ {
+ FamilyName = "Comments",
+ FamilyType = ColumnType.Super,
+ KeyValueType = CassandraType.AsciiType,
+ SuperColumnNameType = CassandraType.DateType,
+ ColumnNameType = CassandraType.UTF8Type,
+ DefaultColumnValueType = CassandraType.UTF8Type
+ });
+ }
+ }
+
+ #endregion
+
+ #region Console Helpers
+
+ private static void ConsoleHeader(string header)
+ {
+ Console.WriteLine(@"
************************************************
** " + header + @"
************************************************");
- }
-
- #endregion
-
- #region Create Post
-
- private static void CreateFirstPost()
- {
- using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
- {
- var key = "first-blog-post";
-
- var postFamily = db.GetColumnFamily("Posts");
- var tagsFamily = db.GetColumnFamily("Tags");
-
- // create post
- ConsoleHeader("create post");
- dynamic post = postFamily.CreateRecord(key: key);
- post.Title = "My First Cassandra Post";
- post.Body = "Blah. Blah. Blah. about my first post on how great Cassandra is to work with.";
- post.Author = "Nick Berardi";
- post.PostedOn = DateTimeOffset.Now;
-
- // create tags
- ConsoleHeader("create post tags");
- dynamic tags = tagsFamily.CreateRecord(key: key);
- tags[0] = "Cassandra";
- tags[1] = ".NET";
- tags[2] = "Database";
- tags[3] = "NoSQL";
-
- // attach the post to the database
- ConsoleHeader("attaching record");
- db.Attach(post);
- db.Attach(tags);
-
- // save the changes
- ConsoleHeader("saving changes");
- db.SaveChanges();
- }
- }
-
- private static void CreateSecondPost()
- {
- using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
- {
- var key = "second-blog-post";
-
- var postFamily = db.GetColumnFamily("Posts");
- var tagsFamily = db.GetColumnFamily("Tags");
-
- // create post
- ConsoleHeader("create post");
- dynamic post = postFamily.CreateRecord(key: key);
- post.Title = "My Second Cassandra Post";
- post.Body = "Blah. Blah. Blah. about my second post on how great Cassandra is to work with.";
- post.Author = "Nick Berardi";
- post.PostedOn = DateTimeOffset.Now;
-
- // create tags
- ConsoleHeader("create post tags");
- dynamic tags = tagsFamily.CreateRecord(key: key);
- tags[0] = "Cassandra";
- tags[1] = ".NET";
- tags[2] = "Database";
- tags[3] = "NoSQL";
-
- // attach the post to the database
- ConsoleHeader("attaching record");
- db.Attach(post);
- db.Attach(tags);
-
- // save the changes
- ConsoleHeader("saving changes");
- db.SaveChanges();
- }
- }
-
- #endregion
-
- #region Read Post
-
- private static void ReadFirstPost()
- {
- using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
- {
- var key = "first-blog-post";
-
- var postFamily = db.GetColumnFamily("Posts");
- var tagsFamily = db.GetColumnFamily("Tags");
-
- // get the post back from the database
- ConsoleHeader("getting 'first-blog-post'");
-
- // query using API
- dynamic post = postFamily.Get(key).FirstOrDefault();
-
- // query using CQL-LINQ
- dynamic tags = (
- from t in tagsFamily
- where t.Key == key
- select t).FirstOrDefault();
-
- // show details
- ConsoleHeader("showing post");
- Console.WriteLine(
- String.Format("=={0} by {1}==\n{2}",
- post.Title,
- post.Author,
- post.Body
- ));
-
- // show tags
- ConsoleHeader("showing tags");
- foreach (var tag in tags)
- Console.WriteLine(String.Format("{0}:{1}", tag.ColumnName, tag.ColumnValue));
- }
- }
-
- private static void ReadAllPosts()
- {
- using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
- {
- var key = "first-blog-post";
-
- var tagsFamily = db.GetColumnFamily("Tags");
-
- // get the post back from the database
- ConsoleHeader("getting 'first-blog-post'");
-
- // query using CQL
- var posts = db.ExecuteQuery("SELECT * FROM Posts LIMIT 25");
-
- // query using API
- dynamic tags = tagsFamily.Get(key).FirstOrDefault();
-
- // show details
- ConsoleHeader("showing post");
- foreach (dynamic post in posts)
- {
- Console.WriteLine(
- String.Format("=={0} by {1}==\n{2}",
- post.Title,
- post.Author,
- post.Body
- ));
- }
-
- // show tags
- ConsoleHeader("showing tags");
- foreach (var tag in tags)
- Console.WriteLine(String.Format("{0}:{1}", tag.ColumnName, tag.ColumnValue));
- }
- }
-
- #endregion
-
- #region Update Post
-
- private static void UpdateFirstPost()
- {
- using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
- {
- var key = "first-blog-post";
-
- var postFamily = db.GetColumnFamily("Posts");
-
- // get the post back from the database
- ConsoleHeader("getting 'first-blog-post' for update");
-
- // query using API
- dynamic post = postFamily.Get(key).FirstOrDefault();
-
- post.Title = post.Title + "(updated)";
- post.Body = post.Body + "(updated)";
- post.Author = post.Author + "(updated)";
- post.PostedOn = DateTimeOffset.Now;
-
- // attach the post to the database
- ConsoleHeader("attaching record");
- db.Attach(post);
-
- // save the changes
- ConsoleHeader("saving changes");
- db.SaveChanges();
- }
- }
-
- #endregion
+ }
+
+ #endregion
+
+ #region Create Post
+
+ private static void CreateFirstPost()
+ {
+ using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
+ {
+ var key = "first-blog-post";
+
+ var postFamily = db.GetColumnFamily("Posts");
+ var tagsFamily = db.GetColumnFamily("Tags");
+
+ // create post
+ ConsoleHeader("create post");
+ dynamic post = postFamily.CreateRecord(key: key);
+ post.Title = "My First Cassandra Post";
+ post.Body = "Blah. Blah. Blah. about my first post on how great Cassandra is to work with.";
+ post.Author = "Nick Berardi";
+ post.PostedOn = DateTimeOffset.Now;
+
+
+ // create tags
+ ConsoleHeader("create post tags");
+ dynamic tags = tagsFamily.CreateRecord(key: key);
+ tags[0] = "Cassandra";
+ tags[1] = ".NET";
+ tags[2] = "Database";
+ tags[3] = "NoSQL";
+
+ // attach the post to the database
+ ConsoleHeader("attaching record");
+ db.Attach(post);
+ db.Attach(tags);
+
+ // save the changes
+ ConsoleHeader("saving changes");
+ db.SaveChanges();
+ }
+ }
+
+ private static void CreateSecondPost()
+ {
+ using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
+ {
+ var key = "second-blog-post";
+
+ var postFamily = db.GetColumnFamily("Posts");
+ var tagsFamily = db.GetColumnFamily("Tags");
+
+ // create post
+ ConsoleHeader("create post");
+ dynamic post = postFamily.CreateRecord(key: key);
+ post.Title = "My Second Cassandra Post";
+ post.Body = "Blah. Blah. Blah. about my second post on how great Cassandra is to work with.";
+ post.Author = "Nick Berardi";
+ post.PostedOn = DateTimeOffset.Now;
+
+ // create tags
+ ConsoleHeader("create post tags");
+ dynamic tags = tagsFamily.CreateRecord(key: key);
+ tags[0] = "Cassandra";
+ tags[1] = ".NET";
+ tags[2] = "Database";
+ tags[3] = "NoSQL";
+
+ // attach the post to the database
+ ConsoleHeader("attaching record");
+ db.Attach(post);
+ db.Attach(tags);
+
+ // save the changes
+ ConsoleHeader("saving changes");
+ db.SaveChanges();
+ }
+ }
+
+ #endregion
+
+ #region Read Post
+
+ private static void ReadFirstPost()
+ {
+ using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
+ {
+ var key = "first-blog-post";
+
+ var postFamily = db.GetColumnFamily("Posts");
+ var tagsFamily = db.GetColumnFamily("Tags");
+
+ // get the post back from the database
+ ConsoleHeader("getting 'first-blog-post'");
+
+ // query using API
+ dynamic post = postFamily.Get(key).FirstOrDefault();
+
+ // query using CQL-LINQ
+ dynamic tags = (
+ from t in tagsFamily
+ where t.Key == key
+ select t).FirstOrDefault();
+
+ // show details
+ ConsoleHeader("showing post");
+ Console.WriteLine(
+ String.Format("=={0} by {1}==\n{2}",
+ post.Title,
+ post.Author,
+ post.Body
+ ));
+
+ // show tags
+ ConsoleHeader("showing tags");
+ foreach (var tag in tags)
+ Console.WriteLine(String.Format("{0}:{1}", tag.ColumnName, tag.ColumnValue));
+ }
+ }
+
+ private static void ReadAllPosts()
+ {
+ using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
+ {
+ var key = "first-blog-post";
+
+ var tagsFamily = db.GetColumnFamily("Tags");
+
+ // get the post back from the database
+ ConsoleHeader("getting 'first-blog-post'");
+
+ // query using CQL
+ var posts = db.ExecuteQuery("SELECT * FROM Posts LIMIT 25");
+
+ // query using API
+ dynamic tags = tagsFamily.Get(key).FirstOrDefault();
+
+ // show details
+ ConsoleHeader("showing post");
+ foreach (dynamic post in posts)
+ {
+ Console.WriteLine(
+ String.Format("=={0} by {1}==\n{2}",
+ post.Title,
+ post.Author,
+ post.Body
+ ));
+ }
+
+ // show tags
+ ConsoleHeader("showing tags");
+ foreach (var tag in tags)
+ Console.WriteLine(String.Format("{0}:{1}", tag.ColumnName, tag.ColumnValue));
+ }
+ }
+
+ #endregion
+
+ #region Update Post
+
+ private static void UpdateFirstPost()
+ {
+ using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
+ {
+ var key = "first-blog-post";
+
+ var postFamily = db.GetColumnFamily("Posts");
+
+ // get the post back from the database
+ ConsoleHeader("getting 'first-blog-post' for update");
+
+ // query using API
+ dynamic post = postFamily.Get(key).FirstOrDefault();
+
+ post.Title = post.Title + "(updated)";
+ post.Body = post.Body + "(updated)";
+ post.Author = post.Author + "(updated)";
+ post.PostedOn = DateTimeOffset.Now;
+
+ // attach the post to the database
+ ConsoleHeader("attaching record");
+ db.Attach(post);
+
+ // save the changes
+ ConsoleHeader("saving changes");
+ db.SaveChanges();
+ }
+ }
+
+ #endregion
+
+ #region Create Comments
+
+ private static void CreateComments()
+ {
+ using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
+ {
+ var key = "first-blog-post";
+
+ // get the comments family
+ var commentsFamily = db.GetSuperColumnFamily("Comments");
+
+ ConsoleHeader("create comments");
+ dynamic postComments = commentsFamily.CreateRecord(key: key);
+
+ // lets attach it to the database before we add the comments
+ db.Attach(postComments);
+
+ var dt = new DateTime(2010, 11, 29, 5, 03, 00, DateTimeKind.Local);
+
+ // add 5 comments
+ for (int i = 0; i < 5; i++)
+ {
+ dynamic comment = postComments.CreateSuperColumn();
+ comment.Name = "Nick Berardi";
+ comment.Email = "nick@coderjournal.com";
+ comment.Website = "www.coderjournal.com";
+ comment.Comment = "Wow fluent cassandra is really great and easy to use.";
+
+ var commentPostedOn = dt;
+ postComments[commentPostedOn] = comment;
+
+ Console.WriteLine("Comment " + (i + 1) + " Posted On " + commentPostedOn.ToLongTimeString());
+ dt = dt.AddMinutes(2);
+ }
+
+ // save the comments
+ db.SaveChanges();
+ }
+ }
+
+ #endregion
+
+ #region Read Comments
+
+ private static void ReadComments()
+ {
+ using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
+ {
+ var key = "first-blog-post";
+ var lastDate = DateTime.Now;
+
+ // get the comments family
+ var commentsFamily = db.GetSuperColumnFamily("Comments");
+
+ for (int page = 0; page < 2; page++)
+ {
+ // lets back the date off by a millisecond so we don't get paging overlaps
+ lastDate = lastDate.AddMilliseconds(-1D);
+
+ ConsoleHeader("showing page " + page + " of comments starting at " + lastDate.ToLocalTime());
+
+ // query using API
+ var comments = commentsFamily.Get(key)
+ .ReverseColumns()
+ .StartWithColumn(lastDate)
+ .TakeColumns(3)
+ .FirstOrDefault();
+
+ foreach (dynamic comment in comments)
+ {
+ var dateTime = (DateTime)comment.ColumnName;
+
+ Console.WriteLine(String.Format("{0:T} : {1} ({2} - {3})",
+ dateTime.ToLocalTime(),
+ comment.Name,
+ comment.Email,
+ comment.Website
+ ));
+
+ lastDate = dateTime;
+ }
+ }
+ }
+ }
+
+ #endregion
+
+ #region CreateColumnFamilyWithUUIDOperator
+ private static void CreateColumnFamilyWithUUIDOperator()
+ {
+
+ using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
+ {
+
+ db.ExecuteNonQuery("CREATE TABLE TestCF (KEY text PRIMARY KEY) WITH comparator=uuid AND default_validation=text;");
+
+ Guid columnName1 = GuidGenerator.GenerateTimeBasedGuid(DateTime.Now);
+
+ Guid columnName2 = GuidGenerator.GenerateTimeBasedGuid(DateTime.Now);
+
+ db.ExecuteNonQuery(string.Format("INSERT INTO TestCF (KEY, {0}, {1}) VALUES ('Key1', 'Value1', 'Value2')", columnName1, columnName2));
+
+ List<ICqlRow> rows = db.ExecuteQuery("SELECT * FROM TestCF WHERE KEY = 'Key1'").ToList();
+
+ Guid value = rows[0].Columns[1].ColumnName.GetValue<Guid>();
+
+ ConsoleHeader("Returned data from db");
+ ConsoleHeader(value.ToString());
+ }
+ }
+ #endregion
+
+ #region CreateColumnFamilyWithTimestampOperator
+ private static void CreateColumnFamilyWithTimestampOperator()
+ {
+ using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
+ {
+
+ db.ExecuteNonQuery("CREATE TABLE TestCF2 (KEY text PRIMARY KEY) WITH comparator=timestamp AND default_validation=text;");
- #region Create Comments
+ DateTimeOffset UnixStart = new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero);
+ DateTimeOffset TimeNow = DateTimeOffset.UtcNow;
- private static void CreateComments()
- {
- using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
- {
- var key = "first-blog-post";
+ var columnName2 = Convert.ToInt64(Math.Floor((TimeNow - UnixStart).TotalMilliseconds));
+ var columnName1 = columnName2 + 5000;
- // get the comments family
- var commentsFamily = db.GetSuperColumnFamily("Comments");
+ db.ExecuteNonQuery(string.Format("INSERT INTO TestCF2 (KEY, {0}, {1}) VALUES ('Key1', 'Value1', 'Value2')", columnName1, columnName2));
- ConsoleHeader("create comments");
- dynamic postComments = commentsFamily.CreateRecord(key: key);
+ List<ICqlRow> rows = db.ExecuteQuery("SELECT * FROM TestCF2 WHERE KEY = 'Key1'").ToList();
- // lets attach it to the database before we add the comments
- db.Attach(postComments);
+ DateTime value1 = rows[0].Columns[1].ColumnName.GetValue<DateTime>();
+ DateTime value2 = rows[0].Columns[2].ColumnName.GetValue<DateTime>();
- var dt = new DateTime(2010, 11, 29, 5, 03, 00, DateTimeKind.Local);
+ ConsoleHeader("Returned data from db for timestamp comparator");
+ ConsoleHeader(value1.ToString());
+ ConsoleHeader(value2.ToString());
- // add 5 comments
- for (int i = 0; i < 5; i++)
- {
- dynamic comment = postComments.CreateSuperColumn();
- comment.Name = "Nick Berardi";
- comment.Email = "nick@coderjournal.com";
- comment.Website = "www.coderjournal.com";
- comment.Comment = "Wow fluent cassandra is really great and easy to use.";
+ }
+ }
+ #endregion
+ #region TombstoneTest
+ private static void TombstoneTest()
+ {
+ using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
+ {
- var commentPostedOn = dt;
- postComments[commentPostedOn] = comment;
- Console.WriteLine("Comment " + (i + 1) + " Posted On " + commentPostedOn.ToLongTimeString());
- dt = dt.AddMinutes(2);
- }
+ db.ExecuteNonQuery("CREATE TABLE OfferReservation (KEY int PRIMARY KEY) WITH comparator = text AND default_validation = float");
+ db.ExecuteNonQuery("INSERT INTO OfferReservation (KEY, '25:100') VALUES (5, 0.25)");
+ db.ExecuteNonQuery("INSERT INTO OfferReservation (KEY, '25:101') VALUES (5, 0.25)");
+ db.ExecuteNonQuery("DELETE '25:100' FROM OfferReservation WHERE KEY = 5");
- // save the comments
- db.SaveChanges();
- }
- }
+ List<ICqlRow> rows = db.ExecuteQuery("SELECT '25:100' FROM OfferReservation WHERE KEY = 5").ToList();
- #endregion
+ }
+ }
+ #endregion
- #region Read Comments
+ #region BigDecimalTest
+ private static void BigDecimalTest()
+ {
+ using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
+ {
- private static void ReadComments()
- {
- using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
- {
- var key = "first-blog-post";
- var lastDate = DateTime.Now;
+ // arrange
+ db.ExecuteNonQuery("CREATE TABLE OfferReservation2 (KEY text PRIMARY KEY) WITH comparator = text AND default_validation = decimal");
+ db.ExecuteNonQuery("INSERT INTO OfferReservation2 (KEY, 'MyColumn') VALUES ('Key0', 1000000000000000000)");
+ db.ExecuteNonQuery("INSERT INTO OfferReservation2 (KEY, 'MyColumn') VALUES ('Key1', 0.25)");
+ db.ExecuteNonQuery("INSERT INTO OfferReservation2 (KEY, 'MyColumn') VALUES ('Key2', 2000000000000.1234)");
+ db.ExecuteNonQuery("INSERT INTO OfferReservation2 (KEY, 'MyColumn') VALUES ('Key3', -0.25)");
+ db.ExecuteNonQuery("INSERT INTO OfferReservation2 (KEY, 'MyColumn') VALUES ('Key4', -0.25122333)");
- // get the comments family
- var commentsFamily = db.GetSuperColumnFamily("Comments");
+ var actual = db.ExecuteQuery("SELECT * FROM OfferReservation2");
- for (int page = 0; page < 2; page++)
- {
- // lets back the date off by a millisecond so we don't get paging overlaps
- lastDate = lastDate.AddMilliseconds(-1D);
+ var results = actual.ToList();
- ConsoleHeader("showing page " + page + " of comments starting at " + lastDate.ToLocalTime());
- // query using API
- var comments = commentsFamily.Get(key)
- .ReverseColumns()
- .StartWithColumn(lastDate)
- .TakeColumns(3)
- .FirstOrDefault();
+ var firstValue = (decimal)results.First(x => x.Key == "Key0")["MyColumn"];
+ var secondValue = (decimal)results.First(x => x.Key == "Key1")["MyColumn"];
+ var thirdValue = (decimal)results.First(x => x.Key == "Key2")["MyColumn"];
+ var fourthValue = (decimal)results.First(x => x.Key == "Key3")["MyColumn"];
+ var fifthValue = (decimal)results.First(x => x.Key == "Key4")["MyColumn"];
- foreach (dynamic comment in comments)
- {
- var dateTime = (DateTime)comment.ColumnName;
+ ConsoleHeader("Returned data from Big Decimal Test");
+ ConsoleHeader(firstValue.ToString());
+ ConsoleHeader(secondValue.ToString());
+ ConsoleHeader(thirdValue.ToString());
+ ConsoleHeader(fourthValue.ToString());
+ ConsoleHeader(fifthValue.ToString());
+ }
+ }
+ #endregion
+
+ private static void Main(string[] args)
+ {
+ SetupKeyspace();
- Console.WriteLine(String.Format("{0:T} : {1} ({2} - {3})",
- dateTime.ToLocalTime(),
- comment.Name,
- comment.Email,
- comment.Website
- ));
+ CreateFirstPost();
- lastDate = dateTime;
- }
- }
- }
- }
+ CreateSecondPost();
- #endregion
+ ReadFirstPost();
- private static void Main(string[] args)
- {
- SetupKeyspace();
+ ReadAllPosts();
- CreateFirstPost();
+ UpdateFirstPost();
- CreateSecondPost();
+ ReadFirstPost();
- ReadFirstPost();
+ CreateComments();
- ReadAllPosts();
+ CreateColumnFamilyWithUUIDOperator();
- UpdateFirstPost();
+ CreateColumnFamilyWithTimestampOperator();
- ReadFirstPost();
+ ReadComments();
- CreateComments();
+ TombstoneTest();
- ReadComments();
+ BigDecimalTest();
- Console.Read();
- }
- }
+ Console.Read();
+ }
+ }
}
View
9 test/FluentCassandra.Sandbox/app.config
@@ -1,3 +1,8 @@
-<?xml version="1.0"?>
+<?xml version="1.0" encoding="utf-8" ?>
<configuration>
-<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
+ <appSettings>
+ <add key="TestServer" value="dev-cass1-1"></add>
+ <add key="TestPort" value="9160"></add>
+ <add key="TestKeySpace" value="TestingLH2"></add>
+ </appSettings>
+</configuration>
View
5 test/FluentCassandra.Tests/CassandraDatabaseSetup.cs
@@ -3,6 +3,7 @@
using FluentCassandra.Connections;
using FluentCassandra.Types;
using System.Collections.Generic;
+using System.Configuration;
namespace FluentCassandra
{
@@ -37,8 +38,8 @@ public class User
public const string TestStandardName = "Test1";
public const string TestSuperName = "SubTest1";
- public const string Keyspace = "Testing";
- public static readonly Server Server = new Server("localhost");
+ public static readonly string Keyspace = ConfigurationManager.AppSettings["TestKeySpace"];
+ public static readonly Server Server = new Server(ConfigurationManager.AppSettings["TestServer"]);
public CassandraDatabaseSetup(bool reset = false)
{
View
5 test/FluentCassandra.Tests/Connections/ConnectionProviderTests.cs
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using Xunit;
+using System.Configuration;
namespace FluentCassandra.Connections
{
@@ -12,7 +13,7 @@ public void NormalConnectionProvider()
{
// arrange
var expected = typeof(NormalConnectionProvider);
- var connectionString = "Keyspace=Testing";
+ var connectionString = "Keyspace=" + ConfigurationManager.AppSettings["TestKeySpace"];
// act
var result = new ConnectionBuilder(connectionString);
@@ -27,7 +28,7 @@ public void PooledConnectionProvider()
{
// arrange
var expected = typeof(PooledConnectionProvider);
- var connectionString = "Keyspace=Testing;Pooling=True";
+ var connectionString = "Keyspace=" + ConfigurationManager.AppSettings["TestKeySpace"] + ";Pooling=True";
// act
var result = new ConnectionBuilder(connectionString);
View
9 test/FluentCassandra.Tests/Connections/NormalConnectionProviderTests.cs
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using Xunit;
+using System.Configuration;
namespace FluentCassandra.Connections
{
@@ -10,16 +11,16 @@ public class NormalConnectionProviderTests
/// <summary>
/// Needed to switch to testing ports since the network timeout was making the tests unbearably long.
/// </summary>
- private readonly string _failoverConnectionString = "Keyspace=Testing;Connection Timeout=1;Server=127.0.0.1:1234,127.0.0.1:4567,127.0.0.1";
+ private readonly string _failoverConnectionString = "Keyspace=" + ConfigurationManager.AppSettings["TestKeySpace"] + ";Connection Timeout=1;Server=" + ConfigurationManager.AppSettings["TestServer"] + ":" + ConfigurationManager.AppSettings["TestPort"] + "";
[Fact]
public void Fails_Over()
{
// arrange
- var expectedHost = "127.0.0.1";
- var expectedPort = Server.DefaultPort;
+ var expectedHost = ConfigurationManager.AppSettings["TestServer"];
+ var expectedPort = Convert.ToInt16(ConfigurationManager.AppSettings["TestPort"]);
- // act
+ // act
var result = new ConnectionBuilder(_failoverConnectionString);
var provider = ConnectionProviderFactory.Get(result);
var conn = provider.Open();
View
6 test/FluentCassandra.Tests/FluentCassandra.Tests.csproj
@@ -36,6 +36,7 @@
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System" />
+ <Reference Include="System.configuration" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
@@ -108,7 +109,10 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
- <None Include="packages.config" />
+ <None Include="app.config" />
+ <None Include="packages.config">
+ <SubType>Designer</SubType>
+ </None>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
View
5 test/FluentCassandra.Tests/Linq/LinqToCqlObjectsTests.cs
@@ -3,6 +3,7 @@
using Xunit;
using FluentCassandra.Types;
using System;
+using System.Configuration;
namespace FluentCassandra.Linq
{
@@ -22,8 +23,8 @@ public class User
public LinqToCqlObjectsTests()
{
- var keyspaceName = "Testing";
- var server = new Server("localhost");
+ var keyspaceName = ConfigurationManager.AppSettings["TestKeySpace"];
+ var server = new Server(ConfigurationManager.AppSettings["TestServer"]);
_db = new CassandraContext(keyspace: keyspaceName, server: server);
_family = _db.GetColumnFamily<AsciiType>("Users");
View
5 test/FluentCassandra.Tests/Linq/LinqToCqlTests.cs
@@ -3,6 +3,7 @@
using Xunit;
using FluentCassandra.Types;
using System;
+using System.Configuration;
namespace FluentCassandra.Linq
{
@@ -14,8 +15,8 @@ public class LinqToCqlTests : IDisposable
public LinqToCqlTests()
{
- var keyspaceName = "Testing";
- var server = new Server("localhost");
+ var keyspaceName = ConfigurationManager.AppSettings["TestKeySpace"];
+ var server = new Server(ConfigurationManager.AppSettings["TestServer"]);
_db = new CassandraContext(keyspace: keyspaceName, server: server);
_family = _db.GetColumnFamily<AsciiType>("Users");
Something went wrong with that request. Please try again.