Skip to content

Commit 99ee634

Browse files
feat(offchain): new JD in memory client (#518)
Added a pure in memory JD client for testing purposes.
1 parent 406cb82 commit 99ee634

File tree

4 files changed

+1293
-0
lines changed

4 files changed

+1293
-0
lines changed

.changeset/gold-frogs-enjoy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"chainlink-deployments-framework": minor
3+
---
4+
5+
feat(offchain): new JD in memory client

offchain/jd/memory/doc.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Package memory provides an in-memory implementation of the Job Distributor client.
2+
//
3+
// This package is designed for testing purposes when you don't need a real JD backend.
4+
// All data is stored in memory and is lost when the client is garbage collected.
5+
//
6+
// # Thread Safety
7+
//
8+
// The MemoryJobDistributor implementation is thread-safe and uses sync.RWMutex to protect
9+
// concurrent access to internal data structures. Multiple goroutines can safely call methods
10+
// on the same MemoryJobDistributor instance concurrently.
11+
//
12+
// # Usage
13+
//
14+
// Create a new in-memory JD client:
15+
//
16+
// client := memory.NewMemoryJobDistributor()
17+
//
18+
// Use it like any other JD client:
19+
//
20+
// resp, err := client.ProposeJob(ctx, &jobv1.ProposeJobRequest{
21+
// NodeId: "test-node",
22+
// Spec: "job spec here",
23+
// })
24+
//
25+
// # Limitations
26+
//
27+
// - No persistence: All data is stored in memory only
28+
// - Test-only: This implementation is intended for testing and should not be used in production environments
29+
//
30+
// # Implementation Details
31+
//
32+
// The client maintains four in-memory maps:
33+
// - jobs: Stores job instances by job ID
34+
// - proposals: Stores job proposals by proposal ID
35+
// - nodes: Stores node registrations by node ID
36+
// - keypairs: Stores CSA keypairs by public key
37+
//
38+
// All write operations (create, update, delete) modify these maps directly,
39+
// and read operations return data from these maps.
40+
package memory

0 commit comments

Comments
 (0)