Skip to content

Commit 4ac1926

Browse files
committed
RDBC-692 RavenDB_11217Test::sessionWideNoTrackingShouldWork
1 parent c9ef278 commit 4ac1926

File tree

7 files changed

+159
-42
lines changed

7 files changed

+159
-42
lines changed

ravendb/documents/session/document_session.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,8 @@ def __load_internal_stream(self, keys: List[str], operation: LoadOperation, stre
346346

347347
def load_starting_with(
348348
self,
349-
object_type: Type[_T],
350349
id_prefix: str,
350+
object_type: Optional[Type[_T]] = None,
351351
matches: Optional[str] = None,
352352
start: Optional[int] = None,
353353
page_size: Optional[int] = None,
@@ -727,17 +727,16 @@ def __load_starting_with_internal(
727727

728728
def load_starting_with(
729729
self,
730-
object_type: type,
731730
id_prefix: str,
732-
matches: str,
733-
start: int,
734-
page_size: int,
735-
exclude: str,
736-
start_after: str,
737-
) -> object:
738-
load_starting_with_operation = LoadStartingWithOperation(self._session)
739-
self.__load_starting_with_internal(
740-
id_prefix, load_starting_with_operation, None, matches, start, page_size, exclude, start_after
731+
object_type: Optional[Type[_T]] = None,
732+
matches: Optional[str] = None,
733+
start: Optional[int] = None,
734+
page_size: Optional[int] = None,
735+
exclude: Optional[str] = None,
736+
start_after: Optional[str] = None,
737+
) -> List[_T]:
738+
return self._session.load_starting_with(
739+
id_prefix, object_type, matches, start, page_size, exclude, start_after
741740
)
742741

743742
def load_starting_with_into_stream(

ravendb/documents/session/operations/lazy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ def load(
210210

211211
def load_starting_with(
212212
self,
213-
object_type: Type[_T],
214213
id_prefix: str,
214+
object_type: Optional[Type[_T]],
215215
matches: str = None,
216216
start: int = 0,
217217
page_size: int = 25,

ravendb/tests/counters_tests/test_query_on_counters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,12 +692,12 @@ def test_counters_should_be_cached_on_collection(self):
692692
session.counters_for("orders/1-A").increment("downloads", 200)
693693
session.save_changes()
694694

695-
list(session.query(object_type=Order).include(lambda i: i.include_counters(["downloads"])))
695+
list(session.query(object_type=Order).include(lambda i: i.include_counters("downloads")))
696696
self.assertEqual(300, session.counters_for("orders/1-A").get("downloads"))
697697
session.counters_for("orders/1-A").increment("downloads", 200)
698698
session.save_changes()
699699

700-
list(session.query(object_type=Order).include(lambda i: i.include_counters(["downloads"])))
700+
list(session.query(object_type=Order).include(lambda i: i.include_counters("downloads")))
701701
self.assertEqual(500, session.counters_for("orders/1-A").get("downloads"))
702702

703703
with self.store.open_session() as session:

ravendb/tests/jvm_migrated_tests/issues_tests/test_ravenDB_11217.py

Lines changed: 135 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,150 @@
22

33
from ravendb.documents.session.misc import SessionOptions
44
from ravendb.documents.session.query import QueryStatistics
5-
from ravendb.infrastructure.orders import Product
5+
from ravendb.infrastructure.orders import Product, Supplier
66
from ravendb.tests.test_base import TestBase
77

88

99
class TestRavenDB11217(TestBase):
1010
def setUp(self):
1111
super(TestRavenDB11217, self).setUp()
1212

13-
def test_session_wide_no_caching_should_work(self):
13+
def test_session_wide_no_tracking_should_work(self):
1414
with self.store.open_session() as session:
15-
stats: Optional[QueryStatistics] = None
15+
supplier = Supplier()
16+
supplier.name = "Supplier1"
1617

17-
def __stats_callback(statistics: QueryStatistics):
18-
nonlocal stats
19-
stats = statistics
18+
session.store(supplier)
2019

21-
list(session.query(object_type=Product).statistics(__stats_callback).where_equals("name", "HR"))
22-
self.assertGreaterEqual(stats.duration_in_ms, 0)
23-
list(session.query(object_type=Product).statistics(__stats_callback).where_equals("name", "HR"))
24-
self.assertEqual(-1, stats.duration_in_ms)
20+
product = Product()
21+
product.name = "Product1"
22+
product.supplier = supplier.Id
2523

26-
no_cache_options = SessionOptions()
27-
no_cache_options.no_caching = True
24+
session.store(product)
25+
session.save_changes()
2826

29-
with self.store.open_session(session_options=no_cache_options) as session:
30-
list(session.query(object_type=Product).statistics(__stats_callback).where_equals("name", "HR"))
31-
self.assertGreaterEqual(stats.duration_in_ms, 0)
32-
list(session.query(object_type=Product).statistics(__stats_callback).where_equals("name", "HR"))
33-
self.assertGreaterEqual(stats.duration_in_ms, 0)
27+
no_tracking_options = SessionOptions()
28+
no_tracking_options.no_tracking = True
29+
30+
with self.store.open_session(session_options=no_tracking_options) as session:
31+
supplier = Supplier()
32+
supplier.name = "Supplier2"
33+
34+
with self.assertRaises(RuntimeError):
35+
session.store(supplier)
36+
37+
with self.store.open_session(session_options=no_tracking_options) as session:
38+
self.assertEqual(0, session.advanced.number_of_requests)
39+
40+
product1 = session.load("products/1-A", Product, lambda b: b.include_documents("supplier"))
41+
42+
self.assertEqual(1, session.advanced.number_of_requests)
43+
44+
self.assertIsNotNone(product1)
45+
self.assertEqual("Product1", product1.name)
46+
self.assertFalse(session.advanced.is_loaded(product1.Id))
47+
self.assertFalse(session.advanced.is_loaded(product1.supplier))
48+
49+
supplier = session.load(product1.supplier, Supplier)
50+
self.assertIsNotNone(supplier)
51+
self.assertEqual("Supplier1", supplier.name)
52+
self.assertEqual(2, session.advanced.number_of_requests)
53+
self.assertFalse(session.advanced.is_loaded(supplier.Id))
54+
55+
product2 = session.load("products/1-A", Product, lambda b: b.include_documents(("supplier")))
56+
self.assertNotEqual(product2, product1)
57+
58+
with self.store.open_session(session_options=no_tracking_options) as session:
59+
self.assertEqual(0, session.advanced.number_of_requests)
60+
61+
product1 = session.advanced.load_starting_with("products/", Product)[0]
62+
63+
self.assertEqual(1, session.advanced.number_of_requests)
64+
65+
self.assertIsNotNone(product1)
66+
self.assertEqual("Product1", product1.name)
67+
self.assertFalse(session.advanced.is_loaded(product1.Id))
68+
self.assertFalse(session.advanced.is_loaded(product1.supplier))
69+
70+
supplier = session.advanced.load_starting_with(product1.supplier, Supplier)[0]
71+
72+
self.assertIsNotNone(supplier)
73+
self.assertEqual("Supplier1", supplier.name)
74+
self.assertEqual(2, session.advanced.number_of_requests)
75+
self.assertFalse(session.advanced.is_loaded(supplier.Id))
76+
77+
product2 = session.advanced.load_starting_with("products/", Product)[0]
78+
self.assertNotEqual(product2, product1)
79+
80+
with self.store.open_session(session_options=no_tracking_options) as session:
81+
self.assertEqual(0, session.advanced.number_of_requests)
82+
products = list(session.query(object_type=Product).include("supplier"))
83+
84+
self.assertEqual(1, session.advanced.number_of_requests)
85+
self.assertEqual(1, len(products))
86+
87+
product1 = products[0]
88+
self.assertIsNotNone(product1)
89+
self.assertFalse(session.advanced.is_loaded(product1.Id))
90+
self.assertFalse(session.advanced.is_loaded(product1.supplier))
91+
92+
supplier = session.load(product1.supplier, Supplier)
93+
self.assertIsNotNone(supplier)
94+
self.assertEqual("Supplier1", supplier.name)
95+
self.assertEqual(2, session.advanced.number_of_requests)
96+
self.assertFalse(session.advanced.is_loaded(supplier.Id))
97+
98+
products = list(session.query(object_type=Product).include("supplier"))
99+
self.assertEqual(1, len(products))
100+
101+
product2 = products[0]
102+
self.assertNotEqual(product2, product1)
103+
104+
with self.store.open_session() as session:
105+
session.counters_for("products/1-A").increment("c1")
106+
session.save_changes()
107+
108+
with self.store.open_session(session_options=no_tracking_options) as session:
109+
product1 = session.load("products/1-A", Product)
110+
counters = session.counters_for(product1.Id)
111+
112+
counters.get("c1")
113+
114+
self.assertEqual(2, session.advanced.number_of_requests)
115+
116+
counters.get("c1")
117+
118+
self.assertEqual(3, session.advanced.number_of_requests)
119+
120+
val1 = counters.get_all()
121+
122+
self.assertEqual(4, session.advanced.number_of_requests)
123+
124+
val2 = counters.get_all()
125+
126+
self.assertEqual(5, session.advanced.number_of_requests)
127+
128+
self.assertNotEqual(id(val2), id(val1))
129+
130+
131+
def test_session_wide_no_caching_should_work(self):
132+
with self.store.open_session() as session:
133+
stats: Optional[QueryStatistics] = None
134+
135+
def __stats_callback(statistics: QueryStatistics):
136+
nonlocal stats
137+
stats = statistics
138+
139+
list(session.query(object_type=Product).statistics(__stats_callback).where_equals("name", "HR"))
140+
self.assertGreaterEqual(stats.duration_in_ms, 0)
141+
list(session.query(object_type=Product).statistics(__stats_callback).where_equals("name", "HR"))
142+
self.assertEqual(-1, stats.duration_in_ms)
143+
144+
no_cache_options = SessionOptions()
145+
no_cache_options.no_caching = True
146+
147+
with self.store.open_session(session_options=no_cache_options) as session:
148+
list(session.query(object_type=Product).statistics(__stats_callback).where_equals("name", "HR"))
149+
self.assertGreaterEqual(stats.duration_in_ms, 0)
150+
list(session.query(object_type=Product).statistics(__stats_callback).where_equals("name", "HR"))
151+
self.assertGreaterEqual(stats.duration_in_ms, 0)

ravendb/tests/jvm_migrated_tests/mailing_list_tests/test_load_all_starting_with.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def test_load_all_starting_with(self):
2525
session.save_changes()
2626

2727
with self.store.open_session() as session:
28-
test_classes = session.advanced.lazily.load_starting_with(Abc, "abc/")
28+
test_classes = session.advanced.lazily.load_starting_with("abc/", Abc)
2929

3030
test2_classes = session.query(object_type=Xyz).wait_for_non_stale_results().lazily().value
3131
self.assertEqual(1, len(test_classes.value))

ravendb/tests/operations_tests/test_operations.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def test_patch_by_index(self):
8282
)
8383
operation.wait_for_completion()
8484
with self.store.open_session() as session:
85-
result = session.load_starting_with(Patch, "patches")
85+
result = session.load_starting_with("patches", Patch)
8686
values = list(map(lambda patch: patch.patched, result))
8787
self.assertEqual(3, len(result))
8888
self.assertEqual(3, len(values))
@@ -135,7 +135,7 @@ def test_delete_by_index(self):
135135
)
136136
operation.wait_for_completion()
137137
with self.store.open_session() as session:
138-
result = session.load_starting_with(User, "users")
138+
result = session.load_starting_with("users", User)
139139
self.assertEqual(1, len(result))
140140
self.assertNotEqual("delete", result[0].name)
141141

@@ -159,15 +159,15 @@ def test_patch_by_collection(self):
159159
)
160160
operation.wait_for_completion()
161161
with self.store.open_session() as session:
162-
result = session.load_starting_with(Patch, "patches")
162+
result = session.load_starting_with("patches", Patch)
163163
values = map(lambda patch: patch.patched, result)
164164

165165
for v in values:
166166
self.assertTrue(v)
167167

168168
def test_delete_by_collection_(self):
169169
with self.store.open_session() as session:
170-
self.assertEqual(1, len(session.load_starting_with(User, "users")))
170+
self.assertEqual(1, len(session.load_starting_with("users", User)))
171171
index_query = IndexQuery("From Users")
172172
operation = DeleteByQueryOperation(query_to_delete=index_query)
173173
result = self.store.operations.send(operation)
@@ -180,7 +180,7 @@ def test_delete_by_collection_(self):
180180
)
181181
op.wait_for_completion()
182182
with self.store.open_session() as session:
183-
self.assertEqual(0, len(session.load_starting_with(User, "users")))
183+
self.assertEqual(0, len(session.load_starting_with("users", User)))
184184

185185

186186
if __name__ == "__main__":

ravendb/tests/raven_commands_tests/test_get_by_prefix.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,27 @@ def tearDown(self):
3636

3737
def test_start_with(self):
3838
with self.store.open_session() as session:
39-
response = session.load_starting_with(dict, "products/MB-")
39+
response = session.load_starting_with("products/MB-", dict)
4040
self.assertEqual(4, len(response))
4141

4242
def test_matches(self):
4343
with self.store.open_session() as session:
44-
response = session.load_starting_with(dict, "products/MB-", matches="2*")
44+
response = session.load_starting_with("products/MB-", dict, matches="2*")
4545
self.assertEqual(2, len(response))
4646

4747
def test_excludes(self):
4848
with self.store.open_session() as session:
49-
response = session.load_starting_with(dict, "products/BM-", exclude="2*")
49+
response = session.load_starting_with("products/BM-", dict, exclude="2*")
5050
self.assertEqual(1, len(response))
5151

5252
def test_start_after(self):
5353
with self.store.open_session() as session:
54-
response = session.load_starting_with(dict, "products/MB-", matches="2*", start_after="products/MB-200")
54+
response = session.load_starting_with("products/MB-", dict, matches="2*", start_after="products/MB-200")
5555
self.assertEqual(1, len(response))
5656

5757
def test_page(self):
5858
with self.store.open_session() as session:
59-
response = session.load_starting_with(dict, "products/MB", start=1, page_size=2)
59+
response = session.load_starting_with("products/MB", dict, start=1, page_size=2)
6060
self.assertEqual(2, len(response))
6161

6262

0 commit comments

Comments
 (0)