Skip to content

Commit 400f866

Browse files
NH-3931 - additional test cases, and relaxing tests expectations on batch grouping efficiency.
1 parent dd74ab3 commit 400f866

19 files changed

+504
-15
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace NHibernate.Test.Insertordering.AnimalModel
4+
{
5+
public class Animal
6+
{
7+
public virtual Guid Id { get; set; }
8+
public virtual string Name { get; set; }
9+
public virtual Person Owner { get; set; }
10+
}
11+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace NHibernate.Test.Insertordering.AnimalModel
2+
{
3+
public class Cat : Animal
4+
{
5+
public virtual string EyeColor { get; set; }
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace NHibernate.Test.Insertordering.AnimalModel
2+
{
3+
public class Dog : Animal
4+
{
5+
public virtual string Country { get; set; }
6+
}
7+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
using System.Collections;
2+
using NHibernate.Cfg;
3+
using NUnit.Framework;
4+
5+
namespace NHibernate.Test.Insertordering.AnimalModel
6+
{
7+
[TestFixture]
8+
public class Fixture : TestCase
9+
{
10+
protected override IList Mappings
11+
{
12+
get { return new[] { "Insertordering.AnimalModel.Mappings.hbm.xml" }; }
13+
}
14+
15+
protected override string MappingsAssembly
16+
{
17+
get { return "NHibernate.Test"; }
18+
}
19+
20+
protected override void Configure(Configuration configuration)
21+
{
22+
configuration.DataBaseIntegration(x =>
23+
{
24+
x.BatchSize = 10;
25+
x.OrderInserts = true;
26+
});
27+
}
28+
29+
protected override void OnTearDown()
30+
{
31+
using (var session = OpenSession())
32+
using (var tran = session.BeginTransaction())
33+
{
34+
session.Delete("from Animal");
35+
session.Delete("from Person");
36+
tran.Commit();
37+
}
38+
}
39+
40+
[Test]
41+
public void ElaboratedModel()
42+
{
43+
using (var session = OpenSession())
44+
using (var tran = session.BeginTransaction())
45+
{
46+
var personWithAnimals = new PersonWithAnimals { Name = "fabio" };
47+
var personWithCats = new PersonWithCats { Name = "dario" };
48+
var personWithSivasKangals = new PersonWithSivasKangals { Name = "tuna" };
49+
var personWithDogs = new PersonWithDogs { Name = "davy" };
50+
51+
var animalForAnimals = new Animal { Name = "Pasha", Owner = personWithAnimals };
52+
var dogForAnimals = new Dog { Name = "Efe", Country = "Turkey", Owner = personWithAnimals };
53+
var catForAnimals = new Cat { Name = "Tekir", EyeColor = "green", Owner = personWithAnimals };
54+
var sivasKangalForAnimals = new SivasKangal { Name = "Karabas", Country = "Turkey", HouseAddress = "Atakoy", Owner = personWithAnimals };
55+
56+
personWithAnimals.AnimalsGeneric.Add(animalForAnimals);
57+
personWithAnimals.AnimalsGeneric.Add(dogForAnimals);
58+
personWithAnimals.AnimalsGeneric.Add(catForAnimals);
59+
personWithAnimals.AnimalsGeneric.Add(sivasKangalForAnimals);
60+
61+
var animalForCats = new Animal { Name = "Pasha2", Owner = personWithCats };
62+
var catForCats = new Cat { Name = "Tekir2", EyeColor = "green", Owner = personWithCats };
63+
var dogForCats = new Dog { Name = "Efe2", Country = "Turkey", Owner = personWithCats };
64+
personWithCats.AnimalsGeneric.Add(catForCats);
65+
66+
var catForDogs = new Cat { Name = "Tekir3", EyeColor = "blue", Owner = personWithDogs };
67+
var dogForDogs = new Dog { Name = "Efe3", Country = "Turkey", Owner = personWithDogs };
68+
var sivasKangalForDogs = new SivasKangal { Name = "Karabas3", Country = "Turkey", HouseAddress = "Atakoy", Owner = personWithDogs };
69+
personWithDogs.AnimalsGeneric.Add(dogForDogs);
70+
personWithDogs.AnimalsGeneric.Add(sivasKangalForDogs);
71+
72+
var animalForSivasKangals = new Animal { Name = "Pasha4", Owner = personWithSivasKangals };
73+
var dogForSivasKangals = new Dog { Name = "Efe4", Country = "Turkey", Owner = personWithSivasKangals };
74+
var catForSivasKangals = new Cat { EyeColor = "red", Name = "Tekir4", Owner = personWithSivasKangals };
75+
var sivasKangalForSivasKangals = new SivasKangal { Name = "Karabas4", Country = "Turkey", HouseAddress = "Atakoy", Owner = personWithSivasKangals };
76+
personWithSivasKangals.AnimalsGeneric.Add(sivasKangalForSivasKangals);
77+
78+
session.Save(animalForCats);
79+
session.Save(dogForCats);
80+
81+
session.Save(catForDogs);
82+
83+
session.Save(animalForSivasKangals);
84+
session.Save(dogForSivasKangals);
85+
session.Save(catForSivasKangals);
86+
87+
session.Save(personWithAnimals);
88+
session.Save(personWithCats);
89+
session.Save(personWithDogs);
90+
session.Save(personWithSivasKangals);
91+
92+
Assert.DoesNotThrow(() => { tran.Commit(); });
93+
}
94+
}
95+
}
96+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
3+
assembly="NHibernate.Test"
4+
namespace="NHibernate.Test.Insertordering.AnimalModel">
5+
6+
<class name="Animal" discriminator-value="0">
7+
<id name="Id" generator="guid.comb" />
8+
<discriminator column="AnimalType" type="int" force="true"/>
9+
<property name="Name" type="string"/>
10+
<many-to-one name="Owner" class="Person" column="OwnerId"/>
11+
<subclass name="Cat" discriminator-value="1"/>
12+
<subclass name="Dog" discriminator-value="2">
13+
<property name="Country"/>
14+
<subclass name="SivasKangal" discriminator-value="3">
15+
<property name="HouseAddress"></property>
16+
</subclass>
17+
</subclass>
18+
</class>
19+
<class name="Person" discriminator-value="0">
20+
<id name="Id" generator="guid.comb" />
21+
22+
<discriminator column="PersonType" type="int"/>
23+
<property name="Name"/>
24+
<bag name="AnimalsGeneric" lazy="true" inverse="true" cascade="save-update">
25+
<key column="OwnerId" />
26+
<one-to-many class="Animal"/>
27+
</bag>
28+
<subclass name="PersonWithAnimals" discriminator-value="1">
29+
30+
</subclass>
31+
<subclass name="PersonWithCats" discriminator-value="2">
32+
<bag name="CatsGeneric" lazy="true" inverse="true" cascade="save-update">
33+
<key column="OwnerId" />
34+
<one-to-many class="Cat"/>
35+
</bag>
36+
</subclass>
37+
<subclass name="PersonWithDogs" discriminator-value="3">
38+
<bag name="DogsGeneric" lazy="true" inverse="true" cascade="save-update">
39+
<key column="OwnerId" />
40+
<one-to-many class="Dog"/>
41+
</bag>
42+
</subclass>
43+
<subclass name="PersonWithSivasKangals" discriminator-value="4">
44+
<bag name="SivasKangalsGeneric" lazy="true" inverse="true" cascade="save-update">
45+
<key column="OwnerId" />
46+
<one-to-many class="SivasKangal"/>
47+
</bag>
48+
49+
</subclass>
50+
<subclass name="PersonWithAllTypes" discriminator-value="5">
51+
<bag name="DogsGeneric" lazy="true" inverse="true">
52+
<key column="OwnerId" />
53+
<one-to-many class="Dog"/>
54+
</bag>
55+
<bag name="CatsGeneric" lazy="true" inverse="true">
56+
<key column="OwnerId" />
57+
<one-to-many class="Cat"/>
58+
</bag>
59+
<bag name="SivasKangalsGeneric" lazy="true" inverse="true">
60+
<key column="OwnerId" />
61+
<one-to-many class="SivasKangal"/>
62+
</bag>
63+
</subclass>
64+
</class>
65+
</hibernate-mapping>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace NHibernate.Test.Insertordering.AnimalModel
5+
{
6+
public class Person
7+
{
8+
public virtual Guid Id { get; set; }
9+
public virtual string Name { get; set; }
10+
public virtual IList<Animal> AnimalsGeneric { get; set; } = new List<Animal>();
11+
}
12+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Collections.Generic;
2+
3+
namespace NHibernate.Test.Insertordering.AnimalModel
4+
{
5+
public class PersonWithAllTypes : Person
6+
{
7+
public virtual IList<Dog> DogsGeneric { get; set; }
8+
public virtual IList<SivasKangal> SivasKangalsGeneric { get; set; }
9+
public virtual IList<Cat> CatsGeneric { get; set; }
10+
}
11+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace NHibernate.Test.Insertordering.AnimalModel
2+
{
3+
public class PersonWithAnimals : Person
4+
{
5+
}
6+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System.Collections.Generic;
2+
3+
namespace NHibernate.Test.Insertordering.AnimalModel
4+
{
5+
public class PersonWithCats : Person
6+
{
7+
public virtual IList<Cat> CatsGeneric { get; set; } = new List<Cat>();
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System.Collections.Generic;
2+
3+
namespace NHibernate.Test.Insertordering.AnimalModel
4+
{
5+
public class PersonWithDogs : Person
6+
{
7+
public virtual IList<Dog> DogsGeneric { get; set; } = new List<Dog>();
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System.Collections.Generic;
2+
3+
namespace NHibernate.Test.Insertordering.AnimalModel
4+
{
5+
public class PersonWithSivasKangals : Person
6+
{
7+
public virtual IList<SivasKangal> SivasKangalsGeneric { get; set; } = new List<SivasKangal>();
8+
}
9+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace NHibernate.Test.Insertordering.AnimalModel
2+
{
3+
public class SivasKangal : Dog
4+
{
5+
public virtual string HouseAddress { get; set; }
6+
}
7+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
using System.Collections;
2+
using System.Linq;
3+
using NHibernate.Cfg;
4+
using NHibernate.Linq;
5+
using NUnit.Framework;
6+
7+
namespace NHibernate.Test.Insertordering.FamilyModel
8+
{
9+
[TestFixture]
10+
public class Fixture : TestCase
11+
{
12+
protected override IList Mappings
13+
{
14+
get { return new[] { "Insertordering.FamilyModel.Mappings.hbm.xml" }; }
15+
}
16+
17+
protected override string MappingsAssembly
18+
{
19+
get { return "NHibernate.Test"; }
20+
}
21+
22+
protected override void Configure(Configuration configuration)
23+
{
24+
configuration.DataBaseIntegration(x =>
25+
{
26+
x.BatchSize = 10;
27+
x.OrderInserts = true;
28+
// Uncomment batcher lines here and in OnSetUp and OnTearDown for debugging purpose.
29+
//x.Batcher<InsertOrderingFixture.StatsBatcherFactory>();
30+
});
31+
}
32+
33+
protected override void OnSetUp()
34+
{
35+
/*
36+
InsertOrderingFixture.StatsBatcher.Reset();
37+
InsertOrderingFixture.StatsBatcher.StatsEnabled = true;
38+
*/
39+
}
40+
41+
protected override void OnTearDown()
42+
{
43+
//InsertOrderingFixture.StatsBatcher.StatsEnabled = false;
44+
45+
using (var session = OpenSession())
46+
using (var tran = session.BeginTransaction())
47+
{
48+
session.Delete("from System.Object");
49+
tran.Commit();
50+
}
51+
}
52+
53+
[Test]
54+
public void CircularReferences()
55+
{
56+
using (var session = OpenSession())
57+
using (var tran = session.BeginTransaction())
58+
{
59+
var jeanne = new Woman { Name = "Jeanne" };
60+
var paul = new Man { Name = "Paul" };
61+
62+
var paulette = new Woman { Name = "Paulette", Mother = jeanne, Father = paul };
63+
var monique = new Woman { Name = "Monique", Mother = jeanne, Father = paul };
64+
var alice = new Woman { Name = "Alice", Mother = jeanne, Father = paul };
65+
var yves = new Man { Name = "Yves", Mother = jeanne, Father = paul };
66+
var denis = new Man { Name = "Denis", Mother = jeanne, Father = paul };
67+
68+
var laure = new Woman { Name = "Laure", Mother = paulette };
69+
var valerie = new Woman { Name = "Valérie", Mother = paulette };
70+
var caroline = new Woman { Name = "Caroline", Mother = monique };
71+
var cathy = new Woman { Name = "Cathy", Father = yves };
72+
var helene = new Woman { Name = "Hélène", Father = yves };
73+
var nicolas = new Man { Name = "Nicolas", Mother = monique };
74+
var frederic = new Man { Name = "Frédéric", Mother = monique };
75+
var arnaud = new Man { Name = "Arnaud", Father = denis };
76+
77+
session.Save(alice);
78+
session.Save(laure);
79+
session.Save(valerie);
80+
session.Save(caroline);
81+
session.Save(cathy);
82+
session.Save(helene);
83+
session.Save(nicolas);
84+
session.Save(frederic);
85+
session.Save(arnaud);
86+
87+
Assert.DoesNotThrow(() => { tran.Commit(); });
88+
}
89+
90+
using (var session = OpenSession())
91+
using (var tran = session.BeginTransaction())
92+
{
93+
Assert.AreEqual(9, session.Query<Woman>().Count());
94+
Assert.AreEqual(6, session.Query<Man>().Count());
95+
}
96+
}
97+
}
98+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
3+
assembly="NHibernate.Test"
4+
namespace="NHibernate.Test.Insertordering.FamilyModel">
5+
6+
<class name="Woman">
7+
<id name="Id" generator="guid.comb" />
8+
9+
<property name="Name"/>
10+
<many-to-one name="Mother" cascade="save-update" />
11+
<many-to-one name="Father" cascade="save-update" />
12+
</class>
13+
14+
<class name="Man">
15+
<id name="Id" generator="guid.comb" />
16+
17+
<property name="Name"/>
18+
<many-to-one name="Mother" cascade="save-update" />
19+
<many-to-one name="Father" cascade="save-update" />
20+
</class>
21+
</hibernate-mapping>

0 commit comments

Comments
 (0)