public void AttributeBased_Single_PartitionKey_Test() { var definition = new AttributeBasedTypeDefinition(typeof(DecoratedUser)); Assert.False(definition.CaseSensitive); Assert.False(definition.CompactStorage); Assert.False(definition.AllowFiltering); Assert.False(definition.ExplicitColumns); Assert.AreEqual(0, definition.ClusteringKeys.Length); CollectionAssert.AreEqual(new[] { "userid" }, definition.PartitionKeys); }
public void AttributeBased_Composite_PartitionKey_Test() { var definition = new AttributeBasedTypeDefinition(typeof(DecoratedTimeSeries)); Assert.True(definition.CaseSensitive); Assert.False(definition.CompactStorage); Assert.False(definition.AllowFiltering); Assert.False(definition.ExplicitColumns); CollectionAssert.AreEqual(new [] {Tuple.Create("Time", SortOrder.Unspecified)}, definition.ClusteringKeys); CollectionAssert.AreEqual(new[] { "name", "Slice" }, definition.PartitionKeys); }
public void Counter_LinqAttributes_Parallel() { var config = new Cassandra.Mapping.Attributes.AttributeBasedTypeDefinition(typeof(PocoWithCounterAttribute)); var table = new Table <PocoWithCounterAttribute>(_session, new MappingConfiguration().Define(config)); table.Create(); var cqlClient = new Mapper(_session, new MappingConfiguration().Define(config)); List <PocoWithCounterAttribute> counterPocos = new List <PocoWithCounterAttribute>(); for (int i = 0; i < 100; i++) { counterPocos.Add( new PocoWithCounterAttribute() { KeyPart1 = Guid.NewGuid(), KeyPart2 = (decimal)123, }); } int counterIncrements = 2000; string updateStr = String.Format("UPDATE \"{0}\" SET \"{1}\"=\"{1}\" + 1 WHERE \"{2}\"=? and \"{3}\"=?", table.Name.ToLower(), "counter", "keypart1", "keypart2"); var updateSession = _session.Prepare(updateStr); Parallel.ForEach(counterPocos, pocoWithCounter => { var boundStatement = updateSession.Bind(new object[] { pocoWithCounter.KeyPart1, pocoWithCounter.KeyPart2 }); for (int j = 0; j < counterIncrements; j++) { _session.Execute(boundStatement); } pocoWithCounter.Counter += counterIncrements; }); List <PocoWithCounterAttribute> countersQueried = cqlClient.Fetch <PocoWithCounterAttribute>().ToList(); foreach (PocoWithCounterAttribute pocoWithCounterExpected in counterPocos) { bool counterFound = false; foreach (PocoWithCounterAttribute pocoWithCounterActual in countersQueried) { if (pocoWithCounterExpected.KeyPart1 == pocoWithCounterActual.KeyPart1) { Assert.AreEqual(pocoWithCounterExpected.KeyPart2, pocoWithCounterExpected.KeyPart2); Assert.AreEqual(pocoWithCounterExpected.Counter, pocoWithCounterExpected.Counter); counterFound = true; } } Assert.IsTrue(counterFound, "Counter with first key part: " + pocoWithCounterExpected.KeyPart1 + " was not found!"); } }
public void AttributeBasedTypeDefinition_Defaults_Tests() { //Non decorated Poco var definition = new AttributeBasedTypeDefinition(typeof(AllTypesEntity)); Assert.False(definition.CaseSensitive); Assert.False(definition.CompactStorage); Assert.False(definition.AllowFiltering); Assert.False(definition.ExplicitColumns); Assert.AreEqual(0, definition.ClusteringKeys.Length); Assert.AreEqual(0, definition.PartitionKeys.Length); Assert.Null(definition.KeyspaceName); Assert.AreEqual("AllTypesEntity", definition.TableName); Assert.AreEqual(typeof(AllTypesEntity), definition.PocoType); }
public void Counter_Success() { var config = new AttributeBasedTypeDefinition(typeof(PocoWithCounterAttribute)); var table = new Table<PocoWithCounterAttribute>(_session, new MappingConfiguration().Define(config)); table.Create(); var cqlClient = new Mapper(_session, new MappingConfiguration().Define(config)); List<PocoWithCounterAttribute> counterPocos = new List<PocoWithCounterAttribute>(); for (int i = 0; i < 10; i++) { counterPocos.Add( new PocoWithCounterAttribute() { KeyPart1 = Guid.NewGuid(), KeyPart2 = (decimal)123, }); } int counterIncrements = 100; string updateStr = String.Format("UPDATE \"{0}\" SET \"{1}\"=\"{1}\" + 1 WHERE \"{2}\"=? and \"{3}\"=?", table.Name.ToLower(), "counter", "keypart1", "keypart2"); var updateSession = _session.Prepare(updateStr); foreach (PocoWithCounterAttribute pocoWithCounter in counterPocos) { var boundStatement = updateSession.Bind(new object[] { pocoWithCounter.KeyPart1, pocoWithCounter.KeyPart2 }); for (int j = 0; j < counterIncrements; j++) _session.Execute(boundStatement); pocoWithCounter.Counter += counterIncrements; } List<PocoWithCounterAttribute> countersQueried = cqlClient.Fetch<PocoWithCounterAttribute>().ToList(); foreach (PocoWithCounterAttribute pocoWithCounterExpected in counterPocos) { bool counterFound = false; foreach (PocoWithCounterAttribute pocoWithCounterActual in countersQueried) { if (pocoWithCounterExpected.KeyPart1 == pocoWithCounterActual.KeyPart1) { Assert.AreEqual(pocoWithCounterExpected.KeyPart2, pocoWithCounterExpected.KeyPart2); Assert.AreEqual(pocoWithCounterExpected.Counter, pocoWithCounterExpected.Counter); counterFound = true; } } Assert.IsTrue(counterFound, "Counter with first key part: " + pocoWithCounterExpected.KeyPart1 + " was not found!"); } }