major changes
This commit is contained in:
@@ -17,14 +17,14 @@ type mockGrainPool struct {
|
||||
applied []proto.Message
|
||||
}
|
||||
|
||||
func (m *mockGrainPool) Apply(ctx context.Context, id uint64, mutations ...proto.Message) (*MutationResult[*mockGrain], error) {
|
||||
func (m *mockGrainPool) Apply(ctx context.Context, id uint64, mutations ...proto.Message) (*MutationResult[mockGrain], error) {
|
||||
m.applied = mutations
|
||||
// Simulate successful application
|
||||
return &MutationResult[*mockGrain]{
|
||||
Result: &mockGrain{},
|
||||
return &MutationResult[mockGrain]{
|
||||
Result: mockGrain{},
|
||||
Mutations: []ApplyResult{
|
||||
{Error: nil}, // Assume success
|
||||
{Error: nil},
|
||||
{Type: "AddItem", Mutation: &cart_messages.AddItem{ItemId: 1, Quantity: 2}, Error: nil},
|
||||
{Type: "RemoveItem", Mutation: &cart_messages.RemoveItem{Id: 1}, Error: nil},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
@@ -33,7 +33,7 @@ func (m *mockGrainPool) Get(ctx context.Context, id uint64) (*mockGrain, error)
|
||||
return &mockGrain{}, nil
|
||||
}
|
||||
|
||||
func (m *mockGrainPool) OwnerHost(id uint64) (Host, bool) {
|
||||
func (m *mockGrainPool) OwnerHost(id uint64) (Host[mockGrain], bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ func TestApplyRequestWithMutations(t *testing.T) {
|
||||
pool := &mockGrainPool{}
|
||||
|
||||
// Create gRPC server
|
||||
server, err := NewControlServer[*mockGrain](DefaultServerConfig(), pool)
|
||||
server, err := NewControlServer[mockGrain](DefaultServerConfig(), pool)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create server: %v", err)
|
||||
}
|
||||
@@ -88,8 +88,16 @@ func TestApplyRequestWithMutations(t *testing.T) {
|
||||
}
|
||||
|
||||
// Verify response
|
||||
if !resp.Accepted {
|
||||
t.Errorf("expected Accepted=true, got false")
|
||||
if resp.State == nil {
|
||||
t.Errorf("expected State to be non-nil")
|
||||
}
|
||||
if len(resp.Mutations) != 2 {
|
||||
t.Errorf("expected 2 mutation results, got %d", len(resp.Mutations))
|
||||
}
|
||||
for i, mut := range resp.Mutations {
|
||||
if mut.Error != nil {
|
||||
t.Errorf("expected no error in mutation %d, got %s", i, *mut.Error)
|
||||
}
|
||||
}
|
||||
|
||||
// Verify mutations were extracted and applied
|
||||
@@ -103,3 +111,40 @@ func TestApplyRequestWithMutations(t *testing.T) {
|
||||
t.Errorf("expected RemoveItem with Id=1, got %v", pool.applied[1])
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetRequest(t *testing.T) {
|
||||
// Setup mock pool
|
||||
pool := &mockGrainPool{}
|
||||
|
||||
// Create gRPC server
|
||||
server, err := NewControlServer[mockGrain](DefaultServerConfig(), pool)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create server: %v", err)
|
||||
}
|
||||
defer server.GracefulStop()
|
||||
|
||||
// Create client connection
|
||||
conn, err := grpc.Dial("localhost:1337", grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
t.Fatalf("failed to dial: %v", err)
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
client := control_plane_messages.NewControlPlaneClient(conn)
|
||||
|
||||
// Prepare GetRequest
|
||||
req := &control_plane_messages.GetRequest{
|
||||
Id: 123,
|
||||
}
|
||||
|
||||
// Call Get
|
||||
resp, err := client.Get(context.Background(), req)
|
||||
if err != nil {
|
||||
t.Fatalf("Get failed: %v", err)
|
||||
}
|
||||
|
||||
// Verify response
|
||||
if resp.Grain == nil {
|
||||
t.Errorf("expected Grain to be non-nil")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user