history_v2_persistence.go ×3

Frontier kind: Code frontier

unlabeled · c_8b01ae9a85b7

7 tests · 4938 LOC · 183 files · introduces 0 tests · 179 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
3 ranges179 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
891 ranges4938 lines · 183 files · Browse complete extent
All tests (intent)
7 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 179 introduced LOC across 3 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

go.temporal.io/server/common/persistence/persistence-tests/history_v2_persistence.go 179 introduced LOC · 3 ranges

Open complete file

148
149 // TestReadBranchByPagination test
150 > func (s *HistoryV2PersistenceSuite) TestReadBranchByPagination() { history_v2_persistence.go
151 > treeID := uuid.NewString()
152 > bi, err := s.newHistoryBranch(treeID)
153 > s.Nil(err)
154 >
155 > historyW := &historypb.History{}
156 > events := s.genRandomEvents([]int64{1, 2, 3}, 0)
157 > err = s.appendNewBranchAndFirstNode(bi, events, 1, "branchInfo")
158 > s.Nil(err)
159 > historyW.Events = events
160 >
161 > events = s.genRandomEvents([]int64{4}, 0)
162 > err = s.appendNewNode(bi, events, 2)
163 > s.Nil(err)
164 > historyW.Events = append(historyW.Events, events...)
165 >
166 > events = s.genRandomEvents([]int64{5, 6, 7, 8}, 4)
167 > err = s.appendNewNode(bi, events, 6)
168 > s.Nil(err)
169 > historyW.Events = append(historyW.Events, events...)
170 >
171 > // stale event batch
172 > events = s.genRandomEvents([]int64{6, 7, 8}, 1)
173 > err = s.appendNewNode(bi, events, 3)
174 > s.Nil(err)
175 > // stale event batch
176 > events = s.genRandomEvents([]int64{6, 7, 8}, 2)
177 > err = s.appendNewNode(bi, events, 4)
178 > s.Nil(err)
179 > // stale event batch
180 > events = s.genRandomEvents([]int64{6, 7, 8}, 3)
181 > err = s.appendNewNode(bi, events, 5)
182 > s.Nil(err)
183 >
184 > events = s.genRandomEvents([]int64{9}, 4)
185 > err = s.appendNewNode(bi, events, 7)
186 > s.Nil(err)
187 > historyW.Events = append(historyW.Events, events...)
188 >
189 > // Start to read from middle, should not return error, but the first batch should be ignored by application layer
190 > req := &p.ReadHistoryBranchRequest{
191 > BranchToken: bi,
192 > MinEventID: 6,
193 > MaxEventID: 10,
194 > PageSize: 4,
195 > NextPageToken: nil,
196 > ShardID: s.ShardInfo.GetShardId(),
197 > }
198 > // first page
199 > resp, err := s.ExecutionManager.ReadHistoryBranch(s.ctx, req)
200 > s.Nil(err)
201 > s.Equal(4, len(resp.HistoryEvents))
202 > s.Equal(int64(6), resp.HistoryEvents[0].GetEventId())
203 >
204 > events = s.genRandomEvents([]int64{10}, 4)
205 > err = s.appendNewNode(bi, events, 8)
206 > s.Nil(err)
207 > historyW.Events = append(historyW.Events, events...)
208 >
209 > events = s.genRandomEvents([]int64{11}, 4)
210 > err = s.appendNewNode(bi, events, 9)
211 > s.Nil(err)
212 > historyW.Events = append(historyW.Events, events...)
213 >
214 > events = s.genRandomEvents([]int64{12}, 4)
215 > err = s.appendNewNode(bi, events, 10)
216 > s.Nil(err)
217 > historyW.Events = append(historyW.Events, events...)
218 >
219 > events = s.genRandomEvents([]int64{13, 14, 15}, 4)
220 > err = s.appendNewNode(bi, events, 11)
221 > s.Nil(err)
222 > // we don't append this batch because we will fork from 13
223 > // historyW.Events = append(historyW.Events, events...)
224 >
225 > // fork from here
226 > bi2, err := s.fork(bi, 13)
227 > s.Nil(err)
228 >
229 > events = s.genRandomEvents([]int64{13}, 4)
230 > err = s.appendNewNode(bi2, events, 12)
231 > s.Nil(err)
232 > historyW.Events = append(historyW.Events, events...)
233 >
234 > events = s.genRandomEvents([]int64{14}, 4)
235 > err = s.appendNewNode(bi2, events, 13)
236 > s.Nil(err)
237 > historyW.Events = append(historyW.Events, events...)
238 >
239 > events = s.genRandomEvents([]int64{15, 16, 17}, 4)
240 > err = s.appendNewNode(bi2, events, 14)
241 > s.Nil(err)
242 > historyW.Events = append(historyW.Events, events...)
243 >
244 > events = s.genRandomEvents([]int64{18, 19, 20}, 4)
245 > err = s.appendNewNode(bi2, events, 15)
246 > s.Nil(err)
247 > historyW.Events = append(historyW.Events, events...)
248 >
249 > // read branch to verify
250 > historyR := &historypb.History{}
251 >
252 > req = &p.ReadHistoryBranchRequest{
253 > BranchToken: bi2,
254 > MinEventID: 1,
255 > MaxEventID: 21,
256 > PageSize: 3,
257 > NextPageToken: nil,
258 > ShardID: s.ShardInfo.GetShardId(),
259 > }
260 >
261 > // first page
262 > resp, err = s.ExecutionManager.ReadHistoryBranch(s.ctx, req)
263 > s.Nil(err)
264 >
265 > s.Equal(8, len(resp.HistoryEvents))
266 > historyR.Events = append(historyR.Events, resp.HistoryEvents...)
267 > req.NextPageToken = resp.NextPageToken
268 >
269 > // this page is all stale batches
270 > // doe to difference in Cassandra / MySQL pagination
271 > // the stale event batch may get returned
272 > resp, err = s.ExecutionManager.ReadHistoryBranch(s.ctx, req)
273 > s.Nil(err)
274 > historyR.Events = append(historyR.Events, resp.HistoryEvents...)
275 > req.NextPageToken = resp.NextPageToken
276 > if len(resp.HistoryEvents) == 0 {
277 > // second page
278 > resp, err = s.ExecutionManager.ReadHistoryBranch(s.ctx, req)
279 > s.Nil(err)
280 > s.Equal(3, len(resp.HistoryEvents))
281 > historyR.Events = append(historyR.Events, resp.HistoryEvents...)
282 > req.NextPageToken = resp.NextPageToken
283 > } else if len(resp.HistoryEvents) == 3 {
284 // no op
285 } else {
288
289 // 3rd page, since we fork from nodeID=13, we can only see one batch of 12 here
290 > resp, err = s.ExecutionManager.ReadHistoryBranch(s.ctx, req) history_v2_persistence.go
291 > s.Nil(err)
292 > s.Equal(1, len(resp.HistoryEvents))
293 > historyR.Events = append(historyR.Events, resp.HistoryEvents...)
294 > req.NextPageToken = resp.NextPageToken
295 >
296 > // 4th page, 13~17
297 > resp, err = s.ExecutionManager.ReadHistoryBranch(s.ctx, req)
298 > s.Nil(err)
299 > s.Equal(5, len(resp.HistoryEvents))
300 > historyR.Events = append(historyR.Events, resp.HistoryEvents...)
301 > req.NextPageToken = resp.NextPageToken
302 >
303 > // last page: one batch of 18-20
304 > // We have only one page left and the page size is set to one. In this case,
305 > // persistence may or may not return a nextPageToken.
306 > // If it does return a token, we need to ensure that if the token returned is used
307 > // to get history again, no error and history events should be returned.
308 > req.PageSize = 1
309 > resp, err = s.ExecutionManager.ReadHistoryBranch(s.ctx, req)
310 > s.Nil(err)
311 > s.Equal(3, len(resp.HistoryEvents))
312 > historyR.Events = append(historyR.Events, resp.HistoryEvents...)
313 > req.NextPageToken = resp.NextPageToken
314 > if len(resp.NextPageToken) != 0 {
315 > resp, err = s.ExecutionManager.ReadHistoryBranch(s.ctx, req)
316 > s.Nil(err)
317 > s.Equal(0, len(resp.HistoryEvents))
318 > }
319
320 > s.ProtoEqual(historyW, historyR) history_v2_persistence.go
321 > s.Equal(0, len(resp.NextPageToken))
322 >
323 > // MinEventID is in the middle of the last batch and this is the first request (NextPageToken
324 > // is empty), the call should return an error.
325 > req.MinEventID = 19
326 > req.NextPageToken = nil
327 > _, err = s.ExecutionManager.ReadHistoryBranch(s.ctx, req)
328 > s.IsType(&serviceerror.NotFound{}, err)
329 >
330 > err = s.deleteHistoryBranch(bi2)
331 > s.Nil(err)
332 > err = s.deleteHistoryBranch(bi)
333 > s.Nil(err)
334 > branches := s.descTree(treeID)
335 > s.Equal(0, len(branches))
336 }
337