// Test HAMTDirectory <-> BasicDirectory switch based on directory size. The
// switch is managed by the DynamicDirectory abstraction.
Test HAMTDirectory <-> BasicDirectory switch based on directory size. The
switch is managed by the DynamicDirectory abstraction.
// Test HAMTDirectory < - > BasicDirectory switch based on directory size . The // switch is managed by the DynamicDirectory abstraction .
func TestDynamicDirectorySwitch(t *testing.T) {
	oldHamtOption := HAMTShardingSize
	defer func() { HAMTShardingSize = oldHamtOption }()
	HAMTShardingSize = 0 
	linksize.LinkSizeFunction = mockLinkSizeFunc(1)
	defer func() { linksize.LinkSizeFunction = productionLinkSize }()
	ds := mdtest.Mock()
	dir := NewDirectory(ds)
	checkBasicDirectory(t, dir, "new dir is not BasicDirectory")
	ctx := context.Background()
	child := ft.EmptyDirNode()
	err := ds.Add(ctx, child)
	assert.NoError(t, err)
	err = dir.AddChild(ctx, "1", child)
	assert.NoError(t, err)
	checkBasicDirectory(t, dir, "added child, option still disabled")
	HAMTShardingSize = math.MaxInt32
	err = dir.AddChild(ctx, "2", child)
	assert.NoError(t, err)
	checkBasicDirectory(t, dir, "added child, option now enabled but at max")
	HAMTShardingSize = 1
	err = dir.AddChild(ctx, "2", child)
	assert.NoError(t, err)
	checkHAMTDirectory(t, dir, "added child, option at min, should switch up")
	HAMTShardingSize = 2
	err = dir.RemoveChild(ctx, "2")
	assert.NoError(t, err)
	checkBasicDirectory(t, dir, "removed threshold entry, option at min, should switch down")
}
func TestDynamicDirectorySwitch ( t * testing . T ) { oldHamtOption := HAMTShardingSize defer func ( ) { HAMTShardingSize = oldHamtOption } ( ) HAMTShardingSize = 0 linksize . LinkSizeFunction = mockLinkSizeFunc ( 1 ) defer func ( ) { linksize . LinkSizeFunction = productionLinkSize } ( ) ds := mdtest . Mock ( ) dir := NewDirectory ( ds ) checkBasicDirectory ( t , dir , " " ) ctx := context . Background ( ) child := ft . EmptyDirNode ( ) err := ds . Add ( ctx , child ) assert . NoError ( t , err ) err = dir . AddChild ( ctx , " " , child ) assert . NoError ( t , err ) checkBasicDirectory ( t , dir , " " ) HAMTShardingSize = math . MaxInt32 err = dir . AddChild ( ctx , " " , child ) assert . NoError ( t , err ) checkBasicDirectory ( t , dir , " " ) HAMTShardingSize = 1 err = dir . AddChild ( ctx , " " , child ) assert . NoError ( t , err ) checkHAMTDirectory ( t , dir , " " ) HAMTShardingSize = 2 err = dir . RemoveChild ( ctx , " " ) assert . NoError ( t , err ) checkBasicDirectory ( t , dir , " " ) }
Test HAMTDirectory <-> BasicDirectory switch based on directory size.
Test HAMTDirectory < - > BasicDirectory switch based on directory size .
// Disable automatic switch at the start. // Set a threshold so big a new entry won't trigger the change. // Now set it so low to make sure any new entry will trigger the upgrade. // We are already above the threshold, we trigger the switch with an overwrite // (any AddChild() should reevaluate the size). // Set threshold at the number of current entries and delete the last one // to trigger a switch and evaluate if the rest of the entries are conserved.