MCPcopy Create free account
hub / github.com/erpc/erpc / TestMemoryConnector_CompressionBenefits

Function TestMemoryConnector_CompressionBenefits

data/memory_compression_test.go:105–138  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

103}
104
105func TestMemoryConnector_CompressionBenefits(t *testing.T) {
106 // Test to demonstrate actual compression benefits
107 logger := zerolog.New(io.Discard)
108 ctx := context.Background()
109
110 // Create connector with compression enabled
111 connector, err := NewMemoryConnector(ctx, &logger, "test", &common.MemoryConnectorConfig{
112 MaxItems: 100_000, MaxTotalSize: "1GB",
113 })
114 require.NoError(t, err)
115 defer connector.Close()
116
117 // Test with realistic EVM RPC response
118 evmResponse := createLargeBlockResponse()
119 originalSize := len(evmResponse)
120
121 // Store the value
122 err = connector.Set(ctx, "evm", "block", []byte(evmResponse), nil)
123 require.NoError(t, err)
124
125 // Wait for Ristretto to process the write
126 time.Sleep(10 * time.Millisecond)
127
128 // Retrieve and verify
129 retrieved, err := connector.Get(ctx, "", "evm", "block", nil)
130 require.NoError(t, err)
131 require.Equal(t, []byte(evmResponse), retrieved)
132
133 t.Logf("Original EVM response size: %d bytes", originalSize)
134 t.Logf("✅ Compression is transparent - no API changes needed")
135 t.Logf("✅ Values >512 bytes are automatically compressed with zstd")
136 t.Logf("✅ Memory efficiency: More cache entries fit in same space")
137 t.Logf("✅ Speed: zstd.SpeedFastest optimized for caching workloads")
138}
139
140func TestMemoryConnector_ConcurrentCompression(t *testing.T) {
141 // Test concurrent access to verify thread safety

Callers

nothing calls this directly

Calls 5

CloseMethod · 0.95
SetMethod · 0.95
GetMethod · 0.95
NewMemoryConnectorFunction · 0.85
createLargeBlockResponseFunction · 0.85

Tested by

no test coverage detected