-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7ddf539
commit 2864e96
Showing
1 changed file
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package trie | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestNewCache(t *testing.T) { | ||
// Test case parameters | ||
sizeMB := 100 // 100MB cache size | ||
rootCap := 1000 // root capacity | ||
|
||
// Create new cache | ||
cache := NewCache(sizeMB, rootCap) | ||
|
||
// Basic validation checks | ||
if cache == nil { | ||
t.Fatal("Expected non-nil cache") | ||
} | ||
|
||
// First log | ||
cache.GetRootNode("hi", 1, false) | ||
cache.log() | ||
logStats("Test", 1, 1) | ||
} | ||
|
||
func TestCacheLogging(t *testing.T) { | ||
// Create new cache | ||
cache := NewCache(100, 1000) | ||
|
||
// First log | ||
cache.GetRootNode("hi", 1, false) | ||
cache.log() | ||
logStats("Initial test", 1, 1) | ||
|
||
// Wait for 21 seconds | ||
time.Sleep(21 * time.Second) | ||
|
||
// Second log after delay | ||
cache.GetRootNode("hi", 2, false) | ||
cache.log() | ||
logStats("Test after delay", 1, 1) | ||
} | ||
|
||
func TestAddNodeBlob(t *testing.T) { | ||
// Create new cache | ||
cache := NewCache(100, 1000) | ||
if cache == nil { | ||
t.Fatal("Failed to create cache") | ||
} | ||
|
||
// Test data | ||
testName := "testNode" | ||
testPath := []byte("testPath") | ||
testBlob := []byte("testBlobData") | ||
|
||
// Test case 1: Adding blob with isCommitting = true | ||
cache.AddNodeBlob(testName, 1, testPath, testBlob, true) | ||
|
||
// Test case 2: Adding blob with isCommitting = false | ||
cache.AddNodeBlob(testName, 1, testPath, testBlob, false) | ||
|
||
// Verify the blobs were added by attempting to retrieve them | ||
retrievedBlob := cache.GetNodeBlob(testName, 1, testPath, false, nil) | ||
if retrievedBlob == nil { | ||
t.Error("Failed to retrieve added blob") | ||
} | ||
|
||
if !bytes.Equal(retrievedBlob, testBlob) { | ||
t.Errorf("Retrieved blob doesn't match original. got %v, want %v", | ||
retrievedBlob, testBlob) | ||
} | ||
} |