MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / test_dataBlockOutOfOrderBuilding

Function test_dataBlockOutOfOrderBuilding

tests/unit/test_datablock.c:185–231  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

183}
184
185void test_dataBlockOutOfOrderBuilding() {
186 // This test checks for a fragmented, data block out of order re-construction.
187 DataBlock *dataBlock = DataBlock_New(DATABLOCK_BLOCK_CAP, 1, sizeof(int), NULL);
188 int insert_arr1[4] = {8, 2, 3, 6};
189 int delete_arr[2] = {4, 7};
190 int insert_arr2[4] = {9, 1, 5, 0};
191 int expected[8] = {0, 1, 2, 3, 5, 6, 8, 9};
192
193 // Insert the first array.
194 for(int i = 0; i < 4; i++) {
195 int *item = (int *)DataBlock_AllocateItemOutOfOrder(dataBlock, insert_arr1[i]);
196 *item = insert_arr1[i];
197 }
198 TEST_ASSERT(4 == dataBlock->itemCount);
199 TEST_ASSERT(0 == array_len(dataBlock->deletedIdx));
200
201 // Mark deleted values.
202 for(int i = 0; i < 2; i++) {
203 DataBlock_MarkAsDeletedOutOfOrder(dataBlock, delete_arr[i]);
204 }
205
206 TEST_ASSERT(4 == dataBlock->itemCount);
207 TEST_ASSERT(2 == array_len(dataBlock->deletedIdx));
208
209 // Add another array
210 for(int i = 0; i < 4; i++) {
211 int *item = (int *)DataBlock_AllocateItemOutOfOrder(dataBlock, insert_arr2[i]);
212 *item = insert_arr2[i];
213 }
214
215 TEST_ASSERT(8 == dataBlock->itemCount);
216 TEST_ASSERT(2 == array_len(dataBlock->deletedIdx));
217
218 // Validate
219 DataBlockIterator *it = DataBlock_Scan(dataBlock);
220 for(int i = 0; i < 8; i++) {
221 int *item = (int *)DataBlockIterator_Next(it, NULL);
222 TEST_ASSERT(*item == expected[i]);
223 }
224 TEST_ASSERT(!DataBlockIterator_Next(it, NULL));
225
226 TEST_ASSERT(dataBlock->deletedIdx[0] == 4 || dataBlock->deletedIdx[0] == 7);
227 TEST_ASSERT(dataBlock->deletedIdx[1] == 4 || dataBlock->deletedIdx[1] == 7);
228
229 DataBlock_Free(dataBlock);
230 DataBlockIterator_Free(it);
231}
232
233TEST_LIST = {
234 {"dataBlockNew", test_dataBlockNew},

Callers

nothing calls this directly

Calls 8

DataBlock_NewFunction · 0.85
array_lenFunction · 0.85
DataBlock_ScanFunction · 0.85
DataBlockIterator_NextFunction · 0.85
DataBlock_FreeFunction · 0.85
DataBlockIterator_FreeFunction · 0.85

Tested by

no test coverage detected