Skip to content

Commit

Permalink
Test store requests for root node (#332)
Browse files Browse the repository at this point in the history
  • Loading branch information
outofforest authored Dec 22, 2024
1 parent 77a756b commit 9c495f2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions space/space.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ func (s *Space[K, V]) set(
s.config.State.Clear(volatileAddress)

store(&v.storeRequest.Store[v.storeRequest.PointersToStore-1].Pointer.VolatileAddress, volatileAddress)
v.storeRequest.Store[v.storeRequest.PointersToStore-1].VolatileAddress = volatileAddress
}

// Starting from here the data node is allocated.
Expand Down
35 changes: 35 additions & 0 deletions space/space_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2386,3 +2386,38 @@ func TestSpaceDeallocation(t *testing.T) {
requireT.Equal(expectedVolatileAddresses, volatileAddresses)
requireT.Equal(expectedPersistentAddresses, persistentAddresses)
}

// TestNodesToStoreOnRootNode verifies that correct store requests are produced when setting items in the root node.
func TestNodesToStoreOnRootNode(t *testing.T) {
requireT := require.New(t)

appState := state.NewForTest(t, stateSize)
txFactory := pipeline.NewTransactionRequestFactory()

s := NewSpaceTest[uint64, uint64](t, appState, nil, false)

tx := txFactory.New()
numOfItems := s.s.config.DataNodeAssistant.NumOfItems()
for i := range numOfItems {
v := s.NewEntry(TestKey[uint64]{
Key: i,
KeyHash: types.KeyHash(i + 1),
}, StageData)

requireT.NoError(s.SetKey(tx, v, i))
}

var count uint64
for sr := tx.StoreRequest; sr != nil; sr = sr.Next {
count++
requireT.Equal(int8(1), sr.PointersToStore)
requireT.Equal(s.s.config.SpaceRoot.Pointer.VolatileAddress, sr.Store[0].VolatileAddress)
requireT.Equal(s.s.config.SpaceRoot.Pointer.VolatileAddress, sr.Store[0].Pointer.VolatileAddress)
requireT.Zero(sr.Store[0].Pointer.PersistentAddress)
requireT.Zero(sr.Store[0].Pointer.SnapshotID)
requireT.Zero(sr.Store[0].Pointer.Revision)
requireT.NotNil(sr.Store[0].Hash)
}

requireT.Equal(numOfItems, count)
}

0 comments on commit 9c495f2

Please sign in to comment.