-
Notifications
You must be signed in to change notification settings - Fork 1.2k
strengthen alluxio runtime helpers #5777
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -285,9 +285,15 @@ func init() { | |
|
|
||
| // Replicas gets the replicas of runtime worker | ||
| func (runtime *AlluxioRuntime) Replicas() int32 { | ||
| if runtime == nil { | ||
| return 0 | ||
| } | ||
| return runtime.Spec.Replicas | ||
| } | ||
|
|
||
| func (runtime *AlluxioRuntime) GetStatus() *RuntimeStatus { | ||
| if runtime == nil { | ||
| return &RuntimeStatus{} | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The nil-receiver guard returns |
||
| } | ||
| return &runtime.Status | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| /* | ||
| Copyright 2026 The Fluid Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package v1alpha1 | ||
|
|
||
| import "testing" | ||
|
|
||
| func TestAlluxioRuntime_Replicas(t *testing.T) { | ||
| testCases := map[string]struct { | ||
| runtime *AlluxioRuntime | ||
| want int32 | ||
| }{ | ||
| "nil runtime defaults to zero": { | ||
| runtime: nil, | ||
| want: 0, | ||
| }, | ||
| "returns configured replicas": { | ||
| runtime: &AlluxioRuntime{ | ||
| Spec: AlluxioRuntimeSpec{ | ||
| Replicas: 3, | ||
| }, | ||
| }, | ||
| want: 3, | ||
| }, | ||
| "returns zero replicas when not configured": { | ||
| runtime: &AlluxioRuntime{}, | ||
| want: 0, | ||
| }, | ||
| } | ||
|
|
||
| for name, tc := range testCases { | ||
| t.Run(name, func(t *testing.T) { | ||
| got := tc.runtime.Replicas() | ||
| if got != tc.want { | ||
| t.Fatalf("Replicas() = %d, want %d", got, tc.want) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestAlluxioRuntime_GetStatus(t *testing.T) { | ||
| t.Run("nil runtime returns empty status pointer", func(t *testing.T) { | ||
| var runtime *AlluxioRuntime | ||
| got := runtime.GetStatus() | ||
| if got == nil { | ||
| t.Fatalf("GetStatus() returned nil") | ||
| } | ||
| if got.MasterPhase != RuntimePhaseNone { | ||
| t.Fatalf("GetStatus().MasterPhase = %q, want %q", got.MasterPhase, RuntimePhaseNone) | ||
| } | ||
| }) | ||
|
|
||
| t.Run("returns pointer to runtime status", func(t *testing.T) { | ||
| runtime := &AlluxioRuntime{ | ||
| Status: RuntimeStatus{ | ||
| MasterPhase: RuntimePhaseReady, | ||
| WorkerPhase: RuntimePhasePartialReady, | ||
| }, | ||
| } | ||
|
|
||
| got := runtime.GetStatus() | ||
| if got == nil { | ||
| t.Fatalf("GetStatus() returned nil") | ||
| } | ||
| if got.MasterPhase != RuntimePhaseReady { | ||
| t.Fatalf("GetStatus().MasterPhase = %q, want %q", got.MasterPhase, RuntimePhaseReady) | ||
| } | ||
|
|
||
| got.FusePhase = RuntimePhaseNotReady | ||
| if runtime.Status.FusePhase != RuntimePhaseNotReady { | ||
| t.Fatalf("GetStatus() should return underlying status pointer") | ||
| } | ||
| }) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a brief comment explaining the nil-receiver return value, e.g.:
// nil AlluxioRuntime defaults to 0 replicas. This makes the intent explicit and prevents future readers from questioning whether the nil check is intentional or just defensive.