Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #136 from Aaronontheweb/master

Super counter column support + unit tests + unit test bug fixes
  • Loading branch information...
commit 84fdae0c444d4bb7263ece4cd6282218f106d40a 2 parents 98bef21 + 8664730
@Aaronontheweb Aaronontheweb authored
View
8 src/CassandraColumnFamilyOperations.cs
@@ -62,6 +62,14 @@ public static void InsertCounterColumn(this CassandraColumnFamily family, Cassan
family.ExecuteOperation(op);
}
+ public static void InsertCounterColumn(this CassandraColumnFamily family, CassandraObject key,
+ CassandraObject superColumnName, CassandraObject columnName,
+ long columnValue)
+ {
+ var op = new AddColumn(key, superColumnName, columnName, columnValue);
+ family.ExecuteOperation(op);
+ }
+
#endregion
#region GetColumn
View
9 test/FluentCassandra.Integration.Tests/CassandraDatabaseSetup.cs
@@ -17,6 +17,7 @@ public class CassandraDatabaseSetup
public CassandraColumnFamily UserFamily;
public CassandraColumnFamily CounterFamily;
+ public CassandraSuperColumnFamily SuperCounterFamily;
public User[] Users = new[] {
new User { Id = 1, Name = "Darren Gemmell", Email = "darren@somewhere.com", Age = 32 },
@@ -54,6 +55,7 @@ public CassandraDatabaseSetup(bool reset = false, string cqlVersion = CqlVersion
SuperFamily = DB.GetColumnFamily<AsciiType, AsciiType>("Super");
UserFamily = DB.GetColumnFamily("Users");
CounterFamily = DB.GetColumnFamily("Counters");
+ SuperCounterFamily = DB.GetSuperColumnFamily("SuperCounters");
if (exists && !reset)
return;
@@ -90,6 +92,13 @@ public void ResetDatabase()
ColumnNameType = CassandraType.AsciiType,
DefaultColumnValueType = CassandraType.CounterColumnType
});
+ keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema(type:ColumnType.Super)
+ {
+ FamilyName = "SuperCounters",
+ SuperColumnNameType = CassandraType.AsciiType,
+ ColumnNameType = CassandraType.AsciiType,
+ DefaultColumnValueType = CassandraType.CounterColumnType
+ });
keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema {
FamilyName = "StandardDecimalType",
ColumnNameType = CassandraType.DecimalType
View
1  test/FluentCassandra.Integration.Tests/FluentCassandra.Integration.Tests.csproj
@@ -56,6 +56,7 @@
<Compile Include="Operations\GetRangeSliceTest.cs" />
<Compile Include="Operations\GetSliceTest.cs" />
<Compile Include="Operations\InsertColumnTest.cs" />
+ <Compile Include="Operations\InsertCounterColumnTest.cs" />
<Compile Include="Operations\MultiGetSliceTest.cs" />
<Compile Include="Operations\RemoveColumnTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
View
7 test/FluentCassandra.Integration.Tests/Operations/InsertColumnTest.cs
@@ -57,12 +57,13 @@ public void SuperColumnFamily()
// act
_superFamily.InsertColumn(_testKey, _testSuperName, _testName, value, timestamp, timeToLive);
- var column = _family.Get(_testKey).Execute();
+ var column = _superFamily.Get(_testKey).Execute();
var actual = column.FirstOrDefault().Columns.FirstOrDefault();
// assert
- Assert.Equal(_testName, (string)actual.ColumnName);
- Assert.Equal(value, (double)actual.ColumnValue);
+ Assert.Equal(_testSuperName, (string)actual.ColumnName);
+ Assert.Equal(_testName, (string)actual.Columns[0].ColumnName);
+ Assert.Equal(value, (double)actual.Columns[0].ColumnValue);
}
}
}
View
65 test/FluentCassandra.Integration.Tests/Operations/InsertCounterColumnTest.cs
@@ -0,0 +1,65 @@
+using System;
+using System.Linq;
+using FluentCassandra.Types;
+using Xunit;
+
+
+namespace FluentCassandra.Integration.Tests.Operations
+{
+ public class InsertCounterColumnTest : IUseFixture<CassandraDatabaseSetupFixture>, IDisposable
+ {
+ private CassandraContext _db;
+ private CassandraColumnFamily _counterFamily;
+ private CassandraSuperColumnFamily _superCounterFamily;
+
+ public void SetFixture(CassandraDatabaseSetupFixture data)
+ {
+ var setup = data.DatabaseSetup();
+ _db = setup.DB;
+ _counterFamily = setup.CounterFamily;
+ _superCounterFamily = setup.SuperCounterFamily;
+ }
+
+ public void Dispose()
+ {
+ _db.Dispose();
+ }
+
+ private const string _testKey = "CounterTest1";
+ private const string _testName = "Test1";
+ private const string _testSuperName = "SubTest1";
+
+ [Fact]
+ public void CounterColumnFamily()
+ {
+ //arrange
+ long value = 1L;
+
+ //act
+ _counterFamily.InsertCounterColumn(_testKey, _testName, value);
+ var column = _counterFamily.Get(_testKey).Execute();
+ var actual = column.FirstOrDefault().Columns.FirstOrDefault();
+
+ // assert
+ Assert.Equal(_testName, (string)actual.ColumnName);
+ Assert.Equal(value, (double)actual.ColumnValue);
+ }
+
+ [Fact]
+ public void SuperCounterColumnFamily()
+ {
+ //arrange
+ long value = 1L;
+
+ //act
+ _superCounterFamily.InsertCounterColumn(_testKey, _testSuperName, _testName, value);
+ var column = _superCounterFamily.Get(_testKey).Execute();
+ var actual = column.FirstOrDefault().Columns.FirstOrDefault();
+
+ // assert
+ Assert.Equal(_testSuperName, (string)actual.ColumnName);
+ Assert.Equal(_testName, (string)actual.Columns[0].ColumnName);
+ Assert.Equal(value, (double)actual.Columns[0].ColumnValue);
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.